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