MediaWiki master
ApiQueryPageProps.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Api;
24
28
35
36 private PageProps $pageProps;
37
38 public function __construct(
39 ApiQuery $query,
40 string $moduleName,
41 PageProps $pageProps
42 ) {
43 parent::__construct( $query, $moduleName, 'pp' );
44 $this->pageProps = $pageProps;
45 }
46
47 public function execute() {
48 # Only operate on existing pages
49 $pages = $this->getPageSet()->getGoodPages();
50
52 if ( $params['continue'] ) {
53 $cont = $this->parseContinueParamOrDie( $params['continue'], [ 'int' ] );
54 $continueValue = $cont[0];
55 $filteredPages = [];
56 foreach ( $pages as $id => $page ) {
57 if ( $id >= $continueValue ) {
58 $filteredPages[$id] = $page;
59 }
60 }
61 $pages = $filteredPages;
62 }
63
64 if ( $pages === [] ) {
65 # Nothing to do
66 return;
67 }
68
69 if ( $params['prop'] ) {
70 $properties = $this->pageProps->getProperties( $pages, $params['prop'] );
71 } else {
72 $properties = $this->pageProps->getAllProperties( $pages );
73 }
74
75 ksort( $properties );
76
77 $result = $this->getResult();
78 foreach ( $properties as $pageid => $props ) {
79 if ( !$this->addPageProps( $result, $pageid, $props ) ) {
80 break;
81 }
82 }
83 }
84
94 private function addPageProps( $result, $page, $props ) {
95 ApiResult::setArrayType( $props, 'assoc' );
96 $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
97
98 if ( !$fit ) {
99 $this->setContinueEnumParameter( 'continue', $page );
100 }
101
102 return $fit;
103 }
104
105 public function getCacheMode( $params ) {
106 return 'public';
107 }
108
109 public function getAllowedParams() {
110 return [
111 'continue' => [
112 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
113 ],
114 'prop' => [
115 ParamValidator::PARAM_ISMULTI => true,
116 ],
117 ];
118 }
119
120 protected function getExamplesMessages() {
121 $title = Title::newMainPage()->getPrefixedText();
122 $mp = rawurlencode( $title );
123
124 return [
125 "action=query&prop=pageprops&titles={$mp}|MediaWiki"
126 => 'apihelp-query+pageprops-example-simple',
127 ];
128 }
129
130 public function getHelpUrls() {
131 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';
132 }
133}
134
136class_alias( ApiQueryPageProps::class, 'ApiQueryPageProps' );
array $params
The job parameters.
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
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:851
This is a base class for all Query modules.
getPageSet()
Get the PageSet object to work on.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
A query module to show basic page information.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getHelpUrls()
Return links to more detailed help pages about the module.
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, PageProps $pageProps)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
This is the main query class.
Definition ApiQuery.php:48
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Gives access to properties of a page.
Definition PageProps.php:35
Represents a title within MediaWiki.
Definition Title.php:78
Service for formatting and validating API parameters.