MediaWiki  1.34.0
ApiQueryCategoryInfo.php
Go to the documentation of this file.
1 <?php
30 
31  public function __construct( ApiQuery $query, $moduleName ) {
32  parent::__construct( $query, $moduleName, 'ci' );
33  }
34 
35  public function execute() {
36  $params = $this->extractRequestParams();
37  $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
38  if ( empty( $alltitles[NS_CATEGORY] ) ) {
39  return;
40  }
41  $categories = $alltitles[NS_CATEGORY];
42 
43  $titles = $this->getPageSet()->getGoodAndMissingTitles();
44  $cattitles = [];
45  foreach ( $categories as $c ) {
47  $t = $titles[$c];
48  $cattitles[$c] = $t->getDBkey();
49  }
50 
51  $this->addTables( [ 'category', 'page', 'page_props' ] );
52  $this->addJoinConds( [
53  'page' => [ 'LEFT JOIN', [
54  'page_namespace' => NS_CATEGORY,
55  'page_title=cat_title' ] ],
56  'page_props' => [ 'LEFT JOIN', [
57  'pp_page=page_id',
58  'pp_propname' => 'hiddencat' ] ],
59  ] );
60 
61  $this->addFields( [
62  'cat_title',
63  'cat_pages',
64  'cat_subcats',
65  'cat_files',
66  'cat_hidden' => 'pp_propname'
67  ] );
68  $this->addWhere( [ 'cat_title' => $cattitles ] );
69 
70  if ( !is_null( $params['continue'] ) ) {
71  $title = $this->getDB()->addQuotes( $params['continue'] );
72  $this->addWhere( "cat_title >= $title" );
73  }
74  $this->addOption( 'ORDER BY', 'cat_title' );
75 
76  $res = $this->select( __METHOD__ );
77 
78  $catids = array_flip( $cattitles );
79  foreach ( $res as $row ) {
80  $vals = [];
81  $vals['size'] = (int)$row->cat_pages;
82  $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
83  $vals['files'] = (int)$row->cat_files;
84  $vals['subcats'] = (int)$row->cat_subcats;
85  $vals['hidden'] = (bool)$row->cat_hidden;
86  $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
87  if ( !$fit ) {
88  $this->setContinueEnumParameter( 'continue', $row->cat_title );
89  break;
90  }
91  }
92  }
93 
94  public function getCacheMode( $params ) {
95  return 'public';
96  }
97 
98  public function getAllowedParams() {
99  return [
100  'continue' => [
101  ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
102  ],
103  ];
104  }
105 
106  protected function getExamplesMessages() {
107  return [
108  'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar'
109  => 'apihelp-query+categoryinfo-example-simple',
110  ];
111  }
112 
113  public function getHelpUrls() {
114  return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categoryinfo';
115  }
116 }
ApiQueryBase\addPageSubItems
addPageSubItems( $pageId, $data)
Add a sub-element under the page element with the given page ID.
Definition: ApiQueryBase.php:454
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:193
ApiQuery
This is the main query class.
Definition: ApiQuery.php:37
ApiQueryCategoryInfo
This query adds the "<categories>" subelement to all pages with the list of categories the page is in...
Definition: ApiQueryCategoryInfo.php:29
ApiBase\PARAM_HELP_MSG
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition: ApiBase.php:131
ApiQueryCategoryInfo\getHelpUrls
getHelpUrls()
Return links to more detailed help pages about the module.
Definition: ApiQueryCategoryInfo.php:113
ApiQueryCategoryInfo\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryCategoryInfo.php:94
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:350
$res
$res
Definition: testCompression.php:52
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:107
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:161
ApiQueryBase\select
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:375
$t
$t
Definition: make-normalization-table.php:143
ApiBase\extractRequestParams
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:761
$title
$title
Definition: testCompression.php:34
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:74
ApiQueryCategoryInfo\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryCategoryInfo.php:35
ApiQueryBase\addJoinConds
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
Definition: ApiQueryBase.php:182
ApiQueryCategoryInfo\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryCategoryInfo.php:98
ApiQueryCategoryInfo\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiQueryCategoryInfo.php:106
ApiQueryBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:132
ApiQueryCategoryInfo\__construct
__construct(ApiQuery $query, $moduleName)
Definition: ApiQueryCategoryInfo.php:31
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:228
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:492