r59744 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59743‎ | r59744 | r59745 >
Date:21:00, 4 December 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.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_OSMDispMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -54,7 +54,7 @@
5555 }
5656
5757 private static function initializeParams() {
58 - global $egMapsAvailableServices, $egMapsDefaultService, $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
 58+ global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
5959
6060 self::$parameters = array(
6161 'service' => array(
@@ -62,7 +62,7 @@
6363 'criteria' => array(
6464 'in_array' => $egMapsAvailableServices
6565 ),
66 - 'default' => $egMapsDefaultService
 66+ 'default' => $egMapsDefaultServices['pf']
6767 ),
6868 'coordinates' => array(
6969 'aliases' => array('coords', 'location', 'locations'),
@@ -335,6 +335,6 @@
336336 }
337337
338338 return $paramValue;
339 - }
 339+ }
340340
341341 }
\ No newline at end of file
Index: trunk/extensions/Maps/Maps.php
@@ -23,40 +23,49 @@
2424 die( 'Not an entry point.' );
2525 }
2626
 27+// Include the Validator extension if that hasn't been done yet, since it's required for Maps to work.
2728 if( !defined( 'Validator_VERSION' ) ) {
28 - // Include the Validator extension if that hasn't been done yet, since it's required for Maps to work.
29 - include_once('extensions/Validator/Validator.php');
 29+ @include_once('extensions/Validator/Validator.php');
3030 }
3131
32 -define('Maps_VERSION', '0.5 a16');
 32+// Only initialize the extension when all dependencies are present.
 33+if (defined( 'Validator_VERSION' )) {
 34+ define('Maps_VERSION', '0.5 a18');
 35+
 36+ $egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
 37+ $egMapsIP = $IP . '/extensions/Maps';
 38+
 39+ $egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
 40+
 41+ // Include the settings file
 42+ require_once($egMapsIP . '/Maps_Settings.php');
 43+
 44+ // Register the initialization function of Maps.
 45+ $wgExtensionFunctions[] = 'efMapsSetup';
 46+
 47+ $wgExtensionMessagesFiles['Maps'] = $egMapsIP . '/Maps.i18n.php';
 48+
 49+ $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks';
 50+
 51+ // Autoload the general classes
 52+ $wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php';
 53+ $wgAutoloadClasses['MapsMapper'] = $egMapsIP . '/Maps_Mapper.php';
 54+ $wgAutoloadClasses['MapsUtils'] = $egMapsIP . '/Maps_Utils.php';
 55+
 56+ if (empty($egMapsServices)) $egMapsServices = array();
 57+}
