r60259 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60258‎ | r60259 | r60260 >
Date:15:06, 21 December 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.5.1. Extended static map support.
Modified paths:
  • /trunk/extensions/Maps/Geocoders/Maps_BaseGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSM.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMCgiBin.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.php
@@ -33,7 +33,7 @@
3434 echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.';
3535 }
3636 else {
37 - define('Maps_VERSION', '0.5.1 a1');
 37+ define('Maps_VERSION', '0.5.1 a2');
3838
3939 $egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
4040 $egMapsIP = $IP . '/extensions/Maps';
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMCgiBin.php
@@ -63,21 +63,24 @@
6464 * @return string
6565 */
6666 public function getUrl() {
67 - $args =
68 - $this->options['base_url']
69 - . '?'
70 - . 'bbox=' . implode( ',', $this->bounds )
71 - . '&amp;scale=' . $this->scale
72 - . '&amp;format=' . $this->options['format'];
73 -
74 - // Hack to support my custom cgi-bin/export script
75 - if ( isset( $this->options['get_args'] ) ) {
76 - $args .=
77 - '&amp;maptype=' . $this->options['get_args']['maptype']
78 - . '&amp;locale=' . $this->lang;
 67+ $urlElements = array();
 68+
 69+ $urlElements[] = $this->options['base_url'];
 70+ $urlElements[] = '?bbox=';
 71+ $urlElements[] = implode( ',', $this->bounds );
 72+ $urlElements[] = '&amp;scale=';
 73+ $urlElements[] = $this->scale;
 74+ $urlElements[] = '&amp;format=';
 75+ $urlElements[] = $this->options['format'];
 76+ $urlElements[] = '&amp;locale=';
 77+ $urlElements[] = $this->lang;
 78+
 79+ if (array_key_exists('maptype', $this->options)) {
 80+ $urlElements[] = '&amp;maptype=';
 81+ $urlElements[] = $this->options['maptype'];
7982 }
8083
81 - return $args;
 84+ return implode('', $urlElements);
8285 }
8386
8487 /**
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php
@@ -22,7 +22,7 @@
2323 *
2424 */
2525 protected function setMapSettings() {
26 - global $egMapsOSMZoom, $egMapsOSMPrefix;
 26+ global $egMapsOSMZoom, $egMapsOSMPrefix,$egMapsOSMStaticAsDefault, $egMapsOSMStaticActivatable;
2727
2828 $this->elementNamePrefix = $egMapsOSMPrefix;
2929 $this->defaultZoom = $egMapsOSMZoom;
@@ -34,14 +34,20 @@
3535 'criteria' => array(
3636 'in_array' => array('yes', 'no')
3737 ),
38 - 'default' => 'no'
 38+ 'default' => $egMapsOSMStaticAsDefault ? 'yes' : 'no'
3939 ),
4040 'mode' => array(
4141 'criteria' => array(
4242 'in_array' => $modes
4343 ),
44 - 'default' => $modes[0]
45 - ),
 44+ 'default' => $modes[0]
 45+ ),
 46+ 'activatable' => array(
 47+ 'criteria' => array(
 48+ 'in_array' => array('yes', 'no')
 49+ ),
 50+ 'default' => $egMapsOSMStaticActivatable ? 'yes' : 'no'
 51+ ),
4652 );
4753 }
4854
@@ -84,7 +90,6 @@
8591 EOT;
8692
8793 $this->output .= $this->static == 'yes' ? $this->getStaticMap() : $this->getDynamicMap();
88 -
8994 }
9095
9196 /**
@@ -110,30 +115,35 @@
111116 * @return string
112117 */
113118 private function getStaticMap() {
114 - $clickToActivate = wfMsg('maps_click_to_activate');
115 -
116119 $mode = MapsOSM::getModeData($this->mode);
117120
118 - $staticType = $mode['static_rendering']['type'];
119 - $staticOptions = $mode['static_rendering']['options'];
 121+ $staticType = $mode['handler'];
 122+ $staticOptions = $mode['options'];
120123
121 - $static = new $staticType($this->centre_lat, $this->centre_lon, $this->zoom, $this->width, $this->height, $this->lang, $staticOptions);
122 - $rendering_url = $static->getUrl();
 124+ $static = new $staticType($this->centre_lat, $this->centre_lon, $this->zoom, $this->width, $this->height, $this->lang, $staticOptions);
 125+ $rendering_url = $static->getUrl();
123126
 127+ $alt = wfMsg('maps_centred_on') . " $this->centre_lat, $this->centre_lon.";
 128+
 129+ if ($this->activatable != 'no') {
 130+ $title = wfMsg('maps_click_to_activate');
 131+ $activationCode = "onclick=\"slippymaps['$this->mapName'].init();\"";
 132+ }
 133+ else {
 134+ $activationCode = '';
 135+ $title = $alt;
 136+ }
 137+
124138 return <<<EOT
125 - <!-- map div -->
126139 <div id="$this->mapName" class="map" style="width:{$this->width}px; height:{$this->height}px;">
127 - <!-- Static preview -->
128 - <img
129 - id="$this->mapName-preview"
 140+ <img id="$this->mapName-preview"
130141 class="mapPreview"
131 - src="{$rendering_url}"
132 - onclick="slippymaps['$this->mapName'].init();"
 142+ src="{$rendering_url}"
133143 width="$this->width"
134144 height="$this->height"
135 - alt="Map centred on $this->centre_lat, $this->centre_lon."
136 - title="$clickToActivate"/>
137 - <!-- /map div -->
 145+ alt="$alt"
 146+ title="$title"
 147+ $activationCode />
138148 </div>
139149 EOT;
140150 }
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSM.php
@@ -94,57 +94,49 @@
9595
9696 private static $modes = array(
9797 'osm-wm' => array(
98 - // First layer = default
99 - 'layers' => array( 'osm-like' ),
 98+ 'handler' => 'MapsOSMCgiBin',
 99+ 'options' => array(
 100+ 'base_url' => 'http://cassini.toolserver.org/cgi-bin/export',
 101+
 102+ 'format' => 'png',
 103+ 'numZoomLevels' => 16,
 104+ 'maxResolution' => 156543.0339,
 105+ 'unit' => 'm',
 106+ 'sphericalMercator' => true,
100107
101 - 'static_rendering' => array(
102 - 'type' => 'MapsOSMCgiBin',
103 - 'options' => array(
104 - 'base_url' => 'http://cassini.toolserver.org/cgi-bin/export',
105 -
106 - 'format' => 'png',
107 - 'numZoomLevels' => 16,
108 - 'maxResolution' => 156543.0339,
109 - 'unit' => 'm',
110 - 'sphericalMercator' => true,
111 -
112 - // More GET arguments
113 - 'get_args' => array(
114 - 'locale' => true, // Will use $wgContLang->getCode()
115 - 'maptype' => 'osm-like'
116 - ),
117 - ),
 108+ 'maptype' => 'osm-like'
118109 ),
119110 ),
120111
121112 'osm' => array(
122 - // First layer = default
123 - 'layers' => array( 'mapnik', 'osmarender', 'maplint', 'cycle' ),
124 -
125 - 'static_rendering' => array(
126 - 'type' => 'MapsOSMCgiBin',
127 - 'options' => array(
128 - 'base_url' => 'http://tile.openstreetmap.org/cgi-bin/export',
129 -
130 - 'format' => 'png',
131 - 'numZoomLevels' => 16,
132 - 'maxResolution' => 156543.0339,
133 - 'unit' => 'm',
134 - 'sphericalMercator' => true
135 - ),
 113+ 'handler' => 'MapsOSMCgiBin',
 114+ 'options' => array(
 115+ 'base_url' => 'http://tile.openstreetmap.org/cgi-bin/export',
 116+
 117+ 'format' => 'png',
 118+ 'numZoomLevels' => 16,
 119+ 'maxResolution' => 156543.0339,
 120+ 'unit' => 'm',
 121+ 'sphericalMercator' => true
136122 ),
137123 ),
138 -
139 - 'satellite' => array(
140 - 'layers' => array( 'urban', 'landsat', 'bluemarble' ),
141 - 'static_rendering' => null,
142 - ),
143124 );
144125
 126+ /**
 127+ * Returns an array containing the names of all modes.
 128+ *
 129+ * @return array
 130+ */
145131 public static function getModeNames() {
146132 return array_keys(self::$modes);
147133 }
148134
 135+ /**
 136+ * Returns the data of a mode.
 137+ *
 138+ * @param string $modeName
 139+ * @return array
 140+ */
149141 public static function getModeData($modeName) {
150142 return self::$modes[$modeName];
151143 }
Index: trunk/extensions/Maps/Maps.i18n.php
@@ -39,6 +39,7 @@
4040
4141 // Static maps
4242 'maps_click_to_activate' => 'Click to activate map',
 43+ 'maps_centred_on' => 'Map centred on',
4344
4445 // Google Maps overlays
4546 'maps_overlays' => 'Overlays',
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -171,7 +171,7 @@
172172 $egMapsGoogleAutozoom = true;
173173
174174 # Array of String. The default controls for Google Maps. This value will only be used when the user does not provide one.
175 -# Available values: auto, large, small, large-original, small-original, zoom, type, type-menu, overview-map, scale, nav-label
 175+# Available values: auto, large, small, large-original, small-original, zoom, type, type-menu, overview-map, scale, nav-label, overlays
176176 $egMapsGMapControls = array('auto', 'scale', 'type', 'overlays');
177177
178178 # Array. The default overlays for the Google Maps overlays control, and wether they should be shown at pageload.
@@ -237,4 +237,7 @@
238238
239239 # Array of String. The default controls for OSM maps. This value will only be used when the user does not provide one.
240240 # Available values: layerswitcher, mouseposition, autopanzoom, panzoom, panzoombar, scaleline, navigation, keyboarddefaults, overviewmap, permalink
241 -$egMapsOSMControls = array('layerswitcher', 'mouseposition', 'autopanzoom', 'scaleline', 'navigation');
\ No newline at end of file
 241+$egMapsOSMControls = array('layerswitcher', 'mouseposition', 'autopanzoom', 'scaleline', 'navigation');
 242+
 243+$egMapsOSMStaticAsDefault = false;
 244+$egMapsOSMStaticActivatable = true;
\ No newline at end of file
Index: trunk/extensions/Maps/Geocoders/Maps_BaseGeocoder.php
@@ -58,7 +58,6 @@
5959 if (array_key_exists('HTTP_USER_AGENT', $_SERVER))
6060 curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
6161 // TODO else curl_setopt($ch, CURLOPT_USERAGENT, "MediaWiki/Maps extension");
62 - //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
6362 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
6463
6564 $result = curl_exec($ch);

Follow-up revisions

RevisionCommit summaryAuthorDate
r60261i18n/L10n correction on r60259siebrand16:05, 21 December 2009

Status & tagging log