r59560 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59559‎ | r59560 | r59561 >
Date:19:12, 29 November 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.5. Fixed several issues with parameter validation.
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/Maps_ParamValidator.php (modified) (history)
  • /trunk/extensions/Maps/Maps_ValidationFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -54,9 +54,16 @@
5555 }
5656
5757 private static function initializeParams() {
58 - global $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
 58+ global $egMapsAvailableServices, $egMapsDefaultService, $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
5959
6060 self::$parameters = array(
 61+ 'service' => array(
 62+ 'aliases' => array(),
 63+ 'criteria' => array(
 64+ 'in_array' => $egMapsAvailableServices
 65+ ),
 66+ 'default' => $egMapsDefaultService
 67+ ),
6168 'coordinates' => array(
6269 'aliases' => array('coords', 'location', 'locations'),
6370 'criteria' => array(
Index: trunk/extensions/Maps/Maps.php
@@ -23,7 +23,7 @@
2424 die( 'Not an entry point.' );
2525 }
2626
27 -define('Maps_VERSION', '0.5 a7');
 27+define('Maps_VERSION', '0.5 a8');
2828
2929 // Constants indicating the strictness of the parameter validation.
3030 define('Maps_ERRORS_NONE', 0);
Index: trunk/extensions/Maps/Maps_ValidationFunctions.php
@@ -83,6 +83,34 @@
8484 }
8585 }
8686 return $true;
87 - }
 87+ }
8888
 89+ /**
 90+ * Returns if all items in the string are present in the array.
 91+ * The first element of the $args array should be the delimieter,
 92+ * the second one an array holding the haystack.
 93+ *
 94+ * @param string $needles
 95+ * @param array $args
 96+ *
 97+ * @return boolean
 98+ */
 99+ public static function all_str_in_array($needles, array $args) {
 100+ return self::all_in_array(explode($args[0], $needles), $args[1]);
 101+ }
 102+
 103+ /**
 104+ * Returns if any items in the string are present in the array.
 105+ * The first element of the $args array should be the delimieter,
 106+ * the second one an array holding the haystack.
 107+ *
 108+ * @param string $needles
 109+ * @param array $args
 110+ *
 111+ * @return boolean
 112+ */
 113+ public static function any_str_in_array($needles, array $args) {
 114+ return self::any_in_array(explode($args[0], $needles), $args[1]);
 115+ }
 116+
89117 }
\ No newline at end of file
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -29,13 +29,6 @@
3030
3131 self::$mainParams = array
3232 (
33 - 'service' => array(
34 - 'aliases' => array(),
35 - 'criteria' => array(
36 - 'in_array' => $egMapsAvailableServices
37 - ),
38 - 'default' => $egMapsDefaultService
39 - ),
4033 'zoom' => array(
4134 'aliases' => array(),
4235 'criteria' => array(
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -53,26 +53,26 @@
5454
5555 $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
5656 'zoom' => array(
57 - 'default' => $egMapsGoogleMapsZoom,
58 - ),
 57+ 'default' => $egMapsGoogleMapsZoom,
 58+ ),
5959 'controls' => array(
6060 'criteria' => array(), // TODO
6161 'default' => implode(',', $egMapsGMapControls)
62 - ),
 62+ ),
6363 'type' => array (
6464 'aliases' => array('map-type', 'map type'),
6565 'criteria' => array(
66 - 'in_array' => array($allowedTypes)
 66+ 'in_array' => $allowedTypes
6767 ),
6868 'default' => $egMapsGoogleMapsType
6969 ),
7070 'types' => array (
7171 'aliases' => array('map-types', 'map types'),
7272 'criteria' => array(
73 - 'all_in_array' => array($allowedTypes)
 73+ 'all_str_in_array' => array(',', $allowedTypes)
7474 ),
7575 'default' => implode(',', $egMapsGoogleMapsTypes)
76 - ),
 76+ ),
7777 'autozoom' => array(
7878 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'),
7979 'criteria' => array(
@@ -92,51 +92,29 @@
9393 ),
9494 );
9595 }
96 -
 96+
