use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableAccessException;
use Wikimedia\Rdbms\Database;
+use Wikimedia\Rdbms\IDatabase;
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 );
);
}
- $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 ) );
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;
*/
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`
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`
}
$logEntry->setParameters( $params );
$logEntry->setRelations( [ 'Tag' => $tag ] );
- $logEntry->setTags( $logEntryTags );
+ $logEntry->addTags( $logEntryTags );
$logId = $logEntry->insert( $dbw );
$logEntry->publish( $logId );
*/
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`
*/
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`
*/
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`
$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`
* @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();
}
}