Explicit variable definition, tweak documentation
[lhc/web/wiklou.git] / includes / api / ApiQueryBacklinks.php
index aed143a..eb2c9c0 100644 (file)
@@ -1,11 +1,10 @@
 <?php
-
-/*
- * Created on Oct 16, 2006
- *
+/**
  * API for MediaWiki 1.8+
  *
- * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Created on Oct 16, 2006
+ *
+ * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +20,8 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
  */
 
 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -62,13 +63,15 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
        );
 
        public function __construct( $query, $moduleName ) {
-               extract( $this->backlinksSettings[$moduleName] );
+               $settings = $this->backlinksSettings[$moduleName];
+               $prefix = $settings['prefix'];
+               $code = $settings['code'];
                $this->resultArr = array();
 
                parent::__construct( $query, $moduleName, $code );
                $this->bl_ns = $prefix . '_namespace';
                $this->bl_from = $prefix . '_from';
-               $this->bl_table = $linktbl;
+               $this->bl_table = $settings['linktbl'];
                $this->bl_code = $code;
 
                $this->hasNS = $moduleName !== 'imageusage';
@@ -92,6 +95,10 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                $this->run();
        }
 
+       public function getCacheMode( $params ) {
+               return 'public';
+       }
+
        public function executeGenerator( $resultPageSet ) {
                $this->run( $resultPageSet );
        }
@@ -199,7 +206,7 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                $botMax  = ( $this->redirect ? ApiBase::LIMIT_BIG2 / 2 : ApiBase::LIMIT_BIG2 );
                if ( $this->params['limit'] == 'max' ) {
                        $this->params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
-                       $this->getResult()->addValue( 'limits', $this->getModuleName(), $this->params['limit'] );
+                       $this->getResult()->setParsedLimit( $this->getModuleName(), $this->params['limit'] );
                }
 
                $this->processContinue();
@@ -241,9 +248,9 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                                        // We've reached the one extra which shows that there are additional pages to be had. Stop here...
                                        // We need to keep the parent page of this redir in
                                        if ( $this->hasNS ) {
-                                               $parentID = $this->pageMap[$row-> { $this->bl_ns } ][$row-> { $this->bl_title } ];
+                                               $parentID = $this->pageMap[$row->{$this->bl_ns}][$row->{$this->bl_title}];
                                        } else {
-                                               $parentID = $this->pageMap[NS_IMAGE][$row-> { $this->bl_title } ];
+                                               $parentID = $this->pageMap[NS_IMAGE][$row->{$this->bl_title}];
                                        }
                                        $this->continueStr = $this->getContinueRedirStr( $parentID, $row->page_id );
                                        break;
@@ -341,8 +348,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
                                } else {
                                        $this->rootTitle = $title;
                                }
-                       } else {
-                               $this->dieUsageMsg( array( 'missingparam', 'title' ) );
                        }
                }
 
@@ -400,7 +405,10 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
 
        public function getAllowedParams() {
                $retval = array(
-                       'title' => null,
+                       'title' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true
+                       ),
                        'continue' => null,
                        'namespace' => array(
                                ApiBase::PARAM_ISMULTI => true,
@@ -464,7 +472,6 @@ class ApiQueryBacklinks extends ApiQueryGeneratorBase {
        public function getPossibleErrors() {
                return array_merge( parent::getPossibleErrors(), array(
                        array( 'invalidtitle', 'title' ),
-                       array( 'missingparam', 'title' ),
                        array( 'code' => 'bad_image_title', 'info' => "The title for {$this->getModuleName()} query must be an image" ),
                        array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
                ) );