Remove full form of ChangeTags::buildTagFilterSelector
[lhc/web/wiklou.git] / includes / changetags / ChangeTags.php
1 <?php
2 /**
3 * Recent changes tagging.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Change tagging
22 */
23
24 class ChangeTags {
25 /**
26 * Can't delete tags with more than this many uses. Similar in intent to
27 * the bigdelete user right
28 * @todo Use the job queue for tag deletion to avoid this restriction
29 */
30 const MAX_DELETE_USES = 5000;
31
32 /**
33 * @var string[]
34 */
35 private static $coreTags = [ 'mw-contentmodelchange' ];
36
37 /**
38 * Creates HTML for the given tags
39 *
40 * @param string $tags Comma-separated list of tags
41 * @param string $page A label for the type of action which is being displayed,
42 * for example: 'history', 'contributions' or 'newpages'
43 * @param IContextSource|null $context
44 * @note Even though it takes null as a valid argument, an IContextSource is preferred
45 * in a new code, as the null value is subject to change in the future
46 * @return array Array with two items: (html, classes)
47 * - html: String: HTML for displaying the tags (empty string when param $tags is empty)
48 * - classes: Array of strings: CSS classes used in the generated html, one class for each tag
49 */
50 public static function formatSummaryRow( $tags, $page, IContextSource $context = null ) {
51 if ( !$tags ) {
52 return [ '', [] ];
53 }
54 if ( !$context ) {
55 $context = RequestContext::getMain();
56 }
57
58 $classes = [];
59
60 $tags = explode( ',', $tags );
61 $displayTags = [];
62 foreach ( $tags as $tag ) {
63 if ( !$tag ) {
64 continue;
65 }
66 $description = self::tagDescription( $tag );
67 if ( $description === false ) {
68 continue;
69 }
70 $displayTags[] = Xml::tags(
71 'span',
72 [ 'class' => 'mw-tag-marker ' .
73 Sanitizer::escapeClass( "mw-tag-marker-$tag" ) ],
74 $description
75 );
76 $classes[] = Sanitizer::escapeClass( "mw-tag-$tag" );
77 }
78
79 if ( !$displayTags ) {
80 return [ '', [] ];
81 }
82
83 $markers = $context->msg( 'tag-list-wrapper' )
84 ->numParams( count( $displayTags ) )
85 ->rawParams( $context->getLanguage()->commaList( $displayTags ) )
86 ->parse();
87 $markers = Xml::tags( 'span', [ 'class' => 'mw-tag-markers' ], $markers );
88
89 return [ $markers, $classes ];
90 }
91
92 /**
93 * Get a short description for a tag.
94 *
95 * Checks if message key "mediawiki:tag-$tag" exists. If it does not,
96 * returns the HTML-escaped tag name. Uses the message if the message
97 * exists, provided it is not disabled. If the message is disabled,
98 * we consider the tag hidden, and return false.
99 *
100 * @param string $tag Tag
101 * @return string|bool Tag description or false if tag is to be hidden.
102 * @since 1.25 Returns false if tag is to be hidden.
103 */
104 public static function tagDescription( $tag ) {
105 $msg = wfMessage( "tag-$tag" );
106 if ( !$msg->exists() ) {
107 // No such message, so return the HTML-escaped tag name.
108 return htmlspecialchars( $tag );
109 }
110 if ( $msg->isDisabled() ) {
111 // The message exists but is disabled, hide the tag.
112 return false;
113 }
114
115 // Message exists and isn't disabled, use it.
116 return $msg->parse();
117 }
118
119 /**
120 * Add tags to a change given its rc_id, rev_id and/or log_id
121 *
122 * @param string|string[] $tags Tags to add to the change
123 * @param int|null $rc_id The rc_id of the change to add the tags to
124 * @param int|null $rev_id The rev_id of the change to add the tags to
125 * @param int|null $log_id The log_id of the change to add the tags to
126 * @param string $params Params to put in the ct_params field of table 'change_tag'
127 *
128 * @throws MWException
129 * @return bool False if no changes are made, otherwise true
130 */
131 public static function addTags( $tags, $rc_id = null, $rev_id = null,
132 $log_id = null, $params = null
133 ) {
134 $result = self::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params );
135 return (bool)$result[0];
136 }
137
138 /**
139 * Add and remove tags to/from a change given its rc_id, rev_id and/or log_id,
140 * without verifying that the tags exist or are valid. If a tag is present in
141 * both $tagsToAdd and $tagsToRemove, it will be removed.
142 *
143 * This function should only be used by extensions to manipulate tags they
144 * have registered using the ListDefinedTags hook. When dealing with user
145 * input, call updateTagsWithChecks() instead.
146 *
147 * @param string|array|null $tagsToAdd Tags to add to the change
148 * @param string|array|null $tagsToRemove Tags to remove from the change
149 * @param int|null &$rc_id The rc_id of the change to add the tags to.
150 * Pass a variable whose value is null if the rc_id is not relevant or unknown.
151 * @param int|null &$rev_id The rev_id of the change to add the tags to.
152 * Pass a variable whose value is null if the rev_id is not relevant or unknown.
153 * @param int|null &$log_id The log_id of the change to add the tags to.
154 * Pass a variable whose value is null if the log_id is not relevant or unknown.
155 * @param string $params Params to put in the ct_params field of table
156 * 'change_tag' when adding tags
157 *
158 * @throws MWException When $rc_id, $rev_id and $log_id are all null
159 * @return array Index 0 is an array of tags actually added, index 1 is an
160 * array of tags actually removed, index 2 is an array of tags present on the
161 * revision or log entry before any changes were made
162 *
163 * @since 1.25
164 */
165 public static function updateTags(
166 $tagsToAdd, $tagsToRemove,
167 &$rc_id = null, &$rev_id = null, &$log_id = null, $params = null
168 ) {
169
170 $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags...
171 $tagsToRemove = array_filter( (array)$tagsToRemove );
172
173 if ( !$rc_id && !$rev_id && !$log_id ) {
174 throw new MWException( 'At least one of: RCID, revision ID, and log ID MUST be ' .
175 'specified when adding or removing a tag from a change!' );
176 }
177
178 $dbw = wfGetDB( DB_MASTER );
179
180 // Might as well look for rcids and so on.
181 if ( !$rc_id ) {
182 // Info might be out of date, somewhat fractionally, on replica DB.
183 // LogEntry/LogPage and WikiPage match rev/log/rc timestamps,
184 // so use that relation to avoid full table scans.
185 if ( $log_id ) {
186 $rc_id = $dbw->selectField(
187 [ 'logging', 'recentchanges' ],
188 'rc_id',
189 [
190 'log_id' => $log_id,
191 'rc_timestamp = log_timestamp',
192 'rc_logid = log_id'
193 ],
194 __METHOD__
195 );
196 } elseif ( $rev_id ) {
197 $rc_id = $dbw->selectField(
198 [ 'revision', 'recentchanges' ],
199 'rc_id',
200 [
201 'rev_id' => $rev_id,
202 'rc_timestamp = rev_timestamp',
203 'rc_this_oldid = rev_id'
204 ],
205 __METHOD__
206 );
207 }
208 } elseif ( !$log_id && !$rev_id ) {
209 // Info might be out of date, somewhat fractionally, on replica DB.
210 $log_id = $dbw->selectField(
211 'recentchanges',
212 'rc_logid',
213 [ 'rc_id' => $rc_id ],
214 __METHOD__
215 );
216 $rev_id = $dbw->selectField(
217 'recentchanges',
218 'rc_this_oldid',
219 [ 'rc_id' => $rc_id ],
220 __METHOD__
221 );
222 }
223
224 if ( $log_id && !$rev_id ) {
225 $rev_id = $dbw->selectField(
226 'log_search',
227 'ls_value',
228 [ 'ls_field' => 'associated_rev_id', 'ls_log_id' => $log_id ],
229 __METHOD__
230 );
231 } elseif ( !$log_id && $rev_id ) {
232 $log_id = $dbw->selectField(
233 'log_search',
234 'ls_log_id',
235 [ 'ls_field' => 'associated_rev_id', 'ls_value' => $rev_id ],
236 __METHOD__
237 );
238 }
239
240 // update the tag_summary row
241 $prevTags = [];
242 if ( !self::updateTagSummaryRow( $tagsToAdd, $tagsToRemove, $rc_id, $rev_id,
243 $log_id, $prevTags ) ) {
244
245 // nothing to do
246 return [ [], [], $prevTags ];
247 }
248
249 // insert a row into change_tag for each new tag
250 if ( count( $tagsToAdd ) ) {
251 $tagsRows = [];
252 foreach ( $tagsToAdd as $tag ) {
253 // Filter so we don't insert NULLs as zero accidentally.
254 // Keep in mind that $rc_id === null means "I don't care/know about the
255 // rc_id, just delete $tag on this revision/log entry". It doesn't
256 // mean "only delete tags on this revision/log WHERE rc_id IS NULL".
257 $tagsRows[] = array_filter(
258 [
259 'ct_tag' => $tag,
260 'ct_rc_id' => $rc_id,
261 'ct_log_id' => $log_id,
262 'ct_rev_id' => $rev_id,
263 'ct_params' => $params
264 ]
265 );
266 }
267
268 $dbw->insert( 'change_tag', $tagsRows, __METHOD__, [ 'IGNORE' ] );
269 }
270
271 // delete from change_tag
272 if ( count( $tagsToRemove ) ) {
273 foreach ( $tagsToRemove as $tag ) {
274 $conds = array_filter(
275 [
276 'ct_tag' => $tag,
277 'ct_rc_id' => $rc_id,
278 'ct_log_id' => $log_id,
279 'ct_rev_id' => $rev_id
280 ]
281 );
282 $dbw->delete( 'change_tag', $conds, __METHOD__ );
283 }
284 }
285
286 self::purgeTagUsageCache();
287 return [ $tagsToAdd, $tagsToRemove, $prevTags ];
288 }
289
290 /**
291 * Adds or removes a given set of tags to/from the relevant row of the
292 * tag_summary table. Modifies the tagsToAdd and tagsToRemove arrays to
293 * reflect the tags that were actually added and/or removed.
294 *
295 * @param array &$tagsToAdd
296 * @param array &$tagsToRemove If a tag is present in both $tagsToAdd and
297 * $tagsToRemove, it will be removed
298 * @param int|null $rc_id Null if not known or not applicable
299 * @param int|null $rev_id Null if not known or not applicable
300 * @param int|null $log_id Null if not known or not applicable
301 * @param array &$prevTags Optionally outputs a list of the tags that were
302 * in the tag_summary row to begin with
303 * @return bool True if any modifications were made, otherwise false
304 * @since 1.25
305 */
306 protected static function updateTagSummaryRow( &$tagsToAdd, &$tagsToRemove,
307 $rc_id, $rev_id, $log_id, &$prevTags = [] ) {
308
309 $dbw = wfGetDB( DB_MASTER );
310
311 $tsConds = array_filter( [
312 'ts_rc_id' => $rc_id,
313 'ts_rev_id' => $rev_id,
314 'ts_log_id' => $log_id
315 ] );
316
317 // Can't both add and remove a tag at the same time...
318 $tagsToAdd = array_diff( $tagsToAdd, $tagsToRemove );
319
320 // Update the summary row.
321 // $prevTags can be out of date on replica DBs, especially when addTags is called consecutively,
322 // causing loss of tags added recently in tag_summary table.
323 $prevTags = $dbw->selectField( 'tag_summary', 'ts_tags', $tsConds, __METHOD__ );
324 $prevTags = $prevTags ? $prevTags : '';
325 $prevTags = array_filter( explode( ',', $prevTags ) );
326
327 // add tags
328 $tagsToAdd = array_values( array_diff( $tagsToAdd, $prevTags ) );
329 $newTags = array_unique( array_merge( $prevTags, $tagsToAdd ) );
330
331 // remove tags
332 $tagsToRemove = array_values( array_intersect( $tagsToRemove, $newTags ) );
333 $newTags = array_values( array_diff( $newTags, $tagsToRemove ) );
334
335 sort( $prevTags );
336 sort( $newTags );
337 if ( $prevTags == $newTags ) {
338 // No change.
339 return false;
340 }
341
342 if ( !$newTags ) {
343 // no tags left, so delete the row altogether
344 $dbw->delete( 'tag_summary', $tsConds, __METHOD__ );
345 } else {
346 $dbw->replace( 'tag_summary',
347 [ 'ts_rev_id', 'ts_rc_id', 'ts_log_id' ],
348 array_filter( array_merge( $tsConds, [ 'ts_tags' => implode( ',', $newTags ) ] ) ),
349 __METHOD__
350 );
351 }
352
353 return true;
354 }
355
356 /**
357 * Helper function to generate a fatal status with a 'not-allowed' type error.
358 *
359 * @param string $msgOne Message key to use in the case of one tag
360 * @param string $msgMulti Message key to use in the case of more than one tag
361 * @param array $tags Restricted tags (passed as $1 into the message, count of
362 * $tags passed as $2)
363 * @return Status
364 * @since 1.25
365 */
366 protected static function restrictedTagError( $msgOne, $msgMulti, $tags ) {
367 $lang = RequestContext::getMain()->getLanguage();
368 $count = count( $tags );
369 return Status::newFatal( ( $count > 1 ) ? $msgMulti : $msgOne,
370 $lang->commaList( $tags ), $count );
371 }
372
373 /**
374 * Is it OK to allow the user to apply all the specified tags at the same time
375 * as they edit/make the change?
376 *
377 * @param array $tags Tags that you are interested in applying
378 * @param User|null $user User whose permission you wish to check, or null if
379 * you don't care (e.g. maintenance scripts)
380 * @return Status
381 * @since 1.25
382 */
383 public static function canAddTagsAccompanyingChange( array $tags,
384 User $user = null ) {
385
386 if ( !is_null( $user ) ) {
387 if ( !$user->isAllowed( 'applychangetags' ) ) {
388 return Status::newFatal( 'tags-apply-no-permission' );
389 } elseif ( $user->isBlocked() ) {
390 return Status::newFatal( 'tags-apply-blocked' );
391 }
392 }
393
394 // to be applied, a tag has to be explicitly defined
395 // @todo Allow extensions to define tags that can be applied by users...
396 $allowedTags = self::listExplicitlyDefinedTags();
397 $disallowedTags = array_diff( $tags, $allowedTags );
398 if ( $disallowedTags ) {
399 return self::restrictedTagError( 'tags-apply-not-allowed-one',
400 'tags-apply-not-allowed-multi', $disallowedTags );
401 }
402
403 return Status::newGood();
404 }
405
406 /**
407 * Adds tags to a given change, checking whether it is allowed first, but
408 * without adding a log entry. Useful for cases where the tag is being added
409 * along with the action that generated the change (e.g. tagging an edit as
410 * it is being made).
411 *
412 * Extensions should not use this function, unless directly handling a user
413 * request to add a particular tag. Normally, extensions should call
414 * ChangeTags::updateTags() instead.
415 *
416 * @param array $tags Tags to apply
417 * @param int|null $rc_id The rc_id of the change to add the tags to
418 * @param int|null $rev_id The rev_id of the change to add the tags to
419 * @param int|null $log_id The log_id of the change to add the tags to
420 * @param string $params Params to put in the ct_params field of table
421 * 'change_tag' when adding tags
422 * @param User $user Who to give credit for the action
423 * @return Status
424 * @since 1.25
425 */
426 public static function addTagsAccompanyingChangeWithChecks(
427 array $tags, $rc_id, $rev_id, $log_id, $params, User $user
428 ) {
429
430 // are we allowed to do this?
431 $result = self::canAddTagsAccompanyingChange( $tags, $user );
432 if ( !$result->isOK() ) {
433 $result->value = null;
434 return $result;
435 }
436
437 // do it!
438 self::addTags( $tags, $rc_id, $rev_id, $log_id, $params );
439
440 return Status::newGood( true );
441 }
442
443 /**
444 * Is it OK to allow the user to adds and remove the given tags tags to/from a
445 * change?
446 *
447 * @param array $tagsToAdd Tags that you are interested in adding
448 * @param array $tagsToRemove Tags that you are interested in removing
449 * @param User|null $user User whose permission you wish to check, or null if
450 * you don't care (e.g. maintenance scripts)
451 * @return Status
452 * @since 1.25
453 */
454 public static function canUpdateTags( array $tagsToAdd, array $tagsToRemove,
455 User $user = null ) {
456
457 if ( !is_null( $user ) ) {
458 if ( !$user->isAllowed( 'changetags' ) ) {
459 return Status::newFatal( 'tags-update-no-permission' );
460 } elseif ( $user->isBlocked() ) {
461 return Status::newFatal( 'tags-update-blocked' );
462 }
463 }
464
465 if ( $tagsToAdd ) {
466 // to be added, a tag has to be explicitly defined
467 // @todo Allow extensions to define tags that can be applied by users...
468 $explicitlyDefinedTags = self::listExplicitlyDefinedTags();
469 $diff = array_diff( $tagsToAdd, $explicitlyDefinedTags );
470 if ( $diff ) {
471 return self::restrictedTagError( 'tags-update-add-not-allowed-one',
472 'tags-update-add-not-allowed-multi', $diff );
473 }
474 }
475
476 if ( $tagsToRemove ) {
477 // to be removed, a tag must not be defined by an extension, or equivalently it
478 // has to be either explicitly defined or not defined at all
479 // (assuming no edge case of a tag both explicitly-defined and extension-defined)
480 $softwareDefinedTags = self::listSoftwareDefinedTags();
481 $intersect = array_intersect( $tagsToRemove, $softwareDefinedTags );
482 if ( $intersect ) {
483 return self::restrictedTagError( 'tags-update-remove-not-allowed-one',
484 'tags-update-remove-not-allowed-multi', $intersect );
485 }
486 }
487
488 return Status::newGood();
489 }
490
491 /**
492 * Adds and/or removes tags to/from a given change, checking whether it is
493 * allowed first, and adding a log entry afterwards.
494 *
495 * Includes a call to ChangeTag::canUpdateTags(), so your code doesn't need
496 * to do that. However, it doesn't check whether the *_id parameters are a
497 * valid combination. That is up to you to enforce. See ApiTag::execute() for
498 * an example.
499 *
500 * @param array|null $tagsToAdd If none, pass array() or null
501 * @param array|null $tagsToRemove If none, pass array() or null
502 * @param int|null $rc_id The rc_id of the change to add the tags to
503 * @param int|null $rev_id The rev_id of the change to add the tags to
504 * @param int|null $log_id The log_id of the change to add the tags to
505 * @param string $params Params to put in the ct_params field of table
506 * 'change_tag' when adding tags
507 * @param string $reason Comment for the log
508 * @param User $user Who to give credit for the action
509 * @return Status If successful, the value of this Status object will be an
510 * object (stdClass) with the following fields:
511 * - logId: the ID of the added log entry, or null if no log entry was added
512 * (i.e. no operation was performed)
513 * - addedTags: an array containing the tags that were actually added
514 * - removedTags: an array containing the tags that were actually removed
515 * @since 1.25
516 */
517 public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
518 $rc_id, $rev_id, $log_id, $params, $reason, User $user ) {
519
520 if ( is_null( $tagsToAdd ) ) {
521 $tagsToAdd = [];
522 }
523 if ( is_null( $tagsToRemove ) ) {
524 $tagsToRemove = [];
525 }
526 if ( !$tagsToAdd && !$tagsToRemove ) {
527 // no-op, don't bother
528 return Status::newGood( (object)[
529 'logId' => null,
530 'addedTags' => [],
531 'removedTags' => [],
532 ] );
533 }
534
535 // are we allowed to do this?
536 $result = self::canUpdateTags( $tagsToAdd, $tagsToRemove, $user );
537 if ( !$result->isOK() ) {
538 $result->value = null;
539 return $result;
540 }
541
542 // basic rate limiting
543 if ( $user->pingLimiter( 'changetag' ) ) {
544 return Status::newFatal( 'actionthrottledtext' );
545 }
546
547 // do it!
548 list( $tagsAdded, $tagsRemoved, $initialTags ) = self::updateTags( $tagsToAdd,
549 $tagsToRemove, $rc_id, $rev_id, $log_id, $params );
550 if ( !$tagsAdded && !$tagsRemoved ) {
551 // no-op, don't log it
552 return Status::newGood( (object)[
553 'logId' => null,
554 'addedTags' => [],
555 'removedTags' => [],
556 ] );
557 }
558
559 // log it
560 $logEntry = new ManualLogEntry( 'tag', 'update' );
561 $logEntry->setPerformer( $user );
562 $logEntry->setComment( $reason );
563
564 // find the appropriate target page
565 if ( $rev_id ) {
566 $rev = Revision::newFromId( $rev_id );
567 if ( $rev ) {
568 $logEntry->setTarget( $rev->getTitle() );
569 }
570 } elseif ( $log_id ) {
571 // This function is from revision deletion logic and has nothing to do with
572 // change tags, but it appears to be the only other place in core where we
573 // perform logged actions on log items.
574 $logEntry->setTarget( RevDelLogList::suggestTarget( null, [ $log_id ] ) );
575 }
576
577 if ( !$logEntry->getTarget() ) {
578 // target is required, so we have to set something
579 $logEntry->setTarget( SpecialPage::getTitleFor( 'Tags' ) );
580 }
581
582 $logParams = [
583 '4::revid' => $rev_id,
584 '5::logid' => $log_id,
585 '6:list:tagsAdded' => $tagsAdded,
586 '7:number:tagsAddedCount' => count( $tagsAdded ),
587 '8:list:tagsRemoved' => $tagsRemoved,
588 '9:number:tagsRemovedCount' => count( $tagsRemoved ),
589 'initialTags' => $initialTags,
590 ];
591 $logEntry->setParameters( $logParams );
592 $logEntry->setRelations( [ 'Tag' => array_merge( $tagsAdded, $tagsRemoved ) ] );
593
594 $dbw = wfGetDB( DB_MASTER );
595 $logId = $logEntry->insert( $dbw );
596 // Only send this to UDP, not RC, similar to patrol events
597 $logEntry->publish( $logId, 'udp' );
598
599 return Status::newGood( (object)[
600 'logId' => $logId,
601 'addedTags' => $tagsAdded,
602 'removedTags' => $tagsRemoved,
603 ] );
604 }
605
606 /**
607 * Applies all tags-related changes to a query.
608 * Handles selecting tags, and filtering.
609 * Needs $tables to be set up properly, so we can figure out which join conditions to use.
610 *
611 * @param string|array $tables Table names, see DatabaseBase::select
612 * @param string|array $fields Fields used in query, see DatabaseBase::select
613 * @param string|array $conds Conditions used in query, see DatabaseBase::select
614 * @param array $join_conds Join conditions, see DatabaseBase::select
615 * @param array $options Options, see Database::select
616 * @param bool|string $filter_tag Tag to select on
617 *
618 * @throws MWException When unable to determine appropriate JOIN condition for tagging
619 */
620 public static function modifyDisplayQuery( &$tables, &$fields, &$conds,
621 &$join_conds, &$options, $filter_tag = false ) {
622 global $wgRequest, $wgUseTagFilter;
623
624 if ( $filter_tag === false ) {
625 $filter_tag = $wgRequest->getVal( 'tagfilter' );
626 }
627
628 // Figure out which conditions can be done.
629 if ( in_array( 'recentchanges', $tables ) ) {
630 $join_cond = 'ct_rc_id=rc_id';
631 } elseif ( in_array( 'logging', $tables ) ) {
632 $join_cond = 'ct_log_id=log_id';
633 } elseif ( in_array( 'revision', $tables ) ) {
634 $join_cond = 'ct_rev_id=rev_id';
635 } elseif ( in_array( 'archive', $tables ) ) {
636 $join_cond = 'ct_rev_id=ar_rev_id';
637 } else {
638 throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' );
639 }
640
641 $fields['ts_tags'] = wfGetDB( DB_REPLICA )->buildGroupConcatField(
642 ',', 'change_tag', 'ct_tag', $join_cond
643 );
644
645 if ( $wgUseTagFilter && $filter_tag ) {
646 // Somebody wants to filter on a tag.
647 // Add an INNER JOIN on change_tag
648
649 $tables[] = 'change_tag';
650 $join_conds['change_tag'] = [ 'INNER JOIN', $join_cond ];
651 $conds['ct_tag'] = $filter_tag;
652 }
653 }
654
655 /**
656 * Build a text box to select a change tag
657 *
658 * @param string $selected Tag to select by default
659 * @param bool $ooui Use an OOUI TextInputWidget as selector instead of a non-OOUI input field
660 * You need to call OutputPage::enableOOUI() yourself.
661 * @return array an array of (label, selector)
662 */
663 public static function buildTagFilterSelector( $selected = '', $ooui = false ) {
664 global $wgUseTagFilter;
665
666 if ( !$wgUseTagFilter || !count( self::listDefinedTags() ) ) {
667 return [];
668 }
669
670 $data = [
671 Html::rawElement(
672 'label',
673 [ 'for' => 'tagfilter' ],
674 wfMessage( 'tag-filter' )->parse()
675 )
676 ];
677
678 if ( $ooui ) {
679 $data[] = new OOUI\TextInputWidget( [
680 'id' => 'tagfilter',
681 'name' => 'tagfilter',
682 'value' => $selected,
683 'classes' => 'mw-tagfilter-input',
684 ] );
685 } else {
686 $data[] = Xml::input(
687 'tagfilter',
688 20,
689 $selected,
690 [ 'class' => 'mw-tagfilter-input mw-ui-input mw-ui-input-inline', 'id' => 'tagfilter' ]
691 );
692 }
693
694 return $data;
695 }
696
697 /**
698 * Defines a tag in the valid_tag table, without checking that the tag name
699 * is valid.
700 * Extensions should NOT use this function; they can use the ListDefinedTags
701 * hook instead.
702 *
703 * @param string $tag Tag to create
704 * @since 1.25
705 */
706 public static function defineTag( $tag ) {
707 $dbw = wfGetDB( DB_MASTER );
708 $dbw->replace( 'valid_tag',
709 [ 'vt_tag' ],
710 [ 'vt_tag' => $tag ],
711 __METHOD__ );
712
713 // clear the memcache of defined tags
714 self::purgeTagCacheAll();
715 }
716
717 /**
718 * Removes a tag from the valid_tag table. The tag may remain in use by
719 * extensions, and may still show up as 'defined' if an extension is setting
720 * it from the ListDefinedTags hook.
721 *
722 * @param string $tag Tag to remove
723 * @since 1.25
724 */
725 public static function undefineTag( $tag ) {
726 $dbw = wfGetDB( DB_MASTER );
727 $dbw->delete( 'valid_tag', [ 'vt_tag' => $tag ], __METHOD__ );
728
729 // clear the memcache of defined tags
730 self::purgeTagCacheAll();
731 }
732
733 /**
734 * Writes a tag action into the tag management log.
735 *
736 * @param string $action
737 * @param string $tag
738 * @param string $reason
739 * @param User $user Who to attribute the action to
740 * @param int $tagCount For deletion only, how many usages the tag had before
741 * it was deleted.
742 * @return int ID of the inserted log entry
743 * @since 1.25
744 */
745 protected static function logTagManagementAction( $action, $tag, $reason,
746 User $user, $tagCount = null ) {
747
748 $dbw = wfGetDB( DB_MASTER );
749
750 $logEntry = new ManualLogEntry( 'managetags', $action );
751 $logEntry->setPerformer( $user );
752 // target page is not relevant, but it has to be set, so we just put in
753 // the title of Special:Tags
754 $logEntry->setTarget( Title::newFromText( 'Special:Tags' ) );
755 $logEntry->setComment( $reason );
756
757 $params = [ '4::tag' => $tag ];
758 if ( !is_null( $tagCount ) ) {
759 $params['5:number:count'] = $tagCount;
760 }
761 $logEntry->setParameters( $params );
762 $logEntry->setRelations( [ 'Tag' => $tag ] );
763
764 $logId = $logEntry->insert( $dbw );
765 $logEntry->publish( $logId );
766 return $logId;
767 }
768
769 /**
770 * Is it OK to allow the user to activate this tag?
771 *
772 * @param string $tag Tag that you are interested in activating
773 * @param User|null $user User whose permission you wish to check, or null if
774 * you don't care (e.g. maintenance scripts)
775 * @return Status
776 * @since 1.25
777 */
778 public static function canActivateTag( $tag, User $user = null ) {
779 if ( !is_null( $user ) ) {
780 if ( !$user->isAllowed( 'managechangetags' ) ) {
781 return Status::newFatal( 'tags-manage-no-permission' );
782 } elseif ( $user->isBlocked() ) {
783 return Status::newFatal( 'tags-manage-blocked' );
784 }
785 }
786
787 // defined tags cannot be activated (a defined tag is either extension-
788 // defined, in which case the extension chooses whether or not to active it;
789 // or user-defined, in which case it is considered active)
790 $definedTags = self::listDefinedTags();
791 if ( in_array( $tag, $definedTags ) ) {
792 return Status::newFatal( 'tags-activate-not-allowed', $tag );
793 }
794
795 // non-existing tags cannot be activated
796 $tagUsage = self::tagUsageStatistics();
797 if ( !isset( $tagUsage[$tag] ) ) { // we already know the tag is undefined
798 return Status::newFatal( 'tags-activate-not-found', $tag );
799 }
800
801 return Status::newGood();
802 }
803
804 /**
805 * Activates a tag, checking whether it is allowed first, and adding a log
806 * entry afterwards.
807 *
808 * Includes a call to ChangeTag::canActivateTag(), so your code doesn't need
809 * to do that.
810 *
811 * @param string $tag
812 * @param string $reason
813 * @param User $user Who to give credit for the action
814 * @param bool $ignoreWarnings Can be used for API interaction, default false
815 * @return Status If successful, the Status contains the ID of the added log
816 * entry as its value
817 * @since 1.25
818 */
819 public static function activateTagWithChecks( $tag, $reason, User $user,
820 $ignoreWarnings = false ) {
821
822 // are we allowed to do this?
823 $result = self::canActivateTag( $tag, $user );
824 if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
825 $result->value = null;
826 return $result;
827 }
828
829 // do it!
830 self::defineTag( $tag );
831
832 // log it
833 $logId = self::logTagManagementAction( 'activate', $tag, $reason, $user );
834 return Status::newGood( $logId );
835 }
836
837 /**
838 * Is it OK to allow the user to deactivate this tag?
839 *
840 * @param string $tag Tag that you are interested in deactivating
841 * @param User|null $user User whose permission you wish to check, or null if
842 * you don't care (e.g. maintenance scripts)
843 * @return Status
844 * @since 1.25
845 */
846 public static function canDeactivateTag( $tag, User $user = null ) {
847 if ( !is_null( $user ) ) {
848 if ( !$user->isAllowed( 'managechangetags' ) ) {
849 return Status::newFatal( 'tags-manage-no-permission' );
850 } elseif ( $user->isBlocked() ) {
851 return Status::newFatal( 'tags-manage-blocked' );
852 }
853 }
854
855 // only explicitly-defined tags can be deactivated
856 $explicitlyDefinedTags = self::listExplicitlyDefinedTags();
857 if ( !in_array( $tag, $explicitlyDefinedTags ) ) {
858 return Status::newFatal( 'tags-deactivate-not-allowed', $tag );
859 }
860 return Status::newGood();
861 }
862
863 /**
864 * Deactivates a tag, checking whether it is allowed first, and adding a log
865 * entry afterwards.
866 *
867 * Includes a call to ChangeTag::canDeactivateTag(), so your code doesn't need
868 * to do that.
869 *
870 * @param string $tag
871 * @param string $reason
872 * @param User $user Who to give credit for the action
873 * @param bool $ignoreWarnings Can be used for API interaction, default false
874 * @return Status If successful, the Status contains the ID of the added log
875 * entry as its value
876 * @since 1.25
877 */
878 public static function deactivateTagWithChecks( $tag, $reason, User $user,
879 $ignoreWarnings = false ) {
880
881 // are we allowed to do this?
882 $result = self::canDeactivateTag( $tag, $user );
883 if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
884 $result->value = null;
885 return $result;
886 }
887
888 // do it!
889 self::undefineTag( $tag );
890
891 // log it
892 $logId = self::logTagManagementAction( 'deactivate', $tag, $reason, $user );
893 return Status::newGood( $logId );
894 }
895
896 /**
897 * Is it OK to allow the user to create this tag?
898 *
899 * @param string $tag Tag that you are interested in creating
900 * @param User|null $user User whose permission you wish to check, or null if
901 * you don't care (e.g. maintenance scripts)
902 * @return Status
903 * @since 1.25
904 */
905 public static function canCreateTag( $tag, User $user = null ) {
906 if ( !is_null( $user ) ) {
907 if ( !$user->isAllowed( 'managechangetags' ) ) {
908 return Status::newFatal( 'tags-manage-no-permission' );
909 } elseif ( $user->isBlocked() ) {
910 return Status::newFatal( 'tags-manage-blocked' );
911 }
912 }
913
914 // no empty tags
915 if ( $tag === '' ) {
916 return Status::newFatal( 'tags-create-no-name' );
917 }
918
919 // tags cannot contain commas (used as a delimiter in tag_summary table) or
920 // slashes (would break tag description messages in MediaWiki namespace)
921 if ( strpos( $tag, ',' ) !== false || strpos( $tag, '/' ) !== false ) {
922 return Status::newFatal( 'tags-create-invalid-chars' );
923 }
924
925 // could the MediaWiki namespace description messages be created?
926 $title = Title::makeTitleSafe( NS_MEDIAWIKI, "Tag-$tag-description" );
927 if ( is_null( $title ) ) {
928 return Status::newFatal( 'tags-create-invalid-title-chars' );
929 }
930
931 // does the tag already exist?
932 $tagUsage = self::tagUsageStatistics();
933 if ( isset( $tagUsage[$tag] ) || in_array( $tag, self::listDefinedTags() ) ) {
934 return Status::newFatal( 'tags-create-already-exists', $tag );
935 }
936
937 // check with hooks
938 $canCreateResult = Status::newGood();
939 Hooks::run( 'ChangeTagCanCreate', [ $tag, $user, &$canCreateResult ] );
940 return $canCreateResult;
941 }
942
943 /**
944 * Creates a tag by adding a row to the `valid_tag` table.
945 *
946 * Includes a call to ChangeTag::canDeleteTag(), so your code doesn't need to
947 * do that.
948 *
949 * @param string $tag
950 * @param string $reason
951 * @param User $user Who to give credit for the action
952 * @param bool $ignoreWarnings Can be used for API interaction, default false
953 * @return Status If successful, the Status contains the ID of the added log
954 * entry as its value
955 * @since 1.25
956 */
957 public static function createTagWithChecks( $tag, $reason, User $user,
958 $ignoreWarnings = false ) {
959
960 // are we allowed to do this?
961 $result = self::canCreateTag( $tag, $user );
962 if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
963 $result->value = null;
964 return $result;
965 }
966
967 // do it!
968 self::defineTag( $tag );
969
970 // log it
971 $logId = self::logTagManagementAction( 'create', $tag, $reason, $user );
972 return Status::newGood( $logId );
973 }
974
975 /**
976 * Permanently removes all traces of a tag from the DB. Good for removing
977 * misspelt or temporary tags.
978 *
979 * This function should be directly called by maintenance scripts only, never
980 * by user-facing code. See deleteTagWithChecks() for functionality that can
981 * safely be exposed to users.
982 *
983 * @param string $tag Tag to remove
984 * @return Status The returned status will be good unless a hook changed it
985 * @since 1.25
986 */
987 public static function deleteTagEverywhere( $tag ) {
988 $dbw = wfGetDB( DB_MASTER );
989 $dbw->startAtomic( __METHOD__ );
990
991 // delete from valid_tag
992 self::undefineTag( $tag );
993
994 // find out which revisions use this tag, so we can delete from tag_summary
995 $result = $dbw->select( 'change_tag',
996 [ 'ct_rc_id', 'ct_log_id', 'ct_rev_id', 'ct_tag' ],
997 [ 'ct_tag' => $tag ],
998 __METHOD__ );
999 foreach ( $result as $row ) {
1000 // remove the tag from the relevant row of tag_summary
1001 $tagsToAdd = [];
1002 $tagsToRemove = [ $tag ];
1003 self::updateTagSummaryRow( $tagsToAdd, $tagsToRemove, $row->ct_rc_id,
1004 $row->ct_rev_id, $row->ct_log_id );
1005 }
1006
1007 // delete from change_tag
1008 $dbw->delete( 'change_tag', [ 'ct_tag' => $tag ], __METHOD__ );
1009
1010 $dbw->endAtomic( __METHOD__ );
1011
1012 // give extensions a chance
1013 $status = Status::newGood();
1014 Hooks::run( 'ChangeTagAfterDelete', [ $tag, &$status ] );
1015 // let's not allow error results, as the actual tag deletion succeeded
1016 if ( !$status->isOK() ) {
1017 wfDebug( 'ChangeTagAfterDelete error condition downgraded to warning' );
1018 $status->setOK( true );
1019 }
1020
1021 // clear the memcache of defined tags
1022 self::purgeTagCacheAll();
1023
1024 return $status;
1025 }
1026
1027 /**
1028 * Is it OK to allow the user to delete this tag?
1029 *
1030 * @param string $tag Tag that you are interested in deleting
1031 * @param User|null $user User whose permission you wish to check, or null if
1032 * you don't care (e.g. maintenance scripts)
1033 * @return Status
1034 * @since 1.25
1035 */
1036 public static function canDeleteTag( $tag, User $user = null ) {
1037 $tagUsage = self::tagUsageStatistics();
1038
1039 if ( !is_null( $user ) ) {
1040 if ( !$user->isAllowed( 'deletechangetags' ) ) {
1041 return Status::newFatal( 'tags-delete-no-permission' );
1042 } elseif ( $user->isBlocked() ) {
1043 return Status::newFatal( 'tags-manage-blocked' );
1044 }
1045 }
1046
1047 if ( !isset( $tagUsage[$tag] ) && !in_array( $tag, self::listDefinedTags() ) ) {
1048 return Status::newFatal( 'tags-delete-not-found', $tag );
1049 }
1050
1051 if ( isset( $tagUsage[$tag] ) && $tagUsage[$tag] > self::MAX_DELETE_USES ) {
1052 return Status::newFatal( 'tags-delete-too-many-uses', $tag, self::MAX_DELETE_USES );
1053 }
1054
1055 $softwareDefined = self::listSoftwareDefinedTags();
1056 if ( in_array( $tag, $softwareDefined ) ) {
1057 // extension-defined tags can't be deleted unless the extension
1058 // specifically allows it
1059 $status = Status::newFatal( 'tags-delete-not-allowed' );
1060 } else {
1061 // user-defined tags are deletable unless otherwise specified
1062 $status = Status::newGood();
1063 }
1064
1065 Hooks::run( 'ChangeTagCanDelete', [ $tag, $user, &$status ] );
1066 return $status;
1067 }
1068
1069 /**
1070 * Deletes a tag, checking whether it is allowed first, and adding a log entry
1071 * afterwards.
1072 *
1073 * Includes a call to ChangeTag::canDeleteTag(), so your code doesn't need to
1074 * do that.
1075 *
1076 * @param string $tag
1077 * @param string $reason
1078 * @param User $user Who to give credit for the action
1079 * @param bool $ignoreWarnings Can be used for API interaction, default false
1080 * @return Status If successful, the Status contains the ID of the added log
1081 * entry as its value
1082 * @since 1.25
1083 */
1084 public static function deleteTagWithChecks( $tag, $reason, User $user,
1085 $ignoreWarnings = false ) {
1086
1087 // are we allowed to do this?
1088 $result = self::canDeleteTag( $tag, $user );
1089 if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
1090 $result->value = null;
1091 return $result;
1092 }
1093
1094 // store the tag usage statistics
1095 $tagUsage = self::tagUsageStatistics();
1096 $hitcount = isset( $tagUsage[$tag] ) ? $tagUsage[$tag] : 0;
1097
1098 // do it!
1099 $deleteResult = self::deleteTagEverywhere( $tag );
1100 if ( !$deleteResult->isOK() ) {
1101 return $deleteResult;
1102 }
1103
1104 // log it
1105 $logId = self::logTagManagementAction( 'delete', $tag, $reason, $user, $hitcount );
1106 $deleteResult->value = $logId;
1107 return $deleteResult;
1108 }
1109
1110 /**
1111 * Lists those tags which core or extensions report as being "active".
1112 *
1113 * @return array
1114 * @since 1.25
1115 */
1116 public static function listSoftwareActivatedTags() {
1117 // core active tags
1118 $tags = self::$coreTags;
1119 if ( !Hooks::isRegistered( 'ChangeTagsListActive' ) ) {
1120 return $tags;
1121 }
1122 return ObjectCache::getMainWANInstance()->getWithSetCallback(
1123 wfMemcKey( 'active-tags' ),
1124 WANObjectCache::TTL_MINUTE * 5,
1125 function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
1126 $setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
1127
1128 // Ask extensions which tags they consider active
1129 Hooks::run( 'ChangeTagsListActive', [ &$tags ] );
1130 return $tags;
1131 },
1132 [
1133 'checkKeys' => [ wfMemcKey( 'active-tags' ) ],
1134 'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
1135 'pcTTL' => WANObjectCache::TTL_PROC_LONG
1136 ]
1137 );
1138 }
1139
1140 /**
1141 * @see listSoftwareActivatedTags
1142 * @deprecated since 1.28 call listSoftwareActivatedTags directly
1143 * @return array
1144 */
1145 public static function listExtensionActivatedTags() {
1146 wfDeprecated( __METHOD__, '1.28' );
1147 return self::listSoftwareActivatedTags();
1148 }
1149
1150 /**
1151 * Basically lists defined tags which count even if they aren't applied to anything.
1152 * It returns a union of the results of listExplicitlyDefinedTags() and
1153 * listExtensionDefinedTags().
1154 *
1155 * @return string[] Array of strings: tags
1156 */
1157 public static function listDefinedTags() {
1158 $tags1 = self::listExplicitlyDefinedTags();
1159 $tags2 = self::listSoftwareDefinedTags();
1160 return array_values( array_unique( array_merge( $tags1, $tags2 ) ) );
1161 }
1162
1163 /**
1164 * Lists tags explicitly defined in the `valid_tag` table of the database.
1165 * Tags in table 'change_tag' which are not in table 'valid_tag' are not
1166 * included.
1167 *
1168 * Tries memcached first.
1169 *
1170 * @return string[] Array of strings: tags
1171 * @since 1.25
1172 */
1173 public static function listExplicitlyDefinedTags() {
1174 $fname = __METHOD__;
1175
1176 return ObjectCache::getMainWANInstance()->getWithSetCallback(
1177 wfMemcKey( 'valid-tags-db' ),
1178 WANObjectCache::TTL_MINUTE * 5,
1179 function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
1180 $dbr = wfGetDB( DB_REPLICA );
1181
1182 $setOpts += Database::getCacheSetOptions( $dbr );
1183
1184 $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', [], $fname );
1185
1186 return array_filter( array_unique( $tags ) );
1187 },
1188 [
1189 'checkKeys' => [ wfMemcKey( 'valid-tags-db' ) ],
1190 'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
1191 'pcTTL' => WANObjectCache::TTL_PROC_LONG
1192 ]
1193 );
1194 }
1195
1196 /**
1197 * Lists tags defined by core or extensions using the ListDefinedTags hook.
1198 * Extensions need only define those tags they deem to be in active use.
1199 *
1200 * Tries memcached first.
1201 *
1202 * @return string[] Array of strings: tags
1203 * @since 1.25
1204 */
1205 public static function listSoftwareDefinedTags() {
1206 // core defined tags
1207 $tags = self::$coreTags;
1208 if ( !Hooks::isRegistered( 'ListDefinedTags' ) ) {
1209 return $tags;
1210 }
1211 return ObjectCache::getMainWANInstance()->getWithSetCallback(
1212 wfMemcKey( 'valid-tags-hook' ),
1213 WANObjectCache::TTL_MINUTE * 5,
1214 function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
1215 $setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
1216
1217 Hooks::run( 'ListDefinedTags', [ &$tags ] );
1218 return array_filter( array_unique( $tags ) );
1219 },
1220 [
1221 'checkKeys' => [ wfMemcKey( 'valid-tags-hook' ) ],
1222 'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
1223 'pcTTL' => WANObjectCache::TTL_PROC_LONG
1224 ]
1225 );
1226 }
1227
1228 /**
1229 * Call listSoftwareDefinedTags directly
1230 *
1231 * @see listSoftwareDefinedTags
1232 * @deprecated since 1.28
1233 */
1234 public static function listExtensionDefinedTags() {
1235 wfDeprecated( __METHOD__, '1.28' );
1236 return self::listSoftwareDefinedTags();
1237 }
1238
1239 /**
1240 * Invalidates the short-term cache of defined tags used by the
1241 * list*DefinedTags functions, as well as the tag statistics cache.
1242 * @since 1.25
1243 */
1244 public static function purgeTagCacheAll() {
1245 $cache = ObjectCache::getMainWANInstance();
1246
1247 $cache->touchCheckKey( wfMemcKey( 'active-tags' ) );
1248 $cache->touchCheckKey( wfMemcKey( 'valid-tags-db' ) );
1249 $cache->touchCheckKey( wfMemcKey( 'valid-tags-hook' ) );
1250
1251 self::purgeTagUsageCache();
1252 }
1253
1254 /**
1255 * Invalidates the tag statistics cache only.
1256 * @since 1.25
1257 */
1258 public static function purgeTagUsageCache() {
1259 $cache = ObjectCache::getMainWANInstance();
1260
1261 $cache->touchCheckKey( wfMemcKey( 'change-tag-statistics' ) );
1262 }
1263
1264 /**
1265 * Returns a map of any tags used on the wiki to number of edits
1266 * tagged with them, ordered descending by the hitcount.
1267 * This does not include tags defined somewhere that have never been applied.
1268 *
1269 * Keeps a short-term cache in memory, so calling this multiple times in the
1270 * same request should be fine.
1271 *
1272 * @return array Array of string => int
1273 */
1274 public static function tagUsageStatistics() {
1275 $fname = __METHOD__;
1276 return ObjectCache::getMainWANInstance()->getWithSetCallback(
1277 wfMemcKey( 'change-tag-statistics' ),
1278 WANObjectCache::TTL_MINUTE * 5,
1279 function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
1280 $dbr = wfGetDB( DB_REPLICA, 'vslow' );
1281
1282 $setOpts += Database::getCacheSetOptions( $dbr );
1283
1284 $res = $dbr->select(
1285 'change_tag',
1286 [ 'ct_tag', 'hitcount' => 'count(*)' ],
1287 [],
1288 $fname,
1289 [ 'GROUP BY' => 'ct_tag', 'ORDER BY' => 'hitcount DESC' ]
1290 );
1291
1292 $out = [];
1293 foreach ( $res as $row ) {
1294 $out[$row->ct_tag] = $row->hitcount;
1295 }
1296
1297 return $out;
1298 },
1299 [
1300 'checkKeys' => [ wfMemcKey( 'change-tag-statistics' ) ],
1301 'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
1302 'pcTTL' => WANObjectCache::TTL_PROC_LONG
1303 ]
1304 );
1305 }
1306
1307 /**
1308 * Indicate whether change tag editing UI is relevant
1309 *
1310 * Returns true if the user has the necessary right and there are any
1311 * editable tags defined.
1312 *
1313 * This intentionally doesn't check "any addable || any deletable", because
1314 * it seems like it would be more confusing than useful if the checkboxes
1315 * suddenly showed up because some abuse filter stopped defining a tag and
1316 * then suddenly disappeared when someone deleted all uses of that tag.
1317 *
1318 * @param User $user
1319 * @return bool
1320 */
1321 public static function showTagEditingUI( User $user ) {
1322 return $user->isAllowed( 'changetags' ) && (bool)self::listExplicitlyDefinedTags();
1323 }
1324 }