Extension:ImageLink

What can this extension do?
Provides a URI anchor with an image stored in the Wiki.

ImageLink.php
<?php /* * ImageLink.php * * MediaWiki extension * @author: Jean-Lou Dupont (http://www.bluecortex.com) * * Purpose: Provides a clickable image link using *          an image stored in the Image namespace and *          an article title (which may or may not exist *           in the database). * * USAGE E.g.: * * Tested Compatibility: MW 1.8.2, 1.9.3 * * DEPENDANCY: ExtensionClass * * HISTORY:	v1.0 *         v1.1 -- re-crafted to derive from 'ExtensionClass' *         v1.2 -- adding proofing against 'bad titles' *         v1.3 -- small fix regarding hook chaining *         v1.4 -- changed hook method for better parser caching integration. * */ $wgExtensionCredits['other'][] = array( 	'name'   => 'ImageLink',	'version' => '1.4',	'author'  => 'Jean-Lou Dupont', 	'url'     => 'http://www.bluecortex.com', );

require_once(dirname( __FILE__ ) . '/ImageLinkClass.php');

ImageLinkClass::singleton;

?>

ImageLinkClass.php
hookInPlace = false; }	public function mg_imagelink( &$parser, $img, $page, 							// mandatory parameters  								$alt=null, $width=null, $height=null, $border=null )// optional parameters /*	 * $img  = image reference i.e. a valid image name e.g. "New Clock.gif" * $page = page reference i.e. a valid page name e.g. "Admin:Show Time" *	 * 	 */	{		$image = Image::newFromName( $img ); if (!$image->exists) return; if (empty($page)) return; $title = Title::newFromText( $page ); if (!is_object($title)) return; $iURL = $image->getURL; $tURL = $title->getLocalUrl; // Optional parameters if ($alt   !== null)	$alt    = "alt='${alt}'"; 		else $alt=''; if ($width !== null)	$width  = "width='${width}'"; 	else $width=''; if ($height !== null)	$height = "height='${height}'";	else $height=''; if ($border !== null)	$border = "border='${border}'";	else $border='';

// just place the hook when we really need it. if (!$this->hookInPlace) {			global $wgHooks; $wgHooks['ParserAfterTidy'][]= array($this, 'hAfterTidy'); $this->hookInPlace = true; }					// let's put an easy marker that we can 'safely' find once we need to render the HTML $t = $this->links[] = "  "; return $t; }

public function hAfterTidy( $parser, &$text ) /*	 * This function is called just before the HTML is rendered to the client browser. */	{		// Some substitution to do? if (empty($this->links)) return; foreach($this->links as $index => $link) {			// our marker will have been escaped by the MW parser. $l = htmlspecialchars($link); // This is what our marker looks like without the escaping. $p = "/\<\/?imagelink\>/si"; $r = preg_replace($p,"", $link); $text = str_ireplace($l, $r, $text); }		return true; // v1.3 fix. } } // end class definition. ?>