r108152 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108151‎ | r108152 | r108153 >
Date:17:24, 5 January 2012
Author:maxsem
Status:ok
Tags:
Comment:
Added prop and filter by primariness
Modified paths:
  • /trunk/extensions/GeoData/ApiQueryGeoSearch.php (modified) (history)
  • /trunk/extensions/GeoData/GeoData.body.php (modified) (history)
  • /trunk/extensions/GeoData/GeoDataHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GeoData/ApiQueryGeoSearch.php
@@ -60,7 +60,7 @@
6161
6262 $dbr = wfGetDB( DB_SLAVE );
6363 $this->addTables( array( 'geo_tags', 'page' ) );
64 - $this->addFields( array( 'gt_lat', 'gt_lon',
 64+ $this->addFields( array( 'gt_lat', 'gt_lon', 'gt_primary',
6565 "{$dbr->tablePrefix()}gd_distance( {$lat}, {$lon}, gt_lat, gt_lon ) AS dist" )
6666 );
6767 // retrieve some fields only if page set needs them
@@ -69,6 +69,11 @@
7070 } else {
7171 $this->addFields( array( "{$dbr->tableName( 'page' )}.*" ) );
7272 }
 73+ foreach( $params['prop'] as $prop ) {
 74+ if ( isset( Coord::$fieldMapping[$prop] ) ) {
 75+ $this->addFields( Coord::$fieldMapping[$prop] );
 76+ }
 77+ }
7378 $this->addWhereFld( 'gt_globe', $params['globe'] );
7479 $this->addWhereRange( 'gt_lat', 'newer', $rect["minLat"], $rect["maxLat"], false );
7580 $this->addWhereRange( 'gt_lon', 'newer', $rect["minLon"], $rect["maxLon"], false );
@@ -81,6 +86,9 @@
8287 if ( isset( $params['maxdim'] ) ) {
8388 $this->addWhere( 'gt_dim < ' . intval( $params['maxdim'] ) );
8489 }
 90+ $primary = array_flip( $params['primary'] );
 91+ $this->addWhereIf( array( 'gt_primary' => 1 ), isset( $primary['yes'] ) && !isset( $primary['no'] ) );
 92+ $this->addWhereIf( array( 'gt_primary' => 0 ), !isset( $primary['yes'] ) && isset( $primary['no'] ) );
8593 $this->addOption( 'ORDER BY', 'dist' );
8694
8795 $limit = $params['limit'];
@@ -101,6 +109,15 @@
102110 'lon' => floatval( $row->gt_lon ),
103111 'dist' => round( $row->dist, 1 ),
104112 );
 113+ if ( $row->gt_primary ) {
 114+ $vals['primary'] = '';
 115+ }
 116+ foreach( $params['prop'] as $prop ) {
 117+ if ( isset( Coord::$fieldMapping[$prop] ) ) {
 118+ $field = Coord::$fieldMapping[$prop];
 119+ $vals[$prop] = $row->$field;
 120+ }
 121+ }
105122 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
106123 if ( !$fit ) {
107124 break;
@@ -145,7 +162,16 @@
146163 ApiBase::PARAM_TYPE => 'namespace',
147164 ApiBase::PARAM_DFLT => NS_MAIN,
148165 ApiBase::PARAM_ISMULTI => true,
149 - )
 166+ ),
 167+ 'prop' => array(
 168+ ApiBase::PARAM_TYPE => array( 'type', 'name', 'country', 'region' ),
 169+ ApiBase::PARAM_ISMULTI => true,
 170+ ),
 171+ 'primary' => array(
 172+ ApiBase::PARAM_TYPE => array( 'yes', 'no' ),
 173+ ApiBase::PARAM_ISMULTI => true,
 174+ ApiBase::PARAM_DFLT => 'yes',
 175+ ),
150176 );
151177 }
152178
@@ -159,6 +185,8 @@
160186 'limit' => 'Maximum number of pages to return',
161187 'globe' => "Globe to search on (by default `{$wgDefaultGlobe}')",
162188 'namespace' => 'Namespace(s) to search',
 189+ 'prop' => 'What additional coordinate properties to return',
 190+ 'primary' => "Whether to return only primary coordinates (`yes'), secondary (`no') or both (`yes|no')",
163191 );
164192 }
165193
Index: trunk/extensions/GeoData/GeoData.body.php
@@ -243,7 +243,7 @@
244244 return $row;
245245 }
246246
247 - private static $fieldMapping = array(
 247+ public static $fieldMapping = array(
248248 'lat' => 'gt_lat',
249249 'lon' => 'gt_lon',
250250 'globe' => 'gt_globe',
Index: trunk/extensions/GeoData/GeoDataHooks.php
@@ -115,7 +115,7 @@
116116 */
117117 private static function applyCoord( ParserOutput $output, Coord $coord ) {
118118 global $wgMaxCoordinatesPerPage;
119 - $count = count( $output->geoData['secondary'] ) + $output->geoData['primary'] ? 1 : 0;
 119+ $count = count( $output->geoData['secondary'] ) + ( $output->geoData['primary'] ? 1 : 0 );
120120 if ( $count >= $wgMaxCoordinatesPerPage ) {
121121 if ( $output->geoData['limitExceeded'] ) {
122122 return Status::newFatal( '' );

Status & tagging log