r82185 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82184‎ | r82185 | r82186 >
Date:19:44, 15 February 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Some geocoder related fixes and version increment to 0.7.5 rc
Modified paths:
  • /trunk/extensions/Maps/INSTALL (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Geocoder.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Geocoders.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/includes/features/Maps_BasePointMap.php (modified) (history)
  • /trunk/extensions/Maps/includes/geocoders/Maps_GoogleGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/includes/geocoders/Maps_YahooGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/includes/manipulations/Maps_ParamGeoService.php (added) (history)
  • /trunk/extensions/Maps/includes/parserHooks/Maps_DisplayPoint.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/INSTALL
@@ -1,4 +1,4 @@
2 -[[Maps 0.7.4]]
 2+[[Maps 0.7.5]]
33
44 In order to use this version of Maps, you need to have Validator 0.3.6 installed. If you get a distribution
55 from this page, you don't need to bother this, since Validator comes bundled with every release, and will
Index: trunk/extensions/Maps/Maps.php
@@ -36,7 +36,7 @@
3737 die( '<b>Error:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.<br />' );
3838 }
3939 else {
40 - define( 'Maps_VERSION', '0.7.5 alpha' );
 40+ define( 'Maps_VERSION', '0.7.5 rc' );
4141
4242 // The different coordinate notations.
4343 define( 'Maps_COORDS_FLOAT', 'float' );
@@ -99,6 +99,7 @@
100100 $manDir = $incDir . 'manipulations/';
101101 $wgAutoloadClasses['MapsParamCoordSet'] = $manDir . 'Maps_ParamCoordSet.php';
102102 $wgAutoloadClasses['MapsParamDimension'] = $manDir . 'Maps_ParamDimension.php';
 103+ $wgAutoloadClasses['MapsParamGeoService'] = $manDir . 'Maps_ParamGeoService.php';
103104 $wgAutoloadClasses['MapsParamImage'] = $manDir . 'Maps_ParamImage.php';
104105 $wgAutoloadClasses['MapsParamLocation'] = $manDir . 'Maps_ParamLocation.php';
105106 $wgAutoloadClasses['MapsParamService'] = $manDir . 'Maps_ParamService.php';
Index: trunk/extensions/Maps/RELEASE-NOTES
@@ -7,6 +7,13 @@
88 http://mapping.referata.com/wiki/Maps/Version_history#Maps_change_log
99
1010
 11+=== Maps 0.7.5 ===
 12+(2011-02-16)
 13+
 14+* Fixed incorrect defaulting of geocoding service.
 15+
 16+* Improved default width of maps.
 17+
1118 === Maps 0.7.4 ===
1219 (2011-01-20)
1320
Index: trunk/extensions/Maps/includes/Maps_Geocoders.php
@@ -35,7 +35,7 @@
3636 *
3737 * @var array of string => string
3838 */
39 - protected static $registeredGeocoders = array();
 39+ public static $registeredGeocoders = array();
4040
4141 /**
4242 * The global geocoder cache, holding geocoded data when enabled.
@@ -297,22 +297,16 @@
298298 * main identifier. If it's not recognized at all (or empty), the default will be used.
299299 * Only call this function when there are geocoders available, else an erro will be thrown.
300300 *
301 - * TODO: implement overrides
302 - *
303301 * @since 0.7
304302 *
305303 * @param string $geocoderIdentifier
306 - * @param string $mappingService
307304 *
308305 * @return string or false
309306 */
310 - protected static function getValidGeocoderIdentifier( $geocoderIdentifier /*, $mappingService */ ) {
 307+ protected static function getValidGeocoderIdentifier( $geocoderIdentifier ) {
311308 global $egMapsDefaultGeoService, $egMapsUserGeoOverrides;
312309 static $validatedDefault = false;
313310
314 - // Get rid of any aliases.
315 - $geocoderIdentifier = self::getMainGeocoderIndentifier( $geocoderIdentifier );
316 -
317311 if ( $geocoderIdentifier == '' || !array_key_exists( $geocoderIdentifier, self::$registeredGeocoders ) ) {
318312 if ( !$validatedDefault ) {
319313 if ( !array_key_exists( $egMapsDefaultGeoService, self::$registeredGeocoders ) ) {
@@ -334,18 +328,4 @@
335329 return $geocoderIdentifier;
336330 }
337331
338 - /**
339 - * Gets the main geocoder identifier by resolving aliases.
340 - *
341 - * @since 0.7
342 - *
343 - * @param string $geocoderIdentifier
344 - *
345 - * @return string
346 - */
347 - protected static function getMainGeocoderIndentifier( $geocoderIdentifier ) {
348 - // TODO: implement actual function
349 - return $geocoderIdentifier;
350 - }
351 -
352 -}
\ No newline at end of file
 332+}
Index: trunk/extensions/Maps/includes/manipulations/Maps_ParamGeoService.php
@@ -0,0 +1,120 @@
 2+<?php
 3+
 4+/**
 5+ * Parameter manipulation ensuring the value is a geocoding service,
 6+ * and taking care of both alias resolving and overrides handling.
 7+ *
 8+ * @since 0.7.5
 9+ *
 10+ * @file Maps_ParamGeoService.php
 11+ * @ingroup Maps
 12+ * @ingroup ParameterManipulations
 13+ *
 14+ * @author Jeroen De Dauw
 15+ */
 16+class MapsParamGeoService extends ItemParameterManipulation {
 17+
 18+ /**
 19+ * @since 0.7.5
 20+ *
 21+ * @var string or false
 22+ */
 23+ protected $mappingServiceParam;
 24+
 25+ /**
 26+ * Constructor.
 27+ *
 28+ * @since 0.7.5
 29+ */
 30+ public function __construct( $mappingServiceParam = false ) {
 31+ parent::__construct();
 32+
 33+ $this->mappingServiceParam = $mappingServiceParam;
 34+ }
 35+
 36+ /**
 37+ * @see ItemParameterManipulation::doManipulation
 38+ *
 39+ * @since 0.7.5
 40+ */
 41+ public function doManipulation( &$value, Parameter $parameter, array &$parameters ) {
 42+ global $egMapsDefaultGeoService, $egMapsUserGeoOverrides;
 43+ static $validatedDefault = false;
 44+
 45+ if ( !MapsGeocoders::canGeocode() ) {
 46+ throw new Exception( 'There are no geocoders registered, so no geocoding can happen.' );
 47+ }
 48+
 49+ // Get rid of any aliases.
 50+ $value = $this->getMainIndentifier( $value );
 51+
 52+ // Override the defaulting.
 53+ if ( $parameter->wasSetToDefault() && $this->mappingServiceParam !== false ) {
 54+ $value = self::resolveOverrides( $value, $parameters[$this->mappingServiceParam]->getValue() );
 55+ }
 56+
 57+ if ( $value == '' || !array_key_exists( $value, MapsGeocoders::$registeredGeocoders ) ) {
 58+ if ( !$validatedDefault ) {
 59+ if ( !array_key_exists( $egMapsDefaultGeoService, MapsGeocoders::$registeredGeocoders ) ) {
 60+ $egMapsDefaultGeoService = array_shift( array_keys( MapsGeocoders::$registeredGeocoders ) );
 61+ if ( is_null( $egMapsDefaultGeoService ) ) {
 62+ throw new Exception( 'Tried to geocode while there are no geocoders available at ' . __METHOD__ );
 63+ }
 64+ }
 65+ }
 66+
 67+ if ( array_key_exists( $egMapsDefaultGeoService, MapsGeocoders::$registeredGeocoders ) ) {
 68+ $value = $egMapsDefaultGeoService;
 69+ }
 70+ else {
 71+ throw new Exception( 'Attempt to use the default geocoder while it does not exist.' );
 72+ }
 73+ }
 74+ }
 75+
 76+ /**
 77+ * Replaces the geocoder identifier in case there is an override specified by
 78+ * one of the registered geocoders.
 79+ *
 80+ * @since 0.7.5
 81+ *
 82+ * @param string $geocoderIdentifier
 83+ * @param string $mappingService
 84+ *
 85+ * @return string
 86+ */
 87+ protected static function resolveOverrides( $geocoderIdentifier, $mappingService ) {
 88+ static $overrides = false;
 89+
 90+ if ( $overrides === false ) {
 91+ $overrides = array();
 92+
 93+ foreach ( MapsGeocoders::$registeredGeocoders as $key => $class ) {
 94+ $overrides[$key] = call_user_func( array( $class, 'getOverrides' ) );
 95+ }
 96+ }
 97+
 98+ foreach ( $overrides as $geocoder => $services ) {
 99+ if ( in_array( $mappingService, $services ) ) {
 100+ return $geocoder;
 101+ }
 102+ }
 103+
 104+ return $geocoderIdentifier;
 105+ }
 106+
 107+ /**
 108+ * Gets the main geocoder identifier by resolving aliases.
 109+ *
 110+ * @since 0.7.5
 111+ *
 112+ * @param string $geocoderIdentifier
 113+ *
 114+ * @return string
 115+ */
 116+ protected function getMainIndentifier( $geocoderIdentifier ) {
 117+ // TODO: implement actual function
 118+ return $geocoderIdentifier;
 119+ }
 120+
 121+}
\ No newline at end of file
Property changes on: trunk/extensions/Maps/includes/manipulations/Maps_ParamGeoService.php
___________________________________________________________________
Added: svn:eol-style
1122 + native
Index: trunk/extensions/Maps/includes/Maps_Mapper.php
@@ -68,7 +68,7 @@
6969 *
7070 * This is a copy of
7171 * @see Xml::encodeJsVar
72 - * which fixes incorrect behaviour with floats.
 72+ * which fixes incorrect behaviour with floats (fixed in MW 1.18).
7373 *
7474 * @since 0.7.1
7575 *
@@ -125,16 +125,11 @@
126126 $params['mappingservice']->setDefault( $egMapsDefaultService );
127127 $params['mappingservice']->addCriteria( new CriterionInArray( MapsMappingServices::getAllServiceValues() ) );
128128
129 - $params['geoservice'] = new Parameter(
130 - 'geoservice',
131 - Parameter::TYPE_STRING,
132 - $egMapsDefaultGeoService,
133 - array(),
134 - array(
135 - new CriterionInArray( $egMapsAvailableGeoServices ),
136 - ),
137 - array( 'mappingservice' )
138 - );
 129+ $params['geoservice'] = new Parameter( 'geoservice' );
 130+ $params['geoservice']->setDefault( $egMapsDefaultGeoService );
 131+ $params['geoservice']->addCriteria( new CriterionInArray( $egMapsAvailableGeoServices ) );
 132+ $params['geoservice']->addDependencies( 'mappingservice' );
 133+ $params['geoservice']->addManipulations( new MapsParamGeoService( 'mappingservice' ) );
139134
140135 $params['zoom'] = new Parameter(
141136 'zoom',
Index: trunk/extensions/Maps/includes/Maps_Geocoder.php
@@ -143,7 +143,7 @@
144144 *
145145 * @return array
146146 */
147 - public function getOverrides() {
 147+ public static function getOverrides() {
148148 return array();
149149 }
150150
Index: trunk/extensions/Maps/includes/parserHooks/Maps_DisplayPoint.php
@@ -141,7 +141,7 @@
142142 // Get an instance of the class handling the current parser hook and service.
143143 $mapClass = $service->getFeatureInstance( 'display_point' );
144144
145 - return $mapClass->getMapHtml( $parameters, $this->parser );
 145+ return $mapClass->getMapHtml( $parameters, $this->parser, $this->frame );
146146 }
147147
148148 /**
Index: trunk/extensions/Maps/includes/geocoders/Maps_GoogleGeocoder.php
@@ -74,7 +74,7 @@
7575 *
7676 * @return array
7777 */
78 - public function getOverrides() {
 78+ public static function getOverrides() {
7979 return array( 'googlemaps2', 'googlemaps3' );
8080 }
8181
Index: trunk/extensions/Maps/includes/geocoders/Maps_YahooGeocoder.php
@@ -69,7 +69,7 @@
7070 *
7171 * @return array
7272 */
73 - public function getOverrides() {
 73+ public static function getOverrides() {
7474 return array( 'yahoomaps' );
7575 }
7676
Index: trunk/extensions/Maps/includes/features/Maps_BasePointMap.php
@@ -81,10 +81,10 @@
8282 *
8383 * @return html
8484 */
85 - public final function getMapHtml( array $params, Parser $parser ) {
 85+ public final function getMapHtml( array $params, Parser $parser, PPFrame $frame = null ) {
8686 $this->setMapProperties( $params );
8787
88 - $this->setMarkerData();
 88+ $this->setMarkerData( $parser, $frame );
8989
9090 $this->setCentre();
9191
@@ -112,15 +112,12 @@
113113 /**
114114 * Fills the $markerData array with the locations and their meta data.
115115 */
116 - private function setMarkerData() {
 116+ private function setMarkerData( Parser $parser, PPFrame $frame = null ) {
117117 global $wgTitle;
118118
119 - // New parser object to render popup contents with.
120 - $parser = new Parser();
 119+ $this->title = $parser->recursiveTagParse( $this->title, $frame );
 120+ $this->label = $parser->recursiveTagParse( $this->label, $frame );
121121
122 - $this->title = $parser->parse( $this->title, $wgTitle, new ParserOptions() )->getText();
123 - $this->label = $parser->parse( $this->label, $wgTitle, new ParserOptions() )->getText();
124 -
125122 // Each $args is an array containg the coordinate set as first element, possibly followed by meta data.
126123 foreach ( $this->coordinates as $args ) {
127124 $markerData = MapsCoordinateParser::parseCoordinates( array_shift( $args ) );
@@ -131,11 +128,11 @@
132129
133130 if ( count( $args ) > 0 ) {
134131 // Parse and add the point specific title if it's present.
135 - $markerData['title'] = $parser->parse( $args[0], $wgTitle, new ParserOptions() )->getText();
 132+ $markerData['title'] = $parser->recursiveTagParse( $args[0], $frame );
136133
137134 if ( count( $args ) > 1 ) {
138135 // Parse and add the point specific label if it's present.
139 - $markerData['label'] = $parser->parse( $args[1], $wgTitle, new ParserOptions() )->getText();
 136+ $markerData['label'] = $parser->recursiveTagParse( $args[1], $frame );
140137
141138 if ( count( $args ) > 2 ) {
142139 // Add the point specific icon if it's present.

Follow-up revisions

RevisionCommit summaryAuthorDate
r83925MFT r82185jeroendedauw16:52, 14 March 2011

Status & tagging log