X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fchangetags%2FChangeTags.php;h=30c2f7a428a02e7d3ea013c32868a6e45637ac24;hb=0d6ef1c0b20093e03e95a6b7f303c7a2de5de3af;hp=40f7180579b06cc0e0bc0e635f44f736b052c7a9;hpb=683621c048d9098a4aa61eb3eb9ff7bad0fca2e0;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 40f7180579..30c2f7a428 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -24,6 +24,7 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Storage\NameTableAccessException; use Wikimedia\Rdbms\Database; +use Wikimedia\Rdbms\IDatabase; class ChangeTags { /** @@ -125,7 +126,7 @@ class ChangeTags { $markers = $context->msg( 'tag-list-wrapper' ) ->numParams( count( $displayTags ) ) - ->rawParams( $context->getLanguage()->commaList( $displayTags ) ) + ->rawParams( implode( ' ', $displayTags ) ) ->parse(); $markers = Xml::tags( 'span', [ 'class' => 'mw-tag-markers' ], $markers ); @@ -358,7 +359,7 @@ class ChangeTags { ); } - $prevTags = self::getPrevTags( $rc_id, $log_id, $rev_id ); + $prevTags = self::getTags( $dbw, $rc_id, $rev_id, $log_id ); // add tags $tagsToAdd = array_values( array_diff( $tagsToAdd, $prevTags ) ); @@ -452,21 +453,36 @@ class ChangeTags { return [ $tagsToAdd, $tagsToRemove, $prevTags ]; } - private static function getPrevTags( $rc_id = null, $log_id = null, $rev_id = null ) { + /** + * Return all the tags associated with the given recent change ID, + * revision ID, and/or log entry ID. + * + * @param IDatabase $db the database to query + * @param int|null $rc_id + * @param int|null $rev_id + * @param int|null $log_id + * @return string[] + */ + public static function getTags( IDatabase $db, $rc_id = null, $rev_id = null, $log_id = null ) { $conds = array_filter( [ 'ct_rc_id' => $rc_id, - 'ct_log_id' => $log_id, 'ct_rev_id' => $rev_id, + 'ct_log_id' => $log_id, ] ); - $dbw = wfGetDB( DB_MASTER ); - $tagIds = $dbw->selectFieldValues( 'change_tag', 'ct_tag_id', $conds, __METHOD__ ); + $tagIds = $db->selectFieldValues( + 'change_tag', + 'ct_tag_id', + $conds, + __METHOD__ + ); $tags = []; + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); foreach ( $tagIds as $tagId ) { - $tags[] = MediaWikiServices::getInstance()->getChangeTagDefStore()->getName( (int)$tagId ); + $tags[] = $changeTagDefStore->getName( (int)$tagId ); } return $tags; @@ -504,7 +520,9 @@ class ChangeTags { */ public static function canAddTagsAccompanyingChange( array $tags, User $user = null ) { if ( !is_null( $user ) ) { - if ( !$user->isAllowed( 'applychangetags' ) ) { + if ( !MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $user, 'applychangetags' ) + ) { return Status::newFatal( 'tags-apply-no-permission' ); } elseif ( $user->getBlock() ) { // @TODO Ensure that the block does not apply to the `applychangetags` @@ -579,7 +597,9 @@ class ChangeTags { User $user = null ) { if ( !is_null( $user ) ) { - if ( !$user->isAllowed( 'changetags' ) ) { + if ( !MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $user, 'changetags' ) + ) { return Status::newFatal( 'tags-update-no-permission' ); } elseif ( $user->getBlock() ) { // @TODO Ensure that the block does not apply to the `changetags` @@ -999,7 +1019,9 @@ class ChangeTags { */ public static function canActivateTag( $tag, User $user = null ) { if ( !is_null( $user ) ) { - if ( !$user->isAllowed( 'managechangetags' ) ) { + if ( !MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $user, 'managechangetags' ) + ) { return Status::newFatal( 'tags-manage-no-permission' ); } elseif ( $user->getBlock() ) { // @TODO Ensure that the block does not apply to the `managechangetags` @@ -1073,7 +1095,9 @@ class ChangeTags { */ public static function canDeactivateTag( $tag, User $user = null ) { if ( !is_null( $user ) ) { - if ( !$user->isAllowed( 'managechangetags' ) ) { + if ( !MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $user, 'managechangetags' ) + ) { return Status::newFatal( 'tags-manage-no-permission' ); } elseif ( $user->getBlock() ) { // @TODO Ensure that the block does not apply to the `managechangetags` @@ -1172,7 +1196,9 @@ class ChangeTags { */ public static function canCreateTag( $tag, User $user = null ) { if ( !is_null( $user ) ) { - if ( !$user->isAllowed( 'managechangetags' ) ) { + if ( !MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $user, 'managechangetags' ) + ) { return Status::newFatal( 'tags-manage-no-permission' ); } elseif ( $user->getBlock() ) { // @TODO Ensure that the block does not apply to the `managechangetags` @@ -1292,7 +1318,9 @@ class ChangeTags { $tagUsage = self::tagUsageStatistics(); if ( !is_null( $user ) ) { - if ( !$user->isAllowed( 'deletechangetags' ) ) { + if ( !MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $user, 'deletechangetags' ) + ) { return Status::newFatal( 'tags-delete-no-permission' ); } elseif ( $user->getBlock() ) { // @TODO Ensure that the block does not apply to the `deletechangetags` @@ -1550,6 +1578,8 @@ class ChangeTags { * @return bool */ public static function showTagEditingUI( User $user ) { - return $user->isAllowed( 'changetags' ) && (bool)self::listExplicitlyDefinedTags(); + return MediaWikiServices::getInstance()->getPermissionManager() + ->userHasRight( $user, 'changetags' ) && + (bool)self::listExplicitlyDefinedTags(); } }