5 * Created on Jul 9, 2009
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
28 * Query module to enumerate change tags.
32 class ApiQueryTags
extends ApiQueryBase
{
34 public function __construct( ApiQuery
$query, $moduleName ) {
35 parent
::__construct( $query, $moduleName, 'tg' );
38 public function execute() {
39 $params = $this->extractRequestParams();
41 $prop = array_flip( $params['prop'] );
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'] );
50 $limit = $params['limit'];
51 $result = $this->getResult();
53 $softwareDefinedTags = array_fill_keys( ChangeTags
::listSoftwareDefinedTags(), 0 );
54 $explicitlyDefinedTags = array_fill_keys( ChangeTags
::listExplicitlyDefinedTags(), 0 );
55 $softwareActivatedTags = array_fill_keys( ChangeTags
::listSoftwareActivatedTags(), 0 );
56 $tagStats = ChangeTags
::tagUsageStatistics();
58 $tagHitcounts = array_merge( $softwareDefinedTags, $explicitlyDefinedTags, $tagStats );
59 $tags = array_keys( $tagHitcounts );
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 ) {
69 # Now make sure the array is sorted for proper continuation
73 foreach ( $tags as $tagName ) {
74 if ( ++
$count > $limit ) {
75 $this->setContinueEnumParameter( 'continue', $tagName );
80 $tag['name'] = $tagName;
82 if ( $fld_displayname ) {
83 $tag['displayname'] = ChangeTags
::tagDescription( $tagName, $this );
86 if ( $fld_description ) {
87 $msg = $this->msg( "tag-$tagName-description" );
88 $tag['description'] = $msg->exists() ?
$msg->text() : '';
91 if ( $fld_hitcount ) {
92 $tag['hitcount'] = intval( $tagHitcounts[$tagName] );
95 $isSoftware = isset( $softwareDefinedTags[$tagName] );
96 $isExplicit = isset( $explicitlyDefinedTags[$tagName] );
99 $tag['defined'] = $isSoftware ||
$isExplicit;
105 // TODO: Can we change this to 'software'?
106 $tag['source'][] = 'extension';
109 $tag['source'][] = 'manual';
114 $tag['active'] = $isExplicit ||
isset( $softwareActivatedTags[$tagName] );
117 $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $tag );
119 $this->setContinueEnumParameter( 'continue', $tagName );
124 $result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'tag' );
127 public function getCacheMode( $params ) {
131 public function getAllowedParams() {
134 ApiBase
::PARAM_HELP_MSG
=> 'api-help-param-continue',
137 ApiBase
::PARAM_DFLT
=> 10,
138 ApiBase
::PARAM_TYPE
=> 'limit',
139 ApiBase
::PARAM_MIN
=> 1,
140 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
141 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
144 ApiBase
::PARAM_DFLT
=> 'name',
145 ApiBase
::PARAM_TYPE
=> [
154 ApiBase
::PARAM_ISMULTI
=> true,
155 ApiBase
::PARAM_HELP_MSG_PER_VALUE
=> [],
160 protected function getExamplesMessages() {
162 'action=query&list=tags&tgprop=displayname|description|hitcount|defined'
163 => 'apihelp-query+tags-example-simple',
167 public function getHelpUrls() {
168 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Tags';