Index: trunk/extensions/GeoData/updateIndexGranularity.php |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +
|
| 5 | +$IP = getenv( 'MW_INSTALL_PATH' );
|
| 6 | +if ( $IP === false ) {
|
| 7 | + $IP = dirname( __FILE__ ) . '/../../..';
|
| 8 | +}
|
| 9 | +require_once( "$IP/maintenance/Maintenance.php" );
|
| 10 | +
|
| 11 | +class UpdateIndexGranularity extends Maintenance {
|
| 12 | + const BATCH_SIZE = 500;
|
| 13 | +
|
| 14 | + public function __construct() {
|
| 15 | + parent::__construct();
|
| 16 | + $this->mDescription = 'Updates GeoData database after $wgGeoDataIndexGranularity has been changed';
|
| 17 | + }
|
| 18 | +
|
| 19 | + public function execute() {
|
| 20 | + global $wgGeoDataIndexGranularity;
|
| 21 | + if ( !isset( $wgGeoDataIndexGranularity ) ) {
|
| 22 | + $this->error( 'Please install GeoData properly', true );
|
| 23 | + }
|
| 24 | + $id = 0;
|
| 25 | + $dbw = wfGetDB( DB_MASTER );
|
| 26 | + do {
|
| 27 | + $ids = array();
|
| 28 | + $dbw->begin( __METHOD__ );
|
| 29 | + $res = $dbw->select( 'geo_tags', 'gt_id',
|
| 30 | + array( "gt_id > $id" ),
|
| 31 | + __METHOD__,
|
| 32 | + array( 'LIMIT' => self::BATCH_SIZE )
|
| 33 | + );
|
| 34 | + foreach ( $res as $row ) {
|
| 35 | + $id = $row->gt_id;
|
| 36 | + $ids[] = $id;
|
| 37 | + }
|
| 38 | + $dbw->update( 'geo_tags',
|
| 39 | + array(
|
| 40 | + "gt_lat_int = ROUND(gt_lat * $wgGeoDataIndexGranularity)",
|
| 41 | + "gt_lon_int = ROUND(gt_lon * $wgGeoDataIndexGranularity)"
|
| 42 | + ),
|
| 43 | + array( 'gt_id' => $ids ),
|
| 44 | + __METHOD__
|
| 45 | + );
|
| 46 | + $dbw->commit( __METHOD__ );
|
| 47 | + $this->output( "$id\n" );
|
| 48 | + wfWaitForSlaves();
|
| 49 | + } while ( count( $ids ) === self::BATCH_SIZE );
|
| 50 | + }
|
| 51 | +}
|
| 52 | +
|
| 53 | +$maintClass = 'UpdateIndexGranularity';
|
| 54 | +require_once( DO_MAINTENANCE );
|
| 55 | +
|
Index: trunk/extensions/GeoData/GeoData.body.php |
— | — | @@ -237,12 +237,13 @@ |
238 | 238 | * @return Array: Associative array in format 'field' => 'value' |
239 | 239 | */ |
240 | 240 | public function getRow( $pageId ) { |
| 241 | + global $wgGeoDataIndexGranularity; |
241 | 242 | $row = array( 'gt_page_id' => $pageId ); |
242 | 243 | foreach ( self::$fieldMapping as $field => $column ) { |
243 | 244 | $row[$column] = $this->$field; |
244 | 245 | } |
245 | | - $row['gt_lat_int'] = round( $this->lat * 10 ); |
246 | | - $row['gt_lon_int'] = round( $this->lon * 10 ); |
| 246 | + $row['gt_lat_int'] = round( $this->lat * $wgGeoDataIndexGranularity ); |
| 247 | + $row['gt_lon_int'] = round( $this->lon * $wgGeoDataIndexGranularity ); |
247 | 248 | return $row; |
248 | 249 | } |
249 | 250 | |
Index: trunk/extensions/GeoData/api/ApiQueryGeoSearch.php |
— | — | @@ -167,13 +167,14 @@ |
168 | 168 | * @return Array |
169 | 169 | */ |
170 | 170 | public static function intRange( $start, $end ) { |
171 | | - $start = round( $start * 10 ); |
172 | | - $end = round( $end * 10 ); |
| 171 | + global $wgGeoDataIndexGranularity; |
| 172 | + $start = round( $start * $wgGeoDataIndexGranularity ); |
| 173 | + $end = round( $end * $wgGeoDataIndexGranularity ); |
173 | 174 | // @todo: works only on Earth |
174 | 175 | if ( $start > $end ) { |
175 | 176 | return array_merge( |
176 | | - range( -1800, $end ), |
177 | | - range( $start, 1800 ) |
| 177 | + range( -180 * $wgGeoDataIndexGranularity, $end ), |
| 178 | + range( $start, 180 * $wgGeoDataIndexGranularity ) |
178 | 179 | ); |
179 | 180 | } else { |
180 | 181 | return range( $start, $end ); |
Index: trunk/extensions/GeoData/GeoData.php |
— | — | @@ -144,3 +144,9 @@ |
145 | 145 | 'unknown globe' => 'none', |
146 | 146 | 'invalid region' => 'track', |
147 | 147 | ); |
| 148 | + |
| 149 | +/** |
| 150 | + * How many gt_(lat|lon)_int units per degree |
| 151 | + * Run updateIndexGranularity.php after changing this |
| 152 | + */ |
| 153 | +$wgGeoDataIndexGranularity = 10; |