Index: trunk/extensions/GeoData/tests/TagTest.php |
— | — | @@ -4,6 +4,10 @@ |
5 | 5 | * @group GeoData |
6 | 6 | */ |
7 | 7 | class TagTest extends MediaWikiTestCase { |
| 8 | + public function setUp() { |
| 9 | + $GLOBALS['wgDefaultDim'] = 1000; // reset to default |
| 10 | + } |
| 11 | + |
8 | 12 | /** |
9 | 13 | * @dataProvider getData |
10 | 14 | */ |
— | — | @@ -27,6 +31,7 @@ |
28 | 32 | |
29 | 33 | public function getData() { |
30 | 34 | return array( |
| 35 | + // Basics |
31 | 36 | array( |
32 | 37 | '{{#coordinates: 10|20|primary}}', |
33 | 38 | array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'primary' => true ), |
— | — | @@ -39,6 +44,7 @@ |
40 | 45 | '{{#coordinates: primary|10|20}}', |
41 | 46 | array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'primary' => true ), |
42 | 47 | ), |
| 48 | + // type |
43 | 49 | array( |
44 | 50 | '{{#coordinates: 10|20|type:city}}', |
45 | 51 | array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'type' => 'city' ), |
— | — | @@ -47,26 +53,56 @@ |
48 | 54 | '{{#coordinates: 10|20|type:city(666)}}', |
49 | 55 | array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'type' => 'city' ), |
50 | 56 | ), |
| 57 | + // Other geohack params |
| 58 | + array( |
| 59 | + '{{#coordinates: 10|20}}', |
| 60 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'dim' => 1000 ), |
| 61 | + ), |
51 | 62 | array( |
52 | 63 | '{{#coordinates:10|20|globe:Moon dim:10_region:RU-mos}}', |
53 | | - array( 'lat' => 10, 'lon' => 20, 'globe' => 'moon', 'country' => 'RU', 'region' => 'MOS' ), |
| 64 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'moon', 'country' => 'RU', 'region' => 'MOS', 'dim' => 10 ), |
54 | 65 | ), |
55 | 66 | array( |
56 | 67 | '{{#coordinates:10|20|globe:Moon dim:10_region:RU}}', |
57 | | - array( 'lat' => 10, 'lon' => 20, 'globe' => 'moon', 'country' => 'RU' ), |
| 68 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'moon', 'country' => 'RU', 'dim' => 10 ), |
58 | 69 | ), |
59 | 70 | array( |
60 | | - '{{#coordinates: 10|20|primary|_dim:3Km_}}', |
61 | | - array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'primary' => true, 'dim' => 3000 ), |
| 71 | + '{{#coordinates: 10|20|_dim:3Km_}}', |
| 72 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'dim' => 3000 ), |
62 | 73 | ), |
63 | 74 | array( |
64 | | - '{{#coordinates: 10|20|primary|foo:bar dim:100m}}', |
| 75 | + '{{#coordinates: 10|20|foo:bar dim:100m}}', |
65 | 76 | array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'dim' => 100 ), |
66 | 77 | ), |
67 | 78 | array( |
68 | | - '{{#coordinates: 10|20|primary|dim:1L}}', |
69 | | - array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth' ), |
| 79 | + '{{#coordinates: 10|20|dim:-300}}', |
| 80 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'dim' => 1000 ), |
70 | 81 | ), |
| 82 | + array( |
| 83 | + '{{#coordinates: 10|20|dim:-10km}}', |
| 84 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'dim' => 1000 ), |
| 85 | + ), |
| 86 | + array( |
| 87 | + '{{#coordinates: 10|20|dim:1L}}', |
| 88 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'dim' => 1000 ), |
| 89 | + ), |
| 90 | + // dim fallbacks |
| 91 | + array( |
| 92 | + '{{#coordinates: 10|20|type:city}}', |
| 93 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'type' => 'city', 'dim' => 10000 ), |
| 94 | + ), |
| 95 | + array( |
| 96 | + '{{#coordinates: 10|20|type:city(2000)}}', |
| 97 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'type' => 'city', 'dim' => 10000 ), |
| 98 | + ), |
| 99 | + array( |
| 100 | + '{{#coordinates: 10|20|type:lulz}}', |
| 101 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'type' => 'lulz', 'dim' => 1000 ), |
| 102 | + ), |
| 103 | + array( |
| 104 | + '{{#coordinates: 10|20|scale:50000}}', |
| 105 | + array( 'lat' => 10, 'lon' => 20, 'globe' => 'earth', 'dim' => 5000 ), |
| 106 | + ), |
71 | 107 | ); |
72 | 108 | } |
73 | 109 | } |
\ No newline at end of file |
Index: trunk/extensions/GeoData/CoordinatesParserFunction.php |
— | — | @@ -129,7 +129,7 @@ |
130 | 130 | * @param Coord $coord |
131 | 131 | */ |
132 | 132 | private function parseTagArgs( Coord $coord ) { |
133 | | - global $wgDefaultGlobe, $wgContLang; |
| 133 | + global $wgDefaultGlobe, $wgContLang, $wgTypeToDim, $wgDefaultDim; |
134 | 134 | $result = Status::newGood(); |
135 | 135 | $args = $this->named; |
136 | 136 | // fear not of overwriting the stuff we've just received from the geohack param, it has minimum precedence |
— | — | @@ -138,15 +138,20 @@ |
139 | 139 | } |
140 | 140 | $coord->primary = isset( $args['primary'] ); |
141 | 141 | $coord->globe = isset( $args['globe'] ) ? $wgContLang->lc( $args['globe'] ) : $wgDefaultGlobe; |
| 142 | + $coord->dim = $wgDefaultDim; |
| 143 | + if ( isset( $args['type'] ) ) { |
| 144 | + $coord->type = preg_replace( '/\(.*?\).*$/', '', $args['type'] ); |
| 145 | + $coord->dim = isset( $wgTypeToDim[$coord->type] ) ? isset( $wgTypeToDim[$coord->type] ) : $wgDefaultDim; |
| 146 | + } |
| 147 | + if ( isset( $args['scale'] ) ) { |
| 148 | + $coord->dim = $args['scale'] / 10; |
| 149 | + } |
142 | 150 | if ( isset( $args['dim'] ) ) { |
143 | 151 | $dim = $this->parseDim( $args['dim'] ); |
144 | | - if ( $dim !== '' ) { |
| 152 | + if ( $dim !== false ) { |
145 | 153 | $coord->dim = $dim; |
146 | 154 | } |
147 | 155 | } |
148 | | - if ( isset( $args['type'] ) ) { |
149 | | - $coord->type = preg_replace( '/\(.*?\).*$/', '', $args['type'] ); |
150 | | - } |
151 | 156 | $coord->name = isset( $args['name'] ) ? $args['name'] : null; |
152 | 157 | if ( isset( $args['region'] ) ) { |
153 | 158 | $code = strtoupper( $args['region'] ); |
— | — | @@ -176,7 +181,7 @@ |
177 | 182 | |
178 | 183 | private function parseDim( $str ) { |
179 | 184 | if ( is_numeric( $str ) ) { |
180 | | - return $str > 0; |
| 185 | + return $str > 0 ? $str : false; |
181 | 186 | } |
182 | 187 | if ( !preg_match( '/^(\d+)(km|m)$/i', $str, $m ) ) { |
183 | 188 | return false; |
Index: trunk/extensions/GeoData/GeoData.php |
— | — | @@ -51,3 +51,34 @@ |
52 | 52 | * Maximum number of coordinates per page, -1 means no limit |
53 | 53 | */ |
54 | 54 | $wgMaxCoordinatesPerPage = 500; |
| 55 | + |
| 56 | +/** |
| 57 | + * Conversion table type --> dim |
| 58 | + */ |
| 59 | +$wgTypeToDim = array( |
| 60 | + 'country' => 1000000, |
| 61 | + 'satellite' => 1000000, |
| 62 | + 'state' => 300000, |
| 63 | + 'adm1st' => 100000, |
| 64 | + 'adm2nd' => 30000, |
| 65 | + 'adm3rd' => 10000, |
| 66 | + 'city' => 10000, |
| 67 | + 'isle' => 10000, |
| 68 | + 'mountain' => 10000, |
| 69 | + 'river' => 10000, |
| 70 | + 'waterbody' => 10000, |
| 71 | + 'event' => 5000, |
| 72 | + 'forest' => 5000, |
| 73 | + 'glacier' => 5000, |
| 74 | + 'airport' => 3000, |
| 75 | + 'railwaystation' => 1000, |
| 76 | + 'edu' => 1000, |
| 77 | + 'pass' => 1000, |
| 78 | + 'camera' => 1000, |
| 79 | + 'landmark' => 1000, |
| 80 | +); |
| 81 | + |
| 82 | +/** |
| 83 | + * Default value of dim if it is unknown |
| 84 | + */ |
| 85 | +$wgDefaultDim = 1000; |