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