Page MenuHomePhabricator

Unnecessary <p> paragraph tags within extension output
Closed, ResolvedPublic

Description

Author: wikipedia

Description:
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>

  1. the second parameter is the callback function for processing the text

between the tags

$wgParser->setHook( "example", "renderExample" );

}

  1. 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>


Version: 1.5.x
Severity: normal

Details

Reference
bz1772

Revisions and Commits

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 8:18 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz1772.
bzimport added a subscriber: Unknown Object (MLST).

$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.

wikipedia wrote:

(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.

lukehjohnson wrote:

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...

dodgy wrote:

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()

jimmy.collins wrote:

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 ***
epriestley added a commit: Unknown Object (Diffusion Commit).Mar 4 2015, 8:23 AM