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