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