Extension:ImageLink

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

Features

 * Local pages
 * Inter-wiki pages

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. * - -- changed to SVN management *         v1.5 -- Support for inter-wiki links */ $wgExtensionCredits['other'][] = array( 	'name'   => 'ImageLink',	'version' => 'v1.5 $LastChangedRevision: 61 $',	'author'  => 'Jean-Lou Dupont', 	'url'     => 'http://www.bluecortex.com', );

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

ImageLinkClass::singleton;

?>

ImageLinkClass.php
hookInPlace = false; $this->done = 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; // distinguish between local and interwiki URI if ($title->isLocal) $tURL = $title->getLocalUrl; else $tURL = $title->getFullURL; // 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; }

$t = "_imagelink_".date('Ymd').count($this->links)."_/imagelink_"; // let's put an easy marker that we can 'safely' find once we need to render the HTML $this->links[] = "";

return $t; }

public function hAfterTidy( $parser, &$text ) /*	 * This function is called just before the HTML is rendered to the client browser. */	{		// sometimes, the parser gets called more than once. if ($this->done) return; $this->done = true; // Some substitution to do? if (empty($this->links)) return;

foreach($this->links as $index => $link) {			$p = "/_imagelink_".date('Ymd').$index."_\/imagelink_/si"; $text = preg_replace( $p, $link, $text ); }		return true; // v1.3 fix. } } // end class definition. ?>