https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113618

Revision: 113618
Author:   maxsem
Date:     2012-03-12 13:05:42 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
Support for geosearches for pages w/o photos

Modified Paths:
--------------
    trunk/extensions/GeoData/api/ApiQueryGeoSearch.php

Modified: trunk/extensions/GeoData/api/ApiQueryGeoSearch.php
===================================================================
--- trunk/extensions/GeoData/api/ApiQueryGeoSearch.php  2012-03-12 12:43:35 UTC 
(rev 113617)
+++ trunk/extensions/GeoData/api/ApiQueryGeoSearch.php  2012-03-12 13:05:42 UTC 
(rev 113618)
@@ -26,6 +26,7 @@
        private function run( $resultPageSet = null ) {
                $params = $this->extractRequestParams();
                $exclude = false;
+               $useIndex = array();
 
                $this->requireOnlyOneParameter( $params, 'coord', 'page' );
                if ( isset( $params['coord'] ) ) {
@@ -91,8 +92,18 @@
                $primary = array_flip( $params['primary'] );
                $this->addWhereIf( array( 'gt_primary' => 1 ), isset( 
$primary['yes'] ) && !isset( $primary['no'] )     );
                $this->addWhereIf( array( 'gt_primary' => 0 ), !isset( 
$primary['yes'] ) && isset( $primary['no'] )     );
-               $this->addOption( 'USE INDEX', 'gt_spatial' );
+               $useIndex['geo_tags'] = 'gt_spatial';
 
+               // Use information from PageImages
+               if ( defined( 'PAGE_IMAGES_INSTALLED' ) && 
$params['withoutphotos'] ) {
+                       $this->addTables( 'page_props' );
+                       $this->addJoinConds( array( 'page_props' => array( 
'LEFT JOIN',
+                               "gt_page_id=pp_page AND 
pp_propname='has_photos'" )
+                       ) );
+                       $this->addWhere( 'pp_page IS NULL' );
+               }
+               $this->addOption( 'USE INDEX', $useIndex );
+
                $limit = $params['limit'];
                
                $res = $this->select( __METHOD__ );
@@ -173,7 +184,7 @@
 
        public function getAllowedParams() {
                global $wgMaxGeoSearchRadius, $wgDefaultGlobe;
-               return array (
+               $params = array (
                        'coord' => array(
                                ApiBase::PARAM_TYPE => 'string',
                        ),
@@ -218,11 +229,15 @@
                                ApiBase::PARAM_DFLT => 'yes',
                        ),
                );
+               if ( defined( 'PAGE_IMAGES_INSTALLED' ) ) {
+                       $params['withoutphotos'] = false;
+               }
+               return $params;
        }
 
        public function getParamDescription() {
                global $wgDefaultGlobe;
-               return array(
+               $params = array(
                        'coord' => 'Coordinate around which to search: two 
floating-point values separated by pipe (|)',
                        'page' => 'Title of page around which to search',
                        'radius' => 'Search radius in meters',
@@ -231,8 +246,12 @@
                        'globe' => "Globe to search on (by default 
``{$wgDefaultGlobe}'')",
                        'namespace' => 'Namespace(s) to search',
                        'prop' => 'What additional coordinate properties to 
return',
-                       'primary' => "Whether to return only primary 
coordinates (``yes''), secondary (``no'') or both (``yes|no'')",
+                       'primary' => "Whether to return only primary 
coordinates (``yes''), secondary (``no'') or both (``yes|no'')"
                );
+               if ( defined( 'PAGE_IMAGES_INSTALLED' ) ) {
+                       $params['withoutphotos'] = 'Return only pages without 
photos';
+               }
+               return $params;
        }
 
        public function getDescription() {


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to