r69451 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69450‎ | r69451 | r69452 >
Date:23:51, 16 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6.5 - improvements to form input handling
Modified paths:
  • /trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/GoogleMaps/SM_GoogleMapsFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/OpenLayers/SM_OpenLayersFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/YahooMaps/SM_YahooMapsFormInput.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/Services/YahooMaps/SM_YahooMapsFormInput.php
@@ -23,18 +23,25 @@
2424 class SMYahooMapsFormInput extends SMFormInput {
2525
2626 /**
27 - * @see MapsMapFeature::setMapSettings()
 27+ * @see SMFormInput::getEarthZoom
 28+ *
 29+ * @since 0.6.5
2830 */
29 - protected function setMapSettings() {
30 - global $egMapsYahooMapsPrefix;
31 -
32 - $this->elementNamePrefix = $egMapsYahooMapsPrefix;
33 - $this->showAddresFunction = 'showYAddress';
34 -
35 - $this->earthZoom = 17;
36 - }
 31+ protected function getEarthZoom() {
 32+ return 17;
 33+ }
3734
3835 /**
 36+ * @see SMFormInput::getShowAddressFunction
 37+ *
 38+ * @since 0.6.5
 39+ */
 40+ protected function getShowAddressFunction() {
 41+ global $egYahooMapsKey;
 42+ return $egYahooMapsKey == '' ? false : 'showYAddress';
 43+ }
 44+
 45+ /**
3946 * @see MapsMapFeature::addFormDependencies()
4047 */
4148 protected function addFormDependencies() {
@@ -52,8 +59,6 @@
5360
5461 /**
5562 * @see MapsMapFeature::addSpecificMapHTML
56 - *
57 - * TODO: fix map name
5863 */
5964 protected function addSpecificMapHTML() {
6065 global $wgOut;
@@ -92,12 +97,4 @@
9398
9499 }
95100
96 - /**
97 - * @see SMFormInput::manageGeocoding()
98 - */
99 - protected function manageGeocoding() {
100 - global $egYahooMapsKey;
101 - return $egYahooMapsKey != '';
102 - }
103 -
104101 }
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/Services/OpenLayers/SM_OpenLayersFormInput.php
@@ -23,15 +23,13 @@
2424 class SMOpenLayersFormInput extends SMFormInput {
2525
2626 /**
27 - * @see MapsMapFeature::setMapSettings()
 27+ * @see SMFormInput::getEarthZoom
 28+ *
 29+ * @since 0.6.5
2830 */
29 - protected function setMapSettings() {
30 - global $egMapsOpenLayersPrefix;
31 -
32 - $this->elementNamePrefix = $egMapsOpenLayersPrefix;
33 -
34 - $this->earthZoom = 1;
35 - }
 31+ protected function getEarthZoom() {
 32+ return 1;
 33+ }
3634
3735 /**
3836 * @see MapsMapFeature::addFormDependencies()
@@ -51,8 +49,6 @@
5250
5351 /**
5452 * @see MapsMapFeature::addSpecificMapHTML
55 - *
56 - * TODO: fix map name
5753 */
5854 protected function addSpecificMapHTML() {
5955 global $wgOut, $wgLang;
Index: trunk/extensions/SemanticMaps/Services/GoogleMaps/SM_GoogleMapsFormInput.php
@@ -27,15 +27,22 @@
2828 class SMGoogleMapsFormInput extends SMFormInput {
2929
3030 /**
31 - * @see MapsMapFeature::setMapSettings()
 31+ * @see SMFormInput::getEarthZoom
 32+ *
 33+ * @since 0.6.5
3234 */
33 - protected function setMapSettings() {
34 - global $egMapsGoogleMapsPrefix;
35 -
36 - $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
37 - $this->showAddresFunction = 'showGAddress';
38 -
39 - $this->earthZoom = 1;
 35+ protected function getEarthZoom() {
 36+ return 1;
 37+ }
 38+
 39+ /**
 40+ * @see SMFormInput::getShowAddressFunction
 41+ *
 42+ * @since 0.6.5
 43+ */
 44+ protected function getShowAddressFunction() {
 45+ global $egGoogleMapsKey;
 46+ return $egGoogleMapsKey == '' ? false : 'showGAddress';
4047 }
4148
4249 /**
@@ -100,13 +107,5 @@
101108 EOT
102109 );
103110 }
104 -
105 - /**
106 - * @see SMFormInput::manageGeocoding
107 - */
108 - protected function manageGeocoding() {
109 - global $egGoogleMapsKey;
110 - return $egGoogleMapsKey != '';
111 - }
112 -
 111+
113112 }
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -35,7 +35,7 @@
3636
3737 // Only initialize the extension when all dependencies are present.
3838 if ( defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' ) ) {
39 - define( 'SM_VERSION', '0.6.5 a4' );
 39+ define( 'SM_VERSION', '0.6.5 a6' );
4040
4141 $useExtensionPath = version_compare( $wgVersion, '1.16', '>=' ) && isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath;
4242 $smgScriptPath = ( $useExtensionPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps';
Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php
@@ -20,36 +20,33 @@
2121 */
2222 protected abstract function addFormDependencies();
2323
24 - protected $service;
 24+ /**
 25+ * Returns the zoom level at which the whole earth is visible.
 26+ */
 27+ protected abstract function getEarthZoom();
2528
2629 /**
27 - * @var string
28 - */
29 - protected $mapName;
 30+ * @var iMappingService
 31+ */
 32+ protected $service;
3033
3134 /**
3235 * @var array
3336 */
3437 protected $markerCoords;
35 -
36 - protected $earthZoom;
3738
38 - protected $showAddresFunction;
 39+ protected $errorList;
3940
40 - protected $enableGeocoding;
 41+ protected $specificParameters = false;
4142
42 - protected $errorList;
43 -
4443 private $coordinates;
4544
46 - protected $specificParameters = false;
47 -
4845 /**
4946 * Constructor.
5047 *
51 - * @param MapsMappingService $service
 48+ * @param iMappingService $service
5249 */
53 - public function __construct( MapsMappingService $service ) {
 50+ public function __construct( iMappingService $service ) {
5451 $this->service = $service;
5552 }
5653
@@ -148,17 +145,16 @@
149146 return array( $this->errorList );
150147 }
151148
152 - $this->enableGeocoding = $this->manageGeocoding();
153 -
154149 $this->setCoordinates();
155150 $this->setCentre();
156151 $this->setZoom();
157152
158153 // Create html element names.
159154 $mapName = $this->service->getMapId();
160 - $this->geocodeFieldName = $mapName . '_geocode_' . $sfgTabIndex;
161 - $this->coordsFieldName = $mapName . '_coords_' . $sfgTabIndex;
162 - $this->infoFieldName = $mapName . '_info_' . $sfgTabIndex;
 155+ $coordsFieldName = $mapName . '_coords_' . $sfgTabIndex;
 156+ $infoFieldName = $mapName . '_info_' . $sfgTabIndex;
 157+
 158+ $geocodingFunction = $this->getShowAddressFunction();
163159
164160 // Create the non specific form HTML.
165161 $this->output .= Html::input(
@@ -168,7 +164,7 @@
169165 array(
170166 'size' => 42, #_O
171167 'tabindex' => $sfgTabIndex,
172 - 'id' => $this->coordsFieldName
 168+ 'id' => $coordsFieldName
173169 )
174170 );
175171
@@ -176,11 +172,13 @@
177173 'span',
178174 array(
179175 'class' => 'error_message',
180 - 'id' => $this->infoFieldName
 176+ 'id' => $infoFieldName
181177 )
182178 );
183179
184 - if ( $this->enableGeocoding ) $this->addGeocodingField( $mapName );
 180+ if ( $geocodingFunction !== false ) {
 181+ $this->addGeocodingField( $geocodingFunction, $mapName, $mapName . '_geocode_' . $sfgTabIndex );
 182+ }
185183
186184 if ( $this->markerCoords === false ) {
187185 $this->markerCoords = array(
@@ -197,7 +195,14 @@
198196 return array( $this->output . $this->errorList, '' );
199197 }
200198
201 - private function addGeocodingField( $mapName ) {
 199+ /**
 200+ * Adds geocoding controls to the form.
 201+ *
 202+ * @param string $geocodingFunction
 203+ * @param string $mapName
 204+ * @param string $geocodeFieldName
 205+ */
 206+ private function addGeocodingField( $geocodingFunction, $mapName, $geocodeFieldName ) {
202207 global $sfgTabIndex, $wgOut, $smgAddedFormJs;
203208 $sfgTabIndex++;
204209
@@ -222,24 +227,24 @@
223228 );
224229 }
225230
226 - $adress_field = SMFormInput::getDynamicInput(
227 - $this->geocodeFieldName,
228 - wfMsg( 'semanticmaps_enteraddresshere' ),
 231+ $adressField = SMFormInput::getDynamicInput(
 232+ $geocodeFieldName,
 233+ htmlspecialchars( wfMsg( 'semanticmaps_enteraddresshere' ) ),
229234 'size="30" name="geocode" style="color: #707070" tabindex="' . htmlspecialchars( $sfgTabIndex ) . '"'
230235 );
231236
232237 $notFoundText = Xml::escapeJsString( wfMsg( 'semanticmaps_notfound' ) );
233238 $mapName = Xml::escapeJsString( $mapName );
234 - $geoFieldName = Xml::escapeJsString( $this->geocodeFieldName );
235 - $coordFieldName = Xml::escapeJsString( $this->coordsFieldName );
 239+ $geoFieldName = Xml::escapeJsString( $geocodeFieldName );
 240+ $coordFieldName = Xml::escapeJsString( $geocodeFieldName );
236241
237 - $this->output .= '<p>' . $adress_field .
 242+ $this->output .= '<p>' . $adressField .
238243 Html::input(
239244 'geosubmit',
240245 wfMsg( 'semanticmaps_lookupcoordinates' ),
241246 'submit',
242247 array(
243 - 'onClick' => "$this->showAddresFunction( document.forms['createbox'].$geoFieldName.value, '$mapName', '$coordFieldName', '$notFoundText'); return false"
 248+ 'onClick' => "$geocodingFunction( document.forms['createbox'].$geoFieldName.value, '$mapName', '$coordFieldName', '$notFoundText'); return false"
244249 )
245250 ) .
246251 '</p>';
@@ -251,7 +256,7 @@
252257 */
253258 private function setZoom() {
254259 if ( empty( $this->coordinates ) ) {
255 - $this->zoom = $this->earthZoom;
 260+ $this->zoom = $this->getEarthZoom();
256261 } else if ( $this->zoom == 'null' ) {
257262 $this->zoom = $this->defaultZoom;
258263 }
@@ -305,17 +310,18 @@
306311 * @return string (html)
307312 */
308313 private static function getDynamicInput( $id, $value, $args = '' ) {
309 - // TODO: escape properly
 314+ // TODO: escape properly, use Html class
310315 return '<input id="' . $id . '" ' . $args . ' value="' . $value . '" onfocus="if (this.value==\'' . $value . '\') {this.value=\'\';}" onblur="if (this.value==\'\') {this.value=\'' . $value . '\';}" />';
311316 }
312317
313318 /**
314 - * Determine if geocoding will be enabled and load the required dependencies.
315 - * Override in deriving classes to enable geocoding functionallity there.
 319+ * Returns the name of the JavaScript function to use for live geocoding,
 320+ * or false to indicate there is no such function. Override this method
 321+ * to implement geocoding functionallity.
316322 *
317 - * @return boolean
 323+ * @return mixed: string or false
318324 */
319 - protected function manageGeocoding() {
 325+ protected function getShowAddressFunction() {
320326 return false;
321327 }
322328

Follow-up revisions

RevisionCommit summaryAuthorDate
r69454Follow up to r69451jeroendedauw00:14, 17 July 2010
r69455Follow up to r69451jeroendedauw00:24, 17 July 2010

Status & tagging log