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 ) ] ) )
153 // HACK MessageLocalizer doesn't have a way to set the right language on a RawMessage,
154 // so extract the language from $msg and use that.
155 // The language doesn't really matter, but we need to set it to avoid requesting
156 // the user's language from session-less entry points (T227233)
157 ->inLanguage( $msg->getLanguage() );
160 if ( $msg->isDisabled() ) {
161 // The message exists but is disabled, hide the tag.
165 // Message exists and isn't disabled, use it.
170 * Get a short description for a tag.
172 * Checks if message key "mediawiki:tag-$tag" exists. If it does not,
173 * returns the HTML-escaped tag name. Uses the message if the message
174 * exists, provided it is not disabled. If the message is disabled,
175 * we consider the tag hidden, and return false.
178 * @param MessageLocalizer $context
179 * @return string|bool Tag description or false if tag is to be hidden.
180 * @since 1.25 Returns false if tag is to be hidden.
182 public static function tagDescription( $tag, MessageLocalizer
$context ) {
183 $msg = self
::tagShortDescriptionMessage( $tag, $context );
184 return $msg ?
$msg->parse() : false;
188 * Get the message object for the tag's long description.
190 * Checks if message key "mediawiki:tag-$tag-description" exists. If it does not,
191 * or if message is disabled, returns false. Otherwise, returns the message object
192 * for the long description.
195 * @param MessageLocalizer $context
196 * @return Message|bool Message object of the tag long description or false if
197 * there is no description.
199 public static function tagLongDescriptionMessage( $tag, MessageLocalizer
$context ) {
200 $msg = $context->msg( "tag-$tag-description" );
201 if ( !$msg->exists() ) {
204 if ( $msg->isDisabled() ) {
205 // The message exists but is disabled, hide the description.
209 // Message exists and isn't disabled, use it.
214 * Get truncated message for the tag's long description.
216 * @param string $tag Tag name.
217 * @param int $length Maximum length of truncated message, including ellipsis.
218 * @param IContextSource $context
220 * @return string Truncated long tag description.
222 public static function truncateTagDescription( $tag, $length, IContextSource
$context ) {
223 // FIXME: Make this accept MessageLocalizer and Language instead of IContextSource
225 $originalDesc = self
::tagLongDescriptionMessage( $tag, $context );
226 // If there is no tag description, return empty string
227 if ( !$originalDesc ) {
231 $taglessDesc = Sanitizer
::stripAllTags( $originalDesc->parse() );
233 return $context->getLanguage()->truncateForVisual( $taglessDesc, $length );
237 * Add tags to a change given its rc_id, rev_id and/or log_id
239 * @param string|string[] $tags Tags to add to the change
240 * @param int|null $rc_id The rc_id of the change to add the tags to
241 * @param int|null $rev_id The rev_id of the change to add the tags to
242 * @param int|null $log_id The log_id of the change to add the tags to
243 * @param string|null $params Params to put in the ct_params field of table 'change_tag'
244 * @param RecentChange|null $rc Recent change, in case the tagging accompanies the action
245 * (this should normally be the case)
247 * @throws MWException
248 * @return bool False if no changes are made, otherwise true
250 public static function addTags( $tags, $rc_id = null, $rev_id = null,
251 $log_id = null, $params = null, RecentChange
$rc = null
253 $result = self
::updateTags( $tags, null, $rc_id, $rev_id, $log_id, $params, $rc );
254 return (bool)$result[0];
258 * Add and remove tags to/from a change given its rc_id, rev_id and/or log_id,
259 * without verifying that the tags exist or are valid. If a tag is present in
260 * both $tagsToAdd and $tagsToRemove, it will be removed.
262 * This function should only be used by extensions to manipulate tags they
263 * have registered using the ListDefinedTags hook. When dealing with user
264 * input, call updateTagsWithChecks() instead.
266 * @param string|array|null $tagsToAdd Tags to add to the change
267 * @param string|array|null $tagsToRemove Tags to remove from the change
268 * @param int|null &$rc_id The rc_id of the change to add the tags to.
269 * Pass a variable whose value is null if the rc_id is not relevant or unknown.
270 * @param int|null &$rev_id The rev_id of the change to add the tags to.
271 * Pass a variable whose value is null if the rev_id is not relevant or unknown.
272 * @param int|null &$log_id The log_id of the change to add the tags to.
273 * Pass a variable whose value is null if the log_id is not relevant or unknown.
274 * @param string|null $params Params to put in the ct_params field of table
275 * 'change_tag' when adding tags
276 * @param RecentChange|null $rc Recent change being tagged, in case the tagging accompanies
278 * @param User|null $user Tagging user, in case the tagging is subsequent to the tagged action
280 * @throws MWException When $rc_id, $rev_id and $log_id are all null
281 * @return array Index 0 is an array of tags actually added, index 1 is an
282 * array of tags actually removed, index 2 is an array of tags present on the
283 * revision or log entry before any changes were made
287 public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null,
288 &$rev_id = null, &$log_id = null, $params = null, RecentChange
$rc = null,
291 $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags...
292 $tagsToRemove = array_filter( (array)$tagsToRemove );
294 if ( !$rc_id && !$rev_id && !$log_id ) {
295 throw new MWException( 'At least one of: RCID, revision ID, and log ID MUST be ' .
296 'specified when adding or removing a tag from a change!' );
299 $dbw = wfGetDB( DB_MASTER
);
301 // Might as well look for rcids and so on.
303 // Info might be out of date, somewhat fractionally, on replica DB.
304 // LogEntry/LogPage and WikiPage match rev/log/rc timestamps,
305 // so use that relation to avoid full table scans.
307 $rc_id = $dbw->selectField(
308 [ 'logging', 'recentchanges' ],
312 'rc_timestamp = log_timestamp',
317 } elseif ( $rev_id ) {
318 $rc_id = $dbw->selectField(
319 [ 'revision', 'recentchanges' ],
323 'rc_timestamp = rev_timestamp',
324 'rc_this_oldid = rev_id'
329 } elseif ( !$log_id && !$rev_id ) {
330 // Info might be out of date, somewhat fractionally, on replica DB.
331 $log_id = $dbw->selectField(
334 [ 'rc_id' => $rc_id ],
337 $rev_id = $dbw->selectField(
340 [ 'rc_id' => $rc_id ],
345 if ( $log_id && !$rev_id ) {
346 $rev_id = $dbw->selectField(
349 [ 'ls_field' => 'associated_rev_id', 'ls_log_id' => $log_id ],
352 } elseif ( !$log_id && $rev_id ) {
353 $log_id = $dbw->selectField(
356 [ 'ls_field' => 'associated_rev_id', 'ls_value' => $rev_id ],
361 $prevTags = self
::getPrevTags( $rc_id, $log_id, $rev_id );
364 $tagsToAdd = array_values( array_diff( $tagsToAdd, $prevTags ) );
365 $newTags = array_unique( array_merge( $prevTags, $tagsToAdd ) );
368 $tagsToRemove = array_values( array_intersect( $tagsToRemove, $newTags ) );
369 $newTags = array_values( array_diff( $newTags, $tagsToRemove ) );
373 if ( $prevTags == $newTags ) {
374 return [ [], [], $prevTags ];
377 // insert a row into change_tag for each new tag
378 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
379 if ( count( $tagsToAdd ) ) {
380 $changeTagMapping = [];
381 foreach ( $tagsToAdd as $tag ) {
382 $changeTagMapping[$tag] = $changeTagDefStore->acquireId( $tag );
385 // T207881: update the counts at the end of the transaction
386 $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tagsToAdd, $fname ) {
389 [ 'ctd_count = ctd_count + 1' ],
390 [ 'ctd_name' => $tagsToAdd ],
396 foreach ( $tagsToAdd as $tag ) {
397 // Filter so we don't insert NULLs as zero accidentally.
398 // Keep in mind that $rc_id === null means "I don't care/know about the
399 // rc_id, just delete $tag on this revision/log entry". It doesn't
400 // mean "only delete tags on this revision/log WHERE rc_id IS NULL".
401 $tagsRows[] = array_filter(
403 'ct_rc_id' => $rc_id,
404 'ct_log_id' => $log_id,
405 'ct_rev_id' => $rev_id,
406 'ct_params' => $params,
407 'ct_tag_id' => $changeTagMapping[$tag] ??
null,
413 $dbw->insert( 'change_tag', $tagsRows, __METHOD__
, [ 'IGNORE' ] );
416 // delete from change_tag
417 if ( count( $tagsToRemove ) ) {
419 foreach ( $tagsToRemove as $tag ) {
420 $conds = array_filter(
422 'ct_rc_id' => $rc_id,
423 'ct_log_id' => $log_id,
424 'ct_rev_id' => $rev_id,
425 'ct_tag_id' => $changeTagDefStore->getId( $tag ),
428 $dbw->delete( 'change_tag', $conds, __METHOD__
);
429 if ( $dbw->affectedRows() ) {
430 // T207881: update the counts at the end of the transaction
431 $dbw->onTransactionPreCommitOrIdle( function () use ( $dbw, $tag, $fname ) {
434 [ 'ctd_count = ctd_count - 1' ],
435 [ 'ctd_name' => $tag ],
441 [ 'ctd_name' => $tag, 'ctd_count' => 0, 'ctd_user_defined' => 0 ],
449 Hooks
::run( 'ChangeTagsAfterUpdateTags', [ $tagsToAdd, $tagsToRemove, $prevTags,
450 $rc_id, $rev_id, $log_id, $params, $rc, $user ] );
452 return [ $tagsToAdd, $tagsToRemove, $prevTags ];
455 private static function getPrevTags( $rc_id = null, $log_id = null, $rev_id = null ) {
456 $conds = array_filter(
458 'ct_rc_id' => $rc_id,
459 'ct_log_id' => $log_id,
460 'ct_rev_id' => $rev_id,
464 $dbw = wfGetDB( DB_MASTER
);
465 $tagIds = $dbw->selectFieldValues( 'change_tag', 'ct_tag_id', $conds, __METHOD__
);
468 foreach ( $tagIds as $tagId ) {
469 $tags[] = MediaWikiServices
::getInstance()->getChangeTagDefStore()->getName( (int)$tagId );
476 * Helper function to generate a fatal status with a 'not-allowed' type error.
478 * @param string $msgOne Message key to use in the case of one tag
479 * @param string $msgMulti Message key to use in the case of more than one tag
480 * @param array $tags Restricted tags (passed as $1 into the message, count of
481 * $tags passed as $2)
485 protected static function restrictedTagError( $msgOne, $msgMulti, $tags ) {
486 $lang = RequestContext
::getMain()->getLanguage();
487 $count = count( $tags );
488 return Status
::newFatal( ( $count > 1 ) ?
$msgMulti : $msgOne,
489 $lang->commaList( $tags ), $count );
493 * Is it OK to allow the user to apply all the specified tags at the same time
494 * as they edit/make the change?
496 * Extensions should not use this function, unless directly handling a user
497 * request to add a tag to a revision or log entry that the user is making.
499 * @param array $tags Tags that you are interested in applying
500 * @param User|null $user User whose permission you wish to check, or null to
501 * check for a generic non-blocked user with the relevant rights
505 public static function canAddTagsAccompanyingChange( array $tags, User
$user = null ) {
506 if ( !is_null( $user ) ) {
507 if ( !$user->isAllowed( 'applychangetags' ) ) {
508 return Status
::newFatal( 'tags-apply-no-permission' );
509 } elseif ( $user->getBlock() ) {
510 // @TODO Ensure that the block does not apply to the `applychangetags`
512 return Status
::newFatal( 'tags-apply-blocked', $user->getName() );
516 // to be applied, a tag has to be explicitly defined
517 $allowedTags = self
::listExplicitlyDefinedTags();
518 Hooks
::run( 'ChangeTagsAllowedAdd', [ &$allowedTags, $tags, $user ] );
519 $disallowedTags = array_diff( $tags, $allowedTags );
520 if ( $disallowedTags ) {
521 return self
::restrictedTagError( 'tags-apply-not-allowed-one',
522 'tags-apply-not-allowed-multi', $disallowedTags );
525 return Status
::newGood();
529 * Adds tags to a given change, checking whether it is allowed first, but
530 * without adding a log entry. Useful for cases where the tag is being added
531 * along with the action that generated the change (e.g. tagging an edit as
534 * Extensions should not use this function, unless directly handling a user
535 * request to add a particular tag. Normally, extensions should call
536 * ChangeTags::updateTags() instead.
538 * @param array $tags Tags to apply
539 * @param int|null $rc_id The rc_id of the change to add the tags to
540 * @param int|null $rev_id The rev_id of the change to add the tags to
541 * @param int|null $log_id The log_id of the change to add the tags to
542 * @param string $params Params to put in the ct_params field of table
543 * 'change_tag' when adding tags
544 * @param User $user Who to give credit for the action
548 public static function addTagsAccompanyingChangeWithChecks(
549 array $tags, $rc_id, $rev_id, $log_id, $params, User
$user
551 // are we allowed to do this?
552 $result = self
::canAddTagsAccompanyingChange( $tags, $user );
553 if ( !$result->isOK() ) {
554 $result->value
= null;
559 self
::addTags( $tags, $rc_id, $rev_id, $log_id, $params );
561 return Status
::newGood( true );
565 * Is it OK to allow the user to adds and remove the given tags tags to/from a
568 * Extensions should not use this function, unless directly handling a user
569 * request to add or remove tags from an existing revision or log entry.
571 * @param array $tagsToAdd Tags that you are interested in adding
572 * @param array $tagsToRemove Tags that you are interested in removing
573 * @param User|null $user User whose permission you wish to check, or null to
574 * check for a generic non-blocked user with the relevant rights
578 public static function canUpdateTags( array $tagsToAdd, array $tagsToRemove,
581 if ( !is_null( $user ) ) {
582 if ( !$user->isAllowed( 'changetags' ) ) {
583 return Status
::newFatal( 'tags-update-no-permission' );
584 } elseif ( $user->getBlock() ) {
585 // @TODO Ensure that the block does not apply to the `changetags`
587 return Status
::newFatal( 'tags-update-blocked', $user->getName() );
592 // to be added, a tag has to be explicitly defined
593 // @todo Allow extensions to define tags that can be applied by users...
594 $explicitlyDefinedTags = self
::listExplicitlyDefinedTags();
595 $diff = array_diff( $tagsToAdd, $explicitlyDefinedTags );
597 return self
::restrictedTagError( 'tags-update-add-not-allowed-one',
598 'tags-update-add-not-allowed-multi', $diff );
602 if ( $tagsToRemove ) {
603 // to be removed, a tag must not be defined by an extension, or equivalently it
604 // has to be either explicitly defined or not defined at all
605 // (assuming no edge case of a tag both explicitly-defined and extension-defined)
606 $softwareDefinedTags = self
::listSoftwareDefinedTags();
607 $intersect = array_intersect( $tagsToRemove, $softwareDefinedTags );
609 return self
::restrictedTagError( 'tags-update-remove-not-allowed-one',
610 'tags-update-remove-not-allowed-multi', $intersect );
614 return Status
::newGood();
618 * Adds and/or removes tags to/from a given change, checking whether it is
619 * allowed first, and adding a log entry afterwards.
621 * Includes a call to ChangeTags::canUpdateTags(), so your code doesn't need
622 * to do that. However, it doesn't check whether the *_id parameters are a
623 * valid combination. That is up to you to enforce. See ApiTag::execute() for
626 * Extensions should generally avoid this function. Call
627 * ChangeTags::updateTags() instead, unless directly handling a user request
628 * to add or remove tags from an existing revision or log entry.
630 * @param array|null $tagsToAdd If none, pass [] or null
631 * @param array|null $tagsToRemove If none, pass [] or null
632 * @param int|null $rc_id The rc_id of the change to add the tags to
633 * @param int|null $rev_id The rev_id of the change to add the tags to
634 * @param int|null $log_id The log_id of the change to add the tags to
635 * @param string|null $params Params to put in the ct_params field of table
636 * 'change_tag' when adding tags
637 * @param string $reason Comment for the log
638 * @param User $user Who to give credit for the action
639 * @return Status If successful, the value of this Status object will be an
640 * object (stdClass) with the following fields:
641 * - logId: the ID of the added log entry, or null if no log entry was added
642 * (i.e. no operation was performed)
643 * - addedTags: an array containing the tags that were actually added
644 * - removedTags: an array containing the tags that were actually removed
647 public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
648 $rc_id, $rev_id, $log_id, $params, $reason, User
$user
650 if ( is_null( $tagsToAdd ) ) {
653 if ( is_null( $tagsToRemove ) ) {
656 if ( !$tagsToAdd && !$tagsToRemove ) {
657 // no-op, don't bother
658 return Status
::newGood( (object)[
665 // are we allowed to do this?
666 $result = self
::canUpdateTags( $tagsToAdd, $tagsToRemove, $user );
667 if ( !$result->isOK() ) {
668 $result->value
= null;
672 // basic rate limiting
673 if ( $user->pingLimiter( 'changetag' ) ) {
674 return Status
::newFatal( 'actionthrottledtext' );
678 list( $tagsAdded, $tagsRemoved, $initialTags ) = self
::updateTags( $tagsToAdd,
679 $tagsToRemove, $rc_id, $rev_id, $log_id, $params, null, $user );
680 if ( !$tagsAdded && !$tagsRemoved ) {
681 // no-op, don't log it
682 return Status
::newGood( (object)[
690 $logEntry = new ManualLogEntry( 'tag', 'update' );
691 $logEntry->setPerformer( $user );
692 $logEntry->setComment( $reason );
694 // find the appropriate target page
696 $rev = Revision
::newFromId( $rev_id );
698 $logEntry->setTarget( $rev->getTitle() );
700 } elseif ( $log_id ) {
701 // This function is from revision deletion logic and has nothing to do with
702 // change tags, but it appears to be the only other place in core where we
703 // perform logged actions on log items.
704 $logEntry->setTarget( RevDelLogList
::suggestTarget( null, [ $log_id ] ) );
707 if ( !$logEntry->getTarget() ) {
708 // target is required, so we have to set something
709 $logEntry->setTarget( SpecialPage
::getTitleFor( 'Tags' ) );
713 '4::revid' => $rev_id,
714 '5::logid' => $log_id,
715 '6:list:tagsAdded' => $tagsAdded,
716 '7:number:tagsAddedCount' => count( $tagsAdded ),
717 '8:list:tagsRemoved' => $tagsRemoved,
718 '9:number:tagsRemovedCount' => count( $tagsRemoved ),
719 'initialTags' => $initialTags,
721 $logEntry->setParameters( $logParams );
722 $logEntry->setRelations( [ 'Tag' => array_merge( $tagsAdded, $tagsRemoved ) ] );
724 $dbw = wfGetDB( DB_MASTER
);
725 $logId = $logEntry->insert( $dbw );
726 // Only send this to UDP, not RC, similar to patrol events
727 $logEntry->publish( $logId, 'udp' );
729 return Status
::newGood( (object)[
731 'addedTags' => $tagsAdded,
732 'removedTags' => $tagsRemoved,
737 * Applies all tags-related changes to a query.
738 * Handles selecting tags, and filtering.
739 * Needs $tables to be set up properly, so we can figure out which join conditions to use.
741 * WARNING: If $filter_tag contains more than one tag, this function will add DISTINCT,
742 * which may cause performance problems for your query unless you put the ID field of your
743 * table at the end of the ORDER BY, and set a GROUP BY equal to the ORDER BY. For example,
744 * if you had ORDER BY foo_timestamp DESC, you will now need GROUP BY foo_timestamp, foo_id
745 * ORDER BY foo_timestamp DESC, foo_id DESC.
747 * @param string|array &$tables Table names, see Database::select
748 * @param string|array &$fields Fields used in query, see Database::select
749 * @param string|array &$conds Conditions used in query, see Database::select
750 * @param array &$join_conds Join conditions, see Database::select
751 * @param string|array &$options Options, see Database::select
752 * @param string|array $filter_tag Tag(s) to select on
754 * @throws MWException When unable to determine appropriate JOIN condition for tagging
756 public static function modifyDisplayQuery( &$tables, &$fields, &$conds,
757 &$join_conds, &$options, $filter_tag = ''
759 global $wgUseTagFilter;
761 // Normalize to arrays
762 $tables = (array)$tables;
763 $fields = (array)$fields;
764 $conds = (array)$conds;
765 $options = (array)$options;
767 $fields['ts_tags'] = self
::makeTagSummarySubquery( $tables );
769 // Figure out which ID field to use
770 if ( in_array( 'recentchanges', $tables ) ) {
771 $join_cond = 'ct_rc_id=rc_id';
772 } elseif ( in_array( 'logging', $tables ) ) {
773 $join_cond = 'ct_log_id=log_id';
774 } elseif ( in_array( 'revision', $tables ) ) {
775 $join_cond = 'ct_rev_id=rev_id';
776 } elseif ( in_array( 'archive', $tables ) ) {
777 $join_cond = 'ct_rev_id=ar_rev_id';
779 throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' );
782 if ( $wgUseTagFilter && $filter_tag ) {
783 // Somebody wants to filter on a tag.
784 // Add an INNER JOIN on change_tag
786 $tables[] = 'change_tag';
787 $join_conds['change_tag'] = [ 'JOIN', $join_cond ];
789 $changeTagDefStore = MediaWikiServices
::getInstance()->getChangeTagDefStore();
790 foreach ( (array)$filter_tag as $filterTagName ) {
792 $filterTagIds[] = $changeTagDefStore->getId( $filterTagName );
793 } catch ( NameTableAccessException
$exception ) {
800 if ( $filterTagIds !== [] ) {
801 $conds['ct_tag_id'] = $filterTagIds;
805 is_array( $filter_tag ) && count( $filter_tag ) > 1 &&
806 !in_array( 'DISTINCT', $options )
808 $options[] = 'DISTINCT';
814 * Make the tag summary subquery based on the given tables and return it.
816 * @param string|array $tables Table names, see Database::select
818 * @return string tag summary subqeury
819 * @throws MWException When unable to determine appropriate JOIN condition for tagging
821 public static function makeTagSummarySubquery( $tables ) {
822 // Normalize to arrays
823 $tables = (array)$tables;
825 // Figure out which ID field to use
826 if ( in_array( 'recentchanges', $tables ) ) {
827 $join_cond = 'ct_rc_id=rc_id';
828 } elseif ( in_array( 'logging', $tables ) ) {
829 $join_cond = 'ct_log_id=log_id';
830 } elseif ( in_array( 'revision', $tables ) ) {
831 $join_cond = 'ct_rev_id=rev_id';
832 } elseif ( in_array( 'archive', $tables ) ) {
833 $join_cond = 'ct_rev_id=ar_rev_id';
835 throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' );
838 $tagTables = [ 'change_tag', 'change_tag_def' ];
839 $join_cond_ts_tags = [ 'change_tag_def' => [ 'JOIN', 'ct_tag_id=ctd_id' ] ];
842 return wfGetDB( DB_REPLICA
)->buildGroupConcatField(
843 ',', $tagTables, $field, $join_cond, $join_cond_ts_tags
848 * Build a text box to select a change tag
850 * @param string $selected Tag to select by default
851 * @param bool $ooui Use an OOUI TextInputWidget as selector instead of a non-OOUI input field
852 * You need to call OutputPage::enableOOUI() yourself.
853 * @param IContextSource|null $context
854 * @note Even though it takes null as a valid argument, an IContextSource is preferred
855 * in a new code, as the null value can change in the future
856 * @return array an array of (label, selector)
858 public static function buildTagFilterSelector(
859 $selected = '', $ooui = false, IContextSource
$context = null
862 $context = RequestContext
::getMain();
865 $config = $context->getConfig();
866 if ( !$config->get( 'UseTagFilter' ) ||
!count( self
::listDefinedTags() ) ) {
873 [ 'for' => 'tagfilter' ],
874 $context->msg( 'tag-filter' )->parse()
879 $data[] = new OOUI\
TextInputWidget( [
881 'name' => 'tagfilter',
882 'value' => $selected,
883 'classes' => 'mw-tagfilter-input',
886 $data[] = Xml
::input(
890 [ 'class' => 'mw-tagfilter-input mw-ui-input mw-ui-input-inline', 'id' => 'tagfilter' ]
898 * Set ctd_user_defined = 1 in change_tag_def without checking that the tag name is valid.
899 * Extensions should NOT use this function; they can use the ListDefinedTags
902 * @param string $tag Tag to create
905 public static function defineTag( $tag ) {
906 $dbw = wfGetDB( DB_MASTER
);
909 'ctd_user_defined' => 1,
916 [ 'ctd_user_defined' => 1 ],
920 // clear the memcache of defined tags
921 self
::purgeTagCacheAll();
925 * Update ctd_user_defined = 0 field in change_tag_def.
926 * The tag may remain in use by extensions, and may still show up as 'defined'
927 * if an extension is setting it from the ListDefinedTags hook.
929 * @param string $tag Tag to remove
932 public static function undefineTag( $tag ) {
933 $dbw = wfGetDB( DB_MASTER
);
937 [ 'ctd_user_defined' => 0 ],
938 [ 'ctd_name' => $tag ],
944 [ 'ctd_name' => $tag, 'ctd_count' => 0 ],
948 // clear the memcache of defined tags
949 self
::purgeTagCacheAll();
953 * Writes a tag action into the tag management log.
955 * @param string $action
957 * @param string $reason
958 * @param User $user Who to attribute the action to
959 * @param int|null $tagCount For deletion only, how many usages the tag had before
961 * @param array $logEntryTags Change tags to apply to the entry
962 * that will be created in the tag management log
963 * @return int ID of the inserted log entry
966 protected static function logTagManagementAction( $action, $tag, $reason,
967 User
$user, $tagCount = null, array $logEntryTags = []
969 $dbw = wfGetDB( DB_MASTER
);
971 $logEntry = new ManualLogEntry( 'managetags', $action );
972 $logEntry->setPerformer( $user );
973 // target page is not relevant, but it has to be set, so we just put in
974 // the title of Special:Tags
975 $logEntry->setTarget( Title
::newFromText( 'Special:Tags' ) );
976 $logEntry->setComment( $reason );
978 $params = [ '4::tag' => $tag ];
979 if ( !is_null( $tagCount ) ) {
980 $params['5:number:count'] = $tagCount;
982 $logEntry->setParameters( $params );
983 $logEntry->setRelations( [ 'Tag' => $tag ] );
984 $logEntry->setTags( $logEntryTags );
986 $logId = $logEntry->insert( $dbw );
987 $logEntry->publish( $logId );
992 * Is it OK to allow the user to activate this tag?
994 * @param string $tag Tag that you are interested in activating
995 * @param User|null $user User whose permission you wish to check, or null if
996 * you don't care (e.g. maintenance scripts)
1000 public static function canActivateTag( $tag, User
$user = null ) {
1001 if ( !is_null( $user ) ) {
1002 if ( !$user->isAllowed( 'managechangetags' ) ) {
1003 return Status
::newFatal( 'tags-manage-no-permission' );
1004 } elseif ( $user->getBlock() ) {
1005 // @TODO Ensure that the block does not apply to the `managechangetags`
1007 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1011 // defined tags cannot be activated (a defined tag is either extension-
1012 // defined, in which case the extension chooses whether or not to active it;
1013 // or user-defined, in which case it is considered active)
1014 $definedTags = self
::listDefinedTags();
1015 if ( in_array( $tag, $definedTags ) ) {
1016 return Status
::newFatal( 'tags-activate-not-allowed', $tag );
1019 // non-existing tags cannot be activated
1020 $tagUsage = self
::tagUsageStatistics();
1021 if ( !isset( $tagUsage[$tag] ) ) { // we already know the tag is undefined
1022 return Status
::newFatal( 'tags-activate-not-found', $tag );
1025 return Status
::newGood();
1029 * Activates a tag, checking whether it is allowed first, and adding a log
1032 * Includes a call to ChangeTag::canActivateTag(), so your code doesn't need
1035 * @param string $tag
1036 * @param string $reason
1037 * @param User $user Who to give credit for the action
1038 * @param bool $ignoreWarnings Can be used for API interaction, default false
1039 * @param array $logEntryTags Change tags to apply to the entry
1040 * that will be created in the tag management log
1041 * @return Status If successful, the Status contains the ID of the added log
1042 * entry as its value
1045 public static function activateTagWithChecks( $tag, $reason, User
$user,
1046 $ignoreWarnings = false, array $logEntryTags = []
1048 // are we allowed to do this?
1049 $result = self
::canActivateTag( $tag, $user );
1050 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1051 $result->value
= null;
1056 self
::defineTag( $tag );
1059 $logId = self
::logTagManagementAction( 'activate', $tag, $reason, $user,
1060 null, $logEntryTags );
1062 return Status
::newGood( $logId );
1066 * Is it OK to allow the user to deactivate this tag?
1068 * @param string $tag Tag that you are interested in deactivating
1069 * @param User|null $user User whose permission you wish to check, or null if
1070 * you don't care (e.g. maintenance scripts)
1074 public static function canDeactivateTag( $tag, User
$user = null ) {
1075 if ( !is_null( $user ) ) {
1076 if ( !$user->isAllowed( 'managechangetags' ) ) {
1077 return Status
::newFatal( 'tags-manage-no-permission' );
1078 } elseif ( $user->getBlock() ) {
1079 // @TODO Ensure that the block does not apply to the `managechangetags`
1081 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1085 // only explicitly-defined tags can be deactivated
1086 $explicitlyDefinedTags = self
::listExplicitlyDefinedTags();
1087 if ( !in_array( $tag, $explicitlyDefinedTags ) ) {
1088 return Status
::newFatal( 'tags-deactivate-not-allowed', $tag );
1090 return Status
::newGood();
1094 * Deactivates a tag, checking whether it is allowed first, and adding a log
1097 * Includes a call to ChangeTag::canDeactivateTag(), so your code doesn't need
1100 * @param string $tag
1101 * @param string $reason
1102 * @param User $user Who to give credit for the action
1103 * @param bool $ignoreWarnings Can be used for API interaction, default false
1104 * @param array $logEntryTags Change tags to apply to the entry
1105 * that will be created in the tag management log
1106 * @return Status If successful, the Status contains the ID of the added log
1107 * entry as its value
1110 public static function deactivateTagWithChecks( $tag, $reason, User
$user,
1111 $ignoreWarnings = false, array $logEntryTags = []
1113 // are we allowed to do this?
1114 $result = self
::canDeactivateTag( $tag, $user );
1115 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1116 $result->value
= null;
1121 self
::undefineTag( $tag );
1124 $logId = self
::logTagManagementAction( 'deactivate', $tag, $reason, $user,
1125 null, $logEntryTags );
1127 return Status
::newGood( $logId );
1131 * Is the tag name valid?
1133 * @param string $tag Tag that you are interested in creating
1137 public static function isTagNameValid( $tag ) {
1139 if ( $tag === '' ) {
1140 return Status
::newFatal( 'tags-create-no-name' );
1143 // tags cannot contain commas (used to be used as a delimiter in tag_summary table),
1144 // pipe (used as a delimiter between multiple tags in
1145 // SpecialRecentchanges and friends), or slashes (would break tag description messages in
1146 // MediaWiki namespace)
1147 if ( strpos( $tag, ',' ) !== false ||
strpos( $tag, '|' ) !== false
1148 ||
strpos( $tag, '/' ) !== false ) {
1149 return Status
::newFatal( 'tags-create-invalid-chars' );
1152 // could the MediaWiki namespace description messages be created?
1153 $title = Title
::makeTitleSafe( NS_MEDIAWIKI
, "Tag-$tag-description" );
1154 if ( is_null( $title ) ) {
1155 return Status
::newFatal( 'tags-create-invalid-title-chars' );
1158 return Status
::newGood();
1162 * Is it OK to allow the user to create this tag?
1164 * Extensions should NOT use this function. In most cases, a tag can be
1165 * defined using the ListDefinedTags hook without any checking.
1167 * @param string $tag Tag that you are interested in creating
1168 * @param User|null $user User whose permission you wish to check, or null if
1169 * you don't care (e.g. maintenance scripts)
1173 public static function canCreateTag( $tag, User
$user = null ) {
1174 if ( !is_null( $user ) ) {
1175 if ( !$user->isAllowed( 'managechangetags' ) ) {
1176 return Status
::newFatal( 'tags-manage-no-permission' );
1177 } elseif ( $user->getBlock() ) {
1178 // @TODO Ensure that the block does not apply to the `managechangetags`
1180 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1184 $status = self
::isTagNameValid( $tag );
1185 if ( !$status->isGood() ) {
1189 // does the tag already exist?
1190 $tagUsage = self
::tagUsageStatistics();
1191 if ( isset( $tagUsage[$tag] ) ||
in_array( $tag, self
::listDefinedTags() ) ) {
1192 return Status
::newFatal( 'tags-create-already-exists', $tag );
1196 $canCreateResult = Status
::newGood();
1197 Hooks
::run( 'ChangeTagCanCreate', [ $tag, $user, &$canCreateResult ] );
1198 return $canCreateResult;
1202 * Creates a tag by adding it to `change_tag_def` table.
1204 * Extensions should NOT use this function; they can use the ListDefinedTags
1207 * Includes a call to ChangeTag::canCreateTag(), so your code doesn't need to
1210 * @param string $tag
1211 * @param string $reason
1212 * @param User $user Who to give credit for the action
1213 * @param bool $ignoreWarnings Can be used for API interaction, default false
1214 * @param array $logEntryTags Change tags to apply to the entry
1215 * that will be created in the tag management log
1216 * @return Status If successful, the Status contains the ID of the added log
1217 * entry as its value
1220 public static function createTagWithChecks( $tag, $reason, User
$user,
1221 $ignoreWarnings = false, array $logEntryTags = []
1223 // are we allowed to do this?
1224 $result = self
::canCreateTag( $tag, $user );
1225 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1226 $result->value
= null;
1231 self
::defineTag( $tag );
1234 $logId = self
::logTagManagementAction( 'create', $tag, $reason, $user,
1235 null, $logEntryTags );
1237 return Status
::newGood( $logId );
1241 * Permanently removes all traces of a tag from the DB. Good for removing
1242 * misspelt or temporary tags.
1244 * This function should be directly called by maintenance scripts only, never
1245 * by user-facing code. See deleteTagWithChecks() for functionality that can
1246 * safely be exposed to users.
1248 * @param string $tag Tag to remove
1249 * @return Status The returned status will be good unless a hook changed it
1252 public static function deleteTagEverywhere( $tag ) {
1253 $dbw = wfGetDB( DB_MASTER
);
1254 $dbw->startAtomic( __METHOD__
);
1256 // fetch tag id, this must be done before calling undefineTag(), see T225564
1257 $tagId = MediaWikiServices
::getInstance()->getChangeTagDefStore()->getId( $tag );
1259 // set ctd_user_defined = 0
1260 self
::undefineTag( $tag );
1262 // delete from change_tag
1263 $dbw->delete( 'change_tag', [ 'ct_tag_id' => $tagId ], __METHOD__
);
1264 $dbw->delete( 'change_tag_def', [ 'ctd_name' => $tag ], __METHOD__
);
1265 $dbw->endAtomic( __METHOD__
);
1267 // give extensions a chance
1268 $status = Status
::newGood();
1269 Hooks
::run( 'ChangeTagAfterDelete', [ $tag, &$status ] );
1270 // let's not allow error results, as the actual tag deletion succeeded
1271 if ( !$status->isOK() ) {
1272 wfDebug( 'ChangeTagAfterDelete error condition downgraded to warning' );
1273 $status->setOK( true );
1276 // clear the memcache of defined tags
1277 self
::purgeTagCacheAll();
1283 * Is it OK to allow the user to delete this tag?
1285 * @param string $tag Tag that you are interested in deleting
1286 * @param User|null $user User whose permission you wish to check, or null if
1287 * you don't care (e.g. maintenance scripts)
1291 public static function canDeleteTag( $tag, User
$user = null ) {
1292 $tagUsage = self
::tagUsageStatistics();
1294 if ( !is_null( $user ) ) {
1295 if ( !$user->isAllowed( 'deletechangetags' ) ) {
1296 return Status
::newFatal( 'tags-delete-no-permission' );
1297 } elseif ( $user->getBlock() ) {
1298 // @TODO Ensure that the block does not apply to the `deletechangetags`
1300 return Status
::newFatal( 'tags-manage-blocked', $user->getName() );
1304 if ( !isset( $tagUsage[$tag] ) && !in_array( $tag, self
::listDefinedTags() ) ) {
1305 return Status
::newFatal( 'tags-delete-not-found', $tag );
1308 if ( isset( $tagUsage[$tag] ) && $tagUsage[$tag] > self
::MAX_DELETE_USES
) {
1309 return Status
::newFatal( 'tags-delete-too-many-uses', $tag, self
::MAX_DELETE_USES
);
1312 $softwareDefined = self
::listSoftwareDefinedTags();
1313 if ( in_array( $tag, $softwareDefined ) ) {
1314 // extension-defined tags can't be deleted unless the extension
1315 // specifically allows it
1316 $status = Status
::newFatal( 'tags-delete-not-allowed' );
1318 // user-defined tags are deletable unless otherwise specified
1319 $status = Status
::newGood();
1322 Hooks
::run( 'ChangeTagCanDelete', [ $tag, $user, &$status ] );
1327 * Deletes a tag, checking whether it is allowed first, and adding a log entry
1330 * Includes a call to ChangeTag::canDeleteTag(), so your code doesn't need to
1333 * @param string $tag
1334 * @param string $reason
1335 * @param User $user Who to give credit for the action
1336 * @param bool $ignoreWarnings Can be used for API interaction, default false
1337 * @param array $logEntryTags Change tags to apply to the entry
1338 * that will be created in the tag management log
1339 * @return Status If successful, the Status contains the ID of the added log
1340 * entry as its value
1343 public static function deleteTagWithChecks( $tag, $reason, User
$user,
1344 $ignoreWarnings = false, array $logEntryTags = []
1346 // are we allowed to do this?
1347 $result = self
::canDeleteTag( $tag, $user );
1348 if ( $ignoreWarnings ?
!$result->isOK() : !$result->isGood() ) {
1349 $result->value
= null;
1353 // store the tag usage statistics
1354 $tagUsage = self
::tagUsageStatistics();
1355 $hitcount = $tagUsage[$tag] ??
0;
1358 $deleteResult = self
::deleteTagEverywhere( $tag );
1359 if ( !$deleteResult->isOK() ) {
1360 return $deleteResult;
1364 $logId = self
::logTagManagementAction( 'delete', $tag, $reason, $user,
1365 $hitcount, $logEntryTags );
1367 $deleteResult->value
= $logId;
1368 return $deleteResult;
1372 * Lists those tags which core or extensions report as being "active".
1377 public static function listSoftwareActivatedTags() {
1379 $tags = self
::getSoftwareTags();
1380 if ( !Hooks
::isRegistered( 'ChangeTagsListActive' ) ) {
1383 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1384 return $cache->getWithSetCallback(
1385 $cache->makeKey( 'active-tags' ),
1386 WANObjectCache
::TTL_MINUTE
* 5,
1387 function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
1388 $setOpts +
= Database
::getCacheSetOptions( wfGetDB( DB_REPLICA
) );
1390 // Ask extensions which tags they consider active
1391 Hooks
::run( 'ChangeTagsListActive', [ &$tags ] );
1395 'checkKeys' => [ $cache->makeKey( 'active-tags' ) ],
1396 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1397 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1403 * Basically lists defined tags which count even if they aren't applied to anything.
1404 * It returns a union of the results of listExplicitlyDefinedTags()
1406 * @return string[] Array of strings: tags
1408 public static function listDefinedTags() {
1409 $tags1 = self
::listExplicitlyDefinedTags();
1410 $tags2 = self
::listSoftwareDefinedTags();
1411 return array_values( array_unique( array_merge( $tags1, $tags2 ) ) );
1415 * Lists tags explicitly defined in the `change_tag_def` table of the database.
1417 * Tries memcached first.
1419 * @return string[] Array of strings: tags
1422 public static function listExplicitlyDefinedTags() {
1423 $fname = __METHOD__
;
1425 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1426 return $cache->getWithSetCallback(
1427 $cache->makeKey( 'valid-tags-db' ),
1428 WANObjectCache
::TTL_MINUTE
* 5,
1429 function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
1430 $dbr = wfGetDB( DB_REPLICA
);
1432 $setOpts +
= Database
::getCacheSetOptions( $dbr );
1434 $tags = $dbr->selectFieldValues(
1437 [ 'ctd_user_defined' => 1 ],
1441 return array_filter( array_unique( $tags ) );
1444 'checkKeys' => [ $cache->makeKey( 'valid-tags-db' ) ],
1445 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1446 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1452 * Lists tags defined by core or extensions using the ListDefinedTags hook.
1453 * Extensions need only define those tags they deem to be in active use.
1455 * Tries memcached first.
1457 * @return string[] Array of strings: tags
1460 public static function listSoftwareDefinedTags() {
1461 // core defined tags
1462 $tags = self
::getSoftwareTags( true );
1463 if ( !Hooks
::isRegistered( 'ListDefinedTags' ) ) {
1466 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1467 return $cache->getWithSetCallback(
1468 $cache->makeKey( 'valid-tags-hook' ),
1469 WANObjectCache
::TTL_MINUTE
* 5,
1470 function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
1471 $setOpts +
= Database
::getCacheSetOptions( wfGetDB( DB_REPLICA
) );
1473 Hooks
::run( 'ListDefinedTags', [ &$tags ] );
1474 return array_filter( array_unique( $tags ) );
1477 'checkKeys' => [ $cache->makeKey( 'valid-tags-hook' ) ],
1478 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1479 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1485 * Invalidates the short-term cache of defined tags used by the
1486 * list*DefinedTags functions, as well as the tag statistics cache.
1489 public static function purgeTagCacheAll() {
1490 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1492 $cache->touchCheckKey( $cache->makeKey( 'active-tags' ) );
1493 $cache->touchCheckKey( $cache->makeKey( 'valid-tags-db' ) );
1494 $cache->touchCheckKey( $cache->makeKey( 'valid-tags-hook' ) );
1495 $cache->touchCheckKey( $cache->makeKey( 'tags-usage-statistics' ) );
1497 MediaWikiServices
::getInstance()->getChangeTagDefStore()->reloadMap();
1501 * Returns a map of any tags used on the wiki to number of edits
1502 * tagged with them, ordered descending by the hitcount.
1503 * This does not include tags defined somewhere that have never been applied.
1504 * @return array Array of string => int
1506 public static function tagUsageStatistics() {
1507 $fname = __METHOD__
;
1509 $cache = MediaWikiServices
::getInstance()->getMainWANObjectCache();
1510 return $cache->getWithSetCallback(
1511 $cache->makeKey( 'tags-usage-statistics' ),
1512 WANObjectCache
::TTL_MINUTE
* 5,
1513 function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
1514 $dbr = wfGetDB( DB_REPLICA
);
1515 $res = $dbr->select(
1517 [ 'ctd_name', 'ctd_count' ],
1520 [ 'ORDER BY' => 'ctd_count DESC' ]
1524 foreach ( $res as $row ) {
1525 $out[$row->ctd_name
] = $row->ctd_count
;
1531 'checkKeys' => [ $cache->makeKey( 'tags-usage-statistics' ) ],
1532 'lockTSE' => WANObjectCache
::TTL_MINUTE
* 5,
1533 'pcTTL' => WANObjectCache
::TTL_PROC_LONG
1539 * Indicate whether change tag editing UI is relevant
1541 * Returns true if the user has the necessary right and there are any
1542 * editable tags defined.
1544 * This intentionally doesn't check "any addable || any deletable", because
1545 * it seems like it would be more confusing than useful if the checkboxes
1546 * suddenly showed up because some abuse filter stopped defining a tag and
1547 * then suddenly disappeared when someone deleted all uses of that tag.
1552 public static function showTagEditingUI( User
$user ) {
1553 return $user->isAllowed( 'changetags' ) && (bool)self
::listExplicitlyDefinedTags();