r65937 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65936‎ | r65937 | r65938 >
Date:03:13, 5 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - Fixed bugs in the form inputs due to the other refactoring
Modified paths:
  • /trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.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
@@ -21,7 +21,6 @@
2222
2323 /**
2424 * @see MapsMapFeature::setMapSettings()
25 - *
2625 */
2726 protected function setMapSettings() {
2827 global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix;
@@ -36,10 +35,9 @@
3736
3837 /**
3938 * @see MapsMapFeature::addFormDependencies()
40 - *
4139 */
4240 protected function addFormDependencies() {
43 - global $wgJsMimeType, $wgParser;
 41+ global $wgOut, $wgParser;
4442 global $smgScriptPath, $smgYahooFormsOnThisPage, $smgStyleVersion, $egMapsJsExt;
4543
4644 MapsYahooMaps::addYMapDependencies( $wgParser );
@@ -47,24 +45,15 @@
4846 if ( empty( $smgYahooFormsOnThisPage ) ) {
4947 $smgYahooFormsOnThisPage = 0;
5048
51 - $wgParser->getOutput()->addHeadItem(
52 - Html::element(
53 - 'script',
54 - array(
55 - 'type' => $wgJsMimeType,
56 - 'src' => "$smgScriptPath/YahooMaps/SM_YahooMapsFunctions{$egMapsJsExt}?$smgStyleVersion"
57 - )
58 - )
59 - );
 49+ $wgOut->addScriptFile( "$smgScriptPath/Services/YahooMaps/SM_YahooMapsFunctions{$egMapsJsExt}?$smgStyleVersion" );
6050 }
6151 }
6252
6353 /**
6454 * @see MapsMapFeature::doMapServiceLoad()
65 - *
6655 */
6756 protected function doMapServiceLoad() {
68 - global $egYahooMapsOnThisPage, $smgYahooFormsOnThisPage;
 57+ global $egYahooMapsOnThisPage, $smgYahooFormsOnThisPage, $egMapsYahooMapsPrefix;
6958
7059 self::addFormDependencies();
7160
@@ -72,13 +61,13 @@
7362 $smgYahooFormsOnThisPage++;
7463
7564 $this->elementNr = $egYahooMapsOnThisPage;
 65+ $this->mapName = $egMapsYahooMapsPrefix . '_' . $egYahooMapsOnThisPage;
7666 }
7767
7868 /**
7969 * @see MapsMapFeature::addSpecificMapHTML()
80 - *
8170 */
82 - protected function addSpecificMapHTML( Parser $parser ) {
 71+ protected function addSpecificMapHTML() {
8372 global $wgOut;
8473
8574 $this->output .= Html::element(
Index: trunk/extensions/SemanticMaps/Services/OpenLayers/SM_OpenLayersFormInput.php
@@ -21,7 +21,6 @@
2222
2323 /**
2424 * @see MapsMapFeature::setMapSettings()
25 - *
2625 */
2726 protected function setMapSettings() {
2827 global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
@@ -35,10 +34,9 @@
3635
3736 /**
3837 * @see MapsMapFeature::addFormDependencies()
39 - *
4038 */
4139 protected function addFormDependencies() {
42 - global $wgJsMimeType, $wgParser;
 40+ global $wgOut, $wgParser;
4341 global $smgScriptPath, $smgOLFormsOnThisPage, $smgStyleVersion, $egMapsJsExt;
4442
4543 MapsOpenLayers::addOLDependencies( $wgParser );
@@ -46,24 +44,15 @@
4745 if ( empty( $smgOLFormsOnThisPage ) ) {
4846 $smgOLFormsOnThisPage = 0;
4947
50 - $wgParser->getOutput()->addHeadItem(
51 - Html::element(
52 - 'script',
53 - array(
54 - 'type' => $wgJsMimeType,
55 - 'src' => "$smgScriptPath/OpenLayers/SM_OpenLayersFunctions{$egMapsJsExt}?$smgStyleVersion"
56 - )
57 - )
58 - );
 48+ $wgOut->addScriptFile( "$smgScriptPath/Services/OpenLayers/SM_OpenLayersFunctions{$egMapsJsExt}?$smgStyleVersion" );
5949 }
6050 }
6151
6252 /**
6353 * @see MapsMapFeature::doMapServiceLoad()
64 - *
6554 */
6655 protected function doMapServiceLoad() {
67 - global $egOpenLayersOnThisPage, $smgOLFormsOnThisPage;
 56+ global $egOpenLayersOnThisPage, $smgOLFormsOnThisPage, $egMapsOpenLayersPrefix;
6857
6958 self::addFormDependencies();
7059
@@ -71,13 +60,13 @@
7261 $smgOLFormsOnThisPage++;
7362
7463 $this->elementNr = $egOpenLayersOnThisPage;
 64+ $this->mapName = $egMapsOpenLayersPrefix . '_' . $egOpenLayersOnThisPage;
7565 }
7666
7767 /**
7868 * @see MapsMapFeature::addSpecificMapHTML()
79 - *
8069 */
81 - protected function addSpecificMapHTML( Parser $parser ) {
 70+ protected function addSpecificMapHTML() {
8271 global $wgOut;
8372
8473 $this->output .= Html::element(
Index: trunk/extensions/SemanticMaps/Services/GoogleMaps/SM_GoogleMapsFormInput.php
@@ -23,7 +23,6 @@
2424
2525 /**
2626 * @see MapsMapFeature::setMapSettings()
27 - *
2827 */
2928 protected function setMapSettings() {
3029 global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
@@ -41,32 +40,22 @@
4241 * @see smw/extensions/SemanticMaps/FormInputs/SMFormInput#addFormDependencies()
4342 */
4443 protected function addFormDependencies() {
45 - global $wgJsMimeType, $wgParser;
 44+ global $wgOut;
4645 global $smgScriptPath, $smgGoogleFormsOnThisPage, $smgStyleVersion, $egMapsJsExt;
4746
48 - MapsGoogleMaps::addGMapDependencies( $wgParser );
 47+ MapsGoogleMaps::addGMapDependencies( $wgOut );
4948
5049 if ( empty( $smgGoogleFormsOnThisPage ) ) {
5150 $smgGoogleFormsOnThisPage = 0;
52 -
53 - $wgParser->getOutput()->addHeadItem(
54 - Html::element(
55 - 'script',
56 - array(
57 - 'type' => $wgJsMimeType,
58 - 'src' => "$smgScriptPath/GoogleMaps/SM_GoogleMapsFunctions{$egMapsJsExt}?$smgStyleVersion"
59 - )
60 - )
61 - );
 51+ $wgOut->addScriptFile( "$smgScriptPath/Services/GoogleMaps/SM_GoogleMapsFunctions{$egMapsJsExt}?$smgStyleVersion" );
6252 }
6353 }
6454
6555 /**
6656 * @see MapsMapFeature::doMapServiceLoad()
67 - *
6857 */
6958 protected function doMapServiceLoad() {
70 - global $egGoogleMapsOnThisPage, $smgGoogleFormsOnThisPage;
 59+ global $egGoogleMapsOnThisPage, $smgGoogleFormsOnThisPage, $egMapsGoogleMapsPrefix;
7160
7261 self::addFormDependencies();
7362
@@ -74,19 +63,19 @@
7564 $smgGoogleFormsOnThisPage++;
7665
7766 $this->elementNr = $egGoogleMapsOnThisPage;
 67+ $this->mapName = $egMapsGoogleMapsPrefix . '_' . $egGoogleMapsOnThisPage;
7868 }
7969
8070 /**
8171 * @see MapsMapFeature::addSpecificFormInputHTML()
82 - *
8372 */
84 - protected function addSpecificMapHTML( Parser $parser ) {
 73+ protected function addSpecificMapHTML() {
8574 global $wgOut;
8675
8776 // Remove the overlays control in case it's present.
 77+ // TODO: make less insane
8878 if ( in_string( 'overlays', $this->controls ) ) {
89 - $this->controls = str_replace( ",'overlays'", '', $this->controls );
90 - $this->controls = str_replace( "'overlays',", '', $this->controls );
 79+ $this->controls = str_replace( array( ",'overlays'", "'overlays'," ), '', $this->controls );
9180 }
9281
9382 $this->output .= Html::element(
@@ -124,12 +113,11 @@
125114
126115 /**
127116 * @see SMFormInput::manageGeocoding()
128 - *
129117 */
130118 protected function manageGeocoding() {
131 - global $egGoogleMapsKey;
132 - $this->enableGeocoding = strlen( trim( $egGoogleMapsKey ) ) > 0;
133 - if ( $this->enableGeocoding ) MapsGoogleMaps::addGMapDependencies( $this->output, $this->parser );
 119+ global $egGoogleMapsKey, $wgParser;
 120+ $this->enableGeocoding = $egGoogleMapsKey != '';
 121+ if ( $this->enableGeocoding ) MapsGoogleMaps::addGMapDependencies( $wgParser );
134122 }
135123
136124 }
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -119,8 +119,6 @@
120120
121121 /**
122122 * @see SMWDataValue::getShortWikiText
123 - *
124 - * TODO: make the output here more readible (and if possible informative)
125123 */
126124 public function getShortWikiText( $linked = null ) {
127125 if ( $this->isValid() && ( $linked !== null ) && ( $linked !== false ) ) {
Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php
@@ -25,6 +25,8 @@
2626 */
2727 protected abstract function addFormDependencies();
2828
 29+ protected $mapName;
 30+
2931 // TODO: change into a single array
3032 protected $marker_lat;
3133 protected $marker_lon;
@@ -53,23 +55,30 @@
5456 * by the feature parameters (the ones spesific to a feature). The result is then
5557 * again overidden by the service parameters (the ones spesific to the service),
5658 * and finally by the spesific parameters (the ones spesific to a service-feature combination).
57 - *
58 - * FIXME: this causes some wicked error?
5959 */
60 - $parameterInfo = /* array_merge_recursive( MapsMapper::getCommonParameters(), */ SMFormInputs::$parameters /* ) */;
 60+ $parameterInfo = array_merge_recursive( MapsMapper::getCommonParameters(), SMFormInputs::$parameters );
6161 $parameterInfo = array_merge_recursive( $parameterInfo, $egMapsServices[$this->serviceName]['parameters'] );
6262 $parameterInfo = array_merge_recursive( $parameterInfo, $this->spesificParameters );
63 - $parameterInfo = array();
6463
6564 $manager = new ValidatorManager();
6665
6766 $showMap = $manager->manageParameters( $mapProperties, $parameterInfo );
6867
6968 if ( $showMap ) {
70 - $this->setMapProperties( $manager->getParameters( false ), __CLASS__ );
 69+ $parameters = $manager->getParameters( false );
 70+
 71+ foreach ( $parameters as $paramName => $paramValue ) {
 72+ if ( !property_exists( __CLASS__, $paramName ) ) {
 73+ $this-> { $paramName } = $paramValue;
 74+ }
 75+ else {
 76+ // If this happens in any way, it could be a big vunerability, so throw an exception.
 77+ throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName );
 78+ }
 79+ }
7180 }
7281
73 - $this->errorList = $manager->getErrorList();
 82+ $this->errorList = $manager->getErrorList();
7483
7584 return $showMap;
7685 }
@@ -83,14 +92,18 @@
8493 * TODO: Use function args for sf stuffz
8594 */
8695 public final function formInputHTML( $coordinates, $input_name, $is_mandatory, $is_disabled, $field_args ) {
87 - global $wgParser, $sfgTabIndex;
 96+ global $sfgTabIndex;
8897
8998 $this->coordinates = $coordinates;
9099
91100 $this->setMapSettings();
92101
93 - $this->setMapProperties( $field_args );
 102+ $showInput = $this->setMapProperties( $field_args );
94103
 104+ if ( !$showInput ) {
 105+ return array( $this->errorList );
 106+ }
 107+
95108 $this->doMapServiceLoad();
96109
97110 $this->manageGeocoding();
@@ -100,8 +113,6 @@
101114 $this->setZoom();
102115
103116 // Create html element names.
104 - $this->setMapName();
105 - $this->mapName .= '_' . $sfgTabIndex;
106117 $this->geocodeFieldName = $this->elementNamePrefix . '_geocode_' . $this->elementNr . '_' . $sfgTabIndex;
107118 $this->coordsFieldName = $this->elementNamePrefix . '_coords_' . $this->elementNr . '_' . $sfgTabIndex;
108119 $this->infoFieldName = $this->elementNamePrefix . '_info_' . $this->elementNr . '_' . $sfgTabIndex;
@@ -128,7 +139,7 @@
129140
130141 if ( $this->enableGeocoding ) $this->addGeocodingField();
131142
132 - $this->addSpecificMapHTML( $wgParser );
 143+ $this->addSpecificMapHTML();
133144
134145 return array( $this->output . $this->errorList, '' );
135146 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r65938Changes for 0.6 - Follow up to r65937jeroendedauw03:14, 5 May 2010

Status & tagging log