Extension:ImageLink

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

Note on Parser Caching
If you are using parser caching, you must wait until the relevant cache entries expire in order for the extension to show results. Alternatively, you can flush the cache and see the results right away.

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 * */ $wgExtensionCredits['other'][] = array( 	'name'   => 'ImageLink',	'version' => '1.3',	'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['OutputPageBeforeHTML'][]= array($this, 'hBeforeHTML'); $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 hBeforeHTML( $op, &$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. ?>