5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Query module to enumerate change tags.
28 class ApiQueryTags
extends ApiQueryBase
{
30 public function __construct( ApiQuery
$query, $moduleName ) {
31 parent
::__construct( $query, $moduleName, 'tg' );
34 public function execute() {
35 $params = $this->extractRequestParams();
37 $prop = array_flip( $params['prop'] );
39 $fld_displayname = isset( $prop['displayname'] );
40 $fld_description = isset( $prop['description'] );
41 $fld_hitcount = isset( $prop['hitcount'] );
42 $fld_defined = isset( $prop['defined'] );
43 $fld_source = isset( $prop['source'] );
44 $fld_active = isset( $prop['active'] );
46 $limit = $params['limit'];
47 $result = $this->getResult();
49 $softwareDefinedTags = array_fill_keys( ChangeTags
::listSoftwareDefinedTags(), 0 );
50 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
51 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
52 $tagStats = ChangeTags
::tagUsageStatistics();
54 $tagHitcounts = array_merge( $softwareDefinedTags, $explicitlyDefinedTags, $tagStats );
55 $tags = array_keys( $tagHitcounts );
57 # Fetch defined tags that aren't past the continuation
58 if ( $params['continue'] !== null ) {
59 $cont = $params['continue'];
60 $tags = array_filter( $tags, function ( $v ) use ( $cont ) {
65 # Now make sure the array is sorted for proper continuation
69 foreach ( $tags as $tagName ) {
70 if ( ++
$count > $limit ) {
71 $this->setContinueEnumParameter( 'continue', $tagName );
76 $tag['name'] = $tagName;
78 if ( $fld_displayname ) {
79 $tag['displayname'] = ChangeTags
::tagDescription( $tagName, $this );
82 if ( $fld_description ) {
83 $msg = $this->msg( "tag-$tagName-description" );
84 $tag['description'] = $msg->exists() ?
$msg->text() : '';
87 if ( $fld_hitcount ) {
88 $tag['hitcount'] = (int)$tagHitcounts[$tagName];
91 $isSoftware = isset( $softwareDefinedTags[$tagName] );
92 $isExplicit = isset( $explicitlyDefinedTags[$tagName] );
95 $tag['defined'] = $isSoftware ||
$isExplicit;
101 // TODO: Can we change this to 'software'?
102 $tag['source'][] = 'extension';
105 $tag['source'][] = 'manual';
110 $tag['active'] = $isExplicit ||
isset( $softwareActivatedTags[$tagName] );
113 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $tag );
115 $this->setContinueEnumParameter( 'continue', $tagName );
120 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'tag' );
123 public function getCacheMode( $params ) {
127 public function getAllowedParams() {
130 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
133 ApiBase
::PARAM_DFLT
=> 10,
134 ApiBase
::PARAM_TYPE
=> 'limit',
135 ApiBase
::PARAM_MIN
=> 1,
136 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
137 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
140 ApiBase
::PARAM_DFLT
=> '',
141 ApiBase
::PARAM_TYPE
=> [
149 ApiBase
::PARAM_ISMULTI
=> true,
150 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
155 protected function getExamplesMessages() {
157 'action=query&list=tags&tgprop=displayname|description|hitcount|defined'
158 => 'apihelp-query+tags-example-simple',
162 public function getHelpUrls() {
163 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Tags';