Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -/** |
| 4 | +/** |
5 | 5 | * A class that holds static helper functions for common functionality that is not map-spesific. |
6 | 6 | * |
7 | 7 | * @file Maps_Mapper.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | } |
16 | 16 | |
17 | 17 | final class MapsMapper { |
18 | | - |
| 18 | + |
19 | 19 | public static function initialize() { |
20 | 20 | global $egMapsSizeRestrictions, $egMapsMapWidth, $egMapsMapHeight; |
21 | 21 | |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | Validator::addOutputFormat( 'coordinateSet', array( __CLASS__, 'formatLocation' ) ); |
28 | 28 | Validator::addOutputFormat( 'coordinateSets', array( __CLASS__, 'formatLocations' ) ); |
29 | 29 | } |
30 | | - |
| 30 | + |
31 | 31 | public static function isLocation( $location ) { |
32 | 32 | if ( self::geocoderIsAvailable() ) { |
33 | 33 | return MapsGeocoder::isLocation( $location ); |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | return MapsCoordinateParser::areCoordinates( $location ); |
36 | 36 | } |
37 | 37 | } |
38 | | - |
| 38 | + |
39 | 39 | public static function areLocations( $locations ) { |
40 | 40 | $locations = (array)$locations; |
41 | 41 | foreach ( $locations as $location ) { |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | } |
46 | 46 | return true; |
47 | 47 | } |
48 | | - |
| 48 | + |
49 | 49 | public static function formatLocation( &$location ) { |
50 | 50 | if ( self::geocoderIsAvailable() ) { |
51 | 51 | $location = MapsGeocoder::attemptToGeocodeToString( $location ); |
— | — | @@ -52,21 +52,21 @@ |
53 | 53 | $location = MapsCoordinateParser::parseAndFormat( $location ); |
54 | 54 | } |
55 | 55 | } |
56 | | - |
| 56 | + |
57 | 57 | public static function formatLocations( &$locations ) { |
58 | 58 | $locations = (array)$locations; |
59 | 59 | foreach ( $locations as &$location ) { |
60 | 60 | self::formatLocation( $location ); |
61 | 61 | } |
62 | 62 | } |
63 | | - |
| 63 | + |
64 | 64 | /** |
65 | 65 | * Returns a valid service. When an invalid service is provided, the default one will be returned. |
66 | 66 | * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName(). |
67 | 67 | * |
68 | 68 | * @param string $service |
69 | 69 | * @param string $feature |
70 | | - * |
| 70 | + * |
71 | 71 | * @return string |
72 | 72 | */ |
73 | 73 | public static function getValidService( $service, $feature ) { |
— | — | @@ -93,10 +93,10 @@ |
94 | 94 | $service = $egMapsDefaultService; |
95 | 95 | } |
96 | 96 | } |
97 | | - |
| 97 | + |
98 | 98 | return $service; |
99 | 99 | } |
100 | | - |
| 100 | + |
101 | 101 | /** |
102 | 102 | * Checks if the service name is an alias for an actual service, |
103 | 103 | * and changes it into the main service name if this is the case. |
— | — | @@ -106,7 +106,7 @@ |
107 | 107 | */ |
108 | 108 | private static function getMainServiceName( $service ) { |
109 | 109 | global $egMapsServices; |
110 | | - |
| 110 | + |
111 | 111 | if ( ! array_key_exists( $service, $egMapsServices ) ) { |
112 | 112 | foreach ( $egMapsServices as $serviceName => $serviceInfo ) { |
113 | 113 | if ( in_array( $service, $serviceInfo['aliases'] ) ) { |
— | — | @@ -115,23 +115,23 @@ |
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | | - |
| 119 | + |
120 | 120 | return $service; |
121 | 121 | } |
122 | | - |
| 122 | + |
123 | 123 | /** |
124 | 124 | * Determines if a value is a valid map dimension, and optionally corrects it. |
125 | | - * |
| 125 | + * |
126 | 126 | * @param string or number $value The value as it was entered by the user. |
127 | | - * @param string $dimension Must be width or hieght. |
| 127 | + * @param string $dimension Must be width or height. |
128 | 128 | * @param boolean $correct If true, the value will be corrected when invalid. Defaults to false. |
129 | 129 | * @param number $default The default value for this dimension. Must be set when $correct = true. |
130 | | - * |
| 130 | + * |
131 | 131 | * @return boolean |
132 | 132 | */ |
133 | 133 | public static function isMapDimension( &$value, $dimension, $correct = false, $default = 0 ) { |
134 | 134 | global $egMapsSizeRestrictions; |
135 | | - |
| 135 | + |
136 | 136 | // See if the notation is valid. |
137 | 137 | if ( !preg_match( '/^\d+(\.\d+)?(px|ex|em|%)?$/', $value ) ) { |
138 | 138 | if ( $correct ) { |
— | — | @@ -140,7 +140,7 @@ |
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | } |
144 | | - |
| 144 | + |
145 | 145 | // Determine the minimum and maximum values. |
146 | 146 | if ( preg_match( '/^.*%$/', $value ) ) { |
147 | 147 | if ( count( $egMapsSizeRestrictions[$dimension] >= 4 ) ) { |
— | — | @@ -155,7 +155,7 @@ |
156 | 156 | $min = $egMapsSizeRestrictions[$dimension][0]; |
157 | 157 | $max = $egMapsSizeRestrictions[$dimension][1]; |
158 | 158 | } |
159 | | - |
| 159 | + |
160 | 160 | // See if the actual value is withing the limits. |
161 | 161 | $number = preg_replace( '/[^0-9]/', '', $value ); |
162 | 162 | if ( $number < $egMapsSizeRestrictions[$dimension][0] ) { |
— | — | @@ -171,22 +171,22 @@ |
172 | 172 | return false; |
173 | 173 | } |
174 | 174 | } |
175 | | - |
| 175 | + |
176 | 176 | // If this is a 'correct the value call', add 'px' if no unit has been provided. |
177 | 177 | if ( $correct ) { |
178 | 178 | if ( !preg_match( '/(px|ex|em|%)$/', $value ) ) { |
179 | 179 | $value .= 'px'; |
180 | 180 | } |
181 | 181 | } |
182 | | - |
| 182 | + |
183 | 183 | return true; |
184 | 184 | } |
185 | | - |
| 185 | + |
186 | 186 | /** |
187 | 187 | * Corrects the provided map demension value when not valid. |
188 | | - * |
| 188 | + * |
189 | 189 | * @param string or number $value The value as it was entered by the user. |
190 | | - * @param string $dimension Must be width or hieght. |
| 190 | + * @param string $dimension Must be width or height. |
191 | 191 | * @param number $default The default value for this dimension. |
192 | 192 | */ |
193 | 193 | public static function setMapDimension( &$value, $dimension, $default ) { |
— | — | @@ -194,41 +194,41 @@ |
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | | - * Returns a boolean indicating if MapsGeocoder is available. |
199 | | - * |
| 198 | + * Returns a boolean indicating if MapsGeocoder is available. |
| 199 | + * |
200 | 200 | * @return Boolean |
201 | 201 | */ |
202 | 202 | public static function geocoderIsAvailable() { |
203 | 203 | global $wgAutoloadClasses; |
204 | 204 | return array_key_exists( 'MapsGeocoder', $wgAutoloadClasses ); |
205 | 205 | } |
206 | | - |
| 206 | + |
207 | 207 | /** |
208 | 208 | * Returns an array containing all the possible values for the service parameter, including aliases. |
209 | | - * |
| 209 | + * |
210 | 210 | * @return array |
211 | 211 | */ |
212 | 212 | public static function getAllServiceValues() { |
213 | 213 | global $egMapsAvailableServices, $egMapsServices; |
214 | | - |
| 214 | + |
215 | 215 | $allServiceValues = array(); |
216 | | - |
| 216 | + |
217 | 217 | foreach ( $egMapsAvailableServices as $availableService ) { |
218 | 218 | $allServiceValues[] = $availableService; |
219 | 219 | $allServiceValues = array_merge( $allServiceValues, $egMapsServices[$availableService]['aliases'] ); |
220 | 220 | } |
221 | | - |
| 221 | + |
222 | 222 | return $allServiceValues; |
223 | 223 | } |
224 | | - |
| 224 | + |
225 | 225 | /** |
226 | | - * This function returns the definitions for the parameters used by every map feature. |
227 | | - * |
| 226 | + * This function returns the definitions for the parameters used by every map feature. |
| 227 | + * |
228 | 228 | * @return array |
229 | 229 | */ |
230 | 230 | public static function getCommonParameters() { |
231 | 231 | global $egMapsAvailableServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsMapWidth, $egMapsMapHeight; |
232 | | - |
| 232 | + |
233 | 233 | return array( |
234 | 234 | 'service' => array( |
235 | 235 | 'criteria' => array( |
— | — | @@ -265,5 +265,5 @@ |
266 | 266 | ), |
267 | 267 | ); |
268 | 268 | } |
269 | | - |
| 269 | + |
270 | 270 | } |