Hi @all,
I used this line of code to get the content of an article within version 1.7.1
Now I did a upgrade to 1.11.0, and it doesn't work anymore? Where's the problem?
On 29/10/2007, demagggus magggus@gmx.de wrote:
Hi @all,
I used this line of code to get the content of an article within version 1.7.1
Now I did a upgrade to 1.11.0, and it doesn't work anymore? Where's the problem?
What line of code?
Rob Church
On 10/29/07, demagggus magggus@gmx.de wrote:
Now I did a upgrade to 1.11.0, and it doesn't work anymore?
Does it return nothing? Does it throw an error? Does it return the wrong text? Is it working some of the time? Is it not working at all? Is it inserting bogus records into the database? Is it sneaking off with your girlfriend when you're not looking?
"Doesn't work" isn't really a sufficient explanation of the problem you're experiencing.
-------- Original-Nachricht --------
Datum: Tue, 30 Oct 2007 18:04:19 +1100 Von: "Andrew Garrett" andrew@epstone.net An: "Wikimedia developers" wikitech-l@lists.wikimedia.org Betreff: Re: [Wikitech-l] How to get the article content?
On 10/29/07, demagggus magggus@gmx.de wrote:
Now I did a upgrade to 1.11.0, and it doesn't work anymore?
Does it return nothing? Does it throw an error? Does it return the wrong text? Is it working some of the time? Is it not working at all? Is it inserting bogus records into the database? Is it sneaking off with your girlfriend when you're not looking?
"Doesn't work" isn't really a sufficient explanation of the problem you're experiencing.
-- Andrew Garrett
Sorry for the short and imprecisely description of my problem. I forgot to activate display_errors so I didn't get any error message, just a blank page.
'$text = $wgArticle->getContent();'
If I try to use this line of code I get the following error-message:
"Fatal error: Call to a member function getContent() on a non-object"
On 10/30/07, "Marcus Schäfer" magggus@gmx.de wrote:
I forgot to activate display_errors so I didn't get any error message, just a blank page.
global $wgArticle;
'$text = $wgArticle->getContent();'
If I try to use this line of code I get the following error-message:
"Fatal error: Call to a member function getContent() on a non-object"
Well then, the problem's pretty simple. See amended code above.
-------- Original-Nachricht --------
Datum: Tue, 30 Oct 2007 20:41:56 +1100 Von: "Andrew Garrett" andrew@epstone.net An: "Wikimedia developers" wikitech-l@lists.wikimedia.org Betreff: Re: [Wikitech-l] How to get the article content?
On 10/30/07, "Marcus Schäfer" magggus@gmx.de wrote:
I forgot to activate display_errors so I didn't get any error message,
just a blank page.
global $wgArticle;
'$text = $wgArticle->getContent();'
If I try to use this line of code I get the following error-message:
"Fatal error: Call to a member function getContent() on a non-object"
Well then, the problem's pretty simple. See amended code above.
-- Andrew Garrett
Even if I call the global $wgArticle variable the same error-message appears. For this reason I thought there were any changes in the code e.g. Because like I mentioned: it worked on older releases!?!
On 10/30/07, "Marcus Schäfer" magggus@gmx.de wrote:
Even if I call the global $wgArticle variable the same error-message appears. For this reason I thought there were any changes in the code e.g. Because like I mentioned: it worked on older releases!?!
Where are you calling it?
-------- Original-Nachricht --------
Datum: Tue, 30 Oct 2007 21:08:53 +1100 Von: "Andrew Garrett" andrew@epstone.net An: "Wikimedia developers" wikitech-l@lists.wikimedia.org Betreff: Re: [Wikitech-l] How to get the article content?
On 10/30/07, "Marcus Schäfer" magggus@gmx.de wrote:
Even if I call the global $wgArticle variable the same error-message
appears. For this reason
I thought there were any changes in the code e.g. Because like I
mentioned: it worked on
older releases!?!
Where are you calling it?
-- Andrew Garrett
I call it within a parser function, like this:
function wfRenderArticleSectionCheck_Magic(&$parser) { global $wgArticle, $wgTitle, $wgParser, $wgLang, $wgLanguageCode; $lan = $wgLang->getCode(); $text = $wgArticle->getContent(); $regex = "'(<section lan=$lan>)(.*)(</section>)'"; preg_match_all($regex, $text, $matches); for($i=0;$i<count($matches[0]);$i++) { $output = $parser->parse($matches[0][$i], $parser->mTitle, $parser->mOptions, true, false); return $output->getText(); continue; } return true; }
On 30/10/2007, "Marcus Schäfer" magggus@gmx.de wrote:
I call it within a parser function, like this:
Never, ever, ever refer to $wgArticle, $wgTitle or $wgParser within a parser hook callback; the first two are not required to exist in order to parse text - there might not be an actual saved article that corresponds to the input (if parsing for the UI, for instance), or the parsing might be taking place within a maintenance script or other environment which hasn't been initialised for the web script.
Furthermore, use of $wgParser is technically incorrect - you're passed a reference to the parent Parser object. While this might be a reference to the same Parser instance as $wgParser (in most cases it will be), you cannot guarantee that from within your extension.
If you need the Title of the wiki text being processed, then you can obtain it from the parser, e.g. $parser->getTitle(), but be careful - it's not necessarily the case that an actual article will exist.
Furthermore, be careful regarding $wgLanguageCode - its purpose changes during initialisation. If in doubt, call Language::getCode() [on the $wgLang and $wgContLang objects].
Rob Church
wikitech-l@lists.wikimedia.org