Bug 27341 - Add drto param to list=deletedrevs
[lhc/web/wiklou.git] / includes / api / ApiQueryAllLinks.php
index 2959b22..4b40ffb 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-
 /**
- * Created on July 7, 2007
  *
- * API for MediaWiki 1.8+
+ *
+ * Created on July 7, 2007
  *
  * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
  *
@@ -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' ) ) {
@@ -43,10 +44,18 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                $this->run();
        }
 
+       public function getCacheMode( $params ) {
+               return 'public';
+       }
+
        public function executeGenerator( $resultPageSet ) {
                $this->run( $resultPageSet );
        }
 
+       /**
+        * @param $resultPageSet ApiPageSet
+        * @return void
+        */
        private function run( $resultPageSet = null ) {
                $db = $this->getDB();
                $params = $this->extractRequestParams();
@@ -85,9 +94,10 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                        );
                }
 
-               if ( !is_null( $params['from'] ) ) {
-                       $this->addWhere( 'pl_title>=' . $db->addQuotes( $this->titlePartToKey( $params['from'] ) ) );
-               }
+               $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) );
+               $to = ( is_null( $params['to'] ) ? null : $this->titlePartToKey( $params['to'] ) );
+               $this->addWhereRange( 'pl_title', 'newer', $from, $to );
+
                if ( isset( $params['prefix'] ) ) {
                        $this->addWhere( 'pl_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) );
                }
@@ -100,10 +110,9 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                $this->addOption( 'USE INDEX', 'pl_namespace' );
                $limit = $params['limit'];
                $this->addOption( 'LIMIT', $limit + 1 );
-               if ( $params['unique'] ) {
-                       $this->addOption( 'ORDER BY', 'pl_title' );
-               } else {
-                       $this->addOption( 'ORDER BY', 'pl_title, pl_from' );
+
+               if ( !$params['unique'] ) {
+                       $this->addOption( 'ORDER BY', 'pl_from' );
                }
 
                $res = $this->select( __METHOD__ );
@@ -157,6 +166,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                return array(
                        'continue' => null,
                        'from' => null,
+                       'to' => null,
                        'prefix' => null,
                        'unique' => false,
                        'prop' => array(
@@ -182,11 +192,17 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
        }
 
        public function getParamDescription() {
+               $p = $this->getModulePrefix();
                return array(
                        'from' => 'The page title to start enumerating from',
+                       'to' => 'The page title to stop enumerating at',
                        'prefix' => 'Search for all page titles that begin with this value',
-                       'unique' => "Only show unique links. Cannot be used with generator or {$this->getModulePrefix()}prop=ids",
-                       'prop' => 'What pieces of information to include',
+                       'unique' => "Only show unique links. Cannot be used with generator or {$p}prop=ids",
+                       'prop' => array(
+                               'What pieces of information to include',
+                               " ids    - Adds pageid of where the link is from (Cannot be used with {$p}unique)",
+                               ' title  - Adds the title of the link',
+                       ),
                        'namespace' => 'The namespace to enumerate',
                        'limit' => 'How many total links to return',
                        'continue' => 'When more results are available, use this to continue',
@@ -198,9 +214,10 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
        }
 
        public function getPossibleErrors() {
+               $m = $this->getModuleName();
                return array_merge( parent::getPossibleErrors(), array(
-                       array( 'code' => 'params', 'info' => $this->getModuleName() . ' cannot be used as a generator in unique links mode' ),
-                       array( 'code' => 'params', 'info' => $this->getModuleName() . ' cannot return corresponding page ids in unique links mode' ),
+                       array( 'code' => 'params', 'info' => "{$m} cannot be used as a generator in unique links mode" ),
+                       array( 'code' => 'params', 'info' => "{$m} cannot return corresponding page ids in unique links mode" ),
                        array( 'code' => 'params', 'info' => 'alcontinue and alfrom cannot be used together' ),
                        array( 'code' => 'badcontinue', 'info' => 'Invalid continue parameter' ),
                ) );
@@ -208,11 +225,11 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
 
        protected function getExamples() {
                return array(
-                       'api.php?action=query&list=alllinks&alunique&alfrom=B',
+                       'api.php?action=query&list=alllinks&alunique=&alfrom=B',
                );
        }
 
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
-}
\ No newline at end of file
+}