Re: Global parser not initialized on special pages?

Brian Wolff <[email protected]>
Newsgroups gmane.org.wikimedia.mediawiki
Message-ID <CA+oo+DUGShhR76ygzNJ=CdsrNwYXeybjnPV36F6CgUo_Gp0EVA@mail.gmail.com>
This is expected. You should not make assumptions about the state of the
global Parser instance in a special page. In some circumstances (especially
transclusions) it might be in a parse, other times it won't be.

If you're rendering an i18n message, its better to use ->parse() of the
Message class then to pass it through the parser directly.

Alternatively use
\MediaWiki\MediaWikiServices::getInstance()->getParser()->getFreshParser()
and then initialize it yourself by calling ->parse() on the Parser, so you
always know what the state is for sure.

--
Brian

On Fri, Jun 11, 2021 at 9:27 AM Sebastian Trueg <[email protected]> wrote:

> Hi everyone,
>
> my skin uses the global parser in order to render some parts of the
> navigation bar via templates (Parser::recursivePreprocess). This works
> fine on all normal pages (and even some special ones like
> Special:Version), but not on special pages like Special:AllPages.
>
> Some debugging revealed that on Special:AllPages the global parser
> object (\MediaWiki\MediaWikiServices::getInstance()->getParser()) is not
> properly initialized. Member variables like mOptions and mTitle are null
> which results in tons of NPEs.
>
> Any idea why that is? Is that a bug or am I mis-using the parser?
>
> Regards,
> Sebastian
> _______________________________________________
> MediaWiki-l mailing list -- [email protected]
> List information:
> https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
>

_______________________________________________
MediaWiki-l mailing list -- [email protected]
List information: https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.