r108633 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108632‎ | r108633 | r108634 >
Date:16:06, 11 January 2012
Author:maxsem
Status:ok
Tags:
Comment:
Parse region codes consisting of just country code
Modified paths:
  • /trunk/extensions/GeoData/CoordinatesParserFunction.php (modified) (history)
  • /trunk/extensions/GeoData/tests/TagTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GeoData/tests/TagTest.php
@@ -18,6 +18,7 @@
1919 return;
2020 }
2121 $all = $out->geoData->getAll();
 22+ $this->assertEquals( 1, count( $all ), 'A result was expected' );
2223 $coord = $all[0];
2324 foreach ( $expected as $field => $value ) {
2425 $this->assertEquals( $value, $coord->$field, "Checking field $field" );
@@ -42,6 +43,10 @@
4344 '{{#coordinates:10|20|globe:Moon dim:10_region:RU-mos}}',
4445 array( 'lat' => 10, 'lon' => 20, 'globe' => 'moon', 'country' => 'RU', 'region' => 'MOS' ),
4546 ),
 47+ array(
 48+ '{{#coordinates:10|20|globe:Moon dim:10_region:RU}}',
 49+ array( 'lat' => 10, 'lon' => 20, 'globe' => 'moon', 'country' => 'RU' ),
 50+ ),
4651 array(
4752 '{{#coordinates: 10|20|primary|_dim:3Km_}}',
4853 array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'primary' => true, 'dim' => 3000 ),
Index: trunk/extensions/GeoData/CoordinatesParserFunction.php
@@ -146,9 +146,9 @@
147147 $coord->name = isset( $args['name'] ) ? $args['name'] : null;
148148 if ( isset( $args['region'] ) ) {
149149 $code = strtoupper( $args['region'] );
150 - if ( preg_match( '/([A-Z]{2})(?:-([A-Z0-9]{1,3}))/', $code, $m ) ) {
 150+ if ( preg_match( '/([A-Z]{2})(?:-([A-Z0-9]{1,3}))?/', $code, $m ) ) {
151151 $coord->country = $m[1];
152 - $coord->region = $m[2];
 152+ $coord->region = isset( $m[2] ) ? $m[2] : null;
153153 } else {
154154 $result->warning( 'geodata-bad-region', $args['region'] ); //@todo: actually use this warning
155155 }

Status & tagging log