3358
34 -$egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
35 -$egMapsIP = $IP . '/extensions/Maps';
36 -
37 -$egMapsStyleVersion = $wgStyleVersion . '-' . Maps_VERSION;
38 -
39 -// Include the settings file
40 -require_once($egMapsIP . '/Maps_Settings.php');
41 -
42 -$wgExtensionFunctions[] = 'efMapsSetup';
43 -
44 -$wgExtensionMessagesFiles['Maps'] = $egMapsIP . '/Maps.i18n.php';
45 -
46 -$wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks';
47 -
48 -// Autoload the general classes
49 -$wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php';
50 -$wgAutoloadClasses['MapsMapper'] = $egMapsIP . '/Maps_Mapper.php';
51 -$wgAutoloadClasses['MapsUtils'] = $egMapsIP . '/Maps_Utils.php';
52 -
53 -if (empty($egMapsServices)) $egMapsServices = array();
54 -
5559 /**
5660 * Initialization function for the Maps extension.
5761 */
5862 function efMapsSetup() {
5963 global $wgExtensionCredits, $wgLang, $wgAutoloadClasses, $IP;
6064 global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsDefaultGeoService, $egMapsAvailableGeoServices, $egMapsIP, $egMapsAvailableFeatures;
 65+
 66+ // Remove all hooked in services that should not be available.
 67+ foreach($egMapsServices as $service => $data) {
 68+ if (! in_array($service, $egMapsAvailableServices)) unset($egMapsServices[$service]);
 69+ }
6170
6271 // Enure that the default service and geoservice are one of the enabled ones.
6372 $egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0];
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php
@@ -111,7 +111,7 @@
112112 *
113113 * @return string
114114 */
115 - private function getStaticMap() {
 115+ private function getStaticMap() {
116116 $clickToActivate = wfMsg('maps_click_to_activate');
117117
118118 $mode = MapsOSM::getModeData($this->mode);
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSM.php
@@ -80,7 +80,7 @@
8181 'base_url' => 'http://cassini.toolserver.org/cgi-bin/export',
8282
8383 'format' => 'png',
84 - 'numZoomLevels' => 19,
 84+ 'numZoomLevels' => 16,
8585 'maxResolution' => 156543.0339,
8686 'unit' => 'm',
8787 'sphericalMercator' => true,
@@ -104,7 +104,7 @@
105105 'base_url' => 'http://tile.openstreetmap.org/cgi-bin/export',
106106
107107 'format' => 'png',
108 - 'numZoomLevels' => 19,
 108+ 'numZoomLevels' => 16,
109109 'maxResolution' => 156543.0339,
110110 'unit' => 'm',
111111 'sphericalMercator' => true
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -24,8 +24,7 @@
2525 private static $mainParams;
2626
2727 public static function initializeMainParams() {
28 - global $egMapsAvailableServices, $egMapsDefaultService, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsDefaultCentre;
29 - global $egMapsSizeRestrictions, $egMapsMapWidth, $egMapsMapHeight, $egMapsDefaultTitle, $egMapsDefaultLabel;
 28+ global $egMapsSizeRestrictions, $egMapsMapWidth, $egMapsMapHeight;
3029
3130 self::$mainParams = array
3231 (
@@ -106,55 +105,8 @@
107106 if ($toLower) $itemString = strtolower($itemString);
108107 return $itemString;
109108 }
110 -
111 - /**
112 - * Returns a valid service. When an invalid service is provided, the default one will be returned.
113 - * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName().
114 - *
115 - * @param string $service
116 - * @param string $feature
117 - *
118 - * @return string
119 - */
120 - public static function getValidService($service, $feature) {
121 - global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultServices, $egMapsServices;
122 -
123 - $service = self::getMainServiceName($service);
124 -
125 - $shouldChange = ! array_key_exists($service, $egMapsServices);
126 - if (! $shouldChange) $shouldChange = ! array_key_exists($feature, $egMapsServices[$service]);
127 -
128 - if ($shouldChange) {
129 - $service = array_key_exists($feature, $egMapsDefaultServices) ? $egMapsDefaultServices[$feature] : $egMapsDefaultService;
130 - }
131 -
132 - if(! in_array($service, $egMapsAvailableServices)) $service = $egMapsDefaultService;
133 -
134 - return $service;
135 - }
136109
137110 /**
138 - * Checks if the service name is an alias for an actual service,
139 - * and changes it into the main service name if this is the case.
140 - *
141 - * @param string $service
142 - * @return string
143 - */
144 - public static function getMainServiceName($service) {
145 - global $egMapsServices;
146 -
147 - if (! array_key_exists($service, $egMapsServices)) {
148 - foreach ($egMapsServices as $serviceName => $serviceInfo) {
149 - if (in_array($service, $serviceInfo['aliases'])) {
150 - $service = $serviceName;
151 - }
152 - }
153 - }
154 -
155 - return $service;
156 - }
157 -
158 - /**
159111 * Returns a valid version of the types.
160112 *
161113 * @param array $types
@@ -198,5 +150,51 @@
199151 return $types;
200152 }
201153
202 -
 154+ /**
 155+ * Returns a valid service. When an invalid service is provided, the default one will be returned.
 156+ * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName().
 157+ *
 158+ * @param string $service
 159+ * @param string $feature
 160+ *
 161+ * @return string
 162+ */
 163+ public static function getValidService($service, $feature) {
 164+ global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultServices, $egMapsServices;
 165+
 166+ $service = self::getMainServiceName($service);
 167+
 168+ $shouldChange = ! array_key_exists($service, $egMapsServices);
 169+ if (! $shouldChange) $shouldChange = ! array_key_exists($feature, $egMapsServices[$service]);
 170+
 171+ if ($shouldChange) {
 172+ $service = array_key_exists($feature, $egMapsDefaultServices) ? $egMapsDefaultServices[$feature] : $egMapsDefaultService;
 173+ }
 174+
 175+ if(! in_array($service, $egMapsAvailableServices)) $service = $egMapsDefaultService;
 176+
 177+ return $service;
 178+ }
 179+
 180+ /**
 181+ * Checks if the service name is an alias for an actual service,
 182+ * and changes it into the main service name if this is the case.
 183+ *
 184+ * @param string $service
 185+ * @return string
 186+ */
 187+ private static function getMainServiceName($service) {
 188+ global $egMapsServices;
 189+
 190+ if (! array_key_exists($service, $egMapsServices)) {
 191+ foreach ($egMapsServices as $serviceName => $serviceInfo) {
 192+ if (in_array($service, $serviceInfo['aliases'])) {
 193+ $service = $serviceName;
 194+ break;
 195+ }
 196+ }
 197+ }
 198+
 199+ return $service;
 200+ }
203201 }
Index: trunk/extensions/Maps/Maps.i18n.php
@@ -35,7 +35,7 @@
3636 'maps_googlemaps' => 'Google Maps',
3737 'maps_yahoomaps' => 'Yahoo! Maps',
3838 'maps_openlayers' => 'OpenLayers',
39 - 'maps_osm' => 'OpenStreetMaps',
 39+ 'maps_osm' => 'OpenStreetMap',
4040
4141 // Static maps
4242 'maps_click_to_activate' => 'Click to activate map',
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -65,7 +65,7 @@
6666 include_once $egMapsIP . '/OpenLayers/Maps_OpenLayers.php'; // OpenLayers
6767 include_once $egMapsIP . '/YahooMaps/Maps_YahooMaps.php'; // Yahoo! Maps
6868 include_once $egMapsIP . '/OpenStreetMap/Maps_OSM.php'; // OpenLayers optimized for OSM
69 -
 69+
7070 # Array of String. Array containing all the mapping services that will be made available to the user.
7171 # Currently Maps provides the following services: googlemaps, yahoomaps, openlayers
7272 $egMapsAvailableServices = array('googlemaps', 'yahoomaps', 'openlayers', 'osm');
@@ -78,7 +78,7 @@
7979 # Array of String. The default mapping service for each feature, which will be used when no valid service is provided by the user.
8080 # Each service needs to be enabled, if not, the first one from the available services will be taken.
8181 # Note: The default service needs to be available for the feature you set it for, since it's used as a fallback mechanism.
82 -$egMapsDefaultServices = array('pf' => 'googlemaps', 'qp' => 'googlemaps', 'fi' => 'googlemaps');
 82+$egMapsDefaultServices = array('pf' => 'googlemaps');
8383
8484
8585

Status & tagging log