Index: trunk/extensions/GeoData/ApiQueryGeoSearch.php |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | |
62 | 62 | $dbr = wfGetDB( DB_SLAVE ); |
63 | 63 | $this->addTables( array( 'geo_tags', 'page' ) ); |
64 | | - $this->addFields( array( 'gt_lat', 'gt_lon', |
| 64 | + $this->addFields( array( 'gt_lat', 'gt_lon', 'gt_primary', |
65 | 65 | "{$dbr->tablePrefix()}gd_distance( {$lat}, {$lon}, gt_lat, gt_lon ) AS dist" ) |
66 | 66 | ); |
67 | 67 | // retrieve some fields only if page set needs them |
— | — | @@ -69,6 +69,11 @@ |
70 | 70 | } else { |
71 | 71 | $this->addFields( array( "{$dbr->tableName( 'page' )}.*" ) ); |
72 | 72 | } |
| 73 | + foreach( $params['prop'] as $prop ) { |
| 74 | + if ( isset( Coord::$fieldMapping[$prop] ) ) { |
| 75 | + $this->addFields( Coord::$fieldMapping[$prop] ); |
| 76 | + } |
| 77 | + } |
73 | 78 | $this->addWhereFld( 'gt_globe', $params['globe'] ); |
74 | 79 | $this->addWhereRange( 'gt_lat', 'newer', $rect["minLat"], $rect["maxLat"], false ); |
75 | 80 | $this->addWhereRange( 'gt_lon', 'newer', $rect["minLon"], $rect["maxLon"], false ); |
— | — | @@ -81,6 +86,9 @@ |
82 | 87 | if ( isset( $params['maxdim'] ) ) { |
83 | 88 | $this->addWhere( 'gt_dim < ' . intval( $params['maxdim'] ) ); |
84 | 89 | } |
| 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'] ) ); |
85 | 93 | $this->addOption( 'ORDER BY', 'dist' ); |
86 | 94 | |
87 | 95 | $limit = $params['limit']; |
— | — | @@ -101,6 +109,15 @@ |
102 | 110 | 'lon' => floatval( $row->gt_lon ), |
103 | 111 | 'dist' => round( $row->dist, 1 ), |
104 | 112 | ); |
| 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 | + } |
105 | 122 | $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); |
106 | 123 | if ( !$fit ) { |
107 | 124 | break; |
— | — | @@ -145,7 +162,16 @@ |
146 | 163 | ApiBase::PARAM_TYPE => 'namespace', |
147 | 164 | ApiBase::PARAM_DFLT => NS_MAIN, |
148 | 165 | 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 | + ), |
150 | 176 | ); |
151 | 177 | } |
152 | 178 | |
— | — | @@ -159,6 +185,8 @@ |
160 | 186 | 'limit' => 'Maximum number of pages to return', |
161 | 187 | 'globe' => "Globe to search on (by default `{$wgDefaultGlobe}')", |
162 | 188 | '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')", |
163 | 191 | ); |
164 | 192 | } |
165 | 193 | |
Index: trunk/extensions/GeoData/GeoData.body.php |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | return $row; |
245 | 245 | } |
246 | 246 | |
247 | | - private static $fieldMapping = array( |
| 247 | + public static $fieldMapping = array( |
248 | 248 | 'lat' => 'gt_lat', |
249 | 249 | 'lon' => 'gt_lon', |
250 | 250 | 'globe' => 'gt_globe', |
Index: trunk/extensions/GeoData/GeoDataHooks.php |
— | — | @@ -115,7 +115,7 @@ |
116 | 116 | */ |
117 | 117 | private static function applyCoord( ParserOutput $output, Coord $coord ) { |
118 | 118 | global $wgMaxCoordinatesPerPage; |
119 | | - $count = count( $output->geoData['secondary'] ) + $output->geoData['primary'] ? 1 : 0; |
| 119 | + $count = count( $output->geoData['secondary'] ) + ( $output->geoData['primary'] ? 1 : 0 ); |
120 | 120 | if ( $count >= $wgMaxCoordinatesPerPage ) { |
121 | 121 | if ( $output->geoData['limitExceeded'] ) { |
122 | 122 | return Status::newFatal( '' ); |