summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryLangLinks.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryLangLinks.php')
-rw-r--r--includes/api/ApiQueryLangLinks.php61
1 files changed, 53 insertions, 8 deletions
diff --git a/includes/api/ApiQueryLangLinks.php b/includes/api/ApiQueryLangLinks.php
index 04a930db..e7d84fc3 100644
--- a/includes/api/ApiQueryLangLinks.php
+++ b/includes/api/ApiQueryLangLinks.php
@@ -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,14 +52,36 @@ 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
+ $lastId = 0; // database has no ID 0
+ $count = 0;
$db = $this->getDB();
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}");
+ break;
+ }
if ($lastId != $row->ll_from) {
if($lastId != 0) {
$this->addPageSubItems($lastId, $data);
@@ -64,7 +90,7 @@ class ApiQueryLangLinks extends ApiQueryBase {
$lastId = $row->ll_from;
}
- $entry = array('lang'=>$row->ll_lang);
+ $entry = array('lang' => $row->ll_lang);
ApiResult :: setContent($entry, $row->ll_title);
$data[] = $entry;
}
@@ -76,6 +102,26 @@ class ApiQueryLangLinks extends ApiQueryBase {
$db->freeResult($res);
}
+ 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,
+ );
+ }
+
+ public function getParamDescription () {
+ return array(
+ 'limit' => 'How many langlinks to return',
+ 'continue' => 'When more results are available, use this to continue',
+ );
+ }
+
public function getDescription() {
return 'Returns all interlanguage links from the given page(s)';
}
@@ -88,7 +134,6 @@ class ApiQueryLangLinks extends ApiQueryBase {
}
public function getVersion() {
- return __CLASS__ . ': $Id: ApiQueryLangLinks.php 30222 2008-01-28 19:05:26Z catrope $';
+ return __CLASS__ . ': $Id: ApiQueryLangLinks.php 37534 2008-07-10 21:08:37Z brion $';
}
}
-