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
On 11-03-14 10:53 AM, Daniel Barrett wrote:
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:
Use a<foo> parser tag to generate some wikitext
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
Method 1 is doomed to fail in situations where we fetch from the parser cache. Which is ideally most of the visitor page views.
You may be able to use a combination of the ParserCache and it's setProperty, OutputPageParserOutput, and BeforePageDisplay. iirc I used something like that in the Description2 extension.
SkinAfterBottomScripts looks annoying without an $out param though.
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
Daniel Friesen writes:
You may be able to use a combination of the ParserCache and it's setProperty, OutputPageParserOutput, and BeforePageDisplay. iirc I used something like that in the Description2 extension.
Thanks Daniel. In that case, my followup question is: what do you mean by "combination"? What method would you use to communicate among the callbacks for these hooks? Just setProperty/getProperty on the ParserOutput object, or something else?
Thanks, DanB
mediawiki-l@lists.wikimedia.org