User:Sysy~metawiki/Joshua Oreman's icon extension
Appearance
See also Bug 539: Allow images that link somewhere other than the image page
From: Joshua Oreman <oremanj at gmail dot com> Mailed-By: wikimedia.org To: MediaWiki announcements and site admin list <mediawiki-l at wikimedia.org> Date: Aug 30, 2005 2:04 PM
Untested, but should work.
extensions/ImageLink.php:
require_once('../includes/Image.php'); $wgExtensionFunctions[] = "wfImageLink"; function wfImageLink() { global $wgParser; $wgParser->setHook ('imglink', 'renderImageLink'); } function renderImageLink ($text, $attr) { global $wgParser, $wgUser, $wgTitle; $parserOptions = ParserOptions::newFromUser( $wgUser ); $parser =& new Parser(); $output =& $parser->parse("[[".$input."|IMAGE]]", $wgTitle, $parserOptions); $ret = $output->getText(); $itag = "<img border='0' "; foreach ($attr as $k => $v) { if ($k == "src") { $itag .= "src='" . Image::imageUrl($attr['src']) . "' "; } else { $itag .= "$k='$v' "; } $itag .= "/>"; return str_replace ($ret, "IMAGE", $itag); }
and add
require_once('extensions/ImageLink.php');
to LocalSettings.php.
To use, do
<imglink src='MyImage'>Destination page</imglink>
instead of the doesn't-work
[[Destination page|[[Image:MyImage]]]]
You can also use height and width attributes on the <imglink> tag.
Comments
[edit]- Rowan Collins added on the mailing list: it would be "nicer" to use specific link-related functions rather than parsing as a text link and replacing. Also, can't you just use $wgParser rather than $parser=new Parser?