Remove double globals.
[lhc/web/wiklou.git] / includes / api / ApiQueryIWBacklinks.php
index 7e539fc..909da72 100644 (file)
@@ -33,15 +33,23 @@ if ( !defined( 'MEDIAWIKI' ) ) {
  * This gives links pointing to the given interwiki
  * @ingroup API
  */
-class ApiQueryIWBacklinks extends ApiQueryBase {
+class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
 
        public function __construct( $query, $moduleName ) {
                parent::__construct( $query, $moduleName, 'iwbl' );
        }
 
        public function execute() {
+               $this->run();
+       }
+
+       public function executeGenerator( $resultPageSet ) {
+               $this->run( $resultPageSet );
+       }
+
+       public function run( $resultPageSet = null ) {
                $params = $this->extractRequestParams();
-               
+
                if ( isset( $params['title'] ) && !isset( $params['prefix'] ) ) {
                        $this->dieUsageMsg( array( 'missingparam', 'prefix' ) );
                }
@@ -64,7 +72,7 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
                                "iwl_from >= $from)))"
                        );
                }
-               
+
                $prop = array_flip( $params['prop'] );
                $iwprefix = isset( $prop['iwprefix'] );
                $iwtitle = isset( $prop['iwtitle'] );
@@ -89,9 +97,10 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
 
                $this->addOption( 'LIMIT', $params['limit'] + 1 );
 
-               $db = $this->getDB();
                $res = $this->select( __METHOD__ );
 
+               $pages = array();
+
                $count = 0;
                $result = $this->getResult();
                foreach ( $res as $row ) {
@@ -101,36 +110,45 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
                                $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
                                break;
                        }
-                       
-                       $entry = array();
-                       
-                       $entry['pageid'] = intval( $row->page_id );
-                       $entry['ns'] = $row->page_namespace;
-                       $entry['title'] = $row->page_title;
-                       
-                       if ( $row->page_is_redirect ) {
-                               $entry['redirect'] = '';
-                       }
-                       
-                       if ( $iwprefix ) {
-                               $entry['iwprefix'] = $row->iwl_prefix;
-                       }
-                       
-                       if ( $iwtitle ) {
-                               $entry['iwtitle'] = $row->iwl_title;
-                       }
 
-                       $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
-                       if ( !$fit ) {
-                               $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
-                               break;
+                       if ( !is_null( $resultPageSet ) ) {
+                               $pages[] = Title::newFromRow( $row );
+                       } else {
+                               $entry = array();
+
+                               $entry['pageid'] = intval( $row->page_id );
+                               $entry['ns'] = intval( $row->page_namespace );
+                               $entry['title'] = $row->page_title;
+
+                               if ( $row->page_is_redirect ) {
+                                       $entry['redirect'] = '';
+                               }
+
+                               if ( $iwprefix ) {
+                                       $entry['iwprefix'] = $row->iwl_prefix;
+                               }
+
+                               if ( $iwtitle ) {
+                                       $entry['iwtitle'] = $row->iwl_title;
+                               }
+
+                               $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
+                               if ( !$fit ) {
+                                       $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
+                                       break;
+                               }
                        }
                }
 
-               $this->getResult()->setIndexedTagName_internal(
-                       array( 'query', $this->getModuleName() ),
-                       'iw'
-               );
+               if ( is_null( $resultPageSet ) ) {
+                       $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'iw' );
+               } else {
+                       $resultPageSet->populateFromTitles( $pages );
+               }
+       }
+
+       public function getCacheMode( $params ) {
+               return 'public';
        }
 
        public function getAllowedParams() {
@@ -188,7 +206,7 @@ class ApiQueryIWBacklinks extends ApiQueryBase {
        protected function getExamples() {
                return array(
                        'api.php?action=query&list=iwbacklinks&iwbltitle=Test&iwblprefix=wikibooks',
-                       //'api.php?action=query&generator=iwbacklinks&giwbltitle=Test&iwblprefix=wikibooks&prop=info'
+                       'api.php?action=query&generator=iwbacklinks&giwbltitle=Test&iwblprefix=wikibooks&prop=info'
                );
        }