https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114727
Revision: 114727
Author: maxsem
Date: 2012-04-05 00:12:55 +0000 (Thu, 05 Apr 2012)
Log Message:
-----------
Introduced a setting to specify the number of gt_*_int's per degree, will need
to be set to a higher number on WMF
Modified Paths:
--------------
trunk/extensions/GeoData/GeoData.body.php
trunk/extensions/GeoData/GeoData.php
trunk/extensions/GeoData/api/ApiQueryGeoSearch.php
Added Paths:
-----------
trunk/extensions/GeoData/updateIndexGranularity.php
Modified: trunk/extensions/GeoData/GeoData.body.php
===================================================================
--- trunk/extensions/GeoData/GeoData.body.php 2012-04-05 00:12:01 UTC (rev
114726)
+++ trunk/extensions/GeoData/GeoData.body.php 2012-04-05 00:12:55 UTC (rev
114727)
@@ -237,12 +237,13 @@
* @return Array: Associative array in format 'field' => 'value'
*/
public function getRow( $pageId ) {
+ global $wgGeoDataIndexGranularity;
$row = array( 'gt_page_id' => $pageId );
foreach ( self::$fieldMapping as $field => $column ) {
$row[$column] = $this->$field;
}
- $row['gt_lat_int'] = round( $this->lat * 10 );
- $row['gt_lon_int'] = round( $this->lon * 10 );
+ $row['gt_lat_int'] = round( $this->lat *
$wgGeoDataIndexGranularity );
+ $row['gt_lon_int'] = round( $this->lon *
$wgGeoDataIndexGranularity );
return $row;
}
Modified: trunk/extensions/GeoData/GeoData.php
===================================================================
--- trunk/extensions/GeoData/GeoData.php 2012-04-05 00:12:01 UTC (rev
114726)
+++ trunk/extensions/GeoData/GeoData.php 2012-04-05 00:12:55 UTC (rev
114727)
@@ -144,3 +144,9 @@
'unknown globe' => 'none',
'invalid region' => 'track',
);
+
+/**
+ * How many gt_(lat|lon)_int units per degree
+ * Run updateIndexGranularity.php after changing this
+ */
+$wgGeoDataIndexGranularity = 10;
Modified: trunk/extensions/GeoData/api/ApiQueryGeoSearch.php
===================================================================
--- trunk/extensions/GeoData/api/ApiQueryGeoSearch.php 2012-04-05 00:12:01 UTC
(rev 114726)
+++ trunk/extensions/GeoData/api/ApiQueryGeoSearch.php 2012-04-05 00:12:55 UTC
(rev 114727)
@@ -167,13 +167,14 @@
* @return Array
*/
public static function intRange( $start, $end ) {
- $start = round( $start * 10 );
- $end = round( $end * 10 );
+ global $wgGeoDataIndexGranularity;
+ $start = round( $start * $wgGeoDataIndexGranularity );
+ $end = round( $end * $wgGeoDataIndexGranularity );
// @todo: works only on Earth
if ( $start > $end ) {
return array_merge(
- range( -1800, $end ),
- range( $start, 1800 )
+ range( -180 * $wgGeoDataIndexGranularity, $end
),
+ range( $start, 180 * $wgGeoDataIndexGranularity
)
);
} else {
return range( $start, $end );
Added: trunk/extensions/GeoData/updateIndexGranularity.php
===================================================================
--- trunk/extensions/GeoData/updateIndexGranularity.php
(rev 0)
+++ trunk/extensions/GeoData/updateIndexGranularity.php 2012-04-05 00:12:55 UTC
(rev 114727)
@@ -0,0 +1,54 @@
+<?php
+
+
+$IP = getenv( 'MW_INSTALL_PATH' );
+if ( $IP === false ) {
+ $IP = dirname( __FILE__ ) . '/../../..';
+}
+require_once( "$IP/maintenance/Maintenance.php" );
+
+class UpdateIndexGranularity extends Maintenance {
+ const BATCH_SIZE = 500;
+
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = 'Updates GeoData database after
$wgGeoDataIndexGranularity has been changed';
+ }
+
+ public function execute() {
+ global $wgGeoDataIndexGranularity;
+ if ( !isset( $wgGeoDataIndexGranularity ) ) {
+ $this->error( 'Please install GeoData properly', true );
+ }
+ $id = 0;
+ $dbw = wfGetDB( DB_MASTER );
+ do {
+ $ids = array();
+ $dbw->begin( __METHOD__ );
+ $res = $dbw->select( 'geo_tags', 'gt_id',
+ array( "gt_id > $id" ),
+ __METHOD__,
+ array( 'LIMIT' => self::BATCH_SIZE )
+ );
+ foreach ( $res as $row ) {
+ $id = $row->gt_id;
+ $ids[] = $id;
+ }
+ $dbw->update( 'geo_tags',
+ array(
+ "gt_lat_int = ROUND(gt_lat *
$wgGeoDataIndexGranularity)",
+ "gt_lon_int = ROUND(gt_lon *
$wgGeoDataIndexGranularity)"
+ ),
+ array( 'gt_id' => $ids ),
+ __METHOD__
+ );
+ $dbw->commit( __METHOD__ );
+ $this->output( "$id\n" );
+ wfWaitForSlaves();
+ } while ( count( $ids ) === self::BATCH_SIZE );
+ }
+}
+
+$maintClass = 'UpdateIndexGranularity';
+require_once( DO_MAINTENANCE );
+
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs