}
/**
- * Get a short description for a tag.
+ * Get the message object for the tag's short description.
*
* Checks if message key "mediawiki:tag-$tag" exists. If it does not,
- * returns the HTML-escaped tag name. Uses the message if the message
- * exists, provided it is not disabled. If the message is disabled,
- * we consider the tag hidden, and return false.
+ * returns the tag name in a RawMessage. If the message exists, it is
+ * used, provided it is not disabled. If the message is disabled, we
+ * consider the tag hidden, and return false.
*
+ * @since 1.34
* @param string $tag
* @param MessageLocalizer $context
- * @return string|bool Tag description or false if tag is to be hidden.
- * @since 1.25 Returns false if tag is to be hidden.
+ * @return Message|bool Tag description, or false if tag is to be hidden.
*/
- public static function tagDescription( $tag, MessageLocalizer $context ) {
+ public static function tagShortDescriptionMessage( $tag, MessageLocalizer $context ) {
$msg = $context->msg( "tag-$tag" );
if ( !$msg->exists() ) {
- // No such message, so return the HTML-escaped tag name.
- return htmlspecialchars( $tag );
+ // No such message
+ return new RawMessage( '$1', [ Message::plaintextParam( $tag ) ] );
}
if ( $msg->isDisabled() ) {
// The message exists but is disabled, hide the tag.
}
// Message exists and isn't disabled, use it.
- return $msg->parse();
+ return $msg;
+ }
+
+ /**
+ * Get a short description for a tag.
+ *
+ * Checks if message key "mediawiki:tag-$tag" exists. If it does not,
+ * returns the HTML-escaped tag name. Uses the message if the message
+ * exists, provided it is not disabled. If the message is disabled,
+ * we consider the tag hidden, and return false.
+ *
+ * @param string $tag
+ * @param MessageLocalizer $context
+ * @return string|bool Tag description or false if tag is to be hidden.
+ * @since 1.25 Returns false if tag is to be hidden.
+ */
+ public static function tagDescription( $tag, MessageLocalizer $context ) {
+ $msg = self::tagShortDescriptionMessage( $tag, $context );
+ return $msg ? $msg->parse() : false;
}
/**
* ChangeTags::updateTags() instead, unless directly handling a user request
* to add or remove tags from an existing revision or log entry.
*
- * @param array|null $tagsToAdd If none, pass array() or null
- * @param array|null $tagsToRemove If none, pass array() or null
+ * @param array|null $tagsToAdd If none, pass [] or null
+ * @param array|null $tagsToRemove If none, pass [] or null
* @param int|null $rc_id The rc_id of the change to add the tags to
* @param int|null $rev_id The rev_id of the change to add the tags to
* @param int|null $log_id The log_id of the change to add the tags to
$dbw = wfGetDB( DB_MASTER );
$dbw->startAtomic( __METHOD__ );
+ // fetch tag id, this must be done before calling undefineTag(), see T225564
+ $tagId = MediaWikiServices::getInstance()->getChangeTagDefStore()->getId( $tag );
+
// set ctd_user_defined = 0
self::undefineTag( $tag );
// delete from change_tag
- $tagId = MediaWikiServices::getInstance()->getChangeTagDefStore()->getId( $tag );
$dbw->delete( 'change_tag', [ 'ct_tag_id' => $tagId ], __METHOD__ );
$dbw->delete( 'change_tag_def', [ 'ctd_name' => $tag ], __METHOD__ );
$dbw->endAtomic( __METHOD__ );
$cache->touchCheckKey( $cache->makeKey( 'active-tags' ) );
$cache->touchCheckKey( $cache->makeKey( 'valid-tags-db' ) );
$cache->touchCheckKey( $cache->makeKey( 'valid-tags-hook' ) );
+ $cache->touchCheckKey( $cache->makeKey( 'tags-usage-statistics' ) );
MediaWikiServices::getInstance()->getChangeTagDefStore()->reloadMap();
}
- /**
- * Invalidates the tag statistics cache only.
- * @since 1.25
- * @deprecated since 1.33 the cache this purges no longer exists
- */
- public static function purgeTagUsageCache() {
- wfDeprecated( __METHOD__, '1.33' );
- }
-
/**
* Returns a map of any tags used on the wiki to number of edits
* tagged with them, ordered descending by the hitcount.
* @return array Array of string => int
*/
public static function tagUsageStatistics() {
- $dbr = wfGetDB( DB_REPLICA );
- $res = $dbr->select(
- 'change_tag_def',
- [ 'ctd_name', 'ctd_count' ],
- [],
- __METHOD__,
- [ 'ORDER BY' => 'ctd_count DESC' ]
- );
+ $fname = __METHOD__;
- $out = [];
- foreach ( $res as $row ) {
- $out[$row->ctd_name] = $row->ctd_count;
- }
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ return $cache->getWithSetCallback(
+ $cache->makeKey( 'tags-usage-statistics' ),
+ WANObjectCache::TTL_MINUTE * 5,
+ function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
+ $dbr = wfGetDB( DB_REPLICA );
+ $res = $dbr->select(
+ 'change_tag_def',
+ [ 'ctd_name', 'ctd_count' ],
+ [],
+ $fname,
+ [ 'ORDER BY' => 'ctd_count DESC' ]
+ );
+
+ $out = [];
+ foreach ( $res as $row ) {
+ $out[$row->ctd_name] = $row->ctd_count;
+ }
- return $out;
+ return $out;
+ },
+ [
+ 'checkKeys' => [ $cache->makeKey( 'tags-usage-statistics' ) ],
+ 'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
+ 'pcTTL' => WANObjectCache::TTL_PROC_LONG
+ ]
+ );
}
/**