Hi,
I've written some tags that require javascript packages. Naturally, I want to link to them in the <head> section.
The only way I know how to do it now is to add a hook to 'BeforePageDisplay'. The problem is that then I don't know whether the page actually uses the tag, so a lot of javascript references are added to pages that don't use the tags (and even with caching, the browser needs to validate).
If I add the js reference from inside the tag handler, then it is not added when the content is cached.
So, is there a way of better associating javascript with a page?
Thanks,
Ittay
On 17/05/07, Ittay Dror ittayd@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
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_ext...
On 5/17/07, Rob Church robchur@gmail.com wrote:
On 17/05/07, Ittay Dror ittayd@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@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
thanks! just the sort of hack (solution) i needed! this will work beautifully for me.
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_ext...
On 5/17/07, Rob Church robchur@gmail.com wrote:
On 17/05/07, Ittay Dror ittayd@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@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
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_ext...
On 5/17/07, Rob Church robchur@gmail.com wrote:
On 17/05/07, Ittay Dror ittayd@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@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
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@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@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_ext...
On 5/17/07, Rob Church robchur@gmail.com wrote:
On 17/05/07, Ittay Dror < ittayd@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@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
MediaWiki-l mailing list MediaWiki-l@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@qlusters.com mailto:ittayd@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@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
I tried to find Parser::addHeadItems both in the official 1.10 tar and in the svn repository, but couldn't.
thank you for your help,
ittay
Rob Church wrote on 05/17/07 18:09:
On 17/05/07, Ittay Dror ittayd@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@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
I see two addHeadItems:
includes/OutputPage.php: function addHeadItem( $name, $value ) { includes/ParserOutput.php: function addHeadItem( $section, $tag = false ) {
which one should i use?
thanks,
ittay
Rob Church wrote on 05/17/07 18:09:
On 17/05/07, Ittay Dror ittayd@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@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/mediawiki-l
-----BEGIN PGP SIGNED MESSAGE----- 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 extension:
$parser->mOutput->addHeadItem( "<style type="text/css">/*<![CDATA[*/\n" . ".source-$lang {line-height: normal;}\n" . ".source-$lang li {line-height: normal;}\n" . $geshi->get_stylesheet( false ) . "/*]]>*/</style>\n$sitecss", "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)
mediawiki-l@lists.wikimedia.org