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
00067
00068 if ( count( $this->getPageSet()->getGoodTitles() ) == 1 )
00069 $this->addOption( 'ORDER BY', 'll_lang' );
00070 else
00071 $this->addOption( 'ORDER BY', 'll_from, ll_lang' );
00072 $this->addOption( 'LIMIT', $params['limit'] + 1 );
00073 $res = $this->select( __METHOD__ );
00074
00075 $count = 0;
00076 $db = $this->getDB();
00077 while ( $row = $db->fetchObject( $res ) ) {
00078 if ( ++$count > $params['limit'] ) {
00079
00080
00081 $this->setContinueEnumParameter( 'continue', "{$row->ll_from}|{$row->ll_lang}" );
00082 break;
00083 }
00084 $entry = array( 'lang' => $row->ll_lang );
00085 ApiResult :: setContent( $entry, $row->ll_title );
00086 $fit = $this->addPageSubItem( $row->ll_from, $entry );
00087 if ( !$fit )
00088 {
00089 $this->setContinueEnumParameter( 'continue', "{$row->ll_from}|{$row->ll_lang}" );
00090 break;
00091 }
00092 }
00093 $db->freeResult( $res );
00094 }
00095
00096 public function getCacheMode( $params ) {
00097 return 'public';
00098 }
00099
00100 public function getAllowedParams() {
00101 return array(
00102 'limit' => array(
00103 ApiBase :: PARAM_DFLT => 10,
00104 ApiBase :: PARAM_TYPE => 'limit',
00105 ApiBase :: PARAM_MIN => 1,
00106 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00107 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00108 ),
00109 'continue' => null,
00110 );
00111 }
00112
00113 public function getParamDescription () {
00114 return array(
00115 'limit' => 'How many langlinks to return',
00116 'continue' => 'When more results are available, use this to continue',
00117 );
00118 }
00119
00120 public function getDescription() {
00121 return 'Returns all interlanguage links from the given page(s)';
00122 }
00123
00124 public function getPossibleErrors() {
00125 return array_merge( parent::getPossibleErrors(), array(
00126 array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ),
00127 ) );
00128 }
00129
00130 protected function getExamples() {
00131 return array (
00132 "Get interlanguage links from the [[Main Page]]:",
00133 " api.php?action=query&prop=langlinks&titles=Main%20Page&redirects",
00134 );
00135 }
00136
00137 public function getVersion() {
00138 return __CLASS__ . ': $Id: ApiQueryLangLinks.php 69932 2010-07-26 08:03:21Z tstarling $';
00139 }
00140 }