r67946 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67945‎ | r67946 | r67947 >
Date:13:56, 13 June 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6.3 - Follow up to r67904
Modified paths:
  • /trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInputs.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Features/QueryPrinters/SM_MapPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Features/QueryPrinters/SM_Mapper.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Features/QueryPrinters/SM_QueryPrinters.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/GoogleMaps/SM_GoogleMapsFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/GoogleMaps/SM_GoogleMapsQP.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/OpenLayers/SM_OpenLayersFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/OpenLayers/SM_OpenLayersQP.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/YahooMaps/SM_YahooMapsFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/Services/YahooMaps/SM_YahooMapsQP.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/Services/YahooMaps/SM_YahooMapsQP.php
@@ -14,8 +14,6 @@
1515
1616 final class SMYahooMapsQP extends SMMapPrinter {
1717
18 - public $serviceName = MapsYahooMaps::SERVICE_NAME;
19 -
2018 /**
2119 * @see SMMapPrinter::setQueryPrinterSettings()
2220 */
Index: trunk/extensions/SemanticMaps/Services/YahooMaps/SM_YahooMapsFormInput.php
@@ -15,8 +15,6 @@
1616
1717 final class SMYahooMapsFormInput extends SMFormInput {
1818
19 - public $serviceName = MapsYahooMaps::SERVICE_NAME;
20 -
2119 protected $specificParameters = array();
2220
2321 /**
Index: trunk/extensions/SemanticMaps/Services/OpenLayers/SM_OpenLayersQP.php
@@ -15,8 +15,6 @@
1616
1717 final class SMOpenLayersQP extends SMMapPrinter {
1818
19 - public $serviceName = MapsOpenLayers::SERVICE_NAME;
20 -
2119 /**
2220 * @see SMMapPrinter::setQueryPrinterSettings()
2321 *
Index: trunk/extensions/SemanticMaps/Services/OpenLayers/SM_OpenLayersFormInput.php
@@ -15,8 +15,6 @@
1616
1717 final class SMOpenLayersFormInput extends SMFormInput {
1818
19 - public $serviceName = MapsOpenLayers::SERVICE_NAME;
20 -
2119 protected $specificParameters = array();
2220
2321 /**
Index: trunk/extensions/SemanticMaps/Services/GoogleMaps/SM_GoogleMapsQP.php
@@ -16,8 +16,6 @@
1717
1818 final class SMGoogleMapsQP extends SMMapPrinter {
1919
20 - public $serviceName = MapsGoogleMaps::SERVICE_NAME;
21 -
2220 protected $specificParameters;
2321
2422 /**
Index: trunk/extensions/SemanticMaps/Services/GoogleMaps/SM_GoogleMapsFormInput.php
@@ -17,8 +17,6 @@
1818
1919 final class SMGoogleMapsFormInput extends SMFormInput {
2020
21 - public $serviceName = MapsGoogleMaps::SERVICE_NAME;
22 -
2321 protected $specificParameters = array();
2422
2523 /**
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.3 a3' );
 39+ define( 'SM_VERSION', '0.6.3 a4' );
4040
4141 $smgScriptPath = ( isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps';
4242 $smgDir = dirname( __FILE__ ) . '/';
Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInput.php
@@ -25,6 +25,8 @@
2626 */
2727 protected abstract function addFormDependencies();
2828
 29+ protected $mService;
 30+
2931 /**
3032 * @var string
3133 */
@@ -43,6 +45,10 @@
4446
4547 private $coordinates;
4648
 49+ public function __construct( MapsMappingService $service ) {
 50+ $this->mService = $service;
 51+ }
 52+
4753 /**
4854 * Validates and corrects the provided map properties, and the sets them as class fields.
4955 *
@@ -61,7 +67,7 @@
6268 * and finally by the specific parameters (the ones specific to a service-feature combination).
6369 */
6470 $parameterInfo = array_merge_recursive( MapsMapper::getCommonParameters(), SMFormInputs::$parameters );
65 - $parameterInfo = array_merge_recursive( $parameterInfo, $egMapsServices[$this->serviceName]['parameters'] );
 71+ $parameterInfo = array_merge_recursive( $parameterInfo, $this->mService->getParameterInfo() );
6672 $parameterInfo = array_merge_recursive( $parameterInfo, $this->specificParameters );
6773
6874 $manager = new ValidatorManager();
@@ -258,8 +264,6 @@
259265 * Returns html for an html input field with a default value that will automatically dissapear when
260266 * the user clicks in it, and reappers when the focus on the field is lost and it's still empty.
261267 *
262 - * @author Jeroen De Dauw
263 - *
264268 * @param string $id
265269 * @param string $value
266270 * @param string $args
@@ -269,4 +273,4 @@
270274 private static function getDynamicInput( $id, $value, $args = '' ) {
271275 return '<input id="' . $id . '" ' . $args . ' value="' . $value . '" onfocus="if (this.value==\'' . $value . '\') {this.value=\'\';}" onblur="if (this.value==\'\') {this.value=\'' . $value . '\';}" />';
272276 }
273 -}
 277+}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/Features/FormInputs/SM_FormInputs.php
