r64998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64997‎ | r64998 | r64999 >
Date:17:37, 13 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r64989, fixed some bugs and used new code from Validator
Modified paths:
  • /trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
@@ -104,7 +104,7 @@
105105 $output = '';
106106 break;
107107 case Validator_ERRORS_WARN:
108 - $output = '<b>' . wfMsgExt( 'validator_warning_parameters', array( 'parsemag' ), count( $fails ) ) . '</b>';
 108+ $output = '<b>' . htmlspecialchars( wfMsgExt( 'validator_warning_parameters', array( 'parsemag' ), count( $fails ) ) ) . '</b>';
109109 break;
110110 case Validator_ERRORS_SHOW: default:
111111 global $wgLang;
@@ -209,7 +209,7 @@
210210 $output = '';
211211 break;
212212 case Validator_ERRORS_WARN:
213 - $output = '<b>' . wfMsgExt( 'validator_warning_parameters', array( 'parsemag' ), 1 ) . '</b>';
 213+ $output = '<b>' . htmlspecialchars( wfMsgExt( 'validator_warning_parameters', array( 'parsemag' ), 1 ) ) . '</b>';
214214 break;
215215 case Validator_ERRORS_SHOW: default:
216216 // Show an error that the location could not be geocoded or the coordinates where not recognized.
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php
@@ -54,13 +54,8 @@
5555 * Handler for the geocode parser function. Returns the latitude and longitude
5656 * for the provided address, or an empty string, when the geocoding fails.
5757 *
58 - * @param $parser
59 - * @param string $coordsOrAddress The address to geocode, or coordinates to reformat.
60 - * @param string $service Optional. The geocoding service to use.
61 - * @param string $mappingService Optional. The mapping service that will use the geocoded data.
 58+ * @param Parser $parser
