Merge "Wrap auto-numbering for section heading in a classed span (bug 33450)"
[lhc/web/wiklou.git] / includes / api / ApiQueryAllLinks.php
index 340aea3..6b8fe57 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
  *
  * 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' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * Query module to enumerate links from all pages together.
  *
@@ -43,10 +39,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();
@@ -72,38 +76,39 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                        $this->dieUsage( 'alcontinue and alfrom cannot be used together', 'params' );
                }
                if ( !is_null( $params['continue'] ) ) {
-                       $arr = explode( '|', $params['continue'] );
-                       if ( count( $arr ) != 2 ) {
+                       $continueArr = explode( '|', $params['continue'] );
+                       if ( count( $continueArr ) != 2 ) {
                                $this->dieUsage( 'Invalid continue parameter', 'badcontinue' );
                        }
-                       $from = $this->getDB()->strencode( $this->titleToKey( $arr[0] ) );
-                       $id = intval( $arr[1] );
+                       $continueTitle = $db->addQuotes( $this->titleToKey( $continueArr[0] ) );
+                       $continueFrom = intval( $continueArr[1] );
                        $this->addWhere(
-                               "pl_title > '$from' OR " .
-                               "(pl_title = '$from' AND " .
-                               "pl_from > $id)"
+                               "pl_title > $continueTitle OR " .
+                               "(pl_title = $continueTitle AND " .
+                               "pl_from > $continueFrom)"
                        );
                }
 
-               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() ) );
                }
 
-               $this->addFields( array(
-                       'pl_title',
-               ) );
+               $this->addFields( 'pl_title' );
                $this->addFieldsIf( 'pl_from', !$params['unique'] );
 
                $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', array(
+                               'pl_title',
+                               'pl_from'
+                       ));
                }
 
                $res = $this->select( __METHOD__ );
@@ -157,6 +162,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                return array(
                        'continue' => null,
                        'from' => null,
+                       'to' => null,
                        'prefix' => null,
                        'unique' => false,
                        'prop' => array(
@@ -185,6 +191,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                $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 {$p}prop=ids",
                        'prop' => array(
@@ -198,6 +205,18 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                );
        }
 
+       public function getResultProperties() {
+               return array(
+                       'ids' => array(
+                               'fromid' => 'integer'
+                       ),
+                       'title' => array(
+                               'ns' => 'namespace',
+                               'title' => 'string'
+                       )
+               );
+       }
+
        public function getDescription() {
                return 'Enumerate all links that point to a given namespace';
        }
@@ -212,13 +231,17 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase {
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
-                       'api.php?action=query&list=alllinks&alunique&alfrom=B',
+                       'api.php?action=query&list=alllinks&alunique=&alfrom=B',
                );
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Alllinks';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }
-}
\ No newline at end of file
+}