MediaWiki  1.23.14
ApiQueryTags.php
Go to the documentation of this file.
1 <?php
32 class ApiQueryTags extends ApiQueryBase {
33 
37  private $result;
38 
39  private $limit;
40  private $fld_displayname = false, $fld_description = false,
41  $fld_hitcount = false;
42 
43  public function __construct( $query, $moduleName ) {
44  parent::__construct( $query, $moduleName, 'tg' );
45  }
46 
47  public function execute() {
48  $params = $this->extractRequestParams();
49 
50  $prop = array_flip( $params['prop'] );
51 
52  $this->fld_displayname = isset( $prop['displayname'] );
53  $this->fld_description = isset( $prop['description'] );
54  $this->fld_hitcount = isset( $prop['hitcount'] );
55 
56  $this->limit = $params['limit'];
57  $this->result = $this->getResult();
58 
59  $this->addTables( 'change_tag' );
60  $this->addFields( 'ct_tag' );
61 
62  $this->addFieldsIf( array( 'hitcount' => 'COUNT(*)' ), $this->fld_hitcount );
63 
64  $this->addOption( 'LIMIT', $this->limit + 1 );
65  $this->addOption( 'GROUP BY', 'ct_tag' );
66  $this->addWhereRange( 'ct_tag', 'newer', $params['continue'], null );
67 
68  $res = $this->select( __METHOD__ );
69 
70  $ok = true;
71 
72  foreach ( $res as $row ) {
73  if ( !$ok ) {
74  break;
75  }
76  $ok = $this->doTag( $row->ct_tag, $this->fld_hitcount ? $row->hitcount : 0 );
77  }
78 
79  // include tags with no hits yet
80  foreach ( ChangeTags::listDefinedTags() as $tag ) {
81  if ( !$ok ) {
82  break;
83  }
84  $ok = $this->doTag( $tag, 0 );
85  }
86 
87  $this->result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'tag' );
88  }
89 
90  private function doTag( $tagName, $hitcount ) {
91  static $count = 0;
92  static $doneTags = array();
93 
94  if ( in_array( $tagName, $doneTags ) ) {
95  return true;
96  }
97 
98  if ( ++$count > $this->limit ) {
99  $this->setContinueEnumParameter( 'continue', $tagName );
100 
101  return false;
102  }
103 
104  $tag = array();
105  $tag['name'] = $tagName;
106 
107  if ( $this->fld_displayname ) {
108  $tag['displayname'] = ChangeTags::tagDescription( $tagName );
109  }
110 
111  if ( $this->fld_description ) {
112  $msg = wfMessage( "tag-$tagName-description" );
113  $tag['description'] = $msg->exists() ? $msg->text() : '';
114  }
115 
116  if ( $this->fld_hitcount ) {
117  $tag['hitcount'] = $hitcount;
118  }
119 
120  $doneTags[] = $tagName;
121 
122  $fit = $this->result->addValue( array( 'query', $this->getModuleName() ), null, $tag );
123  if ( !$fit ) {
124  $this->setContinueEnumParameter( 'continue', $tagName );
125 
126  return false;
127  }
128 
129  return true;
130  }
131 
132  public function getCacheMode( $params ) {
133  return 'public';
134  }
135 
136  public function getAllowedParams() {
137  return array(
138  'continue' => null,
139  'limit' => array(
140  ApiBase::PARAM_DFLT => 10,
141  ApiBase::PARAM_TYPE => 'limit',
142  ApiBase::PARAM_MIN => 1,
145  ),
146  'prop' => array(
147  ApiBase::PARAM_DFLT => 'name',
149  'name',
150  'displayname',
151  'description',
152  'hitcount'
153  ),
154  ApiBase::PARAM_ISMULTI => true
155  )
156  );
157  }
158 
159  public function getParamDescription() {
160  return array(
161  'continue' => 'When more results are available, use this to continue',
162  'limit' => 'The maximum number of tags to list',
163  'prop' => array(
164  'Which properties to get',
165  ' name - Adds name of tag',
166  ' displayname - Adds system message for the tag',
167  ' description - Adds description of the tag',
168  ' hitcount - Adds the amount of revisions that have this tag',
169  ),
170  );
171  }
172 
173  public function getResultProperties() {
174  return array(
175  '' => array(
176  'name' => 'string'
177  ),
178  'displayname' => array(
179  'displayname' => 'string'
180  ),
181  'description' => array(
182  'description' => 'string'
183  ),
184  'hitcount' => array(
185  'hitcount' => 'integer'
186  )
187  );
188  }
189 
190  public function getDescription() {
191  return 'List change tags.';
192  }
193 
194  public function getExamples() {
195  return array(
196  'api.php?action=query&list=tags&tgprop=displayname|description|hitcount'
197  );
198  }
199 
200  public function getHelpUrls() {
201  return 'https://www.mediawiki.org/wiki/API:Tags';
202  }
203 }
ApiQueryTags\$result
ApiResult $result
Definition: ApiQueryTags.php:36
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:117
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
ApiQueryBase\select
select( $method, $extraQuery=array())
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:274
ChangeTags\tagDescription
static tagDescription( $tag)
Get a short description for a tag.
Definition: ChangeTags.php:71
$params
$params
Definition: styleTest.css.php:40
ApiQueryTags
Query module to enumerate change tags.
Definition: ApiQueryTags.php:32
ApiQueryTags\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryTags.php:131
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:252
ApiQueryTags\__construct
__construct( $query, $moduleName)
Definition: ApiQueryTags.php:42
ApiQueryTags\$fld_hitcount
$fld_hitcount
Definition: ApiQueryTags.php:40
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:131
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:56
ApiQueryTags\$fld_displayname
$fld_displayname
Definition: ApiQueryTags.php:39
ApiResult
This class represents the result of the API operations.
Definition: ApiResult.php:44
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Definition: ApiBase.php:78
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
ApiBase\PARAM_MAX
const PARAM_MAX
Definition: ApiBase.php:52
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:82
ChangeTags\listDefinedTags
static listDefinedTags()
Basically lists defined tags which count even if they aren't applied to anything.
Definition: ChangeTags.php:302
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiQueryTags\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiQueryTags.php:193
ApiQueryBase\addWhereRange
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
Definition: ApiQueryBase.php:205
ApiQueryTags\doTag
doTag( $tagName, $hitcount)
Definition: ApiQueryTags.php:89
$ok
$ok
Definition: UtfNormalTest.php:71
ApiQueryTags\$limit
$limit
Definition: ApiQueryTags.php:38
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:707
ApiQueryTags\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiQueryTags.php:189
$count
$count
Definition: UtfNormalTest2.php:96
ApiQueryTags\$fld_description
$fld_description
Definition: ApiQueryTags.php:39
ApiQueryTags\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiQueryTags.php:172
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Definition: ApiBase.php:79
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiQueryTags\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryTags.php:135
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiBase\PARAM_MAX2
const PARAM_MAX2
Definition: ApiBase.php:54
ApiQueryTags\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiQueryTags.php:158
ApiQueryTags\getHelpUrls
getHelpUrls()
Definition: ApiQueryTags.php:199
ApiQueryTags\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryTags.php:46
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:404
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
$res
$res
Definition: database.txt:21