MediaWiki REL1_30
ApiQueryTags.php
Go to the documentation of this file.
1<?php
33
34 public function __construct( ApiQuery $query, $moduleName ) {
35 parent::__construct( $query, $moduleName, 'tg' );
36 }
37
38 public function execute() {
40
41 $prop = array_flip( $params['prop'] );
42
43 $fld_displayname = isset( $prop['displayname'] );
44 $fld_description = isset( $prop['description'] );
45 $fld_hitcount = isset( $prop['hitcount'] );
46 $fld_defined = isset( $prop['defined'] );
47 $fld_source = isset( $prop['source'] );
48 $fld_active = isset( $prop['active'] );
49
50 $limit = $params['limit'];
51 $result = $this->getResult();
52
53 $softwareDefinedTags = array_fill_keys( ChangeTags::listSoftwareDefinedTags(), 0 );
54 $explicitlyDefinedTags = array_fill_keys( ChangeTags::listExplicitlyDefinedTags(), 0 );
55 $softwareActivatedTags = array_fill_keys( ChangeTags::listSoftwareActivatedTags(), 0 );
57
58 $tagHitcounts = array_merge( $softwareDefinedTags, $explicitlyDefinedTags, $tagStats );
59 $tags = array_keys( $tagHitcounts );
60
61 # Fetch defined tags that aren't past the continuation
62 if ( $params['continue'] !== null ) {
63 $cont = $params['continue'];
64 $tags = array_filter( $tags, function ( $v ) use ( $cont ) {
65 return $v >= $cont;
66 } );
67 }
68
69 # Now make sure the array is sorted for proper continuation
70 sort( $tags );
71
72 $count = 0;
73 foreach ( $tags as $tagName ) {
74 if ( ++$count > $limit ) {
75 $this->setContinueEnumParameter( 'continue', $tagName );
76 break;
77 }
78
79 $tag = [];
80 $tag['name'] = $tagName;
81
82 if ( $fld_displayname ) {
83 $tag['displayname'] = ChangeTags::tagDescription( $tagName, $this );
84 }
85
86 if ( $fld_description ) {
87 $msg = $this->msg( "tag-$tagName-description" );
88 $tag['description'] = $msg->exists() ? $msg->text() : '';
89 }
90
91 if ( $fld_hitcount ) {
92 $tag['hitcount'] = intval( $tagHitcounts[$tagName] );
93 }
94
95 $isSoftware = isset( $softwareDefinedTags[$tagName] );
96 $isExplicit = isset( $explicitlyDefinedTags[$tagName] );
97
98 if ( $fld_defined ) {
99 $tag['defined'] = $isSoftware || $isExplicit;
100 }
101
102 if ( $fld_source ) {
103 $tag['source'] = [];
104 if ( $isSoftware ) {
105 // TODO: Can we change this to 'software'?
106 $tag['source'][] = 'extension';
107 }
108 if ( $isExplicit ) {
109 $tag['source'][] = 'manual';
110 }
111 }
112
113 if ( $fld_active ) {
114 $tag['active'] = $isExplicit || isset( $softwareActivatedTags[$tagName] );
115 }
116
117 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $tag );
118 if ( !$fit ) {
119 $this->setContinueEnumParameter( 'continue', $tagName );
120 break;
121 }
122 }
123
124 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'tag' );
125 }
126
127 public function getCacheMode( $params ) {
128 return 'public';
129 }
130
131 public function getAllowedParams() {
132 return [
133 'continue' => [
134 ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
135 ],
136 'limit' => [
138 ApiBase::PARAM_TYPE => 'limit',
142 ],
143 'prop' => [
144 ApiBase::PARAM_DFLT => 'name',
146 'name',
147 'displayname',
148 'description',
149 'hitcount',
150 'defined',
151 'source',
152 'active',
153 ],
156 ]
157 ];
158 }
159
160 protected function getExamplesMessages() {
161 return [
162 'action=query&list=tags&tgprop=displayname|description|hitcount|defined'
163 => 'apihelp-query+tags-example-simple',
164 ];
165 }
166
167 public function getHelpUrls() {
168 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Tags';
169 }
170}
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
Definition ApiBase.php:100
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:94
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:91
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:52
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:740
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition ApiBase.php:160
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition ApiBase.php:103
const LIMIT_BIG1
Fast query, standard limit.
Definition ApiBase.php:225
getResult()
Get the result object.
Definition ApiBase.php:632
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
Definition ApiBase.php:128
const LIMIT_BIG2
Fast query, apihighlimits limit.
Definition ApiBase.php:227
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:512
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:55
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Query module to enumerate change tags.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
__construct(ApiQuery $query, $moduleName)
getCacheMode( $params)
Get the cache mode for the data generated by this module.
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.
This is the main query class.
Definition ApiQuery.php:40
static listSoftwareDefinedTags()
Lists tags defined by core or extensions using the ListDefinedTags hook.
static tagDescription( $tag, IContextSource $context)
Get a short description for a tag.
static listSoftwareActivatedTags()
Lists those tags which core or extensions report as being "active".
static tagUsageStatistics()
Returns a map of any tags used on the wiki to number of edits tagged with them, ordered descending by...
static listExplicitlyDefinedTags()
Lists tags explicitly defined in the valid_tag table of the database.
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition hooks.txt:1610
$params