Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php |
— | — | @@ -26,6 +26,13 @@ |
27 | 27 | protected abstract function getEarthZoom(); |
28 | 28 | |
29 | 29 | /** |
| 30 | + * List of parameter definitions for forms. |
| 31 | + * |
| 32 | + * @var array or false |
| 33 | + */ |
| 34 | + protected static $formParameters = false; |
| 35 | + |
| 36 | + /** |
30 | 37 | * @var iMappingService |
31 | 38 | */ |
32 | 39 | protected $service; |
— | — | @@ -35,8 +42,16 @@ |
36 | 43 | */ |
37 | 44 | protected $markerCoords; |
38 | 45 | |
| 46 | + /** |
| 47 | + * @var string |
| 48 | + */ |
39 | 49 | protected $errorList; |
40 | 50 | |
| 51 | + /** |
| 52 | + * Parameters specific to this feature. |
| 53 | + * |
| 54 | + * @var mixed |
| 55 | + */ |
41 | 56 | protected $specificParameters = false; |
42 | 57 | |
43 | 58 | protected $coordsFieldName; |
— | — | @@ -99,7 +114,8 @@ |
100 | 115 | * again overidden by the service parameters (the ones specific to the service), |
101 | 116 | * and finally by the specific parameters (the ones specific to a service-feature combination). |
102 | 117 | */ |
103 | | - $parameterInfo = array_merge_recursive( MapsMapper::getCommonParameters(), SMFormInputs::$parameters ); |
| 118 | + $parameterInfo = MapsMapper::getCommonParameters(); |
| 119 | + $parameterInfo = array_merge_recursive( $parameterInfo, $this->getFormParameterInfo() ); |
104 | 120 | $parameterInfo = array_merge_recursive( $parameterInfo, $this->service->getParameterInfo() ); |
105 | 121 | $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() ); |
106 | 122 | |
— | — | @@ -204,7 +220,7 @@ |
205 | 221 | * @param string $mapName |
206 | 222 | * @param string $geocodeFieldName |
207 | 223 | */ |
208 | | - private function addGeocodingField( $geocodingFunction, $mapName, $geocodeFieldName ) { |
| 224 | + private function addGeocodingField( $geocodingFunction, $mapName, $geocodeFieldId ) { |
209 | 225 | global $sfgTabIndex, $wgOut, $smgAddedFormJs; |
210 | 226 | $sfgTabIndex++; |
211 | 227 | |
— | — | @@ -230,14 +246,19 @@ |
231 | 247 | } |
232 | 248 | |
233 | 249 | $adressField = SMFormInput::getDynamicInput( |
234 | | - $geocodeFieldName, |
235 | | - htmlspecialchars( wfMsg( 'semanticmaps_enteraddresshere' ) ), |
236 | | - 'size="30" name="geocode" style="color: #707070" tabindex="' . htmlspecialchars( $sfgTabIndex ) . '"' |
| 250 | + 'geocode', |
| 251 | + wfMsg( 'semanticmaps_enteraddresshere' ), |
| 252 | + array( |
| 253 | + 'size' => '30', |
| 254 | + 'id' => $geocodeFieldId, |
| 255 | + 'style' => 'color: #707070', |
| 256 | + 'tabindex' => $sfgTabIndex |
| 257 | + ) |
237 | 258 | ); |
238 | 259 | |
239 | 260 | $notFoundText = Xml::escapeJsString( wfMsg( 'semanticmaps_notfound' ) ); |
240 | 261 | $mapName = Xml::escapeJsString( $mapName ); |
241 | | - $geoFieldName = Xml::escapeJsString( $geocodeFieldName ); |
| 262 | + $geoFieldId = Xml::escapeJsString( $geocodeFieldId ); |
242 | 263 | $coordFieldName = Xml::escapeJsString( $this->coordsFieldName ); |
243 | 264 | |
244 | 265 | $this->output .= '<p>' . $adressField . |
— | — | @@ -246,7 +267,7 @@ |
247 | 268 | wfMsg( 'semanticmaps_lookupcoordinates' ), |
248 | 269 | 'submit', |
249 | 270 | array( |
250 | | - 'onClick' => "$geocodingFunction( document.forms['createbox'].$geoFieldName.value, '$mapName', '$coordFieldName', '$notFoundText'); return false" |
| 271 | + 'onClick' => "$geocodingFunction( document.forms['createbox'].$geoFieldId.value, '$mapName', '$coordFieldName', '$notFoundText'); return false" |
251 | 272 | ) |
252 | 273 | ) . |
253 | 274 | '</p>'; |
— | — | @@ -305,15 +326,24 @@ |
306 | 327 | * Returns html for an html input field with a default value that will automatically dissapear when |
307 | 328 | * the user clicks in it, and reappers when the focus on the field is lost and it's still empty. |
308 | 329 | * |
309 | | - * @param string $id |
| 330 | + * @param string $name |
310 | 331 | * @param string $value |
311 | | - * @param string $args |
| 332 | + * @param array $attribs |
312 | 333 | * |
313 | 334 | * @return string (html) |
314 | 335 | */ |
315 | | - private static function getDynamicInput( $id, $value, $args = '' ) { |
316 | | - // TODO: escape properly, use Html class |
317 | | - return '<input id="' . $id . '" ' . $args . ' value="' . $value . '" onfocus="if (this.value==\'' . $value . '\') {this.value=\'\';}" onblur="if (this.value==\'\') {this.value=\'' . $value . '\';}" />'; |
| 336 | + protected static function getDynamicInput( $name, $value, $attribs = array() ) { |
| 337 | + $escapedValue = Xml::escapeJsString( $value ); |
| 338 | + |
| 339 | + $attribs['onfocus'] = "if (this.value==\"$escapedValue\") {this.value='';}"; |
| 340 | + $attribs['onblur'] = "if (this.value=='') {this.value=\"$escapedValue\";}"; |
| 341 | + |
| 342 | + return Html::input( |
| 343 | + $name, |
| 344 | + $value, |
| 345 | + 'text', |
| 346 | + $attribs |
| 347 | + ); |
318 | 348 | } |
319 | 349 | |
320 | 350 | /** |
— | — | @@ -326,5 +356,66 @@ |
327 | 357 | protected function getShowAddressFunction() { |
328 | 358 | return false; |
329 | 359 | } |
| 360 | + |
| 361 | + /** |
| 362 | + * Gets the definitions for the parameters specific to the form input feature. |
| 363 | + * This function implements a form of caching by storing the definitions, once |
| 364 | + * created, in self::$formParameters, and returning that field when set. |
| 365 | + * |
| 366 | + * @since 0.6.5 |
| 367 | + * |
| 368 | + * @return array |
| 369 | + */ |
| 370 | + protected function getFormParameterInfo() { |
| 371 | + $parameters = self::$formParameters; |
330 | 372 | |
| 373 | + if ( $parameters === false ) { |
| 374 | + $parameters = $this->initializeFormParameters(); |
| 375 | + self::$formParameters = $parameters; |
| 376 | + } |
| 377 | + |
| 378 | + return $parameters; |
| 379 | + } |
| 380 | + |
| 381 | + /** |
| 382 | + * Initializes and returns the definitions for the parameters specific to the form input feature. |
| 383 | + * |
| 384 | + * @since 0.6.5 |
| 385 | + * |
| 386 | + * @return array |
| 387 | + */ |
| 388 | + private static function initializeFormParameters() { |
| 389 | + global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
| 390 | + global $smgFIWidth, $smgFIHeight; |
| 391 | + |
| 392 | + return array( |
| 393 | + 'width' => array( |
| 394 | + 'default' => $smgFIWidth |
| 395 | + ), |
| 396 | + 'height' => array( |
| 397 | + 'default' => $smgFIHeight |
| 398 | + ), |
| 399 | + 'centre' => array( |
| 400 | + 'aliases' => array( 'center' ), |
| 401 | + ), |
| 402 | + 'geoservice' => array( |
| 403 | + 'criteria' => array( |
| 404 | + 'in_array' => $egMapsAvailableGeoServices |
| 405 | + ), |
| 406 | + 'default' => $egMapsDefaultGeoService |
| 407 | + ), |
| 408 | + 'mappingservice' => array( |
| 409 | + 'default' => $egMapsDefaultServices['fi'] |
| 410 | + ), |
| 411 | + 'service_name' => array(), |
| 412 | + 'part_of_multiple' => array(), |
| 413 | + 'possible_values' => array( |
| 414 | + 'type' => array( 'string', 'array' ), |
| 415 | + ), |
| 416 | + 'is_list' => array(), |
| 417 | + 'semantic_property' => array(), |
| 418 | + 'value_labels' => array(), |
| 419 | + ); |
| 420 | + } |
| 421 | + |
331 | 422 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInputs.php |
— | — | @@ -19,8 +19,6 @@ |
20 | 20 | |
21 | 21 | final class SMFormInputs { |
22 | 22 | |
23 | | - public static $parameters = array(); |
24 | | - |
25 | 23 | public static function initialize() { |
26 | 24 | global $smgDir, $wgAutoloadClasses, $egMapsServices, $sfgFormPrinter; |
27 | 25 | |
— | — | @@ -32,8 +30,6 @@ |
33 | 31 | |
34 | 32 | $hasFormInputs = false; |
35 | 33 | |
36 | | - self::initializeParams(); |
37 | | - |
38 | 34 | foreach ( $egMapsServices as $service ) { |
39 | 35 | // Check if the service has a form input. |
40 | 36 | $FIClass = $service->getFeature( 'fi' ); |
— | — | @@ -57,39 +53,7 @@ |
58 | 54 | return true; |
59 | 55 | } |
60 | 56 | |
61 | | - private static function initializeParams() { |
62 | | - global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
63 | | - global $smgFIWidth, $smgFIHeight; |
64 | | - |
65 | | - self::$parameters = array( |
66 | | - 'width' => array( |
67 | | - 'default' => $smgFIWidth |
68 | | - ), |
69 | | - 'height' => array( |
70 | | - 'default' => $smgFIHeight |
71 | | - ), |
72 | | - 'centre' => array( |
73 | | - 'aliases' => array( 'center' ), |
74 | | - ), |
75 | | - 'geoservice' => array( |
76 | | - 'criteria' => array( |
77 | | - 'in_array' => $egMapsAvailableGeoServices |
78 | | - ), |
79 | | - 'default' => $egMapsDefaultGeoService |
80 | | - ), |
81 | | - 'mappingservice' => array( |
82 | | - 'default' => $egMapsDefaultServices['fi'] |
83 | | - ), |
84 | | - 'service_name' => array(), |
85 | | - 'part_of_multiple' => array(), |
86 | | - 'possible_values' => array( |
87 | | - 'type' => array( 'string', 'array' ), |
88 | | - ), |
89 | | - 'is_list' => array(), |
90 | | - 'semantic_property' => array(), |
91 | | - 'value_labels' => array(), |
92 | | - ); |
93 | | - } |
| 57 | + |
94 | 58 | |
95 | 59 | /** |
96 | 60 | * Adds a mapping service's form hook. |