X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fchangetags%2FChangeTags.php;h=5aac4956418425d97f0385af255d8b3c19e71fbf;hb=8b2139e1a773ab4be16a58c8cf2edb1c86b4b798;hp=e1b9b27a4bd70d99946f596b778bad61c7067542;hpb=df8e1a3d875d0107b1a9ae696bac4c1233e93da1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index e1b9b27a4b..5aac495641 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -358,8 +358,12 @@ class ChangeTags { public static function canAddTagsAccompanyingChange( array $tags, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'applychangetags' ) ) { - return Status::newFatal( 'tags-apply-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'applychangetags' ) ) { + return Status::newFatal( 'tags-apply-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-apply-blocked' ); + } } // to be applied, a tag has to be explicitly defined @@ -425,8 +429,12 @@ class ChangeTags { public static function canUpdateTags( array $tagsToAdd, array $tagsToRemove, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'changetags' ) ) { - return Status::newFatal( 'tags-update-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'changetags' ) ) { + return Status::newFatal( 'tags-update-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-update-blocked' ); + } } if ( $tagsToAdd ) { @@ -766,8 +774,12 @@ class ChangeTags { * @since 1.25 */ public static function canActivateTag( $tag, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } // defined tags cannot be activated (a defined tag is either extension- @@ -830,8 +842,12 @@ class ChangeTags { * @since 1.25 */ public static function canDeactivateTag( $tag, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } // only explicitly-defined tags can be deactivated @@ -885,8 +901,12 @@ class ChangeTags { * @since 1.25 */ public static function canCreateTag( $tag, User $user = null ) { - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } // no empty tags @@ -1014,8 +1034,12 @@ class ChangeTags { public static function canDeleteTag( $tag, User $user = null ) { $tagUsage = self::tagUsageStatistics(); - if ( !is_null( $user ) && !$user->isAllowed( 'managechangetags' ) ) { - return Status::newFatal( 'tags-manage-no-permission' ); + if ( !is_null( $user ) ) { + if ( !$user->isAllowed( 'managechangetags' ) ) { + return Status::newFatal( 'tags-manage-no-permission' ); + } elseif ( $user->isBlocked() ) { + return Status::newFatal( 'tags-manage-blocked' ); + } } if ( !isset( $tagUsage[$tag] ) && !in_array( $tag, self::listDefinedTags() ) ) { @@ -1090,17 +1114,20 @@ class ChangeTags { public static function listExtensionActivatedTags() { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'active-tags' ), + 300, function ( $oldValue, &$ttl, array &$setOpts ) { - $setOpts += DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); // Ask extensions which tags they consider active $extensionActive = array(); Hooks::run( 'ChangeTagsListActive', array( &$extensionActive ) ); return $extensionActive; }, - 300, - array( wfMemcKey( 'active-tags' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'active-tags' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); } @@ -1132,18 +1159,21 @@ class ChangeTags { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'valid-tags-db' ), + 300, function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { $dbr = wfGetDB( DB_SLAVE ); - $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + $setOpts += Database::getCacheSetOptions( $dbr ); $tags = $dbr->selectFieldValues( 'valid_tag', 'vt_tag', array(), $fname ); return array_filter( array_unique( $tags ) ); }, - 300, - array( wfMemcKey( 'valid-tags-db' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'valid-tags-db' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); } @@ -1159,16 +1189,19 @@ class ChangeTags { public static function listExtensionDefinedTags() { return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'valid-tags-hook' ), + 300, function ( $oldValue, &$ttl, array &$setOpts ) { - $setOpts += DatabaseBase::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); + $setOpts += Database::getCacheSetOptions( wfGetDB( DB_SLAVE ) ); $tags = array(); Hooks::run( 'ListDefinedTags', array( &$tags ) ); return array_filter( array_unique( $tags ) ); }, - 300, - array( wfMemcKey( 'valid-tags-hook' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'valid-tags-hook' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); } @@ -1208,20 +1241,14 @@ class ChangeTags { * @return array Array of string => int */ public static function tagUsageStatistics() { - static $cachedStats = null; - - // Process cache to avoid I/O and repeated regens during holdoff - if ( $cachedStats !== null ) { - return $cachedStats; - } - $fname = __METHOD__; - $cachedStats = ObjectCache::getMainWANInstance()->getWithSetCallback( + return ObjectCache::getMainWANInstance()->getWithSetCallback( wfMemcKey( 'change-tag-statistics' ), + 300, function ( $oldValue, &$ttl, array &$setOpts ) use ( $fname ) { $dbr = wfGetDB( DB_SLAVE, 'vslow' ); - $setOpts += DatabaseBase::getCacheSetOptions( $dbr ); + $setOpts += Database::getCacheSetOptions( $dbr ); $res = $dbr->select( 'change_tag', @@ -1238,12 +1265,12 @@ class ChangeTags { return $out; }, - 300, - array( wfMemcKey( 'change-tag-statistics' ) ), - array( 'lockTSE' => INF ) + array( + 'checkKeys' => array( wfMemcKey( 'change-tag-statistics' ) ), + 'lockTSE' => 300, + 'pcTTL' => 30 + ) ); - - return $cachedStats; } /**