MediaWiki extension: ImageMap (extended) - ImageLink
| ImageMap (extended) Release status: beta | |
|---|---|
| Description: | HTML image maps |
| Author: | Eric Hartwell |
| MediaWiki: | 1.9+ |
| Download: | [1] |
Contents |
[edit] What can this extension do?
This extension adds additional functionality to Tim Starling's Extension:ImageMap for client-side clickable image maps:
- The new <imageLink> tag provides a convenient way to display an image using [[Image:]] syntax with a link to an internal page, an external site, or no link at all.
This extension duplicates and extends the functionality of other existing extensions:
- Like Extension:ImageMap, but simpler syntax and supports no link at all
- Like Extension:ImageLink, but simpler syntax like [[Image:]] and supports no link at all
- Like Extension:LinkedImage, but simpler syntax like [[Image:]] and supports links to external sites and no link at all
[edit] Usage
[edit] Installation
[edit] Parameters
[edit] Changes to LocalSettings.php
require_once("$IP/extensions/ImageMap/ImageMap");
require_once("$IP/extensions/ImageMap/ImageMapExtended");
[edit] Code
The code piggybacks on the Extension:ImageMap extension. Since ImageMap is one of Wikipedia's core extension, I put the code in a separate extension.
<li> <a href="/infodabble/index.php?title=Image:FeedIcon.png" class="image" title=""> <img alt="" longdesc="/infodabble/index.php?title=Image:FeedIcon.png" src="/infodabble/images/thumb/c/c1/FeedIcon.png/16px-FeedIcon.png" width="16" height="16" /> </a> <a href="http://feeds.feedburner.com/Infodabble-WhatsNew" class="external text" title="http://feeds.feedburner.com/Infodabble-WhatsNew" rel="nofollow">What's new</a> </li> <li> <div style="position: relative;"> <a href="http://feeds.feedburner.com/Infodabble-WhatsNew" class="plainlinks" rel="nofollow" title="http://feeds.feedburner.com/Infodabble-WhatsNew"> <img alt="" longdesc="/infodabble/index.php?title=Image:FeedIcon.png" src="/infodabble/images/thumb/c/c1/FeedIcon.png/16px-FeedIcon.png" width="16" height="16"/> </a> </div> <a href="http://feeds.feedburner.com/Infodabble-WhatsNew" class="external text" title="http://feeds.feedburner.com/Infodabble-WhatsNew" rel="nofollow">What's new</a> </li> <li> <div style="position: relative;"> <li> <div class="floatleft"><span><div style="position: relative;"> <li> <div class="floatright"><span><div style="position: relative;"> <li> <div class="center"><div class="floatnone"><span><div style="position: relative;"> <li> <div class="floatnone"><span><div style="position: relative;">
<?php if(! defined( 'MEDIAWIKI' ) ) { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); } else { $wgExtensionCredits['parserhook']['ImageMapExtended'] = array( 'name' => 'ImageMapExtended', 'author' => 'Eric Hartwell', 'url' => 'http://www.ehartwell.com', 'description' => 'Allows client-side clickable image using <nowiki><imageLink></nowiki> tag.', ); } $wgExtensionFunctions[] = 'wfSetupImageMapExtended'; function wfSetupImageMapExtended() { global $wgParser; $wgParser->setHook( 'imagelink', 'renderImageLink' ); } // Show a plain image with an optional link // <imagelink>link|image|imageargs</imagelink> function renderImageLink( $input, $params, $parser ) { $tags = explode( '|', $input ); $link = array_shift ( $tags ); // Use the <imagemap> code to parse the image $html = ImageMap::render( implode( '|', $tags ) . ' default ' . ($link ? $link : '[http://dummy]') . ' desc none ', $params, $parser ); // Strip the relative <div> code since it prevents putting // the images directly inline with the text (e.g. feed icon) $html = preg_replace( '`<div[^>]*style="position.*?>`', '', $html ); $html = preg_replace( '`</a.*?></div.*?>`', '</a>', $html ); // Strip the href if no link was specified if ( !$link ) $html = preg_replace( '`<a.*?>|</a.*?>`', '', $html ); return( $html ); }