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