Extension:ImageMap (McNaught)

Introduction
ImageMap is a Mediawiki 1.5 extension. This extension was built to add Client Side ImageMaps to MediaWiki.

Note: Most up to date version of this extension can be found at: http://www.chekmate.org/wiki/index.php/Projects

Another version is located at User:TeamChaos/HtmlMaps

Note: For MediaWiki 1.9 there is a similar extension: ImageMap. This extension does not use image map information in HTML format loaded from files. Rather, it includes image map information inline between the imagemap tags.

Another version, that includes the functionality of both this extension and the extension in the above note is available on Mediawiki at Imagemap (Alternate). This new version, currently in beta, provides for full map file checking to exclude any non-map HTML statements. It also provides proper linking to map files in a Wiki Family.

Change History

 * 15:25, 24 July 2006 (UTC) - Extension now configured so it no longer caches the wiki page. (Smcnaught)
 * 02:20, 24 July 2006 (UTC) - If whitespace was in the map file, it created a &lt;pre> underneath the image map graphic. This has been corrected. (Smcnaught)
 * 06:09, 18 July 2006 (UTC) - Added better variable definition for $mapfile using global variable $IP (Smcnaught)
 * 01:56, 18 July 2006 (UTC) - Added Error checking to check if $mapfile exists. (Smcnaught)
 * 01:56, 18 July 2006 (UTC) - Added a random component to timestamp as multiple imagemaps on a single page did not work properly. (Smcnaught)

Maintainer
Shannon McNaught (smcnaught) - I am also available on irc.chekmate.org #MediaWiki

Homepage
ChekMate Technical Focus Group

License
ImageMap.php - Adds ImageMap functionality to MediaWiki

Copyright (C) 2006 Shannon McNaught

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Installation
/** * This is the list of preferred extensions for uploading files. Uploading files * with extensions not in this list will trigger a warning. */ $wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'pdf','map' );
 * Copy  ImageMap.php  to "extensions" folder.
 * Change " $mapfile = "/var/www/html/$Mapurl";" within file to point to the parent directory where your wiki folder is located.
 * Add a line  require_once( "extensions/ImageMap.php" );  into "LocalSettings.php".
 * Set up MediaWiki to allow users to upload MAP files, set up something like the following in "LocalSettings.php":

/** Determines if the mime type of uploaded files should be checked * @global boolean $wgVerifyMimeType */ $wgVerifyMimeType= false;
 * Was an issue with MediaWiki not accepting the upload. Needed to change $wgVerifyMimeType to false in "./includes/DefaultSettings.php". Better solutions?

Sample
An online example can be seen at: http://www.chekmate.org/wiki/index.php/MW:_ImageMap_Extension#Samples

ImageMap.php
<?php
 * 1) ImageMap Mediawiki extension
 * 2) original by smcnaught 29.06.2005
 * 3) Installation:
 * 4)  * put this file (ImageMap.php) into the extension directory of your mediawiki installation
 * 5)  * add the following to the end of LocalSettings.php: include("extensions/ImageMap.php");
 * 6) Usage:
 * 7)  Use one section between
 * 1) Usage:
 * 2)  Use one section between

$wgExtensionFunctions[] = "wfImageMapExtension";
 * 1) install extension hook

function wfImageMapExtension { global $wgParser;
 * 1) extension hook callback function

#install parser hook for  tags $wgParser->setHook( "ImageMap", "renderImageMap" ); }

function renderImageMap( $input ) { global $wgServer, $wgScriptPath, $wgTitle, $wgUrlProtocols, $wgUser, $IP;
 * 1) parser hook callback function

global $wgDBprefix; $ts = mktime; $now = gmdate("YmdHis", $ts + 120); $ns = $wgTitle->getNamespace; $ti = wfStrencode($wgTitle->getDBkey); $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion); if ($version>14) $sql = "UPDATE $wgDBprefix"."page SET page_touched='$now' WHERE page_namespace=$ns AND page_title='$ti'"; else            $sql = "UPDATE $wgDBprefix"."cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'"; wfQuery($sql, DB_WRITE, "");
 * 1) Do not cache this wiki page.
 * 2) for details see http://public.kitware.com/Wiki/User:Barre/MediaWiki/Extensions

if (!$input) return "";

$fields= explode("|",$input); $args= array; for ($i=0; $i<sizeof($fields); $i++) { $f= $fields[$i];

if (strpos($f,"=")===False) $args[strtolower(trim($f))]= False; else { list($k,$v)= explode("=",$f,2); if (trim($v)==False) $args[strtolower(trim($k))] = False; else $args[strtolower(trim($k))]= trim($v); } }  $timestamp = mktime. rand(1,29);

#get title from argument-array

$ImageURL= @$args["image"]; $ImageURL= trim($ImageURL); if ($ImageURL=='') { return "No Image"; }

$MapURL= @$args["map"]; $MapURL= trim($MapURL); if ($MapURL=='') { return "No Map"; } $localParser = new Parser; $parserOptions = ParserOptions::newFromUser( $wgUser );

$html = $localParser->parse($ImageURL,$wgTitle,$parserOptions); $Imageurl = preg_replace('/^.*mText); $html = $localParser->parse($MapURL,$wgTitle,$parserOptions); $Mapurl = preg_replace('/^.*mText); $mapfile = "$IP/../$Mapurl"; $lines = array_map('rtrim',file("$mapfile"));

$output="";

if (!file_exists($mapfile)) { $output = $output. "Path to mapfile is incorrect or file does not exist. mapfile should look like: /var/www/html/wiki/images/4/4d/Fish.map";

# Enable for troubleshooting, otherwise comment to hide directory path. #  $output = $output. "$mapfile"; }

// Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { if (preg_match ("/\sname=/i", $line)) { $replacestr = " name=\"$timestamp\""; $line = preg_replace('/\sNAME=\"[a-zA-Z0-9 ]+\"/i',$replacestr,$line); }   $line = preg_replace(array('/\s{2,}/','/^\s+/','/\s+$/'),array(' ',,),$line); $output = $output. $line. "\n"; } return $output;

}

?>

Other sites using this extension

 * ChekMate Technical Focus Group

Imagemapping Tools

 * Clickable Image Map Maker. This web page allows the user to select an image file on his own local hard drive, then creates a second page using that image, and allows the user to very quickly generate the HTML code for an imagemap to be used in his own files. It also offers some handy pop-up menus to speed the process of coding the actual href. Complicated maps can be created in less than a minute (no kidding). Requires a Javascript and frames capable browser, designed and tested on a Mac using Netscape Navigator.
 * Mapedit is a WYSIWYG editor for imagemaps, available for Microsoft Windows and the X Window System. Use Mapedit to generate, or convert to, NCSA, CERN, or client-side map files.