MediaWiki扩展:Google Maps处理
天下维客,你可以修改的网络知识库
本文取自元维基,欢迎共同翻译、整理与大家共享,促进中文wiki发展^_^
| Template:If | |
| Type: | Extension |
|---|---|
| Maturity: | stable |
| MediaWiki: | 1.5 and 1.6 |
| Version: | 0.5.3 |
| Last Update: | 2006-05-11 |
| Description: | Easily create Google maps, and populate them with wiki-fied place markers. |
| MediaWiki extensions | |
GoogleMapsExtension lets wiki users insert satellite and street maps with custom place markers.
Version 0.5.x (5/11/2006) adds an editor's map into the "Edit" page. It is compatible only with MediaWiki 1.6.0 and later. See #Editor's map for details on the editor's map, and #Upgrading or #Installation for the appropriate instructions.
- 0.5.3 fixes a bug introduced in 0.5.2 that prevented compatibility with Safari.
- 0.5.2 fixes a bug that prevented other extensions from using the "EditPage::showEditForm:initial" hook.
- 0.5.1 has cleaner code than 0.5.0, but adds no new features or bug fixes.
Version 0.4.0 (5/7/2006) makes several improvements:
- Modifications to the skin files are no longer necessary
- Each article can now contain more than one map
- Calls to maps.google.com are only made on pages that actually have maps.
Version 0.3.0 (4/3/2006):
- migrates to version 2 of the Google Maps API
- patches a JavaScript injection vulnerability
- fixes a memory leak in Internet Explorer.
All users are advised to upgrade to version 0.3.0 or later.
I wrote this extension because the existing Google Maps extensions weren't flexible or intuitive enough. I couldn't figure out how to just make a map with labels I wanted with User:Mafs/GoogleMapExtension, GISWiki/GoogleMapExtension, or User:IndyGreg/GoogleMapExtension; as far as I can tell, they all require additional <geo> tags associated with your wiki pages, or they need RSS feeds, or they force every label to point to a particular page. This extension is meant to be as simple as possible: it just lets you define points on a map and give them labels, which can themselves contain wiki mark-up.
目录 |
Installation
0. Get a Google Maps API key from [1]. Be sure to enter a URL that will contain all wiki pages as sub-directories, e.g., http://wso.williams.edu/ or http://wso.williams.edu/wiki/.
1. Add this to LocalSettings.php:
$wgGoogleMapsKey = "your key goes here"; require_once( "extensions/GoogleMaps.php" );
2. Download the appropriate file into the extensions folder:
- User:Emiller/GoogleMapsExtension/GoogleMaps.php (version 0.5.1, for MediaWiki 1.6.x) or
- User:Emiller/GoogleMapsExtension/GoogleMaps.php (version 0.4.0, for MediaWiki 1.5.x)
Usage
Syntax
This extension defines a <googlemap> tag. Legal attributes are:
- width (in pixels; defaults to 740)
- height (in pixels; defaults to 600)
- lat (the center latitude on the map)
- lon (the center longitude on the map)
- zoom (the zoom level; 0 is the furthest away, 17 is the closest in)
- type (legal values are normal (or, equivalently, map), hybrid, and satellite; defaults to hybrid)
- controls (small creates +/- zoom buttons, medium has zoom buttons and pan buttons, and large has pan buttons with a sliding scale for zoom)
All attributes are optional. In the content of the tag, you can define one marker per line. Each line should have the latitude, then a comma, then the longitude, then a comma, then a label for the point. The label can include wiki mark-up. So for example:
<googlemap lat="42.711618" lon="-73.205112" zoom="2" controls="small"> 42.711618,-73.205112,the famous [[Sawyer Library]] 42.714779,-73.204544,[[Williams Hall]], a freshman dorm </googlemap>
Will put down two markers with labels "the famous Sawyer Library" and "Williams Hall, a freshman dorm".
Editor's map
As of version 0.5.0, the Google Maps Extension adds features to the "Edit" page to make it easy to define a map and plot points. It inserts a link that says "show map" above the toolbar buttons (bold, italic, etc.). Clicking this link will bring up an editor's map with the latitude, longitude, zoom level, and type specified in $wgGoogleMapsDefaults (see #Re-defining the default values). The user can drag and zoom as normal. However, single-clicking on the map will place a marker on the map. If the user clicks on the marker he just created, a balloon will appear with two links:
- "insert map centered here"
- "add a point here"
The first link will insert a <googlemap> tag into the edit pane wherever the user's text cursor is. This tag will take on the latitude and longitude of the current marker, and the zoom level and type that the editor's map currently has.
The link to "add a point here" will insert the syntax necessary to create a point, e.g.
42.711618,-73.205112,label goes here
and will highlight the phrase "label goes here" (at least in Firefox). Be sure to put your cursor inside your <googlemap></googlemap> tags before clicking "add a point here".
When you're done using the editor's map, just click "hide map" above the toolbar buttons.
Examples
(Feel free to add your own, I'd love to know who's using this extension.)
- Marshall Foundation Annotated History Books
- Tree-climbing at Williams College
- Places to take children in Tokyo
- kTunes Users
- SingletrackWiki
- Sonar 2006 Map on krass.com
- Manitowoc Ultimate Frisbee Concern
Compatible MediaWikis
Google Maps Extension 0.4.x and earlier have been tested to work with both MediaWiki 1.5 and MediaWiki 1.6.
Google Maps Extension 0.5.0 and later work only with MediaWiki 1.6.
Compatible Browsers
Version 0.4.0 of this extension has been test to work on the following browsers (please add to the list if this page shows a map under another browser/version/platform):
- Mozilla 1.7.12 (Windows XP SP2)
- SeaMonkey 1.0 (Windows XP SP2)
- Internet Explorer 6.0 (Windows XP)
- Firefox 1.5 (Mac, Windows XP, Linux [Debian Sarge Unstable/Testing])
- Firefox 1.0 (Mac, Windows XP)
- Opera 8.5 (Mac, Windows 98, Linux [Gentoo])
- Safari 2.0 (Mac)
- Camino 0.8 (Mac)
Version 0.5.0 (including the editor's map) has been tested to work on:
- Firefox 1.5 (Mac, Windows XP)
- Internet Explorer 6.0 (Windows XP)
- Safari 2.0 (Mac)
Re-defining the default values
(0.1.1 and higher) You can re-define the default googlemap attributes in LocalSettings.php; just define keys and values for an associative array called $wgGoogleMapsDefaults. E.g.
$wgGoogleMapsDefaults = array( "zoom" => 4, "type" => "hybrid", "lat" => 42.711 );
These values will apply when the user has not defined them in the <googlemap> tag, and the zoom, type, lat, and lon will be used for creating the editor's map.
Debugging
Note that a new map will be generated only when you save a change to the page that contains the <googlemap>. If you want to test changes to the server just by hitting "Reload" in your browser, add "?action=purge" to the end of the URL. That will ensure that the entire page is generated fresh every time you load it, rather than every time you save it. Alternatively, you can switch off server-side caching altogether by adding this line to LocalSettings.php:
$wgEnableParserCache = false;
Upgrading
From Google Maps Extension 0.4.x
Make sure you're running MediaWiki 1.6.x, and then just put a fresh copy of User:Emiller/GoogleMapsExtension/GoogleMaps.php into your extensions/ folder.
From Google Maps Extension 0.3.x
Note: If you're planning to upgrade MediaWiki anyway, you can just follow the #Installation instructions on your new copy of MediaWiki. However, you may still need to regenerate all of the maps on your site, so be sure to look at step #3 (below) after installation.
Below are instructions on upgrading your GoogleMapsExtension to version 0.4 from a previous version. Since version 0.4 does not require modifications to the skin files, we'll have to un-modify them first, then regenerate all our maps.
0. First, put the appropriate file into your extensions/ folder:
- User:Emiller/GoogleMapsExtension/GoogleMaps.php (version 0.5.1, for MediaWiki 1.6.x), or
- User:Emiller/GoogleMapsExtension/GoogleMaps.php (version 0.4.0, for MediaWiki 1.5.x)
1. Next, open up skins/MonoBook.php and remove these two lines from execute() (line 49-ish):
global $wgGoogleMapsKey;
...
<script src="http://maps.google.com/maps?file=api&v=2&key=<?php echo $wgGoogleMapsKey ?>" type="<?php $this->text('jsmimetype') ?>"></script>
2. Open up includes/Skin.php and remove this line from getHeadScripts() (line 176-ish):
$r .= "<script src=\"http://maps.google.com/maps?file=api&v=2&key={$wgGoogleMapsKey}\" type=\"{$wgJsMimeType}\"></script>\n";
Also, remove $wgGoogleMapsKey from the list of globals two lines above it.
3. If your parser cache is turned on (and it is by default; see $wgEnableParserCache for details), then you will need to regenerate all of the pages that had a map before you upgraded to Version 0.4. For each page that has a map, add "?action=purge" to the end of the page URL in your browser and press return. You might receive a prompt that says "Clear cache?" If so, press OK.
From Google Maps Extension 0.2.x or lower
First, follow the instructions for upgrading from 0.3.x.
Next, you'll need to change the zoom levels. In Version 1 of the Google Maps API, lower zoom numbers meant the map was closer up; but in Version 2, which Google Maps Extension 0.3 and later uses, lower zoom numbers mean the view is further away. To convert your old zoom numbers, use the formula:
newzoom = 17 - oldzoom
Just go through all of your existing maps, compute the new zoom number, and save.
Feature Requests
Just leave a note on the discussion page.
原文参见: Google Maps Extension


