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