MediaWiki master
ApiQueryPagePropNames.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Api;
25
28
36
37 public function __construct( ApiQuery $query, string $moduleName ) {
38 parent::__construct( $query, $moduleName, 'ppn' );
39 }
40
41 public function getCacheMode( $params ) {
42 return 'public';
43 }
44
45 public function execute() {
47
48 $this->addTables( 'page_props' );
49 $this->addFields( 'pp_propname' );
50 $this->addOption( 'DISTINCT' );
51 $this->addOption( 'ORDER BY', 'pp_propname' );
52
53 if ( $params['continue'] ) {
54 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'string' ] );
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}
114
116class_alias( ApiQueryPagePropNames::class, 'ApiQueryPagePropNames' );
array $params
The job parameters.
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:571
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
Definition ApiBase.php:1756
getResult()
Get the result object.
Definition ApiBase.php:710
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:184
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:251
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:851
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:249
This is a base class for all Query modules.
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.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addFields( $value)
Add a set of fields to select to the internal array.
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.
A query module to list used page props.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
__construct(ApiQuery $query, string $moduleName)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
This is the main query class.
Definition ApiQuery.php:48
Service for formatting and validating API parameters.
Type definition for integer types.