MediaWiki master
ApiQueryCategoryInfo.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Api;
24
26
34
35 public function __construct( ApiQuery $query, string $moduleName ) {
36 parent::__construct( $query, $moduleName, 'ci' );
37 }
38
39 public function execute() {
41 $alltitles = $this->getPageSet()->getGoodAndMissingTitlesByNamespace();
42 if ( empty( $alltitles[NS_CATEGORY] ) ) {
43 return;
44 }
45 $categories = $alltitles[NS_CATEGORY];
46
47 $titles = $this->getPageSet()->getGoodAndMissingPages();
48 $cattitles = [];
49 foreach ( $categories as $c ) {
51 $t = $titles[$c];
52 $cattitles[$c] = $t->getDBkey();
53 }
54
55 $this->addTables( [ 'category', 'page', 'page_props' ] );
56 $this->addJoinConds( [
57 'page' => [ 'LEFT JOIN', [
58 'page_namespace' => NS_CATEGORY,
59 'page_title=cat_title' ] ],
60 'page_props' => [ 'LEFT JOIN', [
61 'pp_page=page_id',
62 'pp_propname' => 'hiddencat' ] ],
63 ] );
64
65 $this->addFields( [
66 'cat_title',
67 'cat_pages',
68 'cat_subcats',
69 'cat_files',
70 'cat_hidden' => 'pp_propname'
71 ] );
72 $this->addWhere( [ 'cat_title' => $cattitles ] );
73
74 if ( $params['continue'] !== null ) {
75 $this->addWhere( $this->getDB()->expr( 'cat_title', '>=', $params['continue'] ) );
76 }
77 $this->addOption( 'ORDER BY', 'cat_title' );
78
79 $res = $this->select( __METHOD__ );
80
81 $catids = array_flip( $cattitles );
82 foreach ( $res as $row ) {
83 $vals = [];
84 $vals['size'] = (int)$row->cat_pages;
85 $vals['pages'] = $row->cat_pages - $row->cat_subcats - $row->cat_files;
86 $vals['files'] = (int)$row->cat_files;
87 $vals['subcats'] = (int)$row->cat_subcats;
88 $vals['hidden'] = (bool)$row->cat_hidden;
89 $fit = $this->addPageSubItems( $catids[$row->cat_title], $vals );
90 if ( !$fit ) {
91 $this->setContinueEnumParameter( 'continue', $row->cat_title );
92 break;
93 }
94 }
95 }
96
97 public function getCacheMode( $params ) {
98 return 'public';
99 }
100
101 public function getAllowedParams() {
102 return [
103 'continue' => [
104 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
105 ],
106 ];
107 }
108
109 protected function getExamplesMessages() {
110 return [
111 'action=query&prop=categoryinfo&titles=Category:Foo|Category:Bar'
112 => 'apihelp-query+categoryinfo-example-simple',
113 ];
114 }
115
116 public function getHelpUrls() {
117 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Categoryinfo';
118 }
119}
120
122class_alias( ApiQueryCategoryInfo::class, 'ApiQueryCategoryInfo' );
const NS_CATEGORY
Definition Defines.php:79
array $params
The job parameters.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:184
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:851
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.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
__construct(ApiQuery $query, string $moduleName)
This is the main query class.
Definition ApiQuery.php:48
Represents a title within MediaWiki.
Definition Title.php:78