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

Brion Vibber brion at wikimedia.org
Tue May 29 18:32:38 UTC 2007

Hash: SHA1

Ittay Dror wrote:
> I see two addHeadItems:
> includes/OutputPage.php:        function addHeadItem( $name, $value ) {
> includes/ParserOutput.php:      function addHeadItem( $section, $tag = 
> false ) {
> which one should i use?

The one on the output of the parser object that was passed to your hook.
This will record it in the parser cache record for later output.

I'm not sure this is the most stable api ever, though, it feels a little
weird to me. :) But here's an example in the SyntaxHighlight_GeSHi

			"<style type=\"text/css\">/*<![CDATA[*/\n" .
			".source-$lang {line-height: normal;}\n" .
			".source-$lang li {line-height: normal;}\n" .
			$geshi->get_stylesheet( false ) .
			"source-$lang" );

The first parameter is the actual HTML fragment you want to output.

The second is optional, and is a section keyword which should be unique
to your extension -- if you try to add two head sections with the same
key, only the last one will be output.

This avoids duplicate output when your hook is used more than once in
the same page. You should be sure that they really will be equivalent in
this case; if you output something different on each call, maybe you do
want to output it multiple times.

- -- brion vibber (brion @ wikimedia.org)
Version: GnuPG v1.4.2.2 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the MediaWiki-l mailing list