Last modified: 2012-08-14 11:44:43 UTC
If I write an extension that return somewhat complex output like this: $wgExtensionFunctions[] = "wfExampleExtension"; function wfExampleExtension() { global $wgParser; # register the extension with the WikiText parser # the first parameter is the name of the new tag. In this case it defines the tag <example> ... </example> # the second parameter is the callback function for processing the text between the tags $wgParser->setHook( "example", "renderExample" ); } # The callback function for converting the input text to HTML output function renderExample( $input ) { $output = <<<EOT <script type="text/javascript"> var wa = 'Wikipedia Rocks'; function showWA() { alert(wa); } </script> <div> $input </div> EOT; return $output; } I get the following output: </p><p> <script type="text/javascript"> </p><p> var wa = 'Wikipedia Rocks'; </p><p> function showWA() { </p><p> alert(wa); </p><p> } </p><p> </script> </p> <div> <p> Hi There </p> </div>
$wgParser is a wikisyntax to html renderer. If you give it a text it will attempt to transform it as html (and thus ad <p> everywhere). You want to use $wgOut->addHTML() . See the wikiforum or Findspam.php extensions for an example.
(In reply to comment #1) > $wgParser is a wikisyntax to html renderer. If you give it a text > it will attempt to transform it as html (and thus ad <p> everywhere). > > You want to use $wgOut->addHTML() . > > See the wikiforum or Findspam.php extensions for an example. Thanks for the tip. However, I think that this works only for SpecialPages type of extensions. Where the you write directly to $wgOut. Plain Extensions don't use wgOut, they must return the transformed string passed as $input for further processing.
This is still showing up in at least 1.5.4 . I sent a message out to the listserv, and doesn't seem to be any good answers yet: http://mail.wikipedia.org/pipermail/mediawiki-l/2006-February/thread.html#10022 Guess I'll add my vote, and maybe start reading through some of the Parser Code...
The workaround/fix in Parser.php, in function parse(): Instead of: $text = $this->unstrip( $text, $this->mStripState ); [somecode] $text = $this->doBlockLevels( $text, $linestart ); to: [somecode] $text = $this->doBlockLevels( $text, $linestart ); $text = $this->unstrip( $text, $this->mStripState ); i.e. move the unstrip() to run after doBlockLevels()
Please post patches as attachment (in unified format). Thanks.
Has this bug been fixed with the new preprocessor?
*** This bug has been marked as a duplicate of bug 1319 ***