MediaWiki
REL1_23
|
00001 <?php 00033 class ApiQueryPagePropNames extends ApiQueryBase { 00034 00035 public function __construct( $query, $moduleName ) { 00036 parent::__construct( $query, $moduleName, 'ppn' ); 00037 } 00038 00039 public function getCacheMode( $params ) { 00040 return 'public'; 00041 } 00042 00043 public function execute() { 00044 $params = $this->extractRequestParams(); 00045 00046 $this->addTables( 'page_props' ); 00047 $this->addFields( 'pp_propname' ); 00048 $this->addOption( 'DISTINCT' ); 00049 $this->addOption( 'ORDER BY', 'pp_propname' ); 00050 00051 if ( $params['continue'] ) { 00052 $cont = explode( '|', $params['continue'] ); 00053 $this->dieContinueUsageIf( count( $cont ) != 1 ); 00054 00055 // Add a WHERE clause 00056 $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null ); 00057 } 00058 00059 $limit = $params['limit']; 00060 $this->addOption( 'LIMIT', $limit + 1 ); 00061 00062 $result = $this->getResult(); 00063 $count = 0; 00064 foreach ( $this->select( __METHOD__ ) as $row ) { 00065 if ( ++$count > $limit ) { 00066 // We've reached the one extra which shows that there are 00067 // additional pages to be had. Stop here... 00068 $this->setContinueEnumParameter( 'continue', $row->pp_propname ); 00069 break; 00070 } 00071 00072 $vals = array(); 00073 $vals['propname'] = $row->pp_propname; 00074 $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); 00075 if ( !$fit ) { 00076 $this->setContinueEnumParameter( 'continue', $row->pp_propname ); 00077 break; 00078 } 00079 } 00080 00081 $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' ); 00082 } 00083 00084 public function getAllowedParams() { 00085 return array( 00086 'continue' => null, 00087 'limit' => array( 00088 ApiBase::PARAM_TYPE => 'limit', 00089 ApiBase::PARAM_DFLT => 10, 00090 ApiBase::PARAM_MIN => 1, 00091 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, 00092 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 00093 ), 00094 ); 00095 } 00096 00097 public function getParamDescription() { 00098 return array( 00099 'continue' => 'When more results are available, use this to continue', 00100 'limit' => 'The maximum number of pages to return', 00101 ); 00102 } 00103 00104 public function getDescription() { 00105 return 'List all page prop names in use on the wiki.'; 00106 } 00107 00108 public function getExamples() { 00109 return array( 00110 'api.php?action=query&list=pagepropnames' => 'Get first 10 prop names', 00111 ); 00112 } 00113 00114 public function getHelpUrls() { 00115 return 'https://www.mediawiki.org/wiki/API:Pagepropnames'; 00116 } 00117 }