3 * Recent changes tagging.
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
21 * @ingroup Change tagging
24 use MediaWiki\MediaWikiServices
;
25 use MediaWiki\Storage\NameTableAccessException
;
26 use Wikimedia\Rdbms\Database
;
30 * Can't delete tags with more than this many uses. Similar in intent to
31 * the bigdelete user right
32 * @todo Use the job queue for tag deletion to avoid this restriction
34 const MAX_DELETE_USES
= 5000;
37 * A list of tags defined and used by MediaWiki itself.
39 private static $definedSoftwareTags = [
40 'mw-contentmodelchange',
42 'mw-removed-redirect',
43 'mw-changed-redirect-target',
51 * Loads defined core tags, checks for invalid types (if not array),
52 * and filters for supported and enabled (if $all is false) tags only.
54 * @param bool $all If true, return all valid defined tags. Otherwise, return only enabled ones.
55 * @return array Array of all defined/enabled tags.
57 public static function getSoftwareTags( $all = false ) {
58 global $wgSoftwareTags;
61 if ( !is_array( $wgSoftwareTags ) ) {
62 wfWarn( 'wgSoftwareTags should be associative array of enabled tags.
63 Please refer to documentation for the list of tags you can enable' );
67 $availableSoftwareTags = !$all ?
68 array_keys( array_filter( $wgSoftwareTags ) ) :
69 array_keys( $wgSoftwareTags );
71 $softwareTags = array_intersect(
72 $availableSoftwareTags,
73 self
::$definedSoftwareTags
80 * Creates HTML for the given tags
82 * @param string $tags Comma-separated list of tags
83 * @param string $page A label for the type of action which is being displayed,
84 * for example: 'history', 'contributions' or 'newpages'
85 * @param IContextSource|null $context
86 * @note Even though it takes null as a valid argument, an IContextSource is preferred
87 * in a new code, as the null value is subject to change in the future
88 * @return array Array with two items: (html, classes)
89 * - html: String: HTML for displaying the tags (empty string when param $tags is empty)
90 * - classes: Array of strings: CSS classes used in the generated html, one class for each tag
91 * @return-taint onlysafefor_htmlnoent
93 public static function formatSummaryRow( $tags, $page, IContextSource
$context = null ) {
98 $context = RequestContext
::getMain();
103 $tags = explode( ',', $tags );
105 foreach ( $tags as $tag ) {
109 $description = self
::tagDescription( $tag, $context );
110 if ( $description === false ) {
113 $displayTags[] = Xml
::tags(
115 [ 'class' => 'mw-tag-marker ' .
116 Sanitizer
::escapeClass( "mw-tag-marker-$tag" ) ],
119 $classes[] = Sanitizer
::escapeClass( "mw-tag-$tag" );
122 if ( !$displayTags ) {
126 $markers = $context->msg( 'tag-list-wrapper' )
127 ->numParams( count( $displayTags ) )
128 ->rawParams( $context->getLanguage()->commaList( $displayTags ) )
130 $markers = Xml
::tags( 'span', [ 'class' => 'mw-tag-markers' ], $markers );
132 return [ $markers, $classes ];
136 * Get the message object for the tag's short description.
138 * Checks if message key "mediawiki:tag-$tag" exists. If it does not,
139 * returns the tag name in a RawMessage. If the message exists, it is
140 * used, provided it is not disabled. If the message is disabled, we
141 * consider the tag hidden, and return false.
145 * @param MessageLocalizer $context
146 * @return Message|bool Tag description, or false if tag is to be hidden.
148 public static function tagShortDescriptionMessage( $tag, MessageLocalizer
$context ) {
149 $msg = $context->msg( "tag-$tag" );
150 if ( !$msg->exists() ) {
152 return new RawMessage( '$1', [ Message
::plaintextParam( $tag ) ] );
154 if ( $msg->isDisabled() ) {
155 // The message exists but is disabled, hide the tag.
159 // Message exists and isn't disabled, use it.
164 * Get a short description for a tag.
166 * Checks if message key "mediawiki:tag-$tag" exists. If it does not,
167 * returns the HTML-escaped tag name. Uses the message if the message
168 * exists, provided it is not disabled. If the message is disabled,
169 * we consider the tag hidden, and return false.
172 * @param MessageLocalizer $context
173 * @return string|bool Tag description or false if tag is to be hidden.
174 * @since 1.25 Returns false if tag is to be hidden.
176 public static function tagDescription( $tag, MessageLocalizer
$context ) {
177 $msg = self
::tagShortDescriptionMessage( $tag, $context );
178 return $msg ?
$msg->parse() : false;
182 * Get the message object for the tag's long description.
184 * Checks if message key "mediawiki:tag-$tag-description" exists. If it does not,
185 * or if message is disabled, returns false. Otherwise, returns the message object
186 * for the long description.
189 * @param MessageLocalizer $context
190 * @return Message|bool Message object of the tag long description or false if
191 * there is no description.
193 public static function tagLongDescriptionMessage( $tag, MessageLocalizer
$context ) {
194 $msg = $context->msg( "tag-$tag-description" );
195 if ( !$msg->exists() ) {
198 if ( $msg->isDisabled() ) {
199 // The message exists but is disabled, hide the description.
203 // Message exists and isn't disabled, use it.
208 * Get truncated message for the tag's long description.
210 * @param string $tag Tag name.
211 * @param int $length Maximum length of truncated message, including ellipsis.
212 * @param IContextSource $context
214 * @return string Truncated long tag description.
216 public static function truncateTagDescription( $tag, $length, IContextSource
$context ) {
217 // FIXME: Make this accept MessageLocalizer and Language instead of IContextSource
219 $originalDesc = self
::tagLongDescriptionMessage( $tag, $context );
220 // If there is no tag description, return empty string
221 if ( !$originalDesc ) {
225 $taglessDesc = Sanitizer
::stripAllTags( $originalDesc->parse() );
227 return $context->getLanguage()->truncateForVisual( $taglessDesc, $length );
231 * Add tags to a change given its rc_id, rev_id and/or log_id
233 * @param string|string[] $tags Tags to add to the change
234 * @param int|null $rc_id The rc_id of the change to add the tags to
235 * @param int|null $rev_id The rev_id of the change to add the tags to
236 * @param int|null $log_id The log_id of the change to add the tags to
237 * @param string|null $params Params to put in the ct_params field of table 'change_tag'
238 * @param RecentChange|null $rc Recent change, in case the tagging accompanies the action
239 * (this should normally be the case)
241 * @throws MWException
242 * @return bool False if no changes are made, otherwise true
244 public static function addTags( $tags, $rc_id = null, $rev_id = null,
245 $log_id = null, $params = null, RecentChange
$rc = null
247 $result = self
::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params, $rc );
248 return (bool)$result[0];
252 * Add and remove tags to/from a change given its rc_id, rev_id and/or log_id,
253 * without verifying that the tags exist or are valid. If a tag is present in
254 * both $tagsToAdd and $tagsToRemove, it will be removed.
256 * This function should only be used by extensions to manipulate tags they
257 * have registered using the ListDefinedTags hook. When dealing with user
258 * input, call updateTagsWithChecks() instead.
260 * @param string|array|null $tagsToAdd Tags to add to the change
261 * @param string|array|null $tagsToRemove Tags to remove from the change
262 * @param int|null &$rc_id The rc_id of the change to add the tags to.
263 * Pass a variable whose value is null if the rc_id is not relevant or unknown.
264 * @param int|null &$rev_id The rev_id of the change to add the tags to.
265 * Pass a variable whose value is null if the rev_id is not relevant or unknown.
266 * @param int|null &$log_id The log_id of the change to add the tags to.
267 * Pass a variable whose value is null if the log_id is not relevant or unknown.
268 * @param string|null $params Params to put in the ct_params field of table
269 * 'change_tag' when adding tags
270 * @param RecentChange|null $rc Recent change being tagged, in case the tagging accompanies
272 * @param User|null $user Tagging user, in case the tagging is subsequent to the tagged action
274 * @throws MWException When $rc_id, $rev_id and $log_id are all null
275 * @return array Index 0 is an array of tags actually added, index 1 is an
276 * array of tags actually removed, index 2 is an array of tags present on the
277 * revision or log entry before any changes were made
281 public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null,
282 &$rev_id = null, &$log_id = null, $params = null, RecentChange
$rc = null,
285 $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags...
286 $tagsToRemove = array_filter( (array)$tagsToRemove );
288 if ( !$rc_id && !$rev_id && !$log_id ) {
289 throw new MWException( 'At least one of: RCID, revision ID, and log ID MUST be ' .
290 'specified when adding or removing a tag from a change!' );
293 $dbw = wfGetDB( DB_MASTER
);
295 // Might as well look for rcids and so on.
297 // Info might be out of date, somewhat fractionally, on replica DB.
298 // LogEntry/LogPage and WikiPage match rev/log/rc timestamps,
299 // so use that relation to avoid full table scans.
301 $rc_id = $dbw->selectField(
302 [ 'logging', 'recentchanges' ],
306 'rc_timestamp = log_timestamp',
311 } elseif ( $rev_id ) {
312 $rc_id = $dbw->selectField(
313 [ 'revision', 'recentchanges' ],
317 'rc_timestamp = rev_timestamp',
318 'rc_this_oldid = rev_id'
323 } elseif ( !$log_id && !$rev_id ) {
324 // Info might be out of date, somewhat fractionally, on replica DB.
325 $log_id = $dbw->selectField(
328 [ 'rc_id' => $rc_id ],
331 $rev_id = $dbw->selectField(
334 [ 'rc_id' => $rc_id ],
339 if ( $log_id && !$rev_id ) {
340 $rev_id = $dbw->selectField(
343 [ 'ls_field' => 'associated_rev_id', 'ls_log_id' => $log_id ],
346 } elseif ( !$log_id && $rev_id ) {
347 $log_id = $dbw->selectField(
350 [ 'ls_field' => 'associated_rev_id', 'ls_value' => $rev_id ],
355 $prevTags = self
::getPrevTags( $rc_id, $log_id, $rev_id );
358 $tagsToAdd = array_values( array_diff( $tagsToAdd, $prevTags ) );
359 $newTags = array_unique( array_merge( $prevTags, $tagsToAdd ) );
362 $tagsToRemove = array_values( array_intersect( $tagsToRemove, $newTags ) );
363 $newTags = array_values( array_diff( $newTags, $tagsToRemove ) );
367 if ( $prevTags == $newTags ) {
368 return [ [], [], $prevTags ];
371 // insert a row into change_tag for each new tag
372 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
373 if ( count( $tagsToAdd ) ) {
374 $changeTagMapping = [];
375 foreach ( $tagsToAdd as $tag ) {
376 $changeTagMapping[$tag] = $changeTagDefStore->acquireId( $tag );
379 // T207881: update the counts at the end of the transaction
380 $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tagsToAdd, $fname ) {
383 [ 'ctd_count = ctd_count + 1' ],
384 [ 'ctd_name' => $tagsToAdd ],
390 foreach ( $tagsToAdd as $tag ) {
391 // Filter so we don't insert NULLs as zero accidentally.
392 // Keep in mind that $rc_id === null means "I don't care/know about the
393 // rc_id, just delete $tag on this revision/log entry". It doesn't
394 // mean "only delete tags on this revision/log WHERE rc_id IS NULL".
395 $tagsRows[] = array_filter(
397 'ct_rc_id' => $rc_id,
398 'ct_log_id' => $log_id,
399 'ct_rev_id' => $rev_id,
400 'ct_params' => $params,
401 'ct_tag_id' => $changeTagMapping[$tag] ??
null,
407 $dbw->insert( 'change_tag', $tagsRows, __METHOD__
, [ 'IGNORE' ] );
410 // delete from change_tag
411 if ( count( $tagsToRemove ) ) {
413 foreach ( $tagsToRemove as $tag ) {
414 $conds = array_filter(
416 'ct_rc_id' => $rc_id,
417 'ct_log_id' => $log_id,
418 'ct_rev_id' => $rev_id,
419 'ct_tag_id' => $changeTagDefStore->getId( $tag ),
422 $dbw->delete( 'change_tag', $conds, __METHOD__
);
423 if ( $dbw->affectedRows() ) {
424 // T207881: update the counts at the end of the transaction
425 $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tag, $fname ) {
428 [ 'ctd_count = ctd_count - 1' ],
429 [ 'ctd_name' => $tag ],
435 [ 'ctd_name' => $tag, 'ctd_count' => 0, 'ctd_user_defined' => 0 ],
443 Hooks
::run( 'ChangeTagsAfterUpdateTags', [ $tagsToAdd, $tagsToRemove, $prevTags,
444 $rc_id, $rev_id, $log_id, $params, $rc, $user ] );
446 return [ $tagsToAdd, $tagsToRemove, $prevTags ];
449 private static function getPrevTags( $rc_id = null, $log_id = null, $rev_id = null ) {
450 $conds = array_filter(
452 'ct_rc_id' => $rc_id,
453 'ct_log_id' => $log_id,
454 'ct_rev_id' => $rev_id,
458 $dbw = wfGetDB( DB_MASTER
);
459 $tagIds = $dbw->selectFieldValues( 'change_tag', 'ct_tag_id', $conds, __METHOD__
);
462 foreach ( $tagIds as $tagId ) {
463 $tags[] = MediaWikiServices
::getInstance()->getChangeTagDefStore()->getName( (int)$tagId );
470 * Helper function to generate a fatal status with a 'not-allowed' type error.
472 * @param string $msgOne Message key to use in the case of one tag
473 * @param string $msgMulti Message key to use in the case of more than one tag
474 * @param array $tags Restricted tags (passed as $1 into the message, count of
475 * $tags passed as $2)
479 protected static function restrictedTagError( $msgOne, $msgMulti, $tags ) {
480 $lang = RequestContext
::getMain()->getLanguage();
481 $count = count( $tags );
482 return Status
::newFatal( ( $count > 1 ) ?
$msgMulti : $msgOne,
483 $lang->commaList( $tags ), $count );
487 * Is it OK to allow the user to apply all the specified tags at the same time
488 * as they edit/make the change?
490 * Extensions should not use this function, unless directly handling a user
491 * request to add a tag to a revision or log entry that the user is making.
493 * @param array $tags Tags that you are interested in applying
494 * @param User|null $user User whose permission you wish to check, or null to
495 * check for a generic non-blocked user with the relevant rights
499 public static function canAddTagsAccompanyingChange( array $tags, User
$user = null ) {
500 if ( !is_null( $user ) ) {
501 if ( !$user->isAllowed( 'applychangetags' ) ) {
502 return Status
::newFatal( 'tags-apply-no-permission' );
503 } elseif ( $user->getBlock() ) {
504 // @TODO Ensure that the block does not apply to the `applychangetags`
506 return Status
::newFatal( 'tags-apply-blocked', $user->getName() );
510 // to be applied, a tag has to be explicitly defined
511 $allowedTags = self
::listExplicitlyDefinedTags();
512 Hooks
::run( 'ChangeTagsAllowedAdd', [ &$allowedTags, $tags, $user ] );
513 $disallowedTags = array_diff( $tags, $allowedTags );
514 if ( $disallowedTags ) {
515 return self
::restrictedTagError( 'tags-apply-not-allowed-one',
516 'tags-apply-not-allowed-multi', $disallowedTags );
519 return Status
::newGood();
523 * Adds tags to a given change, checking whether it is allowed first, but
524 * without adding a log entry. Useful for cases where the tag is being added
525 * along with the action that generated the change (e.g. tagging an edit as
528 * Extensions should not use this function, unless directly handling a user
529 * request to add a particular tag. Normally, extensions should call
530 * ChangeTags::updateTags() instead.
532 * @param array $tags Tags to apply
533 * @param int|null $rc_id The rc_id of the change to add the tags to
534 * @param int|null $rev_id The rev_id of the change to add the tags to
535 * @param int|null $log_id The log_id of the change to add the tags to
536 * @param string $params Params to put in the ct_params field of table
537 * 'change_tag' when adding tags
538 * @param User $user Who to give credit for the action
542 public static function addTagsAccompanyingChangeWithChecks(
543 array $tags, $rc_id, $rev_id, $log_id, $params, User
$user
545 // are we allowed to do this?
546 $result = self
::canAddTagsAccompanyingChange( $tags, $user );
547 if ( !$result->isOK() ) {
548 $result->value
= null;
553 self
::addTags( $tags, $rc_id, $rev_id, $log_id, $params );
555 return Status
::newGood( true );
559 * Is it OK to allow the user to adds and remove the given tags tags to/from a
562 * Extensions should not use this function, unless directly handling a user
563 * request to add or remove tags from an existing revision or log entry.
565 * @param array $tagsToAdd Tags that you are interested in adding
566 * @param array $tagsToRemove Tags that you are interested in removing
567 * @param User|null $user User whose permission you wish to check, or null to
568 * check for a generic non-blocked user with the relevant rights
572 public static function canUpdateTags( array $tagsToAdd, array $tagsToRemove,
575 if ( !is_null( $user ) ) {
576 if ( !$user->isAllowed( 'changetags' ) ) {
577 return Status
::newFatal( 'tags-update-no-permission' );
578 } elseif ( $user->getBlock() ) {
579 // @TODO Ensure that the block does not apply to the `changetags`
581 return Status
::newFatal( 'tags-update-blocked', $user->getName() );
586 // to be added, a tag has to be explicitly defined
587 // @todo Allow extensions to define tags that can be applied by users...
588 $explicitlyDefinedTags = self
::listExplicitlyDefinedTags();
589 $diff = array_diff( $tagsToAdd, $explicitlyDefinedTags );
591 return self
::restrictedTagError( 'tags-update-add-not-allowed-one',
592 'tags-update-add-not-allowed-multi', $diff );
596 if ( $tagsToRemove ) {
597 // to be removed, a tag must not be defined by an extension, or equivalently it
598 // has to be either explicitly defined or not defined at all
599 // (assuming no edge case of a tag both explicitly-defined and extension-defined)
600 $softwareDefinedTags = self
::listSoftwareDefinedTags();
601 $intersect = array_intersect( $tagsToRemove, $softwareDefinedTags );
603 return self
::restrictedTagError( 'tags-update-remove-not-allowed-one',
604 'tags-update-remove-not-allowed-multi', $intersect );
608 return Status
::newGood();
612 * Adds and/or removes tags to/from a given change, checking whether it is
613 * allowed first, and adding a log entry afterwards.
615 * Includes a call to ChangeTags::canUpdateTags(), so your code doesn't need
616 * to do that. However, it doesn't check whether the *_id parameters are a
617 * valid combination. That is up to you to enforce. See ApiTag::execute() for
620 * Extensions should generally avoid this function. Call
621 * ChangeTags::updateTags() instead, unless directly handling a user request
622 * to add or remove tags from an existing revision or log entry.
624 * @param array|null $tagsToAdd If none, pass [] or null
625 * @param array|null $tagsToRemove If none, pass [] or null
626 * @param int|null $rc_id The rc_id of the change to add the tags to
627 * @param int|null $rev_id The rev_id of the change to add the tags to
628 * @param int|null $log_id The log_id of the change to add the tags to
629 * @param string|null $params Params to put in the ct_params field of table
630 * 'change_tag' when adding tags
631 * @param string $reason Comment for the log
632 * @param User $user Who to give credit for the action
633 * @return Status If successful, the value of this Status object will be an
634 * object (stdClass) with the following fields:
635 * - logId: the ID of the added log entry, or null if no log entry was added
636 * (i.e. no operation was performed)
637 * - addedTags: an array containing the tags that were actually added
638 * - removedTags: an array containing the tags that were actually removed
641 public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
642 $rc_id, $rev_id, $log_id, $params, $reason, User
$user
644 if ( is_null( $tagsToAdd ) ) {
647 if ( is_null( $tagsToRemove ) ) {
650 if ( !$tagsToAdd && !$tagsToRemove ) {
651 // no-op, don't bother
652 return Status
::newGood( (object)[
659 // are we allowed to do this?
660 $result = self
::canUpdateTags( $tagsToAdd, $tagsToRemove, $user );
661 if ( !$result->isOK() ) {
662 $result->value
= null;
666 // basic rate limiting
667 if ( $user->pingLimiter( 'changetag' ) ) {
668 return Status
::newFatal( 'actionthrottledtext' );
672 list( $tagsAdded, $tagsRemoved, $initialTags ) = self
::updateTags( $tagsToAdd,
673 $tagsToRemove, $rc_id, $rev_id, $log_id, $params, null, $user );
674 if ( !$tagsAdded && !$tagsRemoved ) {
675 // no-op, don't log it
676 return Status
::newGood( (object)[
684 $logEntry = new ManualLogEntry( 'tag', 'update' );
685 $logEntry->setPerformer( $user );
686 $logEntry->setComment( $reason );
688 // find the appropriate target page
690 $rev = Revision
::newFromId( $rev_id );
692 $logEntry->setTarget( $rev->getTitle() );
694 } elseif ( $log_id ) {
695 // This function is from revision deletion logic and has nothing to do with
696 // change tags, but it appears to be the only other place in core where we
697 // perform logged actions on log items.
698 $logEntry->setTarget( RevDelLogList
::suggestTarget( null, [ $log_id ] ) );
701 if ( !$logEntry->getTarget() ) {
702 // target is required, so we have to set something
703 $logEntry->setTarget( SpecialPage
::getTitleFor( 'Tags' ) );
707 '4::revid' => $rev_id,
708 '5::logid' => $log_id,
709 '6:list:tagsAdded' => $tagsAdded,
710 '7:number:tagsAddedCount' => count( $tagsAdded ),
711 '8:list:tagsRemoved' => $tagsRemoved,
712 '9:number:tagsRemovedCount' => count( $tagsRemoved ),
713 'initialTags' => $initialTags,
715 $logEntry->setParameters( $logParams );
716 $logEntry->setRelations( [ 'Tag' => array_merge( $tagsAdded, $tagsRemoved ) ] );
718 $dbw = wfGetDB( DB_MASTER
);
719 $logId = $logEntry->insert( $dbw );
720 // Only send this to UDP, not RC, similar to patrol events
721 $logEntry->publish( $logId, 'udp' );
723 return Status
::newGood( (object)[
725 'addedTags' => $tagsAdded,
726 'removedTags' => $tagsRemoved,
731 * Applies all tags-related changes to a query.
732 * Handles selecting tags, and filtering.
733 * Needs $tables to be set up properly, so we can figure out which join conditions to use.
735 * WARNING: If $filter_tag contains more than one tag, this function will add DISTINCT,
736 * which may cause performance problems for your query unless you put the ID field of your
737 * table at the end of the ORDER BY, and set a GROUP BY equal to the ORDER BY. For example,
738 * if you had ORDER BY foo_timestamp DESC, you will now need GROUP BY foo_timestamp, foo_id
739 * ORDER BY foo_timestamp DESC, foo_id DESC.
741 * @param string|array &$tables Table names, see Database::select
742 * @param string|array &$fields Fields used in query, see Database::select
743 * @param string|array &$conds Conditions used in query, see Database::select
744 * @param array &$join_conds Join conditions, see Database::select
745 * @param string|array &$options Options, see Database::select
746 * @param string|array $filter_tag Tag(s) to select on
748 * @throws MWException When unable to determine appropriate JOIN condition for tagging
750 public static function modifyDisplayQuery( &$tables, &$fields, &$conds,
751 &$join_conds, &$options, $filter_tag = ''
753 global $wgUseTagFilter;
755 // Normalize to arrays
756 $tables = (array)$tables;
757 $fields = (array)$fields;
758 $conds = (array)$conds;
759 $options = (array)$options;
761 $fields['ts_tags'] = self
::makeTagSummarySubquery( $tables );
763 // Figure out which ID field to use
764 if ( in_array( 'recentchanges', $tables ) ) {
765 $join_cond = 'ct_rc_id=rc_id';
766 } elseif ( in_array( 'logging', $tables ) ) {
767 $join_cond = 'ct_log_id=log_id';
768 } elseif ( in_array( 'revision', $tables ) ) {
769 $join_cond = 'ct_rev_id=rev_id';
770 } elseif ( in_array( 'archive', $tables ) ) {
771 $join_cond = 'ct_rev_id=ar_rev_id';
773 throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' );
776 if ( $wgUseTagFilter && $filter_tag ) {
777 // Somebody wants to filter on a tag.
778 // Add an INNER JOIN on change_tag
780 $tables[] = 'change_tag';
781 $join_conds['change_tag'] = [ 'JOIN', $join_cond ];
783 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
784 foreach ( (array)$filter_tag as $filterTagName ) {
786 $filterTagIds[] = $changeTagDefStore->getId( $filterTagName );
787 } catch ( NameTableAccessException
$exception ) {
794 if ( $filterTagIds !== [] ) {
795 $conds['ct_tag_id'] = $filterTagIds;
799 is_array( $filter_tag ) && count( $filter_tag ) > 1 &&
800 !in_array( 'DISTINCT', $options )
802 $options[] = 'DISTINCT';
808 * Make the tag summary subquery based on the given tables and return it.
810 * @param string|array $tables Table names, see Database::select
812 * @return string tag summary subqeury
813 * @throws MWException When unable to determine appropriate JOIN condition for tagging
815 public static function makeTagSummarySubquery( $tables ) {
816 // Normalize to arrays
817 $tables = (array)$tables;
819 // Figure out which ID field to use
820 if ( in_array( 'recentchanges', $tables ) ) {
821 $join_cond = 'ct_rc_id=rc_id';
822 } elseif ( in_array( 'logging', $tables ) ) {
823 $join_cond = 'ct_log_id=log_id';
824 } elseif ( in_array( 'revision', $tables ) ) {
825 $join_cond = 'ct_rev_id=rev_id';
826 } elseif ( in_array( 'archive', $tables ) ) {
827 $join_cond = 'ct_rev_id=ar_rev_id';
829 throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' );
832 $tagTables = [ 'change_tag', 'change_tag_def' ];
833 $join_cond_ts_tags = [ 'change_tag_def' => [ 'JOIN', 'ct_tag_id=ctd_id' ] ];
836 return wfGetDB( DB_REPLICA
)->buildGroupConcatField(
837 ',', $tagTables, $field, $join_cond, $join_cond_ts_tags
842 * Build a text box to select a change tag
844 * @param string $selected Tag to select by default
845 * @param bool $ooui Use an OOUI TextInputWidget as selector instead of a non-OOUI input field
846 * You need to call OutputPage::enableOOUI() yourself.
847 * @param IContextSource|null $context
848 * @note Even though it takes null as a valid argument, an IContextSource is preferred
849 * in a new code, as the null value can change in the future
850 * @return array an array of (label, selector)
852 public static function buildTagFilterSelector(
853 $selected = '', $ooui = false, IContextSource
$context = null
856 $context = RequestContext
::getMain();
859 $config = $context->getConfig();
860 if ( !$config->get( 'UseTagFilter' ) ||
!count( self
::listDefinedTags() ) ) {
867 [ 'for' => 'tagfilter' ],
868 $context->msg( 'tag-filter' )->parse()
873 $data[] = new OOUI\
TextInputWidget( [
875 'name' => 'tagfilter',
876 'value' => $selected,
877 'classes' => 'mw-tagfilter-input',
880 $data[] = Xml
::input(
884 [ 'class' => 'mw-tagfilter-input mw-ui-input mw-ui-input-inline', 'id' => 'tagfilter' ]
892 * Set ctd_user_defined = 1 in change_tag_def without checking that the tag name is valid.
893 * Extensions should NOT use this function; they can use the ListDefinedTags
896 * @param string $tag Tag to create
899 public static function defineTag( $tag ) {
900 $dbw = wfGetDB( DB_MASTER
);
903 'ctd_user_defined' => 1,
910 [ 'ctd_user_defined' => 1 ],
914 // clear the memcache of defined tags
915 self
::purgeTagCacheAll();
919 * Update ctd_user_defined = 0 field in change_tag_def.
920 * The tag may remain in use by extensions, and may still show up as 'defined'
921 * if an extension is setting it from the ListDefinedTags hook.
923 * @param string $tag Tag to remove
926 public static function undefineTag( $tag ) {
927 $dbw = wfGetDB( DB_MASTER
);
931 [ 'ctd_user_defined' => 0 ],
932 [ 'ctd_name' => $tag ],
938 [ 'ctd_name' => $tag, 'ctd_count' => 0 ],
942 // clear the memcache of defined tags
943 self
::purgeTagCacheAll();
947 * Writes a tag action into the tag management log.
949 * @param string $action
951 * @param string $reason
952 * @param User $user Who to attribute the action to
953 * @param int|null $tagCount For deletion only, how many usages the tag had before
955 * @param array $logEntryTags Change tags to apply to the entry
956 * that will be created in the tag management log
957 * @return int ID of the inserted log entry
960 protected static function logTagManagementAction( $action, $tag, $reason,
961 User
$user, $tagCount = null, array $logEntryTags = []
963 $dbw = wfGetDB( DB_MASTER
);
965 $logEntry = new ManualLogEntry( 'managetags', $action );
966 $logEntry->setPerformer( $user );
967 // target page is not relevant, but it has to be set, so we just put in
968 // the title of Special:Tags
969 $logEntry->setTarget( Title
::newFromText( 'Special:Tags' ) );
970 $logEntry->setComment( $reason );
972 $params = [ '4::tag' => $tag ];
973 if ( !is_null( $tagCount ) ) {
974 $params['5:number:count'] = $tagCount;
976 $logEntry->setParameters( $params );
977 $logEntry->setRelations( [ 'Tag' => $tag ] );
978 $logEntry->setTags( $logEntryTags );
980 $logId = $logEntry->insert( $dbw );
981 $logEntry->publish( $logId );
986 * Is it OK to allow the user to activate this tag?
988 * @param string $tag Tag that you are interested in activating
989 * @param User|null $user User whose permission you wish to check, or null if
990 * you don't care (e.g. maintenance scripts)
994 public static function canActivateTag( $tag, User
$user = null ) {
995 if ( !is_null( $user ) ) {
996 if ( !$user->isAllowed( 'managechangetags' ) ) {
997 return Status
::newFatal( 'tags-manage-no-permission' );
998 } elseif ( $user->getBlock() ) {
999 // @TODO Ensure that the block does not apply to the `managechangetags`
1001 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1005 // defined tags cannot be activated (a defined tag is either extension-
1006 // defined, in which case the extension chooses whether or not to active it;
1007 // or user-defined, in which case it is considered active)
1008 $definedTags = self
::listDefinedTags();
1009 if ( in_array( $tag, $definedTags ) ) {
1010 return Status
::newFatal( 'tags-activate-not-allowed', $tag );
1013 // non-existing tags cannot be activated
1014 $tagUsage = self
::tagUsageStatistics();
1015 if ( !isset( $tagUsage[$tag] ) ) { // we already know the tag is undefined
1016 return Status
::newFatal( 'tags-activate-not-found', $tag );
1019 return Status
::newGood();
1023 * Activates a tag, checking whether it is allowed first, and adding a log
1026 * Includes a call to ChangeTag::canActivateTag(), so your code doesn't need
1029 * @param string $tag
1030 * @param string $reason
1031 * @param User $user Who to give credit for the action
1032 * @param bool $ignoreWarnings Can be used for API interaction, default false
1033 * @param array $logEntryTags Change tags to apply to the entry
1034 * that will be created in the tag management log
1035 * @return Status If successful, the Status contains the ID of the added log
1036 * entry as its value
1039 public static function activateTagWithChecks( $tag, $reason, User
$user,
1040 $ignoreWarnings = false, array $logEntryTags = []
1042 // are we allowed to do this?
1043 $result = self
::canActivateTag( $tag, $user );
1044 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1045 $result->value
= null;
1050 self
::defineTag( $tag );
1053 $logId = self
::logTagManagementAction( 'activate', $tag, $reason, $user,
1054 null, $logEntryTags );
1056 return Status
::newGood( $logId );
1060 * Is it OK to allow the user to deactivate this tag?
1062 * @param string $tag Tag that you are interested in deactivating
1063 * @param User|null $user User whose permission you wish to check, or null if
1064 * you don't care (e.g. maintenance scripts)
1068 public static function canDeactivateTag( $tag, User
$user = null ) {
1069 if ( !is_null( $user ) ) {
1070 if ( !$user->isAllowed( 'managechangetags' ) ) {
1071 return Status
::newFatal( 'tags-manage-no-permission' );
1072 } elseif ( $user->getBlock() ) {
1073 // @TODO Ensure that the block does not apply to the `managechangetags`
1075 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1079 // only explicitly-defined tags can be deactivated
1080 $explicitlyDefinedTags = self
::listExplicitlyDefinedTags();
1081 if ( !in_array( $tag, $explicitlyDefinedTags ) ) {
1082 return Status
::newFatal( 'tags-deactivate-not-allowed', $tag );
1084 return Status
::newGood();
1088 * Deactivates a tag, checking whether it is allowed first, and adding a log
1091 * Includes a call to ChangeTag::canDeactivateTag(), so your code doesn't need
1094 * @param string $tag
1095 * @param string $reason
1096 * @param User $user Who to give credit for the action
1097 * @param bool $ignoreWarnings Can be used for API interaction, default false
1098 * @param array $logEntryTags Change tags to apply to the entry
1099 * that will be created in the tag management log
1100 * @return Status If successful, the Status contains the ID of the added log
1101 * entry as its value
1104 public static function deactivateTagWithChecks( $tag, $reason, User
$user,
1105 $ignoreWarnings = false, array $logEntryTags = []
1107 // are we allowed to do this?
1108 $result = self
::canDeactivateTag( $tag, $user );
1109 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1110 $result->value
= null;
1115 self
::undefineTag( $tag );
1118 $logId = self
::logTagManagementAction( 'deactivate', $tag, $reason, $user,
1119 null, $logEntryTags );
1121 return Status
::newGood( $logId );
1125 * Is the tag name valid?
1127 * @param string $tag Tag that you are interested in creating
1131 public static function isTagNameValid( $tag ) {
1133 if ( $tag === '' ) {
1134 return Status
::newFatal( 'tags-create-no-name' );
1137 // tags cannot contain commas (used to be used as a delimiter in tag_summary table),
1138 // pipe (used as a delimiter between multiple tags in
1139 // SpecialRecentchanges and friends), or slashes (would break tag description messages in
1140 // MediaWiki namespace)
1141 if ( strpos( $tag, ',' ) !== false ||
strpos( $tag, '|' ) !== false
1142 ||
strpos( $tag, '/' ) !== false ) {
1143 return Status
::newFatal( 'tags-create-invalid-chars' );
1146 // could the MediaWiki namespace description messages be created?
1147 $title = Title
::makeTitleSafe( NS_MEDIAWIKI
, "Tag-$tag-description" );
1148 if ( is_null( $title ) ) {
1149 return Status
::newFatal( 'tags-create-invalid-title-chars' );
1152 return Status
::newGood();
1156 * Is it OK to allow the user to create this tag?
1158 * Extensions should NOT use this function. In most cases, a tag can be
1159 * defined using the ListDefinedTags hook without any checking.
1161 * @param string $tag Tag that you are interested in creating
1162 * @param User|null $user User whose permission you wish to check, or null if
1163 * you don't care (e.g. maintenance scripts)
1167 public static function canCreateTag( $tag, User
$user = null ) {
1168 if ( !is_null( $user ) ) {
1169 if ( !$user->isAllowed( 'managechangetags' ) ) {
1170 return Status
::newFatal( 'tags-manage-no-permission' );
1171 } elseif ( $user->getBlock() ) {
1172 // @TODO Ensure that the block does not apply to the `managechangetags`
1174 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1178 $status = self
::isTagNameValid( $tag );
1179 if ( !$status->isGood() ) {
1183 // does the tag already exist?
1184 $tagUsage = self
::tagUsageStatistics();
1185 if ( isset( $tagUsage[$tag] ) ||
in_array( $tag, self
::listDefinedTags() ) ) {
1186 return Status
::newFatal( 'tags-create-already-exists', $tag );
1190 $canCreateResult = Status
::newGood();
1191 Hooks
::run( 'ChangeTagCanCreate', [ $tag, $user, &$canCreateResult ] );
1192 return $canCreateResult;
1196 * Creates a tag by adding it to `change_tag_def` table.
1198 * Extensions should NOT use this function; they can use the ListDefinedTags
1201 * Includes a call to ChangeTag::canCreateTag(), so your code doesn't need to
1204 * @param string $tag
1205 * @param string $reason
1206 * @param User $user Who to give credit for the action
1207 * @param bool $ignoreWarnings Can be used for API interaction, default false
1208 * @param array $logEntryTags Change tags to apply to the entry
1209 * that will be created in the tag management log
1210 * @return Status If successful, the Status contains the ID of the added log
1211 * entry as its value
1214 public static function createTagWithChecks( $tag, $reason, User
$user,
1215 $ignoreWarnings = false, array $logEntryTags = []
1217 // are we allowed to do this?
1218 $result = self
::canCreateTag( $tag, $user );
1219 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1220 $result->value
= null;
1225 self
::defineTag( $tag );
1228 $logId = self
::logTagManagementAction( 'create', $tag, $reason, $user,
1229 null, $logEntryTags );
1231 return Status
::newGood( $logId );
1235 * Permanently removes all traces of a tag from the DB. Good for removing
1236 * misspelt or temporary tags.
1238 * This function should be directly called by maintenance scripts only, never
1239 * by user-facing code. See deleteTagWithChecks() for functionality that can
1240 * safely be exposed to users.
1242 * @param string $tag Tag to remove
1243 * @return Status The returned status will be good unless a hook changed it
1246 public static function deleteTagEverywhere( $tag ) {
1247 $dbw = wfGetDB( DB_MASTER
);
1248 $dbw->startAtomic( __METHOD__
);
1250 // fetch tag id, this must be done before calling undefineTag(), see T225564
1251 $tagId = MediaWikiServices
::getInstance()->getChangeTagDefStore()->getId( $tag );
1253 // set ctd_user_defined = 0
1254 self
::undefineTag( $tag );
1256 // delete from change_tag
1257 $dbw->delete( 'change_tag', [ 'ct_tag_id' => $tagId ], __METHOD__
);
1258 $dbw->delete( 'change_tag_def', [ 'ctd_name' => $tag ], __METHOD__
);
1259 $dbw->endAtomic( __METHOD__
);
1261 // give extensions a chance
1262 $status = Status
::newGood();
1263 Hooks
::run( 'ChangeTagAfterDelete', [ $tag, &$status ] );
1264 // let's not allow error results, as the actual tag deletion succeeded
1265 if ( !$status->isOK() ) {
1266 wfDebug( 'ChangeTagAfterDelete error condition downgraded to warning' );
1267 $status->setOK( true );
1270 // clear the memcache of defined tags
1271 self
::purgeTagCacheAll();
1277 * Is it OK to allow the user to delete this tag?
1279 * @param string $tag Tag that you are interested in deleting
1280 * @param User|null $user User whose permission you wish to check, or null if
1281 * you don't care (e.g. maintenance scripts)
1285 public static function canDeleteTag( $tag, User
$user = null ) {
1286 $tagUsage = self
::tagUsageStatistics();
1288 if ( !is_null( $user ) ) {
1289 if ( !$user->isAllowed( 'deletechangetags' ) ) {
1290 return Status
::newFatal( 'tags-delete-no-permission' );
1291 } elseif ( $user->getBlock() ) {
1292 // @TODO Ensure that the block does not apply to the `deletechangetags`
1294 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1298 if ( !isset( $tagUsage[$tag] ) && !in_array( $tag, self
::listDefinedTags() ) ) {
1299 return Status
::newFatal( 'tags-delete-not-found', $tag );
1302 if ( isset( $tagUsage[$tag] ) && $tagUsage[$tag] > self
::MAX_DELETE_USES
) {
1303 return Status
::newFatal( 'tags-delete-too-many-uses', $tag, self
::MAX_DELETE_USES
);
1306 $softwareDefined = self
::listSoftwareDefinedTags();
1307 if ( in_array( $tag, $softwareDefined ) ) {
1308 // extension-defined tags can't be deleted unless the extension
1309 // specifically allows it
1310 $status = Status
::newFatal( 'tags-delete-not-allowed' );
1312 // user-defined tags are deletable unless otherwise specified
1313 $status = Status
::newGood();
1316 Hooks
::run( 'ChangeTagCanDelete', [ $tag, $user, &$status ] );
1321 * Deletes a tag, checking whether it is allowed first, and adding a log entry
1324 * Includes a call to ChangeTag::canDeleteTag(), so your code doesn't need to
1327 * @param string $tag
1328 * @param string $reason
1329 * @param User $user Who to give credit for the action
1330 * @param bool $ignoreWarnings Can be used for API interaction, default false
1331 * @param array $logEntryTags Change tags to apply to the entry
1332 * that will be created in the tag management log
1333 * @return Status If successful, the Status contains the ID of the added log
1334 * entry as its value
1337 public static function deleteTagWithChecks( $tag, $reason, User
$user,
1338 $ignoreWarnings = false, array $logEntryTags = []
1340 // are we allowed to do this?
1341 $result = self
::canDeleteTag( $tag, $user );
1342 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1343 $result->value
= null;
1347 // store the tag usage statistics
1348 $tagUsage = self
::tagUsageStatistics();
1349 $hitcount = $tagUsage[$tag] ??
0;
1352 $deleteResult = self
::deleteTagEverywhere( $tag );
1353 if ( !$deleteResult->isOK() ) {
1354 return $deleteResult;
1358 $logId = self
::logTagManagementAction( 'delete', $tag, $reason, $user,
1359 $hitcount, $logEntryTags );
1361 $deleteResult->value
= $logId;
1362 return $deleteResult;
1366 * Lists those tags which core or extensions report as being "active".
1371 public static function listSoftwareActivatedTags() {
1373 $tags = self
::getSoftwareTags();
1374 if ( !Hooks
::isRegistered( 'ChangeTagsListActive' ) ) {
1377 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1378 return $cache->getWithSetCallback(
1379 $cache->makeKey( 'active-tags' ),
1380 WANObjectCache
::TTL_MINUTE
* 5,
1381 function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
1382 $setOpts +
= Database
::getCacheSetOptions( wfGetDB( DB_REPLICA
) );
1384 // Ask extensions which tags they consider active
1385 Hooks
::run( 'ChangeTagsListActive', [ &$tags ] );
1389 'checkKeys' => [ $cache->makeKey( 'active-tags' ) ],
1390 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1391 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1397 * Basically lists defined tags which count even if they aren't applied to anything.
1398 * It returns a union of the results of listExplicitlyDefinedTags()
1400 * @return string[] Array of strings: tags
1402 public static function listDefinedTags() {
1403 $tags1 = self
::listExplicitlyDefinedTags();
1404 $tags2 = self
::listSoftwareDefinedTags();
1405 return array_values( array_unique( array_merge( $tags1, $tags2 ) ) );
1409 * Lists tags explicitly defined in the `change_tag_def` table of the database.
1411 * Tries memcached first.
1413 * @return string[] Array of strings: tags
1416 public static function listExplicitlyDefinedTags() {
1417 $fname = __METHOD__
;
1419 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1420 return $cache->getWithSetCallback(
1421 $cache->makeKey( 'valid-tags-db' ),
1422 WANObjectCache
::TTL_MINUTE
* 5,
1423 function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
1424 $dbr = wfGetDB( DB_REPLICA
);
1426 $setOpts +
= Database
::getCacheSetOptions( $dbr );
1428 $tags = $dbr->selectFieldValues(
1431 [ 'ctd_user_defined' => 1 ],
1435 return array_filter( array_unique( $tags ) );
1438 'checkKeys' => [ $cache->makeKey( 'valid-tags-db' ) ],
1439 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1440 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1446 * Lists tags defined by core or extensions using the ListDefinedTags hook.
1447 * Extensions need only define those tags they deem to be in active use.
1449 * Tries memcached first.
1451 * @return string[] Array of strings: tags
1454 public static function listSoftwareDefinedTags() {
1455 // core defined tags
1456 $tags = self
::getSoftwareTags( true );
1457 if ( !Hooks
::isRegistered( 'ListDefinedTags' ) ) {
1460 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1461 return $cache->getWithSetCallback(
1462 $cache->makeKey( 'valid-tags-hook' ),
1463 WANObjectCache
::TTL_MINUTE
* 5,
1464 function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
1465 $setOpts +
= Database
::getCacheSetOptions( wfGetDB( DB_REPLICA
) );
1467 Hooks
::run( 'ListDefinedTags', [ &$tags ] );
1468 return array_filter( array_unique( $tags ) );
1471 'checkKeys' => [ $cache->makeKey( 'valid-tags-hook' ) ],
1472 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1473 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1479 * Invalidates the short-term cache of defined tags used by the
1480 * list*DefinedTags functions, as well as the tag statistics cache.
1483 public static function purgeTagCacheAll() {
1484 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1486 $cache->touchCheckKey( $cache->makeKey( 'active-tags' ) );
1487 $cache->touchCheckKey( $cache->makeKey( 'valid-tags-db' ) );
1488 $cache->touchCheckKey( $cache->makeKey( 'valid-tags-hook' ) );
1489 $cache->touchCheckKey( $cache->makeKey( 'tags-usage-statistics' ) );
1491 MediaWikiServices
::getInstance()->getChangeTagDefStore()->reloadMap();
1495 * Returns a map of any tags used on the wiki to number of edits
1496 * tagged with them, ordered descending by the hitcount.
1497 * This does not include tags defined somewhere that have never been applied.
1498 * @return array Array of string => int
1500 public static function tagUsageStatistics() {
1501 $fname = __METHOD__
;
1503 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1504 return $cache->getWithSetCallback(
1505 $cache->makeKey( 'tags-usage-statistics' ),
1506 WANObjectCache
::TTL_MINUTE
* 5,
1507 function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
1508 $dbr = wfGetDB( DB_REPLICA
);
1509 $res = $dbr->select(
1511 [ 'ctd_name', 'ctd_count' ],
1514 [ 'ORDER BY' => 'ctd_count DESC' ]
1518 foreach ( $res as $row ) {
1519 $out[$row->ctd_name
] = $row->ctd_count
;
1525 'checkKeys' => [ $cache->makeKey( 'tags-usage-statistics' ) ],
1526 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1527 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1533 * Indicate whether change tag editing UI is relevant
1535 * Returns true if the user has the necessary right and there are any
1536 * editable tags defined.
1538 * This intentionally doesn't check "any addable || any deletable", because
1539 * it seems like it would be more confusing than useful if the checkboxes
1540 * suddenly showed up because some abuse filter stopped defining a tag and
1541 * then suddenly disappeared when someone deleted all uses of that tag.
1546 public static function showTagEditingUI( User
$user ) {
1547 return $user->isAllowed( 'changetags' ) && (bool)self
::listExplicitlyDefinedTags();