[Mediawiki-l] efficiently adding javascript / css to page header

Jim Wilson wilson.jim.r at gmail.com
Mon May 21 04:21:36 UTC 2007


Hi Ittay,

> do you have any ideas what can be done for 3rd party extensions (i use
> the semantic mediawiki extension, and it adds ~20 scripts and
stylesheets).

I'm not sure exactly what your question is, unfortunately.  What you do to
augment the behavior of an existing 3rd party extension will depend on the
extension.

The example in the article I sent works by injecting HTML comments in the
output of an extension tag.  This works because MW expects extension tags to
return fully formed HTML, not wikitext.

Parser functions and other types of hooking mechanisms (like semantic's
relation operators [[relation to::whatever]]) are not so lucky.  MW expects
to get back wikitext, which it then processes into the body of the page.
This means that if you try to inject HTML comments, the later "add header"
step will fail since the comments will have been stripped by that point.
(The Parser removes HTML comments in wikitext and the output of parser
functions).

The workaround in that case is to add another layer of hackery.
Specifically:

1) A Parser function or other hooking mechanism outputs <pre>@
ENCODED_CONTENT at base64encodedstuff@ENCODED_CONTENT@</pre>

2) A function hooking into ParserBeforeTidy looks for these <pre> tags and
replaces them with <!-- ENCODED_CONTENT base64encodedstuff -->

3) A hook into OutputPageBeforeHTML looks for the HTML comments and takes
actions appropriately (just as in the extension tag example from before)

The reason a <pre> tag is used is that for the most part, MW won't mess with
the content inside (other than converting special chars into entity
references), especially whitespace.  Also, <pre> is immune to whitespace
wrapping - it won't get wrapped in <p></p> when on a line by itself like
other forms of content.

To see an example of this, check out my WikiArticleFeeds extension:

http://jimbojw.com/wiki/index.php?title=WikiArticleFeeds

The class WikiArticleFeedsParser has two methods which correspond to the
first two steps above.  Respectively they are: itemTagsFunction() and
itemTagsPlaceholderCorrections()

Hope this helps!  And sorry if this has nothing to do with what you were
asking :(

-- Jim

On 5/20/07, Ittay Dror <ittayd at qlusters.com> wrote:
>
> do you have any ideas what can be done for 3rd party extensions (i use
> the semantic mediawiki extension, and it adds ~20 scripts and
> stylesheets).
>
>
> thanks,
>
> ittay
>
>
> Jim Wilson wrote on 05/17/07 18:24:
>
> > And if you're stuck with a version of MediaWiki prior to 1.10 - here's
> an
> > alternative:
> >
> >
> http://jimbojw.com/wiki/index.php?title=Doing_more_with_MediaWiki_parser_extensions
> >
> > On 5/17/07, Rob Church <robchur at gmail.com> wrote:
> >
> >> On 17/05/07, Ittay Dror < ittayd at qlusters.com> wrote:
> >>
> >>> So, is there a way of better associating javascript with a page?
> >>>
> >> In newer versions of MediaWiki, use Parser::addHeadItems(); see
> >> associated members and functions in Parser, ParserOutput and
> >> OutputPage.
> >>
> >> This is a recent addition from Tim Starling, which is an alternative
> >> implementation of extension output handlers.
> >>
> >>
> >> Rob Church
> >>
> >> _______________________________________________
> >> MediaWiki-l mailing list
> >> MediaWiki-l at lists.wikimedia.org
> >> http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
> >>
> >>
> > _______________________________________________
> > MediaWiki-l mailing list
> > MediaWiki-l at lists.wikimedia.org
> > http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
> >
> >
>
> --
> *Ittay Dror*
> Chief Architect,
> R&D, Qlusters Inc.
> Web: qlusters.com <http://www.qlusters.com/>
> Email: ittayd at qlusters.com <mailto:ittayd at qlusters.com>
> Phone: +972-3-6081994
>
> openQRM < www.openqrm.org> - Data Center Provisioning
> ------
> I own this number: D0E008A921FF04A9DB8C12668E4315F4. Get your own at
> http://www.freedom-to-tinker.com
>
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l at lists.wikimedia.org
> http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>


More information about the MediaWiki-l mailing list