Index: trunk/extensions/Maps/Maps.i18n.php |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | 'maps_map_cannot_be_displayed' => 'The map cannot be displayed.', |
51 | 51 | |
52 | 52 | // 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.', |
54 | 54 | |
55 | 55 | // Geocoding |
56 | 56 | '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 @@ |
104 | 104 | |
105 | 105 | // Autoload the "includes/criteria/" classes. |
106 | 106 | $criDir = $incDir . 'criteria/'; |
| 107 | + $wgAutoloadClasses['CriterionIsDistance'] = $criDir . 'CriterionIsDistance.php'; |
107 | 108 | $wgAutoloadClasses['CriterionIsLocation'] = $criDir . 'CriterionIsLocation.php'; |
108 | 109 | $wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php'; |
109 | 110 | |
Index: trunk/extensions/Maps/includes/manipulations/Maps_ParamService.php |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | |
43 | 43 | $this->feature = $feature; |
44 | 44 | $this->serviceParams = $serviceParams; |
45 | | - } |
| 45 | + } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @see ItemParameterManipulation::doManipulation |
Index: trunk/extensions/Maps/includes/parserHooks/Maps_Distance.php |
— | — | @@ -58,10 +58,8 @@ |
59 | 59 | |
60 | 60 | $params = array(); |
61 | 61 | |
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() ); |
66 | 64 | |
67 | 65 | $params['unit'] = new Parameter( |
68 | 66 | 'unit', |
— | — | @@ -106,15 +104,7 @@ |
107 | 105 | */ |
108 | 106 | public function render( array $parameters ) { |
109 | 107 | $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'] ); |
119 | 109 | } |
120 | 110 | |
121 | 111 | } |
\ 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 |
1 | 49 | + native |