r53051 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53050‎ | r53051 | r53052 >
Date:13:55, 10 July 2009
Author:avar
Status:deferred
Tags:
Comment:
* Cleaned up SlippyMap.php a bit, e.g. linking to docs on
mediawiki.org instead of maintaining them in the source where
they're bound to get out of date
* Setting our ParserAfterTidy hook in onParserFirstCallInit instead of
in the main file
* Adding parsertests for slippymap, they fail horribly but I'll fix
them up
Modified paths:
  • /trunk/extensions/SlippyMap/SlippyMap.hooks.php (modified) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.php (modified) (history)
  • /trunk/extensions/SlippyMap/slippyMapParserTests.txt (added) (history)

Diff [purge]

Index: trunk/extensions/SlippyMap/SlippyMap.php
@@ -1,81 +1,67 @@
2 -<?php
 2+<?php
 3+if ( ! defined( 'MEDIAWIKI' ) )
 4+ die();
35 /**
4 -* @file
5 -*
6 -* @section DESCRIPTION
7 -*
8 -* OpenStreetMap SlippyMap - MediaWiki extension
9 -*
10 -* This defines what happens when <slippymap> tag is placed in the wikitext
11 -*
12 -* We show a map based on the lat/lon/zoom data passed in. This extension brings in
13 -* the OpenLayers javascript, to show a slippy map.
14 -*
15 -* Usage example:
16 -* <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender></slippymap>
17 -*
18 -* Tile images are not cached local to the wiki.
19 -* To acheive this (remove the OSM dependency) you might set up a squid proxy,
20 -* and modify the requests URLs here accordingly.
21 -*
22 -* This file should be placed in the mediawiki 'extensions' directory
23 -* ...and then it needs to be 'included' within LocalSettings.php
24 -*
25 -* @section LICENSE
26 -*
27 -* Copyright 2008 Harry Wood, Jens Frank, Grant Slater, Raymond Spekking and others
28 -*
29 -* This program is free software; you can redistribute it and/or modify
30 -* it under the terms of the GNU General Public License as published by
31 -* the Free Software Foundation; either version 2 of the License, or
32 -* (at your option) any later version.
33 -*
34 -* This program is distributed in the hope that it will be useful,
35 -* but WITHOUT ANY WARRANTY; without even the implied warranty of
36 -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 -* GNU General Public License for more details.
38 -*
39 -* You should have received a copy of the GNU General Public License
40 -* along with this program; if not, write to the Free Software
41 -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
42 -*
 6+ * SlippyMap extension
 7+ *
 8+ * @file
 9+ * @ingroup Extension
 10+ *
 11+ * This file contains the main include file for the SlippyMap
 12+ * extension of MediaWiki.
 13+ *
 14+ * Usage: Add the following line in LocalSettings.php:
 15+ * require_once( "$IP/extensions/SlippyMap/SlippyMap.php" );
 16+ *
 17+ * See the SlippyMap documenation on mediawiki.org for further usage
 18+ * information.
 19+ *
 20+ * @link http://www.mediawiki.org/wiki/Extension:SlippyMap Documentation
 21+ *
 22+ * Copyright 2008 Harry Wood, Jens Frank, Grant Slater, Raymond Spekking and others
 23+ *
 24+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
4325 */
4426
45 -/**
46 - * Checks if the file is being executed within MediaWiki
47 - */
48 -if ( !defined( 'MEDIAWIKI' ) )
49 - die();
 27+if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
 28+ $wgHooks['ParserFirstCallInit'][] = 'SlippyMapHooks::onParserFirstCallInit';
 29+} else {
 30+ $wgExtensionFunctions[] = 'SlippyMapHooks::onParserFirstCallInit';
 31+}
5032
51 -
52 -/**
53 -* Property: Extension credits
54 -*/
5533 $wgExtensionCredits['parserhook'][] = array(
5634 'path' => __FILE__,
5735 'name' => 'Slippy Map',
58 - 'author' => array( '[http://harrywood.co.uk Harry Wood]', 'Jens Frank', 'Aude', 'Ævar Arnfjörð Bjarmason'),
 36+ 'author' => array('[http://harrywood.co.uk Harry Wood]', 'Jens Frank', 'Aude', 'Ævar Arnfjörð Bjarmason'),
5937 'url' => 'http://www.mediawiki.org/wiki/Extension:SlippyMap',
60 - 'description' => 'Adds a &lt;slippymap&gt; which allows for embedding of static & dynamic maps. Supports multiple map services including [http://openstreetmap.org OpenStreetMap] and NASA Worldwind',
 38+ 'description' => 'Adds a &lt;slippymap&gt; which allows for embedding of static & dynamic maps.Supports multiple map services including [http://openstreetmap.org OpenStreetMap] and NASA Worldwind',
6139 'descriptionmsg' => 'slippymap_desc',
6240 );
6341
 42+/* Shortcut to this extension directory */
