4 * Created on Jul 9, 2009
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2009 Matthew Britton <firstname>.<lastname>@btinternet.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * Query module to enumerate change tags.
36 class ApiQueryTags
extends ApiQueryBase
{
38 private $limit, $result;
39 private $fld_displayname = false, $fld_description = false,
40 $fld_hitcount = false;
42 public function __construct($query, $moduleName) {
43 parent
:: __construct($query, $moduleName, 'tg');
46 public function execute() {
47 $params = $this->extractRequestParams();
49 $prop = array_flip($params['prop']);
51 $this->fld_displayname
= isset($prop['displayname']);
52 $this->fld_description
= isset($prop['description']);
53 $this->fld_hitcount
= isset($prop['hitcount']);
55 $this->limit
= $params['limit'];
56 $this->result
= $this->getResult();
58 $pageSet = $this->getPageSet();
59 $titles = $pageSet->getTitles();
63 if($this->fld_hitcount
) {
64 foreach( ChangeTags
::getHitCounts() as $tag => $count ) {
66 $ok = $this->doTag( $tag, $count );
69 foreach( ChangeTags
::listDefinedTags() as $tag ) {
71 $ok = $this->doTag( $tag, 0 );
75 $this->result
->setIndexedTagName_internal(array('query', $this->getModuleName()), 'tag');
78 private function doTag( $tagName, $hitcount ) {
80 static $doneTags = array();
82 if ( in_array( $tagName, $doneTags ) ) {
86 if(++
$count > $this->limit
)
88 $this->setContinueEnumParameter('continue', $tagName);
93 $tag['name'] = $tagName;
95 if($this->fld_displayname
)
96 $tag['displayname'] = ChangeTags
::tagDescription( $tagName );
98 if($this->fld_description
)
100 $msg = wfMsg( "tag-$tagName-description" );
101 $msg = wfEmptyMsg( "tag-$tagName-description", $msg ) ?
'' : $msg;
102 $tag['description'] = $msg;
105 if($this->fld_hitcount
)
106 $tag['hitcount'] = $hitcount;
108 $doneTags[] = $tagName;
110 $fit = $this->result
->addValue(array('query', $this->getModuleName()), null, $tag);
113 $this->setContinueEnumParameter('continue', $tagName);
120 public function getAllowedParams() {
127 ApiBase
:: PARAM_DFLT
=> 10,
128 ApiBase
:: PARAM_TYPE
=> 'limit',
129 ApiBase
:: PARAM_MIN
=> 1,
130 ApiBase
:: PARAM_MAX
=> ApiBase
:: LIMIT_BIG1
,
131 ApiBase
:: PARAM_MAX2
=> ApiBase
:: LIMIT_BIG2
134 ApiBase
:: PARAM_DFLT
=> 'name',
135 ApiBase
:: PARAM_TYPE
=> array(
141 ApiBase
:: PARAM_ISMULTI
=> true
146 public function getParamDescription() {
148 'continue' => 'When more results are available, use this to continue',
149 'limit' => 'The maximum number of tags to list',
150 'prop' => 'Which properties to get',
154 public function getDescription() {
155 return 'List change tags.';
158 protected function getExamples() {
160 'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
164 public function getVersion() {
165 return __CLASS__
. ': $Id$';