Michael Roach wrote:
I am working on an extension that more or less fully
exposes the Yahoo!
Maps AJAX API and have been exploring different implementation techniques
and could use a little insider insight.
Is it possible to use the php DOM functions to walk the structure of a
MediaWiki article?
Not really, no.
A wiki page is converted from wiki source code (not XML at all) to XHTML (not
guaranteed to be well-formed at this time) in an ugly multi-step process.
If you're writing a parser hook extension, it has only limited access to its
context: it accepts as input some text and a set of parameters, and emits an
HTML fragment. You also have access to the parser object to get a little more
information, but at the time you're working there is neither a DOM tree nor an
XML document you could form one from.
What I really want to do is from within an extension,
to add a new <script>
child to the <head> element of a article. I know about getElementsByTagName
and appendChild but I haven't been able to get them to work with MediaWiki.
Well, articles don't have <head> elements. :) MediaWiki's HTML user
interface
does have a <head> element, though, and you can add things to it at runtime
through $wgOut->addScript().
At this time there's not a cleanly integrated place for parser hook extensions
to fiddle in there unless you completely disable caching for the page; though
you can see my experimental work on this here:
http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/Aggregator/
or you could simply always add the script calling from some runtime hook
function (in which case it would also appear on pages not using the parser hook
extension).
-- brion vibber (brion @
pobox.com)