]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiQueryLangLinks.php
MediaWiki 1.15.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiQueryLangLinks.php
index ae5ff7906458b1ff1554ebdc52ce97711497f47d..3abe5e3d2d7aa7cd3886dd823b95aee9ab71a9e1 100644 (file)
@@ -30,8 +30,8 @@ if (!defined('MEDIAWIKI')) {
 
 /**
  * A query module to list all langlinks (links to correspanding foreign language pages).
- * 
- * @addtogroup API
+ *
+ * @ingroup API
  */
 class ApiQueryLangLinks extends ApiQueryBase {
 
@@ -40,6 +40,10 @@ class ApiQueryLangLinks extends ApiQueryBase {
        }
 
        public function execute() {
+               if ( $this->getPageSet()->getGoodTitleCount() == 0 )
+                       return;
+
+               $params = $this->extractRequestParams();
                $this->addFields(array (
                        'll_from',
                        'll_lang',
@@ -48,35 +52,67 @@ class ApiQueryLangLinks extends ApiQueryBase {
 
                $this->addTables('langlinks');
                $this->addWhereFld('ll_from', array_keys($this->getPageSet()->getGoodTitles()));
-               $this->addOption('ORDER BY', "ll_from, ll_lang");
+               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');
+               else
+                       $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 ($lastId != $row->ll_from) {
-                               if($lastId != 0) {
-                                       $this->addPageSubItems($lastId, $data);
-                                       $data = array();
-                               }
-                               $lastId = $row->ll_from;
+                       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}");
+                               break;
                        }
-
-                       $entry = array('lang'=>$row->ll_lang);
+                       $entry = array('lang' => $row->ll_lang);
                        ApiResult :: setContent($entry, $row->ll_title);
-                       $data[] = $entry;
+                       $fit = $this->addPageSubItem($row->ll_from, $entry);
+                       if(!$fit)
+                       {
+                               $this->setContinueEnumParameter('continue', "{$row->ll_from}|{$row->ll_lang}");
+                               break;
+                       }
                }
+               $db->freeResult($res);
+       }
 
-               if($lastId != 0) {
-                       $this->addPageSubItems($lastId, $data);
-               }
+       public function getAllowedParams() {
+               return array(
+                               'limit' => array(
+                                       ApiBase :: PARAM_DFLT => 10,
+                                       ApiBase :: PARAM_TYPE => 'limit',
+                                       ApiBase :: PARAM_MIN => 1,
+                                       ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
+                                       ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
+                               ),
+                               'continue' => null,
+               );
+       }
 
-               $db->freeResult($res);
+       public function getParamDescription () {
+               return array(
+                       'limit' => 'How many langlinks to return',
+                       'continue' => 'When more results are available, use this to continue',
+               );
        }
 
-       protected function getDescription() {
+       public function getDescription() {
                return 'Returns all interlanguage links from the given page(s)';
        }
 
@@ -88,7 +124,6 @@ class ApiQueryLangLinks extends ApiQueryBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiQueryLangLinks.php 23819 2007-07-07 03:05:09Z yurik $';
+               return __CLASS__ . ': $Id: ApiQueryLangLinks.php 46845 2009-02-05 14:30:59Z catrope $';
        }
-}
-
+}
\ No newline at end of file