r107915 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107914‎ | r107915 | r107916 >
Date:18:11, 3 January 2012
Author:maxsem
Status:ok
Tags:
Comment:
Support for specifying primary tags in a nicer fashion, eg {{#coordinates:lat|lon|primary}}, basic tests
Modified paths:
  • /trunk/extensions/GeoData/GeoData.body.php (modified) (history)
  • /trunk/extensions/GeoData/GeoDataHooks.php (modified) (history)
  • /trunk/extensions/GeoData/tests/TagTest.php (added) (history)

Diff [purge]

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
135 + native
Index: trunk/extensions/GeoData/GeoData.body.php
@@ -165,20 +165,29 @@
166166 return $result;
167167 }
168168
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;
183192 }
184193 }
185194
Index: trunk/extensions/GeoData/GeoDataHooks.php
@@ -5,6 +5,7 @@
66 $dir = dirname( __FILE__ ) . "/tests";
77 $files[] = "$dir/ParseCoordTest.php";
88 $files[] = "$dir/GeoMathTest.php";
 9+ $files[] = "$dir/TagTest.php";
910 return true;
1011 }
1112
@@ -40,6 +41,8 @@
4142 public static function coordinateHandler( $parser, $frame, $args ) {
4243 $output = $parser->getOutput();
4344 self::prepareOutput( $output );
 45+ $info = GeoData::getCoordInfo();
 46+ $primary = $info['primary'];
4447
4548 $unnamed = array();
4649 $named = array();
@@ -52,6 +55,8 @@
5356 $value = trim( $frame->expand( $bits['value'] ) );
5457 if ( $bits['index'] === '' ) {
5558 $named[trim( $frame->expand( $bits['name'] ) )] = $value;
 59+ } elseif ( isset( $primary[$value] ) ) {
 60+ $named['primary'] = true;
5661 } elseif ( preg_match( '/\S+?:\S*?([ _]+\S+?:\S*?)*/', $value ) ) {
5762 $named['geohack'] = $value;
5863 } else {

Sign-offs

UserFlagDate
Nikerabbitinspected07:24, 4 January 2012

Status & tagging log