i wrote a extension to embed gallery2 images into mediawiki 1.5. Everything works fine, except one thing: included templates were not parsed the same way as normal pages.
To explain: I include a new tag like [[foto:1234]]
and the extensions works like this: $wgExtensionFunctions[] = 'registerHook'; function registerHook(){ ... $wgHooks['ParserBeforeStrip'][] = 'replaceR'; } function replaceR(&$article, $&text){ $text = preg_replace_callback([[]] into <img src='' />... , $text ); }
Templates are already stripped before entering 'ParserBeforeStrip', so i get no chance to replace 'before'. The [[Foto:1234]] were already transformed into <a href='/Foto:1234'>Foto:1234</a>
to see the problem: http://www.transarte.net/mediawiki/index.php/Diskussion:Gallery2wiki
Andres Obrero
*i really would appreciate an answer or a hint were to post or mail.*
to make the problem a bit clearer i wrote a small php script (see below) add it into LocalSettings.php as usual and write one page [[template:sample]] wit the content 'abc' and one page [[sample]] with the content 'abc' and {{sample}} which should include template:sample.
the result is:
#ParserBeforeStrip[0]#*ParserAfterStrip[1]*%ParserBeforeTidy[2]%@ParserAfterTidy[3]@abc@@%%**## %ParserBeforeTidy[2]%@ParserAfterTidy[3]@abc@@%%
the interpretation of the result is, that a template does not pass 'ParserBeforeStrip' and 'ParserAfterStrip' or ignore the modifications somehow (&$ problem?).
here the simple sample extension *<?php define ("_PATT_", "abc"); $wgExtensionFunctions[] = 'myTestHook'; $my=0; function myTestHook(){ global $wgHooks; global $wgParser; $wgHooks['ParserBeforeStrip'][]= 'pbs'; $wgHooks['ParserAfterStrip'][] = 'pas'; $wgHooks['ParserBeforeTidy'][] = 'pbt'; $wgHooks['ParserAfterTidy'][] = 'pat'; } function pbs(&$article, &$text, &$strip_state){ global $my; $text = preg_replace("/("._PATT_.")/i", "#ParserBeforeStrip[".($my++)."]#$1##" , $text ); } function pas(&$article, &$text, &$strip_state){ global $my; $text = preg_replace("/("._PATT_.")/i", "*ParserAfterStrip[".($my++)."]*$1**" , $text ); } function pbt(&$article, &$text){ global $my; $text = preg_replace("/("._PATT_.")/i", "%ParserBeforeTidy[".($my++)."]%$1%%" , $text ); } function pat(&$article, &$text){ global $my; $text = preg_replace("/("._PATT_.")/i", "@ParserAfterTidy[".($my++)."]@$1@@" , $text ); } ?>
*(caution: there seems to be a small bug when adding to many extensions - some of them will be completely ignored)*
*Andres Obrero
andres schrieb:
i wrote a extension to embed gallery2 images into mediawiki 1.5. Everything works fine, except one thing: included templates were not parsed the same way as normal pages.
To explain: I include a new tag like [[foto:1234]]
and the extensions works like this: $wgExtensionFunctions[] = 'registerHook'; function registerHook(){ ... $wgHooks['ParserBeforeStrip'][] = 'replaceR'; } function replaceR(&$article, $&text){ $text = preg_replace_callback([[]] into <img src='' />... , $text ); }
Templates are already stripped before entering 'ParserBeforeStrip', so i get no chance to replace 'before'. The [[Foto:1234]] were already transformed into <a href='/Foto:1234'>Foto:1234</a>
to see the problem: http://www.transarte.net/mediawiki/index.php/Diskussion:Gallery2wiki
Andres Obrero _______________________________________________ MediaWiki-l mailing list MediaWiki-l@Wikimedia.org http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org