00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if (!defined('MEDIAWIKI')) {
00027
00028 require_once ("ApiQueryBase.php");
00029 }
00030
00036 class ApiQueryLangLinks extends ApiQueryBase {
00037
00038 public function __construct($query, $moduleName) {
00039 parent :: __construct($query, $moduleName, 'll');
00040 }
00041
00042 public function execute() {
00043 if ( $this->getPageSet()->getGoodTitleCount() == 0 )
00044 return;
00045
00046 $params = $this->extractRequestParams();
00047 $this->addFields(array (
00048 'll_from',
00049 'll_lang',
00050 'll_title'
00051 ));
00052
00053 $this->addTables('langlinks');
00054 $this->addWhereFld('ll_from', array_keys($this->getPageSet()->getGoodTitles()));
00055 if(!is_null($params['continue'])) {
00056 $cont = explode('|', $params['continue']);
00057 if(count($cont) != 2)
00058 $this->dieUsage("Invalid continue param. You should pass the " .
00059 "original value returned by the previous query", "_badcontinue");
00060 $llfrom = intval($cont[0]);
00061 $lllang = $this->getDB()->strencode($cont[1]);
00062 $this->addWhere("ll_from > $llfrom OR ".
00063 "(ll_from = $llfrom AND ".
00064 "ll_lang >= '$lllang')");
00065 }
00066 # Don't order by ll_from if it's constant in the WHERE clause
00067 if(count($this->getPageSet()->getGoodTitles()) == 1)
00068 $this->addOption('ORDER BY', 'll_lang');
00069 else
00070 $this->addOption('ORDER BY', 'll_from, ll_lang');
00071 $this->addOption('LIMIT', $params['limit'] + 1);
00072 $res = $this->select(__METHOD__);
00073
00074 $count = 0;
00075 $db = $this->getDB();
00076 while ($row = $db->fetchObject($res)) {
00077 if (++$count > $params['limit']) {
00078
00079
00080 $this->setContinueEnumParameter('continue', "{$row->ll_from}|{$row->ll_lang}");
00081 break;
00082 }
00083 $entry = array('lang' => $row->ll_lang);
00084 ApiResult :: setContent($entry, $row->ll_title);
00085 $fit = $this->addPageSubItem($row->ll_from, $entry);
00086 if(!$fit)
00087 {
00088 $this->setContinueEnumParameter('continue', "{$row->ll_from}|{$row->ll_lang}");
00089 break;
00090 }
00091 }
00092 $db->freeResult($res);
00093 }
00094
00095 public function getAllowedParams() {
00096 return array(
00097 'limit' => array(
00098 ApiBase :: PARAM_DFLT => 10,
00099 ApiBase :: PARAM_TYPE => 'limit',
00100 ApiBase :: PARAM_MIN => 1,
00101 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00102 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00103 ),
00104 'continue' => null,
00105 );
00106 }
00107
00108 public function getParamDescription () {
00109 return array(
00110 'limit' => 'How many langlinks to return',
00111 'continue' => 'When more results are available, use this to continue',
00112 );
00113 }
00114
00115 public function getDescription() {
00116 return 'Returns all interlanguage links from the given page(s)';
00117 }
00118
00119 protected function getExamples() {
00120 return array (
00121 "Get interlanguage links from the [[Main Page]]:",
00122 " api.php?action=query&prop=langlinks&titles=Main%20Page&redirects",
00123 );
00124 }
00125
00126 public function getVersion() {
00127 return __CLASS__ . ': $Id: ApiQueryLangLinks.php 46845 2009-02-05 14:30:59Z catrope $';
00128 }
00129 }