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 extensionfolder
 * add include("extensions/LinkedImages.php"); to your localconfig.php

LinkedImages.php code
Version: 0.2

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

//renderLinkedImage;

/** * 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) {   $linkedimage=new LinkedImage; $linkedimage->getBoxOption($linkedimage->wikipage,  $input,'wikipage'); $linkedimage->getBoxOption($linkedimage->tooltip,   $input,'tooltip'); $linkedimage->getBoxOption($linkedimage->img_src,   $input,'img_src'); $linkedimage->getBoxOption($linkedimage->img_height, $input,'img_height'); $linkedimage->getBoxOption($linkedimage->img_width, $input,'img_width'); $linkedimage->getBoxOption($linkedimage->img_alt,   $input,'img_alt'); $linkedimage->getBoxOption($linkedimage->img_border, $input,'img_border'); // render and return linked image ... return $linkedimage->render; }

class LinkedImage { var $wikipage; var $tooltip; var $img_src; var $img_alt; var $img_height; var $img_width; var $img_border; public function LinkedImage { $this->setWikipage(''); $this->setTooltip(''); $this->setImg_src(''); $this->setImg_alt(''); $this->setImg_height(''); $this->setImg_width(''); $this->setImg_border(''); }  private function setWikipage($value){ 	$this->wikipage=$value; } private function getWikipage{      	return $this->wikipage; } private function setTooltip($value){ 	$this->tooltip=$value; } private function getTooltip{		 	return $this->tooltip; } private function getTooltipHTML{ if ($this->tooltip != '') { return 'title="'.$this->getTooltip.'" '; } else { return ''; }  }   private function setImg_src($value){  	$this->img_src=$value; } private function getImg_src{		 	return $this->img_src; } private function getImg_srcHTML($getImageUrl=false){ if ($this->img_src != '') { if ($getImageUrl) { return 'src="'.$this->image->getUrl.'" '; } else { return 'src="'.$this->img_src.'" '; }  		} else { return ''; }  }   private function setImg_alt($value){  	$this->img_alt=$value; } private function getImg_alt{		 	return $this->img_alt; } private function getImg_altHTML{ if ($this->img_alt != '') { return 'alt="'.$this->img_alt.'" '; } else { return ''; }  }   private function setImg_height($value){ 	$this->img_heigth=$value;} private function getImg_height{		return $this->img_height;} private function getImg_heightHTML{ if ($this->img_height != '') { return 'height="'.$this->img_height.'" '; } else { return 'height="'.$this->image->getHeight.'" '; }  }   private function setImg_width($value){	$this->img_width=$value; } private function getImg_width{			return $this->img_width; } private function getImg_widthHTML{ if ($this->img_width != '') { return 'width="'.$this->img_width.'" '; } else { return 'width="'.$this->image->getWidth.'" '; }  }   private function setImg_border($value){	$this->img_border=$value; } private function getImg_border{		return $this->img_border; } private function getImg_borderHTML{ if ($this->img_border != '') { return 'border="'.$this->img_border.'" '; } else { return $this->img_border; }  }

public function render { global $wgArticlePath; // check param wikipage existence if ($this->getWikipage == '') { return htmlspecialchars( wfMsg( 'linkedimage_nowikipage' ) ); }

// check param img_src existence if ($this->getImg_src == '') { return htmlspecialchars( wfMsg( 'linkedimage_noimg' ) ); }       // create mediawiki image object ... $this->image = new Image( Title::newFromText( $this->img_src ) ); // return link ... return 'wikipage, $wgArticlePath ).'" '.$this->getTooltipHTML.'> getImg_srcHTML(true). $this->getImg_altHTML. $this->getImg_widthHTML. $this->getImg_heightHTML. $this->getImg_borderHTML. '>'; } // End render public function getBoxOption(&$value,&$input,$name,$isNumber=false) { if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) { if($isNumber) { $value=intval($matches[1]); } else { $value=htmlspecialchars($matches[1]); }	 }   } // End getBoxOption }

?>