r69533 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69532‎ | r69533 | r69534 >
Date:04:52, 19 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6.5 - improved creation of form html
Modified paths:
  • /trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInputs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php
@@ -26,6 +26,13 @@
2727 protected abstract function getEarthZoom();
2828
2929 /**
 30+ * List of parameter definitions for forms.
 31+ *
 32+ * @var array or false
 33+ */
 34+ protected static $formParameters = false;
 35+
 36+ /**
3037 * @var iMappingService
3138 */
3239 protected $service;
@@ -35,8 +42,16 @@
3643 */
3744 protected $markerCoords;
3845
 46+ /**
 47+ * @var string
 48+ */
3949 protected $errorList;
4050
 51+ /**
 52+ * Parameters specific to this feature.
 53+ *
 54+ * @var mixed
 55+ */
4156 protected $specificParameters = false;
4257
4358 protected $coordsFieldName;
@@ -99,7 +114,8 @@
100115 * again overidden by the service parameters (the ones specific to the service),
101116 * and finally by the specific parameters (the ones specific to a service-feature combination).
102117 */
103 - $parameterInfo = array_merge_recursive( MapsMapper::getCommonParameters(), SMFormInputs::$parameters );
 118+ $parameterInfo = MapsMapper::getCommonParameters();
 119+ $parameterInfo = array_merge_recursive( $parameterInfo, $this->getFormParameterInfo() );
104120 $parameterInfo = array_merge_recursive( $parameterInfo, $this->service->getParameterInfo() );
105121 $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() );
106122
@@ -204,7 +220,7 @@
205221 * @param string $mapName
206222 * @param string $geocodeFieldName
207223 */
208 - private function addGeocodingField( $geocodingFunction, $mapName, $geocodeFieldName ) {
 224+ private function addGeocodingField( $geocodingFunction, $mapName, $geocodeFieldId ) {
209225 global $sfgTabIndex, $wgOut, $smgAddedFormJs;
210226 $sfgTabIndex++;
211227
@@ -230,14 +246,19 @@
231247 }
232248
233249 $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+ )
237258 );
238259
239260 $notFoundText = Xml::escapeJsString( wfMsg( 'semanticmaps_notfound' ) );
240261 $mapName = Xml::escapeJsString( $mapName );
241 - $geoFieldName = Xml::escapeJsString( $geocodeFieldName );
 262+ $geoFieldId = Xml::escapeJsString( $geocodeFieldId );
242263 $coordFieldName = Xml::escapeJsString( $this->coordsFieldName );
243264
244265 $this->output .= '<p>' . $adressField .
@@ -246,7 +267,7 @@
247268 wfMsg( 'semanticmaps_lookupcoordinates' ),
248269 'submit',
249270 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"
251272 )
252273 ) .
253274 '</p>';
@@ -305,15 +326,24 @@
306327 * Returns html for an html input field with a default value that will automatically dissapear when
307328 * the user clicks in it, and reappers when the focus on the field is lost and it's still empty.
308329 *
309 - * @param string $id
 330+ * @param string $name
310331 * @param string $value
311 - * @param string $args
 332+ * @param array $attribs
312333 *
313334 * @return string (html)
314335 */
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+ );
318348 }
319349
320350 /**
@@ -326,5 +356,66 @@
327357 protected function getShowAddressFunction() {
328358 return false;
329359 }
 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;
330372
 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+
331422 }
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInputs.php
@@ -19,8 +19,6 @@
2020
2121 final class SMFormInputs {
2222
23 - public static $parameters = array();
24 -
2523 public static function initialize() {
2624 global $smgDir, $wgAutoloadClasses, $egMapsServices, $sfgFormPrinter;
2725
@@ -32,8 +30,6 @@
3331
3432 $hasFormInputs = false;
3533
36 - self::initializeParams();
37 -
3834 foreach ( $egMapsServices as $service ) {
3935 // Check if the service has a form input.
4036 $FIClass = $service->getFeature( 'fi' );
@@ -57,39 +53,7 @@
5854 return true;
5955 }
6056
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+
9458
9559 /**
9660 * Adds a mapping service's form hook.

Status & tagging log