* @ingroup Change tagging
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\Database;
class ChangeTags {
return $msg->parse();
}
+ /**
+ * Get the message object for the tag's long description.
+ *
+ * Checks if message key "mediawiki:tag-$tag-description" exists. If it does not,
+ * or if message is disabled, returns false. Otherwise, returns the message object
+ * for the long description.
+ *
+ * @param string $tag Tag
+ * @param IContextSource $context
+ * @return Message|bool Message object of the tag long description or false if
+ * there is no description.
+ */
+ public static function tagLongDescriptionMessage( $tag, IContextSource $context ) {
+ $msg = $context->msg( "tag-$tag-description" );
+ if ( !$msg->exists() ) {
+ return false;
+ }
+ if ( $msg->isDisabled() ) {
+ // The message exists but is disabled, hide the description.
+ return false;
+ }
+
+ // Message exists and isn't disabled, use it.
+ return $msg;
+ }
+
/**
* Add tags to a change given its rc_id, rev_id and/or log_id
*
&$rev_id = null, &$log_id = null, $params = null, RecentChange $rc = null,
User $user = null
) {
-
$tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags...
$tagsToRemove = array_filter( (array)$tagsToRemove );
// update the tag_summary row
$prevTags = [];
if ( !self::updateTagSummaryRow( $tagsToAdd, $tagsToRemove, $rc_id, $rev_id,
- $log_id, $prevTags ) ) {
-
+ $log_id, $prevTags )
+ ) {
// nothing to do
return [ [], [], $prevTags ];
}
* @since 1.25
*/
protected static function updateTagSummaryRow( &$tagsToAdd, &$tagsToRemove,
- $rc_id, $rev_id, $log_id, &$prevTags = [] ) {
-
+ $rc_id, $rev_id, $log_id, &$prevTags = []
+ ) {
$dbw = wfGetDB( DB_MASTER );
$tsConds = array_filter( [
* @return Status
* @since 1.25
*/
- public static function canAddTagsAccompanyingChange( array $tags,
- User $user = null ) {
-
+ public static function canAddTagsAccompanyingChange( array $tags, User $user = null ) {
if ( !is_null( $user ) ) {
if ( !$user->isAllowed( 'applychangetags' ) ) {
return Status::newFatal( 'tags-apply-no-permission' );
public static function addTagsAccompanyingChangeWithChecks(
array $tags, $rc_id, $rev_id, $log_id, $params, User $user
) {
-
// are we allowed to do this?
$result = self::canAddTagsAccompanyingChange( $tags, $user );
if ( !$result->isOK() ) {
* @since 1.25
*/
public static function canUpdateTags( array $tagsToAdd, array $tagsToRemove,
- User $user = null ) {
-
+ User $user = null
+ ) {
if ( !is_null( $user ) ) {
if ( !$user->isAllowed( 'changetags' ) ) {
return Status::newFatal( 'tags-update-no-permission' );
* @since 1.25
*/
public static function updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
- $rc_id, $rev_id, $log_id, $params, $reason, User $user ) {
-
+ $rc_id, $rev_id, $log_id, $params, $reason, User $user
+ ) {
if ( is_null( $tagsToAdd ) ) {
$tagsToAdd = [];
}
* @since 1.25
*/
protected static function logTagManagementAction( $action, $tag, $reason,
- User $user, $tagCount = null, array $logEntryTags = [] ) {
-
+ User $user, $tagCount = null, array $logEntryTags = []
+ ) {
$dbw = wfGetDB( DB_MASTER );
$logEntry = new ManualLogEntry( 'managetags', $action );
* @since 1.25
*/
public static function activateTagWithChecks( $tag, $reason, User $user,
- $ignoreWarnings = false, array $logEntryTags = [] ) {
-
+ $ignoreWarnings = false, array $logEntryTags = []
+ ) {
// are we allowed to do this?
$result = self::canActivateTag( $tag, $user );
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
* @since 1.25
*/
public static function deactivateTagWithChecks( $tag, $reason, User $user,
- $ignoreWarnings = false, array $logEntryTags = [] ) {
-
+ $ignoreWarnings = false, array $logEntryTags = []
+ ) {
// are we allowed to do this?
$result = self::canDeactivateTag( $tag, $user );
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
* @since 1.25
*/
public static function createTagWithChecks( $tag, $reason, User $user,
- $ignoreWarnings = false, array $logEntryTags = [] ) {
-
+ $ignoreWarnings = false, array $logEntryTags = []
+ ) {
// are we allowed to do this?
$result = self::canCreateTag( $tag, $user );
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
* @since 1.25
*/
public static function deleteTagWithChecks( $tag, $reason, User $user,
- $ignoreWarnings = false, array $logEntryTags = [] ) {
-
+ $ignoreWarnings = false, array $logEntryTags = []
+ ) {
// are we allowed to do this?
$result = self::canDeleteTag( $tag, $user );
if ( $ignoreWarnings ? !$result->isOK() : !$result->isGood() ) {
if ( !Hooks::isRegistered( 'ChangeTagsListActive' ) ) {
return $tags;
}
- return ObjectCache::getMainWANInstance()->getWithSetCallback(
- wfMemcKey( 'active-tags' ),
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ return $cache->getWithSetCallback(
+ $cache->makeKey( 'active-tags' ),
WANObjectCache::TTL_MINUTE * 5,
function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
$setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
return $tags;
},
[
- 'checkKeys' => [ wfMemcKey( 'active-tags' ) ],
+ 'checkKeys' => [ $cache->makeKey( 'active-tags' ) ],
'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
'pcTTL' => WANObjectCache::TTL_PROC_LONG
]
public static function listExplicitlyDefinedTags() {
$fname = __METHOD__;
- return ObjectCache::getMainWANInstance()->getWithSetCallback(
- wfMemcKey( 'valid-tags-db' ),
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ return $cache->getWithSetCallback(
+ $cache->makeKey( 'valid-tags-db' ),
WANObjectCache::TTL_MINUTE * 5,
function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
$dbr = wfGetDB( DB_REPLICA );
return array_filter( array_unique( $tags ) );
},
[
- 'checkKeys' => [ wfMemcKey( 'valid-tags-db' ) ],
+ 'checkKeys' => [ $cache->makeKey( 'valid-tags-db' ) ],
'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
'pcTTL' => WANObjectCache::TTL_PROC_LONG
]
if ( !Hooks::isRegistered( 'ListDefinedTags' ) ) {
return $tags;
}
- return ObjectCache::getMainWANInstance()->getWithSetCallback(
- wfMemcKey( 'valid-tags-hook' ),
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ return $cache->getWithSetCallback(
+ $cache->makeKey( 'valid-tags-hook' ),
WANObjectCache::TTL_MINUTE * 5,
function ( $oldValue, &$ttl, array &$setOpts ) use ( $tags ) {
$setOpts += Database::getCacheSetOptions( wfGetDB( DB_REPLICA ) );
return array_filter( array_unique( $tags ) );
},
[
- 'checkKeys' => [ wfMemcKey( 'valid-tags-hook' ) ],
+ 'checkKeys' => [ $cache->makeKey( 'valid-tags-hook' ) ],
'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
'pcTTL' => WANObjectCache::TTL_PROC_LONG
]
* @since 1.25
*/
public static function purgeTagCacheAll() {
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
- $cache->touchCheckKey( wfMemcKey( 'active-tags' ) );
- $cache->touchCheckKey( wfMemcKey( 'valid-tags-db' ) );
- $cache->touchCheckKey( wfMemcKey( 'valid-tags-hook' ) );
+ $cache->touchCheckKey( $cache->makeKey( 'active-tags' ) );
+ $cache->touchCheckKey( $cache->makeKey( 'valid-tags-db' ) );
+ $cache->touchCheckKey( $cache->makeKey( 'valid-tags-hook' ) );
self::purgeTagUsageCache();
}
* @since 1.25
*/
public static function purgeTagUsageCache() {
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
- $cache->touchCheckKey( wfMemcKey( 'change-tag-statistics' ) );
+ $cache->touchCheckKey( $cache->makeKey( 'change-tag-statistics' ) );
}
/**
*/
public static function tagUsageStatistics() {
$fname = __METHOD__;
- return ObjectCache::getMainWANInstance()->getWithSetCallback(
- wfMemcKey( 'change-tag-statistics' ),
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
+ return $cache->getWithSetCallback(
+ $cache->makeKey( 'change-tag-statistics' ),
WANObjectCache::TTL_MINUTE * 5,
function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) {
$dbr = wfGetDB( DB_REPLICA, 'vslow' );
return $out;
},
[
- 'checkKeys' => [ wfMemcKey( 'change-tag-statistics' ) ],
+ 'checkKeys' => [ $cache->makeKey( 'change-tag-statistics' ) ],
'lockTSE' => WANObjectCache::TTL_MINUTE * 5,
'pcTTL' => WANObjectCache::TTL_PROC_LONG
]