User:Sysy~metawiki/Joshua Oreman's icon extension

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Blue Glass Arrow.svg MediaWiki logo.png
This page should be moved to
Please do not move the page by hand. It will be imported by a administrator with the full edit history. In the meantime, you may continue to edit the page as normal.

See also Bug 539: Allow images that link somewhere other than the image page

From: Joshua Oreman <oremanj at gmail dot com>	Mailed-By:
To: MediaWiki announcements and site admin list <mediawiki-l at>
Date: Aug 30, 2005 2:04 PM

Untested, but should work.



$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


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.


  • 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?