@@ -34,21 +34,21 @@
3535
3636 self::initializeParams();
3737
38 - foreach ( $egMapsServices as $serviceName => $serviceData ) {
39 - // Check if the service has a form input
40 - $hasFI = array_key_exists( 'fi', $serviceData['features'] );
 38+ foreach ( $egMapsServices as $service ) {
 39+ // Check if the service has a form input.
 40+ $FIClass = $service->getFeature( 'fi' );
4141
4242 // If the service has no FI, skipt it and continue with the next one.
43 - if ( !$hasFI ) continue;
 43+ if ( $FIClass === false ) continue;
4444
4545 // At least one form input will be enabled when this point is reached.
4646 $hasFormInputs = true;
4747
4848 // Add the result form input type for the service name.
49 - self::initFormHook( $serviceName, $serviceName );
 49+ self::initFormHook( $service->getName(), $service->getName() );
5050
5151 // Loop through the service alliases, and add them as form input types.
52 - foreach ( $serviceData['aliases'] as $alias ) self::initFormHook( $alias, $serviceName );
 52+ foreach ( $service->getAliases() as $alias ) self::initFormHook( $alias, $service->getName() );
5353 }
5454
5555 // Add the 'map' form input type if there are mapping services that have FI's loaded.
@@ -121,16 +121,18 @@
122122
123123 // Get the service name from the field_args, and set it to null if it doesn't exist.
124124 if ( array_key_exists( 'service_name', $field_args ) ) {
125 - $service_name = $field_args['service_name'];
 125+ $serviceName = $field_args['service_name'];
126126 }
127127 else {
128 - $service_name = null;
 128+ $serviceName = null;
129129 }
130130
131131 // Ensure the service is valid and create a new instance of the handling form input class.
132 - $service_name = MapsMapper::getValidService( $service_name, 'fi' );
133 - $formInput = new $egMapsServices[$service_name]['features']['fi']();
 132+ $serviceName = MapsMapper::getValidService( $serviceName, 'fi' );
 133+ $FIClass = $egMapsServices[$serviceName]->getFeature( 'fi' );
134134
 135+ $formInput = new $FIClass( $egMapsServices[$serviceName] );
 136+
135137 // Get and return the form input HTML from the hook corresponding with the provided service.
136138 return $formInput->formInputHTML( $coordinates, $input_name, $is_mandatory, $is_disabled, $field_args );
137139 }
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/Features/QueryPrinters/SM_QueryPrinters.php
@@ -34,18 +34,18 @@
3535
3636 $hasQueryPrinters = false;
3737
38 - foreach ( $egMapsServices as $serviceName => $serviceData ) {
 38+ foreach ( $egMapsServices as $service ) {
3939 // Check if the service has a query printer.
40 - $hasQP = array_key_exists( 'qp', $serviceData['features'] );
 40+ $QPClass = $service->getFeature( 'qp' );
4141
4242 // If the service has no QP, skipt it and continue with the next one.
43 - if ( !$hasQP ) continue;
 43+ if ( $QPClass === false ) continue;
4444
4545 // At least one query printer will be enabled when this point is reached.
4646 $hasQueryPrinters = true;
4747
4848 // Initiate the format.
49 - self::initFormat( $serviceName, $serviceData['features']['qp'], $serviceData['aliases'] );
 49+ self::initFormat( $service->getName(), $QPClass, $service->getAliases() );
5050 }
5151
5252 // Add the 'map' result format if there are mapping services that have QP's loaded.
Index: trunk/extensions/SemanticMaps/Features/QueryPrinters/SM_MapPrinter.php
@@ -43,7 +43,7 @@
4444 */
4545 protected abstract function addSpecificMapHTML( Parser $parser );
4646
47 - public $serviceName;
 47+ protected $mService;
4848
4949 protected $mLocations = array();
5050
@@ -60,6 +60,10 @@
6161 protected $featureParameters = array();
6262 protected $specificParameters = array();
6363
 64+ public function __construct( $format, $inline, /* MapsMappingService */ $service = null ) {
 65+ $this->mService = $service;
 66+ }
 67+
6468 /**
6569 * Builds up and returns the HTML for the map, with the queried coordinate data on it.
6670 *
@@ -115,7 +119,7 @@
116120 * and finally by the specific parameters (the ones specific to a service-feature combination).
117121 */
118122 $parameterInfo = array_merge_recursive( MapsMapper::getCommonParameters(), $this->featureParameters );
119 - $parameterInfo = array_merge_recursive( $parameterInfo, $egMapsServices[$this->serviceName]['parameters'] );
 123+ $parameterInfo = array_merge_recursive( $parameterInfo, $this->mService->getParameterInfo() );
120124 $parameterInfo = array_merge_recursive( $parameterInfo, $this->specificParameters );
121125
122126 $manager = new ValidatorManager();
@@ -135,7 +139,6 @@
136140 * Sets the map properties as class fields.
137141 *
138142 * @param array $mapProperties
139 - * @param string $className
140143 */
141144 private function setMapProperties( array $mapProperties ) {
142145 foreach ( $mapProperties as $paramName => $paramValue ) {
@@ -149,7 +152,7 @@
150153 }
151154
152155 public final function getResult( $results, $params, $outputmode ) {
153 - // Skip checks, results with 0 entries are normal
 156+ // Skip checks, results with 0 entries are normal.
154157 $this->readParameters( $params, $outputmode );
155158
156159 return $this->getResultText( $results, SMW_OUTPUT_HTML );
@@ -166,9 +169,9 @@
167170 * and add the location data, title, label and icon to the m_locations array.
168171 *
169172 * @param unknown_type $outputmode
170 - * @param unknown_type $row The record you want to add data from
 173+ * @param array $row The record you want to add data from
171174 */
172 - private function addResultRow( $outputmode, $row ) {
 175+ private function addResultRow( $outputmode, array $row ) {
173176 global $wgUser, $smgUseSpatialExtensions;
174177
175178 $skin = $wgUser->getSkin();
@@ -182,11 +185,11 @@
183186 $coords = array();
184187 $label = array();
185188
186 - // Loop throught all fields of the record
 189+ // Loop throught all fields of the record.
187190 foreach ( $row as $i => $field ) {
188191 $pr = $field->getPrintRequest();
189192
190 - // Loop throught all the parts of the field value
 193+ // Loop throught all the parts of the field value.
191194 while ( ( $object = $field->getNextObject() ) !== false ) {
192195 if ( $object->getTypeID() == '_wpg' && $i == 0 ) {
193196 if ( $this->showtitle ) $title = $object->getLongText( $outputmode, $skin );
@@ -248,12 +251,13 @@
249252 }
250253
251254 /**
252 - * Get the icon for a row
 255+ * Get the icon for a row.
253256 *
254 - * @param unknown_type $row
255 - * @return unknown
 257+ * @param array $row
 258+ *
 259+ * @return string
256260 */
257 - private function getLocationIcon( $row ) {
 261+ private function getLocationIcon( array $row ) {
258262 $icon = '';
259263 $legend_labels = array();
260264
@@ -287,7 +291,6 @@
288292
289293 /**
290294 * Sets the zoom level to the provided value, or when not set, to the default.
291 - *
292295 */
293296 private function setZoom() {
294297 if ( strlen( $this->zoom ) < 1 ) {
@@ -303,7 +306,6 @@
304307 /**
305308 * Sets the $centre_lat and $centre_lon fields.
306309 * Note: this needs to be done AFTRE the maker coordinates are set.
307 - *
308310 */
309311 private function setCentre() {
310312 // If a centre value is set, use it.
@@ -357,4 +359,4 @@
358360 return $params;
359361 }
360362
361 -}
 363+}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/Features/QueryPrinters/SM_Mapper.php
@@ -24,9 +24,10 @@
2525 // Note: if this is allowed, then the getParameters should only return the base parameters.
2626 if ( $format == 'map' ) $format = $egMapsDefaultServices['qp'];
2727
28 - $service = MapsMapper::getValidService( $format, 'qp' );
 28+ $service = $egMapsServices[MapsMapper::getValidService( $format, 'qp' )];
 29+ $QPClass = $service->getFeature( 'qp' );
2930
30 - $this->queryPrinter = new $egMapsServices[$service]['features']['qp']( $format, $inline );
 31+ $this->queryPrinter = new $QPClass( $format, $inline, $service );
3132 }
3233
3334 public static function getAliases() {
@@ -61,4 +62,4 @@
6263 return $this->queryPrinter->getMimeType( $res );
6364 }
6465
65 -}
 66+}
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r67904Changes for 0.6.3 - rewrote service handling (incompatible with SM for now)jeroendedauw16:15, 12 June 2010

Status & tagging log