6259 *
63 - * TODO: rewrite
64 - *
6560 * @return string
6661 */
6762 public static function renderGeocoder( Parser $parser ) {
@@ -73,64 +68,47 @@
7469 // We already know the $parser.
7570 array_shift( $args );
7671
77 - // For backward compatibility with pre 0.6.
78 - $defaultParams = array( 'location', 'service', 'mappingservice' );
79 - $parameters = array();
 72+ $manager = new ValidatorManager();
8073
81 - // Determine all parameter names and value, and take care of default (nameless)
82 - // parameters, by turning them into named ones.
83 - foreach( $args as $arg ) {
84 - $parts = explode( '=', $arg );
85 - if ( count( $parts ) == 1 ) {
86 - if ( count( $defaultParams ) > 0 ) {
87 - $defaultParam = array_shift( $defaultParams );
88 - $parameters[$defaultParam] = trim( $parts[0] );
89 - }
90 - } else {
91 - $name = strtolower( trim( array_shift( $parts ) ) );
92 - $parameters[$name] = trim( implode( $parts ) );
93 - }
94 - }
95 -
96 - $parameterInfo = array(
97 - 'location' => array(
98 - 'required' => true
99 - ),
100 - 'mappingservice' => array(
101 - 'criteria' => array(
102 - 'in_array' => $egMapsAvailableServices
 74+ $parameters = $manager->manageMapparameters(
 75+ $args,
 76+ array(
 77+ 'location' => array(
 78+ 'required' => true
10379 ),
104 - 'default' => false
105 - ),
106 - 'service' => array(
107 - 'criteria' => array(
108 - 'in_array' => $egMapsAvailableGeoServices
 80+ 'mappingservice' => array(
 81+ 'criteria' => array(
 82+ 'in_array' => $egMapsAvailableServices
 83+ ),
 84+ 'default' => false
10985 ),
110 - 'default' => $egMapsDefaultGeoService
111 - ),
112 - 'format' => array(
113 - 'criteria' => array(
114 - 'in_array' => $egMapsAvailableCoordNotations
 86+ 'service' => array(
 87+ 'criteria' => array(
 88+ 'in_array' => $egMapsAvailableGeoServices
 89+ ),
 90+ 'default' => $egMapsDefaultGeoService
11591 ),
116 - 'aliases' => array(
117 - 'notation'
118 - ),
119 - 'default' => $egMapsCoordinateNotation
 92+ 'format' => array(
 93+ 'criteria' => array(
 94+ 'in_array' => $egMapsAvailableCoordNotations
 95+ ),
 96+ 'aliases' => array(
 97+ 'notation'
 98+ ),
 99+ 'default' => $egMapsCoordinateNotation
 100+ ),
 101+ 'allowcoordinates' => array(
 102+ 'type' => 'boolean',
 103+ 'default' => $egMapsAllowCoordsGeocoding
 104+ ),
 105+ 'directional' => array(
 106+ 'type' => 'boolean',
 107+ 'default' => $egMapsCoordinateDirectional
 108+ ),
120109 ),
121 - 'allowcoordinates' => array(
122 - 'type' => 'boolean',
123 - 'default' => $egMapsAllowCoordsGeocoding
124 - ),
125 - 'directional' => array(
126 - 'type' => 'boolean',
127 - 'default' => $egMapsCoordinateDirectional
128 - ),
 110+ array( 'location', 'service', 'mappingservice' )
129111 );
130112
131 - $manager = new ValidatorManager();
132 -
133 - $parameters = $manager->manageMapparameters( $parameters, $parameterInfo );
134 -
135113 $doGeocoding = $parameters !== false;
136114
137115 if ( $doGeocoding ) {
@@ -140,7 +118,7 @@
141119 $parameters['service'],
142120 $parameters['mappingservice'],
143121 $parameters['allowcoordinates'],
144 - $parameters['notation'],
 122+ $parameters['format'],
145123 $parameters['directional']
146124 );
147125 return ( $geovalues ? $geovalues : '' ) . $manager->getErrorList();
@@ -157,7 +135,7 @@
158136 * Handler for the geocode parser function. Returns the latitude
159137 * for the provided address, or an empty string, when the geocoding fails.
160138 *
161 - * @param $parser
 139+ * @param Parser $parser
162140 * @param string $address The address to geocode.
163141 * @param string $service Optional. The geocoding service to use.
164142 * @param string $mappingService Optional. The mapping service that will use the geocoded data.
@@ -173,7 +151,7 @@
174152 * Handler for the geocode parser function. Returns the longitude
175153 * for the provided address, or an empty string, when the geocoding fails.
176154 *
177 - * @param $parser
 155+ * @param Parser $parser
178156 * @param string $address The address to geocode.
179157 * @param string $service Optional. The geocoding service to use.
180158 * @param string $mappingService Optional. The mapping service that will use the geocoded data.
Index: trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php
@@ -47,48 +47,31 @@
4848 // We already know the $parser.
4949 array_shift( $args );
5050
51 - // For backward compatibility with pre 0.6.
52 - $defaultParams = array( 'location', 'format', 'directional' );
53 - $parameters = array();
 51+ $manager = new ValidatorManager();
5452
55 - // Determine all parameter names and value, and take care of default (nameless)
56 - // parameters, by turning them into named ones.
57 - foreach( $args as $arg ) {
58 - $parts = explode( '=', $arg );
59 - if ( count( $parts ) == 1 ) {
60 - if ( count( $defaultParams ) > 0 ) {
61 - $defaultParam = array_shift( $defaultParams );
62 - $parameters[$defaultParam] = trim( $parts[0] );
63 - }
64 - } else {
65 - $name = strtolower( trim( array_shift( $parts ) ) );
66 - $parameters[$name] = trim( implode( $parts ) );
67 - }
68 - }
69 -
70 - $parameterInfo = array(
71 - 'location' => array(
72 - 'required' => true
73 - ),
74 - 'format' => array(
75 - 'criteria' => array(
76 - 'in_array' => $egMapsAvailableCoordNotations
 53+ $parameters = $manager->manageMapparameters(
 54+ $args,
 55+ array(
 56+ 'location' => array(
 57+ 'required' => true
7758 ),
78 - 'aliases' => array(
79 - 'notation'
 59+ 'format' => array(
 60+ 'criteria' => array(
 61+ 'in_array' => $egMapsAvailableCoordNotations
 62+ ),
 63+ 'aliases' => array(
 64+ 'notation'
 65+ ),
 66+ 'default' => $egMapsCoordinateNotation
8067 ),
81 - 'default' => $egMapsCoordinateNotation
 68+ 'directional' => array(
 69+ 'type' => 'boolean',
 70+ 'default' => $egMapsCoordinateDirectional
 71+ ),
8272 ),
83 - 'directional' => array(
84 - 'type' => 'boolean',
85 - 'default' => $egMapsCoordinateDirectional
86 - ),
 73+ array( 'location', 'format', 'directional' )
8774 );
8875
89 - $manager = new ValidatorManager();
90 -
91 - $parameters = $manager->manageMapparameters( $parameters, $parameterInfo );
92 -
9376 $doFormatting = $parameters !== false;
9477
9578 if ( $doFormatting ) {
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -7,6 +7,8 @@
88 * @ingroup Maps
99 *
1010 * @author Jeroen De Dauw
 11+ *
 12+ * TODO: clean up this stuff (goes together with refactoring MapsMapFeature and it's subclasses).
1113 */
1214
1315 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -69,13 +71,13 @@
7072 /**
7173 * Returns the output for the call to the specified parser function.
7274 *
73 - * @param $parser
 75+ * @param Parser $parser
7476 * @param array $params
7577 * @param string $parserFunction
7678 *
7779 * @return array
7880 */
79 - public static function getMapHtml( &$parser, array $params, $parserFunction ) {
 81+ public static function getMapHtml( Parser &$parser, array $params, $parserFunction ) {
8082 global $wgLang, $egValidatorErrorLevel;
8183
8284 array_shift( $params ); // We already know the $parser.

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64989Changes for 0.6 - refactored a bunch of stuff and further implemented #geodis...jeroendedauw15:16, 13 April 2010

Status & tagging log