Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php'; |
85 | 85 | $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php'; |
86 | 86 | $wgAutoloadClasses['MapsMappingService'] = $incDir . 'Maps_MappingService.php'; |
87 | | -$wgAutoloadClasses['MapsSettings'] = $incDir . 'Maps_Settings.php'; |
| 87 | +//$wgAutoloadClasses['MapsSettings'] = $incDir . 'Maps_Settings.php'; |
88 | 88 | |
89 | 89 | // Autoload the "includes/criteria/" classes. |
90 | 90 | $criDir = $incDir . 'criteria/'; |
— | — | @@ -229,6 +229,8 @@ |
230 | 230 | |
231 | 231 | # WMF OSM |
232 | 232 | include_once $egMapsDir . 'includes/services/OSM/OSM.php'; |
| 233 | + |
| 234 | +$egMapsSettings = array(); |
233 | 235 | |
234 | 236 | // Include the settings file. |
235 | 237 | require_once $egMapsDir . 'Maps_Settings.php'; |
Index: trunk/extensions/Maps/RELEASE-NOTES |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | |
10 | 10 | |
11 | 11 | === Maps 1.0.1 === |
12 | | -(2011-0x-xx) |
| 12 | +(2011-08-xx) |
13 | 13 | |
14 | 14 | * Added language parameter to the mapsdoc hook. |
15 | 15 | |
Index: trunk/extensions/Maps/includes/Maps_Settings.php |
— | — | @@ -41,7 +41,11 @@ |
42 | 42 | static $defaultSettings = false; |
43 | 43 | |
44 | 44 | if ( $defaultSettings === false ) { |
45 | | - $defaultSettings = include 'Maps.settings.php'; |
| 45 | + $defaultSettings = array(); |
| 46 | + |
| 47 | + foreach( ( include dirname( __FILE__ ) . '/../Maps.settings.php' ) as $setting ) { |
| 48 | + $defaultSettings[$setting->getName()] = $setting->getValue(); |
| 49 | + } |
46 | 50 | } |
47 | 51 | |
48 | 52 | return $defaultSettings; |
— | — | @@ -69,7 +73,7 @@ |
70 | 74 | */ |
71 | 75 | protected static function getPhpCompatSettings() { |
72 | 76 | $mappings = array( |
73 | | - 'egMapsFoobar' => 'foobar' // TODO |
| 77 | + 'egMapsAvailableServices' => 'services', |
74 | 78 | ); |
75 | 79 | |
76 | 80 | $settings = array(); |
— | — | @@ -135,7 +139,7 @@ |
136 | 140 | * |
137 | 141 | * @return array |
138 | 142 | */ |
139 | | - protected abstract static function getDefaultSettings(); |
| 143 | + protected static function getDefaultSettings() { return array(); } |
140 | 144 | |
141 | 145 | /** |
142 | 146 | * Initiate the settings list if not done already. |
— | — | @@ -145,35 +149,48 @@ |
146 | 150 | * @return boolean True if the settings where initiates in this call. |
147 | 151 | */ |
148 | 152 | protected static function initIfNeeded() { |
149 | | - $init = self::$settings === false; |
| 153 | + $init = static::$settings === false; |
150 | 154 | |
151 | 155 | if ( $init ) { |
152 | | - self::$settings = array( |
153 | | - 'default' => self::getDefaultSettings(), |
154 | | - 'php' => self::getPhpSettings() |
| 156 | + static::$settings = array( |
| 157 | + 'default' => static::getDefaultSettings(), |
| 158 | + 'php' => static::getPhpSettings() |
155 | 159 | ); |
156 | 160 | } |
157 | 161 | |
158 | 162 | return $init; |
159 | 163 | } |
160 | 164 | |
| 165 | + /** |
| 166 | + * Returns the settings of the specified groups, merged. |
| 167 | + * If available in the cache, it'll be used. If not, |
| 168 | + * and $cache is true, it'll be cached. |
| 169 | + * |
| 170 | + * @since 1.1 |
| 171 | + * |
| 172 | + * @param array $groups |
| 173 | + * @param boolean $cache |
| 174 | + * |
| 175 | + * @return array |
| 176 | + */ |
161 | 177 | protected static function getMergedSettings( array $groups, $cache = true ) { |
162 | 178 | $names = implode( '|', $groups ); |
163 | 179 | |
164 | | - if ( array_key_exists( $names, self::$mergedCaches ) ) { |
165 | | - return self::$mergedCaches[$names]; |
| 180 | + if ( array_key_exists( $names, static::$mergedCaches ) ) { |
| 181 | + return static::$mergedCaches[$names]; |
166 | 182 | } |
167 | 183 | else { |
168 | 184 | $settings = array(); |
169 | 185 | |
170 | 186 | foreach ( $groups as $group ) { |
171 | | - if ( array_key_exists( $group, self::$settings ) ) { |
172 | | - $settings = array_merge_recursive( $settings, self::$settings[$group] ); |
| 187 | + if ( array_key_exists( $group, static::$settings ) ) { |
| 188 | + // TODO: recursive merge, that does not append for arrays w/o named keys. |
| 189 | + $settings = array_merge( $settings, static::$settings[$group] ); |
173 | 190 | } |
174 | 191 | } |
175 | 192 | |
176 | 193 | if ( $cache ) { |
177 | | - self::$mergedCaches[$names] = $settings; |
| 194 | + static::$mergedCaches[$names] = $settings; |
178 | 195 | } |
179 | 196 | |
180 | 197 | return $settings; |
— | — | @@ -203,16 +220,16 @@ |
204 | 221 | * @return array |
205 | 222 | */ |
206 | 223 | public static function getSettings( $groups = true, $cache = true ) { |
207 | | - self::initIfNeeded(); |
| 224 | + static::initIfNeeded(); |
208 | 225 | |
209 | 226 | if ( $groups === false ) { |
210 | | - return self::getDefaultSettings(); |
| 227 | + return static::getDefaultSettings(); |
211 | 228 | } |
212 | 229 | else { |
213 | 230 | if ( $groups === true ) { |
214 | | - $groups = array_keys( self::$settings ); |
| 231 | + $groups = array_keys( static::$settings ); |
215 | 232 | } |
216 | | - return self::getMergedSettings( $groups, $cache ); |
| 233 | + return static::getMergedSettings( $groups, $cache ); |
217 | 234 | } |
218 | 235 | } |
219 | 236 | |
— | — | @@ -228,7 +245,7 @@ |
229 | 246 | * @return mixed |
230 | 247 | */ |
231 | 248 | public static function get( $settingName, $groups = true, $cache = true ) { |
232 | | - $settings = self::getSettings( $groups, $cache ); |
| 249 | + $settings = static::getSettings( $groups, $cache ); |
233 | 250 | |
234 | 251 | if ( !array_key_exists( $settingName, $settings ) ) { |
235 | 252 | throw new MWException(); // TODO |
— | — | @@ -249,7 +266,7 @@ |
250 | 267 | * @return boolean |
251 | 268 | */ |
252 | 269 | public static function has( $settingName, $groups = true, $cache = true ) { |
253 | | - $settings = self::getSettings( $groups, $cache ); |
| 270 | + $settings = static::getSettings( $groups, $cache ); |
254 | 271 | return array_key_exists( $settingName, $settings ); |
255 | 272 | } |
256 | 273 | |
— | — | @@ -266,16 +283,16 @@ |
267 | 284 | * @return boolean |
268 | 285 | */ |
269 | 286 | public static function set( $settingName, $settingValue, $groupName, $invalidateCache = true ) { |
270 | | - if ( !array_key_exists( $groupName, self::$settings ) ) { |
271 | | - self::$settings[$groupName] = array(); |
| 287 | + if ( !array_key_exists( $groupName, static::$settings ) ) { |
| 288 | + static::$settings[$groupName] = array(); |
272 | 289 | } |
273 | 290 | elseif ( $invalidateCache |
274 | | - && ( !array_key_exists( $settingName, self::$settings[$groupName] ) |
275 | | - || self::$settings[$groupName][$settingName] !== $settingValue ) ) { |
276 | | - self::ivalidateCachesForGroup( $groupName ); |
| 291 | + && ( !array_key_exists( $settingName, static::$settings[$groupName] ) |
| 292 | + || static::$settings[$groupName][$settingName] !== $settingValue ) ) { |
| 293 | + static::ivalidateCachesForGroup( $groupName ); |
277 | 294 | } |
278 | 295 | |
279 | | - self::$settings[$groupName][$settingName] = $settingValue; |
| 296 | + static::$settings[$groupName][$settingName] = $settingValue; |
280 | 297 | } |
281 | 298 | |
282 | 299 | /** |
— | — | @@ -286,11 +303,37 @@ |
287 | 304 | * @param name $group |
288 | 305 | */ |
289 | 306 | protected static function ivalidateCachesForGroup( $group ) { |
290 | | - foreach ( array_keys( self::$mergedCaches ) as $cacheName ) { |
| 307 | + foreach ( array_keys( static::$mergedCaches ) as $cacheName ) { |
291 | 308 | if ( in_array( $groupName, explode( '|', $cacheName ) ) ) { |
292 | | - unset( self::$mergedCaches[$cacheName] ); |
| 309 | + unset( static::$mergedCaches[$cacheName] ); |
293 | 310 | } |
294 | 311 | } |
295 | 312 | } |
296 | 313 | |
297 | 314 | } |
| 315 | + |
| 316 | +class Setting { |
| 317 | + |
| 318 | + public $name; |
| 319 | + public $value; |
| 320 | + public $message = false; |
| 321 | + |
| 322 | + public static function newFromValue( $name, $value ) { |
| 323 | + return new Setting( $name, $value ); |
| 324 | + } |
| 325 | + |
| 326 | + public function __construct( $name, $value, $message = false ) { |
| 327 | + $this->name = $name; |
| 328 | + $this->value = $value; |
| 329 | + $this->message = $message; |
| 330 | + } |
| 331 | + |
| 332 | + public function getValue() { |
| 333 | + return $this->value; |
| 334 | + } |
| 335 | + |
| 336 | + public function getName() { |
| 337 | + return $this->name; |
| 338 | + } |
| 339 | + |
| 340 | +} |