[Mediawiki-l] Custom parser function returning raw code

Minute Electron minuteelectron at googlemail.com
Sun Dec 30 18:45:32 UTC 2007


Hello,

Due to parser tags not being able to correctly handle variables such
as {{{1}}} I created my own custom parser function that calls a parser
tag I've installed so that I could use such variables with it.
Unfortunately instead of outputting the actual image that it should do
it outputs the code raw - I've verified this is something to do with
the parser as I have done some testing and can confirm that before it
is return-ed it is still HTML code, not escaped HTML code. Below is a
copy of my custom code for anyone who is interested in helping. Any
assistance would be greatly appreciated.

<?php

/* Parser Function style work around, calls above function. */

$wgExtensionFunctions[] = 'wfImageLinkWorkAroundParserFunction_Setup';

$wgHooks['LanguageGetMagic'][] = 'wfImageLinkWorkAroundParserFunction_Magic';

function wfImageLinkWorkAroundParserFunction_Setup() {
	global $wgParser;
	$wgParser->setFunctionHook( 'link',
'wfImageLinkWorkAroundParserFunction_Render' );
}

function wfImageLinkWorkAroundParserFunction_Magic( &$magicWords, $langCode ) {
	$magicWords[ 'link' ] = array( 0, 'link' );
	return true;
}

function wfImageLinkWorkAroundParserFunction_Render( &$parser, $target
= '', $alt = "", $src = "", $height = "", $width = "" ) {
	$img = new LinkedImage;
	$img->wikipage = $target;
	$img->tooltip = $alt;
	$img->img_src = $src;
	$img->img_alt = $alt;
	$img->img_height = $height;
	$img->img_width = $width;
	$img->img_border = 0;
	#echo $img->render(); # Outputs actual HTML (e.g. <img src="foo" />)
	return $img->render(); #' Outputs escaped HTML (e.g. &lt;img src="foo" /&gt;)
}

?>

-- 
MinuteElectron.
http://my.brlcad.org/~MinuteElectron/



More information about the MediaWiki-l mailing list