MediaWiki  1.34.0
ApiQueryPageProps.php
Go to the documentation of this file.
1 <?php
29 
30  private $params;
31 
32  public function __construct( ApiQuery $query, $moduleName ) {
33  parent::__construct( $query, $moduleName, 'pp' );
34  }
35 
36  public function execute() {
37  # Only operate on existing pages
38  $pages = $this->getPageSet()->getGoodTitles();
39 
40  $this->params = $this->extractRequestParams();
41  if ( $this->params['continue'] ) {
42  $continueValue = (int)$this->params['continue'];
43  $this->dieContinueUsageIf( strval( $continueValue ) !== $this->params['continue'] );
44  $filteredPages = [];
45  foreach ( $pages as $id => $page ) {
46  if ( $id >= $continueValue ) {
47  $filteredPages[$id] = $page;
48  }
49  }
50  $pages = $filteredPages;
51  }
52 
53  if ( $pages === [] ) {
54  # Nothing to do
55  return;
56  }
57 
58  $pageProps = PageProps::getInstance();
59  $result = $this->getResult();
60  if ( $this->params['prop'] ) {
61  $propnames = $this->params['prop'];
62  $properties = $pageProps->getProperties( $pages, $propnames );
63  } else {
64  $properties = $pageProps->getAllProperties( $pages );
65  }
66 
67  ksort( $properties );
68 
69  foreach ( $properties as $page => $props ) {
70  if ( !$this->addPageProps( $result, $page, $props ) ) {
71  break;
72  }
73  }
74  }
75 
85  private function addPageProps( $result, $page, $props ) {
86  ApiResult::setArrayType( $props, 'assoc' );
87  $fit = $result->addValue( [ 'query', 'pages', $page ], 'pageprops', $props );
88 
89  if ( !$fit ) {
90  $this->setContinueEnumParameter( 'continue', $page );
91  }
92 
93  return $fit;
94  }
95 
96  public function getCacheMode( $params ) {
97  return 'public';
98  }
99 
100  public function getAllowedParams() {
101  return [
102  'continue' => [
103  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
104  ],
105  'prop' => [
106  ApiBase::PARAM_ISMULTI => true,
107  ],
108  ];
109  }
110 
111  protected function getExamplesMessages() {
112  return [
113  'action=query&prop=pageprops&titles=Main%20Page|MediaWiki'
114  => 'apihelp-query+pageprops-example-simple',
115  ];
116  }
117 
118  public function getHelpUrls() {
119  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Pageprops';
120  }
121 }
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
ApiQueryPageProps\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryPageProps.php:36
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:131
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:640
ApiResult\setArrayType
static setArrayType(array &$arr, $type, $kvpKeyName=null)
Set the array data type.
Definition: ApiResult.php:728
PageProps\getInstance
static getInstance()
Definition: PageProps.php:66
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
ApiQueryPageProps\addPageProps
addPageProps( $result, $page, $props)
Add page properties to an ApiResult, adding a continue parameter if it doesn't fit.
Definition: ApiQueryPageProps.php:85
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:761
ApiQueryPageProps\$params
$params
Definition: ApiQueryPageProps.php:30
ApiQueryPageProps\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryPageProps.php:118
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
Definition: ApiBase.php:2208
ApiQueryBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:132
ApiQueryPageProps\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryPageProps.php:32
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:58
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:100
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:492
ApiQueryPageProps\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryPageProps.php:96
ApiQueryPageProps\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryPageProps.php:111