MediaWiki REL1_39
ApiQueryPagePropNames.php
Go to the documentation of this file.
1<?php
26
34
35 public function __construct( ApiQuery $query, $moduleName ) {
36 parent::__construct( $query, $moduleName, 'ppn' );
37 }
38
39 public function getCacheMode( $params ) {
40 return 'public';
41 }
42
43 public function execute() {
44 $params = $this->extractRequestParams();
45
46 $this->addTables( 'page_props' );
47 $this->addFields( 'pp_propname' );
48 $this->addOption( 'DISTINCT' );
49 $this->addOption( 'ORDER BY', 'pp_propname' );
50
51 if ( $params['continue'] ) {
52 $cont = explode( '|', $params['continue'] );
53 $this->dieContinueUsageIf( count( $cont ) != 1 );
54
55 // Add a WHERE clause
56 $this->addWhereRange( 'pp_propname', 'newer', $cont[0], null );
57 }
58
59 $limit = $params['limit'];
60
61 // mysql has issues with limit in loose index T115825
62 if ( $this->getDB()->getType() !== 'mysql' ) {
63 $this->addOption( 'LIMIT', $limit + 1 );
64 }
65
66 $result = $this->getResult();
67 $count = 0;
68 foreach ( $this->select( __METHOD__ ) as $row ) {
69 if ( ++$count > $limit ) {
70 // We've reached the one extra which shows that there are
71 // additional pages to be had. Stop here...
72 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
73 break;
74 }
75
76 $vals = [];
77 $vals['propname'] = $row->pp_propname;
78 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
79 if ( !$fit ) {
80 $this->setContinueEnumParameter( 'continue', $row->pp_propname );
81 break;
82 }
83 }
84
85 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'p' );
86 }
87
88 public function getAllowedParams() {
89 return [
90 'continue' => [
91 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
92 ],
93 'limit' => [
94 ParamValidator::PARAM_TYPE => 'limit',
95 ParamValidator::PARAM_DEFAULT => 10,
96 IntegerDef::PARAM_MIN => 1,
97 IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
98 IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
99 ],
100 ];
101 }
102
103 protected function getExamplesMessages() {
104 return [
105 'action=query&list=pagepropnames'
106 => 'apihelp-query+pagepropnames-example-simple',
107 ];
108 }
109
110 public function getHelpUrls() {
111 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pagepropnames';
112 }
113}
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:1643
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:221
getResult()
Get the result object.
Definition ApiBase.php:629
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:765
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:163
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:223
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:498
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
A query module to list used page props.
__construct(ApiQuery $query, $moduleName)
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
This is the main query class.
Definition ApiQuery.php:41
Service for formatting and validating API parameters.
Type definition for integer types.