[Mediawiki-l] [Wikitech-l] How to modify text to create footer-- ParserBeforeStrip overdoes it

Kelly Jones kelly.terry.jones at gmail.com
Fri May 18 02:24:34 UTC 2007


Thanks, Tim, that worked great!

One issue: I'm using markup in the "foo" I add to the bottom of the
page, and it's obviously not getting parsed.

What function converts "[[foo|bar]]" to "<a href='foo'>bar</a>", and
"==Heading==" to "<h2>Heading</h2>", etc? I could easily write
functions like this myself, except I don't to re-invent the wheel, and
Mediawiki markup has style info, etc.

I poked around w/ Parser::parse() and Parser::internalParse() but got
weird errors about using $this in a non-object context.

-- 
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.

On 5/17/07, Tim Starling <tstarling at wikimedia.org> wrote:
> 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
>
>
> _______________________________________________
> Wikitech-l mailing list
> Wikitech-l at lists.wikimedia.org
> http://lists.wikimedia.org/mailman/listinfo/wikitech-l
>



More information about the MediaWiki-l mailing list