9797 // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP
98 - // TODO: Add a true alliasing system? Might be overkill.
9998 private static $mapTypes = array(
10099 'normal' => 'G_NORMAL_MAP',
101 - 'G_NORMAL_MAP' => 'G_NORMAL_MAP',
102 -
103100 'satellite' => 'G_SATELLITE_MAP',
104 - 'G_SATELLITE_MAP' => 'G_SATELLITE_MAP',
105 -
106101 'hybrid' => 'G_HYBRID_MAP',
107 - 'G_HYBRID_MAP' => 'G_HYBRID_MAP',
108 -
109102 'terrain' => 'G_PHYSICAL_MAP',
110103 'physical' => 'G_PHYSICAL_MAP',
111 - 'G_PHYSICAL_MAP' => 'G_PHYSICAL_MAP',
112 -
113104 'earth' => 'G_SATELLITE_3D_MAP',
114 - 'G_SATELLITE_3D_MAP' => 'G_SATELLITE_3D_MAP',
115 -
116105 'sky' => 'G_SKY_VISIBLE_MAP',
117 - 'G_SKY_VISIBLE_MAP' => 'G_SKY_VISIBLE_MAP',
118 -
119106 'moon' => 'G_MOON_VISIBLE_MAP',
120 - 'G_MOON_VISIBLE_MAP' => 'G_MOON_VISIBLE_MAP',
121 -
122107 'moon-elevation' => 'G_MOON_ELEVATION_MAP',
123 - 'G_MOON_ELEVATION_MAP' => 'G_MOON_ELEVATION_MAP',
124 -
125108 'mars' => 'G_MARS_VISIBLE_MAP',
126 - 'G_MARS_VISIBLE_MAP' => 'G_MARS_VISIBLE_MAP',
127 -
128109 'mars-elevation' => 'G_MARS_ELEVATION_MAP',
129 - 'G_MARS_ELEVATION_MAP' => 'G_MARS_ELEVATION_MAP',
130 -
131 - 'mars-infrared' => 'G_MARS_INFRARED_MAP',
132 - 'G_MARS_INFRARED_MAP' => 'G_MARS_INFRARED_MAP',
 110+ 'mars-infrared' => 'G_MARS_INFRARED_MAP'
133111 );
134 -
 112+
135113 private static $overlayData = array(
136114 'photos' => '0',
137115 'videos' => '1',
138116 'wikipedia' => '2',
139117 'webcams' => '3'
140 - );
 118+ );
141119
142120 /**
143121 * Returns the names of all supported map types.
@@ -146,7 +124,7 @@
147125 public static function getTypeNames() {
148126 return array_keys(self::$mapTypes);
149127 }
150 -
 128+
151129 /**
152130 * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes)
153131 * for the provided a general map type. When no match is found, false
@@ -182,12 +160,12 @@
183161 public static function addGMapDependencies(&$output) {
184162 global $wgJsMimeType, $wgLang;
185163 global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage, $egMapsStyleVersion;
186 -
 164+
187165 if (empty($egGoogleMapsOnThisPage)) {
188166 $egGoogleMapsOnThisPage = 0;
189167
190168 MapsGoogleMaps::validateGoogleMapsKey();
191 -
 169+
192170 // TODO: use strbuilder for performance gain?
193171 $output .= "<script src='http://maps.google.com/maps?file=api&v=2&key=$egGoogleMapsKey&hl={$wgLang->getCode()}' type='$wgJsMimeType'></script>
194172 <script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps/GoogleMapFunctions.js?$egMapsStyleVersion'></script>
Index: trunk/extensions/Maps/Maps_ParamValidator.php
@@ -46,6 +46,8 @@
4747 'not_empty' => array('MapsValidationFunctions', 'not_empty'),
4848 'all_in_array' => array('MapsValidationFunctions', 'all_in_array'),
4949 'any_in_array' => array('MapsValidationFunctions', 'any_in_array'),
 50+ 'all_str_in_array' => array('MapsValidationFunctions', 'all_str_in_array'),
 51+ 'any_str_in_array' => array('MapsValidationFunctions', 'any_str_in_array'),
5052 );
5153
5254 private $parameterInfo;

Status & tagging log