Index: trunk/extensions/GeoData/tests/TagTest.php |
— | — | @@ -0,0 +1,33 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * @group GeoData |
| 6 | + */ |
| 7 | +class TagTest extends MediaWikiTestCase { |
| 8 | + /** |
| 9 | + * @dataProvider getData |
| 10 | + */ |
| 11 | + public function testTagParsing( $input, $expected ) { |
| 12 | + $p = new Parser(); |
| 13 | + $opt = new ParserOptions(); |
| 14 | + $out = $p->parse( $input, Title::newMainPage(), $opt ); |
| 15 | + $this->assertTrue( isset( $out->geoData ) ); |
| 16 | + $coord = $out->geoData['primary'] ? $out->geoData['primary'] : $out->geoData['secondary'][0]; |
| 17 | + foreach ( $expected as $field => $value ) { |
| 18 | + $this->assertEquals( $value, $coord->$field, "Checking field $field" ); |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + public function getData() { |
| 23 | + return array( |
| 24 | + array( |
| 25 | + '{{#coordinates: 10|20|primary}}', |
| 26 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'primary' => true ), |
| 27 | + ), |
| 28 | + array( |
| 29 | + '{{#coordinates:10|20|globe:Moon dim:10_region:RU-mos}}', |
| 30 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'moon', 'country' => 'RU', 'region' => 'MOS' ), |
| 31 | + ), |
| 32 | + ); |
| 33 | + } |
| 34 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/GeoData/tests/TagTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 35 | + native |
Index: trunk/extensions/GeoData/GeoData.body.php |
— | — | @@ -165,20 +165,29 @@ |
166 | 166 | return $result; |
167 | 167 | } |
168 | 168 | |
169 | | - private static function getCoordInfo() { |
170 | | - //@todo: internationalisation? |
171 | | - return array( |
172 | | - 'lat' => array( |
173 | | - 'range' => 90, |
174 | | - '+' => array( 'N' ), |
175 | | - '-' => array( 'S' ), |
176 | | - ), |
177 | | - 'lon' => array( |
178 | | - 'range' => 180, |
179 | | - '+' => array( 'E' ), |
180 | | - '-' => array( 'W' ), |
181 | | - ), |
182 | | - ); |
| 169 | + public static function getCoordInfo() { |
| 170 | + global $wgContLang; |
| 171 | + static $result = null; |
| 172 | + if ( !$result ) { |
| 173 | + $result = array( |
| 174 | + 'lat' => array( |
| 175 | + 'range' => 90, |
| 176 | + '+' => array( 'N' ), |
| 177 | + '-' => array( 'S' ), |
| 178 | + ), |
| 179 | + 'lon' => array( |
| 180 | + 'range' => 180, |
| 181 | + '+' => array( 'E' ), |
| 182 | + '-' => array( 'W' ), |
| 183 | + ), |
| 184 | + 'primary' => array( 'primary' ), |
| 185 | + ); |
| 186 | + if ( $wgContLang->getCode() != 'en' ) { |
| 187 | + $result['primary'][] = wfMessage( 'geodata-primary-coordinate' )->plain(); |
| 188 | + } |
| 189 | + $result['primary'] = array_flip( $result['primary'] ); |
| 190 | + } |
| 191 | + return $result; |
183 | 192 | } |
184 | 193 | } |
185 | 194 | |
Index: trunk/extensions/GeoData/GeoDataHooks.php |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | $dir = dirname( __FILE__ ) . "/tests"; |
7 | 7 | $files[] = "$dir/ParseCoordTest.php"; |
8 | 8 | $files[] = "$dir/GeoMathTest.php"; |
| 9 | + $files[] = "$dir/TagTest.php"; |
9 | 10 | return true; |
10 | 11 | } |
11 | 12 | |
— | — | @@ -40,6 +41,8 @@ |
41 | 42 | public static function coordinateHandler( $parser, $frame, $args ) { |
42 | 43 | $output = $parser->getOutput(); |
43 | 44 | self::prepareOutput( $output ); |
| 45 | + $info = GeoData::getCoordInfo(); |
| 46 | + $primary = $info['primary']; |
44 | 47 | |
45 | 48 | $unnamed = array(); |
46 | 49 | $named = array(); |
— | — | @@ -52,6 +55,8 @@ |
53 | 56 | $value = trim( $frame->expand( $bits['value'] ) ); |
54 | 57 | if ( $bits['index'] === '' ) { |
55 | 58 | $named[trim( $frame->expand( $bits['name'] ) )] = $value; |
| 59 | + } elseif ( isset( $primary[$value] ) ) { |
| 60 | + $named['primary'] = true; |
56 | 61 | } elseif ( preg_match( '/\S+?:\S*?([ _]+\S+?:\S*?)*/', $value ) ) { |
57 | 62 | $named['geohack'] = $value; |
58 | 63 | } else { |