]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiQueryLangLinks.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiQueryLangLinks.php
index 8eaf8d02617e67a0ad5509736ba83a37fc7da49f..9330e380807040c2638275ed7214b5fc26a3af02 100644 (file)
@@ -23,9 +23,9 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ("ApiQueryBase.php");
+       require_once ( "ApiQueryBase.php" );
 }
 
 /**
@@ -35,8 +35,8 @@ if (!defined('MEDIAWIKI')) {
  */
 class ApiQueryLangLinks extends ApiQueryBase {
 
-       public function __construct($query, $moduleName) {
-               parent :: __construct($query, $moduleName, 'll');
+       public function __construct( $query, $moduleName ) {
+               parent :: __construct( $query, $moduleName, 'll' );
        }
 
        public function execute() {
@@ -44,62 +44,57 @@ class ApiQueryLangLinks extends ApiQueryBase {
                        return;
 
                $params = $this->extractRequestParams();
-               $this->addFields(array (
+               $this->addFields( array (
                        'll_from',
                        'll_lang',
                        'll_title'
-               ));
-
-               $this->addTables('langlinks');
-               $this->addWhereFld('ll_from', array_keys($this->getPageSet()->getGoodTitles()));
-               if(!is_null($params['continue'])) {
-                       $cont = explode('|', $params['continue']);
-                       if(count($cont) != 2)
-                               $this->dieUsage("Invalid continue param. You should pass the " .
-                                       "original value returned by the previous query", "_badcontinue");
-                       $llfrom = intval($cont[0]);
-                       $lllang = $this->getDB()->strencode($cont[1]);
-                       $this->addWhere("ll_from > $llfrom OR ".
-                                       "(ll_from = $llfrom AND ".
-                                       "ll_lang >= '$lllang')");
+               ) );
+
+               $this->addTables( 'langlinks' );
+               $this->addWhereFld( 'll_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
+               if ( !is_null( $params['continue'] ) ) {
+                       $cont = explode( '|', $params['continue'] );
+                       if ( count( $cont ) != 2 )
+                               $this->dieUsage( "Invalid continue param. You should pass the " .
+                                       "original value returned by the previous query", "_badcontinue" );
+                       $llfrom = intval( $cont[0] );
+                       $lllang = $this->getDB()->strencode( $cont[1] );
+                       $this->addWhere( "ll_from > $llfrom OR " .
+                                       "(ll_from = $llfrom AND " .
+                                       "ll_lang >= '$lllang')" );
                }
-               # Don't order by ll_from if it's constant in the WHERE clause
-               if(count($this->getPageSet()->getGoodTitles()) == 1)
-                       $this->addOption('ORDER BY', 'll_lang');
+
+               // Don't order by ll_from if it's constant in the WHERE clause
+               if ( count( $this->getPageSet()->getGoodTitles() ) == 1 )
+                       $this->addOption( 'ORDER BY', 'll_lang' );
                else
-                       $this->addOption('ORDER BY', 'll_from, ll_lang');
-               $this->addOption('LIMIT', $params['limit'] + 1);
-               $res = $this->select(__METHOD__);
+                       $this->addOption( 'ORDER BY', 'll_from, ll_lang' );
+               $this->addOption( 'LIMIT', $params['limit'] + 1 );
+               $res = $this->select( __METHOD__ );
 
-               $data = array();
-               $lastId = 0;    // database has no ID 0
                $count = 0;
                $db = $this->getDB();
-               while ($row = $db->fetchObject($res)) {
-                       if (++$count > $params['limit']) {
+               while ( $row = $db->fetchObject( $res ) ) {
+                       if ( ++$count > $params['limit'] ) {
                                // We've reached the one extra which shows that
                                // there are additional pages to be had. Stop here...
-                               $this->setContinueEnumParameter('continue', "{$row->ll_from}|{$row->ll_lang}");
+                               $this->setContinueEnumParameter( 'continue', "{$row->ll_from}|{$row->ll_lang}" );
                                break;
                        }
-                       if ($lastId != $row->ll_from) {
-                               if($lastId != 0) {
-                                       $this->addPageSubItems($lastId, $data);
-                                       $data = array();
-                               }
-                               $lastId = $row->ll_from;
+                       $entry = array( 'lang' => $row->ll_lang );
+                       ApiResult :: setContent( $entry, $row->ll_title );
+                       $fit = $this->addPageSubItem( $row->ll_from, $entry );
+                       if ( !$fit )
+                       {
+                               $this->setContinueEnumParameter( 'continue', "{$row->ll_from}|{$row->ll_lang}" );
+                               break;
                        }
-
-                       $entry = array('lang' => $row->ll_lang);
-                       ApiResult :: setContent($entry, $row->ll_title);
-                       $data[] = $entry;
-               }
-
-               if($lastId != 0) {
-                       $this->addPageSubItems($lastId, $data);
                }
+               $db->freeResult( $res );
+       }
 
-               $db->freeResult($res);
+       public function getCacheMode( $params ) {
+               return 'public';
        }
 
        public function getAllowedParams() {
@@ -125,6 +120,12 @@ class ApiQueryLangLinks extends ApiQueryBase {
        public function getDescription() {
                return 'Returns all interlanguage links from the given page(s)';
        }
+       
+       public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
+               ) );
+       }
 
        protected function getExamples() {
                return array (
@@ -134,6 +135,6 @@ class ApiQueryLangLinks extends ApiQueryBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiQueryLangLinks.php 43271 2008-11-06 22:38:42Z siebrand $';
+               return __CLASS__ . ': $Id: ApiQueryLangLinks.php 69932 2010-07-26 08:03:21Z tstarling $';
        }
 }