r73708 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73707‎ | r73708 | r73709 >
Date:03:47, 25 September 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Addded distance criterion
Modified paths:
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/includes/criteria/CriterionIsDistance.php (added) (history)
  • /trunk/extensions/Maps/includes/manipulations/Maps_ParamService.php (modified) (history)
  • /trunk/extensions/Maps/includes/parserHooks/Maps_Distance.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.i18n.php
@@ -49,7 +49,7 @@
5050 'maps_map_cannot_be_displayed' => 'The map cannot be displayed.',
5151
5252 // Distance
53 - 'maps_invalid_distance' => 'The value $1 is not a valid distance.',
 53+ 'validation-error-invalid-distance' => 'The value $1 is not a valid distance.',
5454
5555 // Geocoding
5656 'maps-geocoder-not-available' => 'The geocoding feature of Maps is not available. Your location can not be geocoded.',
Index: trunk/extensions/Maps/Maps.php
@@ -103,6 +103,7 @@
104104
105105 // Autoload the "includes/criteria/" classes.
106106 $criDir = $incDir . 'criteria/';
 107+ $wgAutoloadClasses['CriterionIsDistance'] = $criDir . 'CriterionIsDistance.php';
107108 $wgAutoloadClasses['CriterionIsLocation'] = $criDir . 'CriterionIsLocation.php';
108109 $wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php';
109110
Index: trunk/extensions/Maps/includes/manipulations/Maps_ParamService.php
@@ -41,7 +41,7 @@
4242
4343 $this->feature = $feature;
4444 $this->serviceParams = $serviceParams;
45 - }
 45+ }
4646
4747 /**
4848 * @see ItemParameterManipulation::doManipulation
Index: trunk/extensions/Maps/includes/parserHooks/Maps_Distance.php
@@ -58,10 +58,8 @@
5959
6060 $params = array();
6161
62 - $params['distance'] = new Parameter(
63 - 'distance'
64 - // TODO: add distance criterion
65 - );
 62+ $params['distance'] = new Parameter( 'distance' );
 63+ $params['distance']->addCriteria( new CriterionIsDistance() );
6664
6765 $params['unit'] = new Parameter(
6866 'unit',
@@ -106,15 +104,7 @@
107105 */
108106 public function render( array $parameters ) {
109107 $distanceInMeters = MapsDistanceParser::parseDistance( $parameters['distance'] );
110 -
111 - if ( $distanceInMeters ) {
112 - $output = MapsDistanceParser::formatDistance( $distanceInMeters, $parameters['unit'], $parameters['decimals'] );
113 - } else {
114 - // TODO: use ParserHook class methods to handle errors
115 - $output = wfMsgExt( 'maps_invalid_distance', 'parsemag', '<b>' . $parameters['distance'] . '</b>' );
116 - }
117 -
118 - return $output;
 108+ return MapsDistanceParser::formatDistance( $distanceInMeters, $parameters['unit'], $parameters['decimals'] );
119109 }
120110
121111 }
\ No newline at end of file
Index: trunk/extensions/Maps/includes/criteria/CriterionIsDistance.php
@@ -0,0 +1,47 @@
 2+<?php
 3+
 4+/**
 5+ * Parameter criterion stating that the value must be a distance.
 6+ *
 7+ * @since 0.7
 8+ *
 9+ * @file CriterionIsDistance.php
 10+ * @ingroup Maps
 11+ * @ingroup Criteria
 12+ *
 13+ * @author Jeroen De Dauw
 14+ */
 15+class CriterionIsDistance extends ItemParameterCriterion {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @since 0.7
 21+ */
 22+ public function __construct() {
 23+ parent::__construct();
 24+ }
 25+
 26+ /**
 27+ * @see ItemParameterCriterion::validate
 28+ */
 29+ protected function doValidation( $value ) {
 30+ return MapsDistanceParser::isDistance( $value );
 31+ }
 32+
 33+ /**
 34+ * @see ItemParameterCriterion::getItemErrorMessage
 35+ */
 36+ protected function getItemErrorMessage( Parameter $parameter ) {
 37+ return wfMsgExt( 'validation-error-invalid-distance', 'parsemag', $parameter->getOriginalName() );
 38+ }
 39+
 40+ /**
 41+ * @see ItemParameterCriterion::getListErrorMessage
 42+ */
 43+ protected function getListErrorMessage( Parameter $parameter, array $invalidItems ) {
 44+ global $wgLang;
 45+ return wfMsgExt( '', 'parsemag', $wgLang->listToText( $invalidItems ), count( $invalidItems ) );
 46+ }
 47+
 48+}
\ No newline at end of file
Property changes on: trunk/extensions/Maps/includes/criteria/CriterionIsDistance.php
___________________________________________________________________
Added: svn:eol-style
149 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r73709Follow up to r73708jeroendedauw03:54, 25 September 2010
r73710Follow up to r73708jeroendedauw04:39, 25 September 2010
r73711Follow up to r73708jeroendedauw04:40, 25 September 2010

Status & tagging log