Extension talk:ImageMap (McNaught)
Add topicHow to create map files
[edit]I want this - but how do I create the .MAP files? What is their format? Some examples would be really helpful.
The following is a typical map file: (I used GIMP Imagemap Plugin to create this one - there are other imagemap makers or you can make it yourself.) (Smcnaught) - I am also available on irc.chekmate.org #MediaWiki <map name="map"> <!-- #$-:Image Map file created by GIMP Imagemap Plugin --> <!-- #$-:GIMP Imagemap Plugin by Maurits Rijk --> <!-- #$-:Please do not edit lines starting with "#$" --> <!-- #$VERSION:2.0 --> <!-- #$AUTHOR:Shannon McNaught --> <area shape="rect" coords="75,0,136,85" href="http://www.yourhost.com/wiki/index.php/BK001" /> <area shape="rect" coords="0,56,72,137" href="http://www.yourhost.com/wiki/index.php/FE001" /> <area shape="rect" coords="137,58,216,135" href="http://www.yourhost.com/wiki/index.php/ZM001" /> <area shape="rect" coords="213,0,286,81" href="http://www.yourhost.com/wiki/index.php/SC001" /> <area shape="rect" coords="285,53,349,137" href="http://www.yourhost.com/wiki/index.php/MN001" /> <area shape="rect" coords="348,1,426,85" href="http://www.yourhost.com/wiki/index.php/DB001" /> <area shape="rect" coords="427,53,497,136" href="http://www.yourhost.com/wiki/index.php/AM001" /> <area shape="rect" coords="398,164,477,280" href="http://www.yourhost.com/wiki/index.php/IX535" /> <area shape="rect" coords="328,205,398,315" href="http://www.yourhost.com/wiki/index.php/IX535" /> <area shape="rect" coords="206,385,308,499" href="http://www.yourhost.com/wiki/index.php/509B" /> <area shape="rect" coords="59,386,156,498" href="http://www.yourhost.com/wiki/index.php/509A" /> <area shape="rect" coords="23,206,103,299" href="http://www.yourhost.com/wiki/index.php/SUNK001" /> <area shape="rect" coords="102,165,178,253" href="http://www.yourhost.com/wiki/index.php/ST001" /> <area shape="rect" coords="177,206,252,294" href="http://www.yourhost.com/wiki/index.php/PD001" /> <area shape="rect" coords="250,166,326,252" href="http://www.yourhost.com/wiki/index.php/SN001" /> <area shape="rect" coords="34,309,326,372" href="http://www.yourhost.com/wiki/index.php/NetworkTAP" /> </map> |
Error messages
[edit]I'm getting 3 error messages on any webpage that uses <imagemap> during a 'Show Preview' of an edit. The submitted page doesn't show the errors, but doesn't hyperlink when clicking on the coordinates.
Warning: file(/var/www/html//wiki/images/6/63/GPINetArch.map): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\wiki\extensions\ImageMap.php on line 71 Warning: array_map(): Argument #2 should be an array in c:\program files\easyphp1-8\www\wiki\extensions\ImageMap.php on line 71 Warning: Invalid argument supplied for foreach() in c:\program files\easyphp1-8\www\wiki\extensions\ImageMap.php on line 76
Using MediaWiki 1.6.3
The .map file I'm using is
<MAP NAME="Network Layout"> <AREA SHAPE="RECT" COORDS="6,143,71,181" HREF="#Citrix Servers"> <AREA SHAPE="RECT" COORDS="69,103,143,122" HREF="Servers#GPI_Mail"> </MAP>
I've also tried with trailing slashes in the <area> tags as indicated in the example.
Ok, I am not sure about the warning errors as I was unable to recreate the problem. Warning: file(/var/www/html//wiki/images/6/63/GPINetArch.map): failed to open stream: No such file or directory in c:\program files\easyphp1-8\www\wiki\extensions\ImageMap.php on line 71 Warning: array_map(): Argument #2 should be an array in c:\program files\easyphp1-8\www\wiki\extensions\ImageMap.php on line 71 Warning: Invalid argument supplied for foreach() in c:\program files\easyphp1-8\www\wiki\extensions\ImageMap.php on line 76 The first error is saying it can not see GPINetArch.map. Is that the correct filename or is it GPINetArch.MAP? The other two errors relate back to the first error. In regards to your imagemap map file. I believe the issue is related to the upper case <MAP NAME="....">. Linux is case sensitive and I built the plugin where the hyperlinks were lowercase. The script also does not like a space in the name= variable. It would also be helpful if you could provide a URL so that I can see how the script reacts on your system. RESOLVED: Case Sensitivity and Spacing Issue[edit]The following may work better, replace the following line $line = preg_replace('/\sname=\"[a-zA-Z0-9]+\"/',$replacestr,$line); with $line = preg_replace('/\sNAME=\"[a-zA-Z0-9 ]+\"/i',$replacestr,$line); (after the 9 is a space, and there is an i after the last /) -- Smcnaught - 05:51, 11 July 2006 (UTC) - I am also available on irc.chekmate.org #MediaWiki |
Linux support only?
[edit]Thanks for the help, but no go. It's not the filename I have wrong, it seems to be this line:
$mapfile = "/var/www/html/$Mapurl";
which refers to a path that doesn't exist on my install. I wasn't looking hard enough at the error message it seems. The actual path to the .map file is \Program Files\EasyPHP1-8\www\wiki\images\6\63\GPINetArch.map
I fixed this by replacing that line with this block:
if( defined( 'MW_INSTALL_PATH' ) ) { $IP = MW_INSTALL_PATH; } else { $IP = dirname( __FILE__ ); } $mapfile = "$IP/../../$Mapurl";
which is pretty messy - I grabbed the MW_INSTALL_PATH from LocalSettings.php (I'm not a PHP programmer), but while it refers to the wiki
directory for LocalSettings.php, it refers to the extensions
directory for ImageMap.php - hence the /../../
I'm sure you could fix this up to be a bit nicer.
So - all working great now. Thanks for a great extension, I'd been looking for a while for something to do exactly this. I was having issues while change the ImageMap.php with changes not appearing - turns out to be a browser refresh issue, even with Ctrl+Refresh. This is what was happening with Show Preview and the saved page having different results.
- Smcnaught -- 16:05, 12 July 2006 (UTC) - I am also available on irc.chekmate.org #MediaWiki Yes, I had hard coded reference to the MapURL. Sorry about that, this was a quick hack together. I will review your code this weekend and add it to the main code. I will also add non-caching code to the script, this should resolve the issue you experienced with the browser refresh. Thanks for your input, it is appreciated. |
No clickability
[edit]We just installed this extension on Kayakwiki, but having some trouble getting it to work. See my attempt here. It's showing the image, but not responding to mouse clicks at all, so I guess it's not picking up the map file properly for some reason. related discussion. Any suggestions?
Is it necessary to change an apache directive to make it recognice .map files. I think it must be. Now my map file does something similar to this example fish map file when viewing directly, whereas before it showed the files contents in plain text. My .map file contents now look like this:
<map name="map"> <area shape="poly" coords="286,81,327,94,348,132,365,132,341,166,358,176,351,202,333,205,317,219,299,220,285,179,275,145,249,143,235,117,257,85" href="http://kayakwiki.org/index.php/Africa" /> <area shape="poly" coords="563,214,561,232,523,244" href="http://kayakwiki.org/index.php/New_Zealand" /> <area shape="poly" coords="455,220,490,220,505,240,537,204,518,173,489,172,458,194" href="http://kayakwiki.org/index.php/Australia" /> <area shape="poly" coords="253,86,289,78,313,81,330,60,314,45,312,19,288,25,255,52" href="http://kayakwiki.org/index.php/Europe" /> <area shape="poly" coords="151,5,203,4,193,53,145,69,128,60,64,58,75,40,100,18" href="http://kayakwiki.org/index.php/Canada" /> <area shape="poly" coords="68,86,116,104,137,102,193,55,144,69,128,60,63,59,74,41,100,19,46,24,29,59" href="http://kayakwiki.org/index.php/Middle_East" /> <area shape="poly" coords="86,122,133,138,116,105,61,83" href="http://kayakwiki.org/index.php/Middle_America" /> <area shape="poly" coords="168,117,139,125,120,108,151,104" href="http://kayakwiki.org/index.php/Carribean" /> <area shape="poly" coords="144,190,156,250,185,258,170,230,200,194,208,158,143,127,122,163" href="http://kayakwiki.org/index.php/South_America" /> <area shape="poly" coords="332,58,313,84,329,96,347,128,373,108,387,106,395,84,389,77,396,71,375,71,359,65,356,83,348,74,331,67" href="http://kayakwiki.org/index.php/Middle_East" /> <area shape="poly" coords="438,167,498,173,558,172,498,141,477,96,502,91,523,27,375,7,313,19,314,45,334,63,354,80,359,65,375,71,396,71,390,78,394,84,388,108,405,142,415,142,428,123" href="http://kayakwiki.org/index.php/Asia" /> </map>
I tried to mimmick your example above. See anything wrong there?
-- Harry Wood 15:02, 17 July 2006 (UTC)
$mapfile variable
[edit]
Smcnaught -- 20:07, 17 July 2006 (UTC) - I am also available on irc.chekmate.org #MediaWiki When I looked at the source of your page, it did not add the map file contents to the page. You may have to change the /var/www/html/ to reference your directory if it is different. I believe you are running on a windows environment and thus the directory would be different. I added some file checking to see if the file exists. $mapfile = "/var/www/html/$Mapurl"; $lines = array_map('rtrim',file("$mapfile")); $output="<img src=\"$Imageurl\" usemap=\"#$timestamp\">"; Add the following at this point in the file: 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); } $output = $output . $line . "\n"; } return $output; |
I implimented the fix to the mapfile path on KayakWiki and it works fine. Thanks a lot for your help.
PS - Please don't take this as negative criticism, but as constructive. I think it would be a good time to modify your extension to be more "standard". For example, most other extensions that I've installed are set up to be installed in their own directory within /extensions/. For example, /extensions/SpamBlacklist/ or /extensions/ParserFunctions/. I installed yours as /extensions/ImageMap/ and it works fine. If you do this, it keeps all the extensions separate and that makes life easier for an admin. All you have to do is change your instructions and one line of code. As well, any future changes should reflect the appropriate directory structure.
The change is require_once( "extensions/ImageMap.php" ); should be changed to reflect the subdirectory and as well, should be preceded with $IP as per other extensions. E.g. my LocalSettings.php ends with:
- require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php" );
- require_once( "$IP/extensions/SpamBlacklist/SpamBlacklist.php" );
- require_once( "$IP/extensions/ImageMap/ImageMap.php" );
Anyway, you've created a great little product and making it "standard" will endear you to all those harried wiki admins out there!
Thanks again! Michael Daly 06:07, 18 July 2006 (UTC)
Security issues
[edit]I noticed a couple serious security problems with this extension. It does no checking on the $Mapurl, so someone can use a ../../../.. path to display the contents of any file on the server. It also does no checking on the contents of the mapfile, so you can use it to bypass MediaWiki's HTML sanitizer and output any HTML (e.g., web forms, JavaScript, etc.) Use with caution. --GregU 05:33, 22 November 2006 (MST)
- Imagemap (Alternate) provides the functionality of this imagemap extension but removes any HTML from the input file that is not specifically related to imagemap and area definition. It doesn't solve the problem of an errant URL in the file, but it eliminates malicious HTML. Michael Daly 20:15, 16 May 2007 (UTC)
Usage from a template
[edit]Maybe a newbie question, but I didn't find the answer elsewhere... The extension works smooth for me unless I call it from a template where I pass the image and link name as a parameter like {{{myImage}}}. If I do this, imagemap throws an error, saying something like "<imagemap> error: invalid titel in link in row 3" (actually I only have the German text which is "<imagemap>-Fehler: ungĂźltiger Titel im Link in Zeile 3" and "<imagemap>-Fehler: In der ersten Zeile muss ein Bild angegeben werden" (in the first row an image needs to be specified, or so). --Ben Marx 08:54, 11 September 2007 (UTC)
- This is a bug in Mediawiki. Nothing can be done. It is not specific to imagemap, it is a general problem with embedding extensions within templates. Michael Daly 22:32, 17 September 2007 (UTC)
Various problems getting the extension to work
[edit]- Is the actual extension itself the text in the box under ImageMap.php? I assume this is the case, but it isn't explained anywhere.
- There's nothing in the file that says $mapfile = "/var/www/html/$Mapurl" I have to assume you meant $mapfile = "$IP/../$Mapurl"; -- is that correct?
- Is there a typo in the $wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'pdf','map' );" line? There's no space before 'map'.
- DefaultSettings.php says very explicitly not to edit anything in it.
- If I put the $wgVerifyMimeType= false; in LocalSettings.php instead, I get the warning This file contains HTML or script code that may be erroneously be interpreted by a web browser. warning when I try to upload anything.
I would really like to get a working way to use imagemaps in my MediaWiki. Please help!
- Do you really need this version of Imagemap? The Wikipedia-supported version Extension:ImageMap is more up-to-date and has fewer problems including no security concerns. That version does not require you to upload map files.
- yes, that's the code.
- Yes
- No, blanks are optional in PHP array content lists.
- Never change DefaultSettings.php if you can avoid it. Most parameters can be copied into LocalSettings.php and changed there. Anything in LocalSettings.php overrides DefaultSettings.php.
- When you turn off mime type verification, you risk uploading content that can corrupt your wiki or compromise the security of your server.
- Yes, I have to use this version. Ubuntu 7.04, which I'm running, only has packages that allow me to run MediaWiki 1.7.1. The newer imagemap extensions only work with 1.9 and above.
- So, if I can't upload the file without getting that nasty warning (and risking corrupting my server's security), how am I supposed to run the ImageMap extension? Do I really have to ignore that warning to actually use your extension?
- You can safely ignore the warnings if you verify that the posted files do not contain any nasty HTML etc.
- One other option is to provide mime info for map files and not use the generic removal of mime verification. That is safer, as it will verify all other files types, but you still have to ensure that the map files do not contain bad stuff. If they only contain image map info, you're fine. If anyone can upload, then the other thing to check is that spammers don't put invalid links into the map files. It's not much of a risk, since spammers don't seem to know about this stuff.
- I put this:
text/plain asc txt mpi
- into Apache's mime.types to allow mpi files with text-only mime validation. My files were *.mpi rather than *.map, since map is a common extension for other uses and can have other forms of mime validation. Just change the file types to:
- $wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'pdf', 'mpi' )
- I don't think there's anything else to do. As long as you specify the map file name as foo.mpi everywhere e.g.:
- <ImageMap>Image=[[Media:fooImage.gif]]|Map=[[Media:foo.mpi]]</ImageMap>
- you should be fine.
- PS, it's not my extension, however, I'm familiar with it since I wrote a replacement for it to minimize the risks and allow easy conversion to the Wikipedia-standard imagemap. Michael Daly 20:51, 12 October 2007 (UTC)
Strange MySQL Error in MW 1.6.12
[edit]Database error From site_name Jump to: navigation, search A database query syntax error has occurred. This may indicate a bug in the software. The last attempted database query was: (SQL query hidden) from within function "". MySQL returned error "1146: Table 'wikidb16.egcur' doesn't exist (localhost)".
This is for Mediawiki 1.6.12 Razool