MediaWiki  master
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' => [
115  ApiBase::PARAM_ISMULTI => true,
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 }
ApiQuery
This is the main query class.
Definition: ApiQuery.php:39
ApiQueryPageProps\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryPageProps.php:47
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:162
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:628
ApiResult\setArrayType
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:715
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:37
ApiQueryPageProps\addPageProps
addPageProps( $result, $page, $props)
Add page properties to an ApiResult, adding a continue parameter if it doesn't fit.
Definition: ApiQueryPageProps.php:94
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:764
ApiQueryPageProps\__construct
__construct(ApiQuery $query, $moduleName, PageProps $pageProps)
Definition: ApiQueryPageProps.php:38
ApiQueryPageProps\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryPageProps.php:127
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:1626
ApiQueryBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:143
ApiQueryPageProps\$pageProps
PageProps $pageProps
Definition: ApiQueryPageProps.php:31
PageProps
Gives access to properties of a page.
Definition: PageProps.php:33
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:77
ApiQueryPageProps
A query module to show basic page information.
Definition: ApiQueryPageProps.php:28
ApiQueryPageProps\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryPageProps.php:109
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:515
ApiQueryPageProps\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryPageProps.php:105
ApiQueryPageProps\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryPageProps.php:120