MediaWiki REL1_37
ApiQueryPageProps.php
Go to the documentation of this file.
1<?php
29
31 private $pageProps;
32
38 public function __construct(
39 ApiQuery $query,
40 $moduleName,
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
51 $params = $this->extractRequestParams();
52 if ( $params['continue'] ) {
53 $continueValue = (int)$params['continue'];
54 $this->dieContinueUsageIf( strval( $continueValue ) !== $params['continue'] );
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' => [
116 ],
117 ];
118 }
119
120 protected function getExamplesMessages() {
121 return [
122 'action=query&prop=pageprops&titles=Main%20Page|MediaWiki'
123 => 'apihelp-query+pageprops-example-simple',
124 ];
125 }
126
127 public function getHelpUrls() {
128 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';
129 }
130}
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition ApiBase.php:1620
getResult()
Get the result object.
Definition ApiBase.php:628
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:764
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:162
const PARAM_ISMULTI
Definition ApiBase.php:77
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.
addPageProps( $result, $page, $props)
Add page properties to an ApiResult, adding a continue parameter if it doesn't fit.
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:37
Gives access to properties of a page.
Definition PageProps.php:33