* @return Status
* @since 1.25
*/
- public static function addTagsAccompanyingChangeWithChecks( array $tags,
- $rc_id, $rev_id, $log_id, $params, User $user ) {
+ 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 );
}
// do it!
- self::addTags( $tagsToAdd, $rc_id, $rev_id, $log_id, $params );
+ self::addTags( $tags, $rc_id, $rev_id, $log_id, $params );
return Status::newGood( true );
}
if ( $rev_id ) {
$rev = Revision::newFromId( $rev_id );
if ( $rev ) {
- $title = $rev->getTitle();
$logEntry->setTarget( $rev->getTitle() );
}
} elseif ( $log_id ) {
* @param User $user Who to attribute the action to
* @param int $tagCount For deletion only, how many usages the tag had before
* it was deleted.
+ * @return int ID of the inserted log entry
* @since 1.25
*/
protected static function logTagManagementAction( $action, $tag, $reason,
* @since 1.25
*/
public static function listExtensionActivatedTags() {
- // Caching...
- global $wgMemc;
+ $cache = ObjectCache::getMainWANInstance();
+
$key = wfMemcKey( 'active-tags' );
- $tags = $wgMemc->get( $key );
+ $tags = $cache->get( $key );
if ( $tags ) {
return $tags;
}
Hooks::run( 'ChangeTagsListActive', array( &$extensionActive ) );
// Short-term caching.
- $wgMemc->set( $key, $extensionActive, 300 );
+ $cache->set( $key, $extensionActive, 300 );
+
return $extensionActive;
}
* @since 1.25
*/
public static function listExplicitlyDefinedTags() {
- // Caching...
- global $wgMemc;
+ $cache = ObjectCache::getMainWANInstance();
+
$key = wfMemcKey( 'valid-tags-db' );
- $tags = $wgMemc->get( $key );
+ $tags = $cache->get( $key );
if ( $tags ) {
return $tags;
}
$emptyTags = array_filter( array_unique( $emptyTags ) );
// Short-term caching.
- $wgMemc->set( $key, $emptyTags, 300 );
+ $cache->set( $key, $emptyTags, 300 );
+
return $emptyTags;
}
* @since 1.25
*/
public static function listExtensionDefinedTags() {
- // Caching...
- global $wgMemc;
+ $cache = ObjectCache::getMainWANInstance();
+
$key = wfMemcKey( 'valid-tags-hook' );
- $tags = $wgMemc->get( $key );
+ $tags = $cache->get( $key );
if ( $tags ) {
return $tags;
}
$emptyTags = array_filter( array_unique( $emptyTags ) );
// Short-term caching.
- $wgMemc->set( $key, $emptyTags, 300 );
+ $cache->set( $key, $emptyTags, 300 );
+
return $emptyTags;
}
* @since 1.25
*/
public static function purgeTagCacheAll() {
- global $wgMemc;
- $wgMemc->delete( wfMemcKey( 'active-tags' ) );
- $wgMemc->delete( wfMemcKey( 'valid-tags-db' ) );
- $wgMemc->delete( wfMemcKey( 'valid-tags-hook' ) );
+ $cache = ObjectCache::getMainWANInstance();
+
+ $cache->delete( wfMemcKey( 'active-tags' ) );
+ $cache->delete( wfMemcKey( 'valid-tags-db' ) );
+ $cache->delete( wfMemcKey( 'valid-tags-hook' ) );
+
self::purgeTagUsageCache();
}
* @since 1.25
*/
public static function purgeTagUsageCache() {
- global $wgMemc;
- $wgMemc->delete( wfMemcKey( 'change-tag-statistics' ) );
+ $cache = ObjectCache::getMainWANInstance();
+
+ $cache->delete( wfMemcKey( 'change-tag-statistics' ) );
}
/**
* @return array Array of string => int
*/
public static function tagUsageStatistics() {
- // Caching...
- global $wgMemc;
+ $cache = ObjectCache::getMainWANInstance();
+
$key = wfMemcKey( 'change-tag-statistics' );
- $stats = $wgMemc->get( $key );
+ $stats = $cache->get( $key );
if ( $stats ) {
return $stats;
}
}
// Cache for a very short time
- $wgMemc->set( $key, $out, 300 );
+ $cache->set( $key, $out, 300 );
+
return $out;
}
+
+ /**
+ * Indicate whether change tag editing UI is relevant
+ *
+ * Returns true if the user has the necessary right and there are any
+ * editable tags defined.
+ *
+ * This intentionally doesn't check "any addable || any deletable", because
+ * it seems like it would be more confusing than useful if the checkboxes
+ * suddenly showed up because some abuse filter stopped defining a tag and
+ * then suddenly disappeared when someone deleted all uses of that tag.
+ *
+ * @param User $user
+ * @return bool
+ */
+ public static function showTagEditingUI( User $user ) {
+ return $user->isAllowed( 'changetags' ) && (bool)self::listExplicitlyDefinedTags();
+ }
}