Kelly Jones wrote:
I'm writing a Mediawiki extension (http://mediawiki.pastey.net/28186) that changes text like "[[X::R::Y]]" to "[[Y]]", and then displays X and R at the bottom the page in a clever way (it's a semantic/RDF extension, because I'm not crazy about the existing Semantic Mediawiki).
To do this, I did:
$wgHooks['ParserBeforeStrip'][] = 'myInternalParseBeforeLinks';
where myInternalParseBeforeLinks(&$parser, &$text) appends "foo" to $text.
This works great for the main article, but "foo" also gets appended to my page footer:
# This page was last modified 16:57, 6 May 2007. This page has been accessed 56 times. {whatever "foo" I added appears here too}
When I create or edit a page, it's even worse: "foo" appears all over the place.
How do I get my hook to JUST add "foo" to the main article and nothing else? As you can tell from the hook name, I originally tried to add this as a InternalParseBeforeLinks hook, but that didn't work either.
I don't think there is any way to do precisely what you want to do, without some pretty serious interface changes. Parser does not know whether it is parsing the primary output or a message -- the best candidate for detection, mRevisionId, may be randomly set for some messages requested after the primary parser output is generated. So you might think that a hook to OutputPage would be the way to go, and indeed that would be a decent solution if you were happy to deal with HTML instead of wikitext. OutputPage no longer gets to see any wikitext in the primary article, it's parsed by Article itself.
So you might consider a patch to Article::view() -- but the path taken to parse articles there is entirely different to the path used for parser cache push on save in Article::editUpdates(), and you would need the footer in both places.
The best idea is probably to parse the footer separately, and then add it to the end of the content area using an OutputPage or Skin hook, say the BeforePageDisplay hook from SkinTemplate::outputPage().
-- Tim Starling