6443 $dir = dirname( __FILE__ ) . '/';
6544
66 -$wgMapModes = array( 'osm', 'satellite' );
 45+/* i18n messages */
 46+$wgExtensionMessagesFiles['SlippyMap'] = $dir . 'SlippyMap.i18n.php';
6747
68 -$wgAutoLoadMaps = false;
 48+/* The classes which make up our extension*/
 49+$wgAutoloadClasses['SlippyMapHooks'] = $dir . 'SlippyMap.hooks.php';
 50+$wgAutoloadClasses['SlippyMap'] = $dir . 'SlippyMap.class.php';
 51+$wgAutoloadClasses['WorldWind'] = $dir . 'SlippyMap.worldwind.php';
6952
70 -$wgExtensionMessagesFiles['SlippyMap'] = $dir . 'SlippyMap.i18n.php';
 53+/* Parser tests */
 54+$wgParserTestFiles[] = $dir . '/slippyMapParserTests.txt';
7155
72 -$wgAutoloadClasses['SlippyMapHooks'] = $dir . 'SlippyMap.hooks.php';
73 -$wgAutoloadClasses['SlippyMap'] = $dir . 'SlippyMap.class.php';
74 -$wgAutoloadClasses['WorldWind'] = $dir . 'SlippyMap.worldwind.php';
 56+/*
 57+ * Configuration variables
 58+ */
7559
76 -if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
77 - $wgHooks['ParserFirstCallInit'][] = 'SlippyMapHooks::onParserFirstCallInit';
78 -} else {
79 - $wgExtensionFunctions[] = 'SlippyMapHooks::onParserFirstCallInit';
80 -}
 60+/* Allowed mode= values on this server */
 61+$wgMapModes = array( 'osm', 'satellite' );
8162
82 -$wgHooks['ParserAfterTidy'][] = 'SlippyMapHooks::wfSlippyMapParserAfterTidy';
 63+/*
 64+ * If true the a JS slippy map will be shown by default to supporting
 65+ * clients, otherwise they'd have to click on the static image to
 66+ * enable the slippy map.
 67+ */
 68+$wgAutoLoadMaps = false;
Index: trunk/extensions/SlippyMap/SlippyMap.hooks.php
@@ -37,6 +37,7 @@
3838
3939 public static function onParserFirstCallInit( ) {
4040 global $wgArticle, $wgOut, $wgLang, $wgParser, $wgScriptPath, $wgJsMimeType, $wgStyleVersion, $wgAutoLoadMaps;
 41+ global $wgHooks;
4142
4243 $smh = new SlippyMapHooks();
4344
@@ -73,7 +74,7 @@
7475 $wgOut->addScript( "<script type='$wgJsMimeType' src='" . $wgScriptPath . "/extensions/SlippyMap/OpenLayers/public/OpenLayers.js?{$wgStyleVersion}'></script>" );
7576 $wgOut->addScript( "<script type='$wgJsMimeType' src='" . $wgScriptPath . "/extensions/SlippyMap/SlippyMap.js?{$wgStyleVersion}'></script>" );
7677 $wgOut->addLink( array( 'rel' => 'stylesheet','type' => 'text/css','href' => $wgScriptPath . '/extensions/SlippyMap/SlippyMap.css' ) );
77 -
 78+ $wgHooks['ParserAfterTidy'][] = 'SlippyMapHooks::wfSlippyMapParserAfterTidy';
7879 $wgParser->setHook( 'slippymap', array( $smh, 'wfParseMapAttributes' ) );
7980 }
8081
Index: trunk/extensions/SlippyMap/slippyMapParserTests.txt
@@ -0,0 +1,28 @@
 2+# Force the test runner to ensure the extension is loaded
 3+!! hooks
 4+slippymap
 5+!! endhooks
 6+
 7+!! test
 8+SlippyMap FIXME: add tests
 9+!! input
 10+<p>FIXME: add tests</p>
 11+!! result
 12+<p>FIXME: add tests</p>
 13+
 14+!! end
 15+
 16+
 17+!! test
 18+SlippyMap: {{#tag:}}
 19+!! input
 20+{{#tag:slippymap
 21+|Blah blah
 22+|mode = osm
 23+|lat = 64.64
 24+|lon = -21.21
 25+|layer = mapnik
 26+}}
 27+!! result
 28+
 29+!! end

Status & tagging log