Extension:LinkedImage

Introduction
LinkedImage is a Mediawiki 1.5 extension.

Usually any displayed image in mediawiki is linked to its own article. This extension was created to provide a possibility to display an image what is linked to an other article than the own one.

Usage - Example
wikipage=Main_Page tooltip=Main Page img_src=Image:Sample.gif img_width=10% img_height=10px img_alt=Sampletext

Installation

 * copy LinkedImages.php to the extensions folder
 * add require_once($IP . '/extensions/LinkedImages.php'); to the end of Localsettings.php

LinkedImages.php code
Version: 0.3

 * @author Alan Trick  * @copyright Public domain * @license Public domain * @package MediaWikiExtensions * @version 0.3 */ /** * Register the LinkedImage extension with MediaWiki */ $wgExtensionFunctions[] = 'wfLinkedImage'; $wgExtensionCredits['parserhook'][] = array( 'name' => 'LinkedImage', 'author' => 'Alexander Kraus', 'author' => 'Alan Trick', 'url' => 'http://meta.wikimedia.org/wiki/LinkedImage', );

/** * Sets the tag that this extension looks for and the function by which it * operates */ function wfLinkedImage { global $wgParser, $wgMessageCache; $wgMessageCache->addMessages( array( 'linkedimage_nowikipage'=> 'LinkedImage: No link target specified! e.g. \'wikipage=Main_page\'', 'linkedimage_noimg'    => 'LinkedImage: No image specified! e.g. \'img_src=Image:LinkedImage.png\'' ) );   $wgParser->setHook('linkedimage', 'renderLinkedImage'); }

function renderLinkedImage($input) { $img=new LinkedImage; $img->getBoxOption($img->wikipage,  $input,'wikipage'); $img->getBoxOption($img->tooltip,   $input,'tooltip'); $img->getBoxOption($img->img_src,   $input,'img_src'); $img->getBoxOption($img->img_height, $input,'img_height'); $img->getBoxOption($img->img_width, $input,'img_width'); $img->getBoxOption($img->img_alt,   $input,'img_alt'); $img->getBoxOption($img->img_border, $input,'img_border'); // render and return linked image ... return $img->render; }

class LinkedImage { public $wikipage = ''; public $tooltip = ''; public $img_src = ''; public $img_alt = ''; public $img_height = ''; public $img_width = ''; public $img_border = ''; private function getTooltipHTML { if ($this->tooltip != '') { return " title='{$this->tooltip}''"; } else return ''; }   public function getURL { global $wgArticlePath, $wgParser; $page = str_replace('', $wgParser->mTitle->getSubpageUrlForm, $this->wikipage); return str_replace( "$1", $page, $wgArticlePath); }   public function getImg { // alt and src are required, alt may be empty though $r = "image->getUrl}' alt='{$this->img_alt}'"; if ($this->img_width != '') $r .= " width='{$this->img_width}'"; if ($this->img_height != '') $r .= " height='{$this->img_height}'"; if ($this->img_border != '') $r .= " border='{$this->img_border}'"; return $r. ' />';   }    public function render { // sanity checking if ($this->wikipage == '') { return htmlspecialchars( wfMsg( 'linkedimage_nowikipage' ) ); }       if ($this->img_src == '') { return htmlspecialchars( wfMsg( 'linkedimage_noimg' ) ); }       // create mediawiki image object ... $this->image = new Image( Title::newFromText( $this->img_src ) ); // return link return "getURL}'{$this->getTooltipHTML}>{$this->getImg}"; }   public function getBoxOption(&$value,&$input,$name) { if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) { $value = htmlspecialchars($matches[1], ENT_QUOTES); }  } } ?>

Changelog

 * Version 0.3: fixed XSS vulnerbility, cleaned up code, added support for in url