[Mediawiki-l] Best practice for integrating a parser tag and another hook callback?

Daniel Barrett danb at VistaPrint.com
Mon Mar 14 17:53:11 UTC 2011


What is the recommended way to get a parser tag like <foo> and another hook callback to communicate or have a shared state? Here's a simple use case:

1.      Use a <foo> parser tag to generate some wikitext
2.      Use the SkinAfterBottomScripts hook to inject that wikitext at the bottom of the page

In this case, what's the best way for the callbacks for <foo> and SkinAfterBottomScripts to share information (in this case, the generated wikitext)? I can think of a few places that <foo> could put its generated wikitext for SkinAfterBottomScripts to access :

Method 1: Put the two callbacks in the same class and create a static variable to hold the wikitext.  I don't like this method because it feels like an ancient "shared memory" solution (with all the usual pitfalls & risks).

Method 2: Create a custom property in the ParserOutput object ($parser->mOutput) and hang the generated wikitext there. This feels a little better, but unfortunately the parameter list for the SkinAfterBottomScripts hook doesn't include a Parser or ParserOutput object, so it can't access the data. (Theoretically one could use $wgParser, but when I tried this, something in between deleted my custom property.)

This is just one example. The real question is: what's the best practice for sharing data/state between two callbacks in a MediaWiki extension?

Thank you very much.
DanB




More information about the MediaWiki-l mailing list