Convert logging namespace to Authority

Change-Id: Icb44acf275a7f9231c4d229b3886ed8a36d5cbd4
This commit is contained in:
Petr Pchelko 2021-01-07 21:00:28 -06:00 committed by Ppchelko
parent eb4e26bc03
commit 3a5c8f0f25
10 changed files with 30 additions and 77 deletions

View file

@ -22,8 +22,6 @@
* @since 1.25
*/
use MediaWiki\MediaWikiServices;
/**
* This class formats block log entries.
*
@ -151,9 +149,7 @@ class BlockLogFormatter extends LogFormatter {
$linkRenderer = $this->getLinkRenderer();
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| !( $subtype === 'block' || $subtype === 'reblock' )
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'block' )
|| !$this->context->getAuthority()->isAllowed( 'block' )
) {
return '';
}

View file

@ -1,7 +1,5 @@
<?php
use MediaWiki\MediaWikiServices;
class ContentModelLogFormatter extends LogFormatter {
protected function getMessageParameters() {
$lang = $this->context->getLanguage();
@ -14,9 +12,7 @@ class ContentModelLogFormatter extends LogFormatter {
public function getActionLinks() {
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| $this->entry->getSubtype() !== 'change'
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'editcontentmodel' )
|| !$this->context->getAuthority()->isAllowed( 'editcontentmodel' )
) {
return '';
}

View file

@ -23,7 +23,6 @@
* @since 1.22
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
/**
@ -144,10 +143,8 @@ class DeleteLogFormatter extends LogFormatter {
}
public function getActionLinks() {
$user = $this->context->getUser();
$linkRenderer = $this->getLinkRenderer();
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ( !$permissionManager->userHasRight( $user, 'deletedhistory' )
if ( !$this->context->getAuthority()->isAllowed( 'deletedhistory' )
|| $this->entry->isDeleted( LogPage::DELETED_ACTION )
) {
return '';
@ -157,7 +154,7 @@ class DeleteLogFormatter extends LogFormatter {
case 'delete': // Show undelete link
case 'delete_redir':
case 'delete_redir2':
if ( $permissionManager->userHasRight( $user, 'undelete' ) ) {
if ( $this->context->getAuthority()->isAllowed( 'undelete' ) ) {
$message = 'undeletelink';
} else {
$message = 'undeleteviewlink';

View file

@ -26,6 +26,7 @@
use MediaWiki\HookContainer\HookRunner;
use MediaWiki\Linker\LinkRenderer;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\Authority;
use Wikimedia\Rdbms\IDatabase;
class LogEventsList extends ContextSource {
@ -227,10 +228,7 @@ class LogEventsList extends ContextSource {
foreach ( LogPage::validTypes() as $type ) {
$page = new LogPage( $type );
$restriction = $page->getRestriction();
if ( MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->getUser(), $restriction )
) {
if ( $this->getAuthority()->isAllowed( $restriction ) ) {
$typesByName[$type] = $page->getName()->text();
}
}
@ -456,12 +454,11 @@ class LogEventsList extends ContextSource {
}
$del = '';
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
// Don't show useless checkbox to people who cannot hide log entries
if ( $permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
$canHide = $permissionManager->userHasRight( $user, 'deletelogentry' );
$canViewSuppressedOnly = $permissionManager->userHasRight( $user, 'viewsuppressed' ) &&
!$permissionManager->userHasRight( $user, 'suppressrevision' );
if ( $this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
$canHide = $this->getAuthority()->isAllowed( 'deletelogentry' );
$canViewSuppressedOnly = $this->getAuthority()->isAllowed( 'viewsuppressed' ) &&
!$this->getAuthority()->isAllowed( 'suppressrevision' );
$entryIsSuppressed = self::isDeleted( $row, LogPage::DELETED_RESTRICTED );
$canViewThisSuppressedEntry = $canViewSuppressedOnly && $entryIsSuppressed;
if ( $row->log_deleted || $canHide ) {
@ -537,21 +534,16 @@ class LogEventsList extends ContextSource {
*
* @param int $bitfield Current field
* @param int $field
* @param User $user User to check
* @param Authority $performer User to check
* @return bool
*/
public static function userCanBitfield( $bitfield, $field, User $user ) {
public static function userCanBitfield( $bitfield, $field, Authority $performer ) {
if ( $bitfield & $field ) {
if ( $bitfield & LogPage::DELETED_RESTRICTED ) {
$permissions = [ 'suppressrevision', 'viewsuppressed' ];
return $performer->isAllowedAny( 'suppressrevision', 'viewsuppressed' );
} else {
$permissions = [ 'deletedhistory' ];
return $performer->isAllowed( 'deletedhistory' );
}
$permissionlist = implode( ', ', $permissions );
wfDebug( "Checking for $permissionlist due to $field match on $bitfield" );
return MediaWikiServices::getInstance()
->getPermissionManager()
->userHasAnyRight( $user, ...$permissions );
}
return true;
}
@ -561,14 +553,12 @@ class LogEventsList extends ContextSource {
* field of this log row, if it's marked as restricted log type.
*
* @param string $type
* @param User $user User to check
* @param Authority $performer User to check
* @return bool
*/
public static function userCanViewLogType( $type, User $user ) {
public static function userCanViewLogType( $type, Authority $performer ) {
$logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( 'LogRestrictions' );
if ( isset( $logRestrictions[$type] ) && !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $user, $logRestrictions[$type] )
if ( isset( $logRestrictions[$type] ) && !$performer->isAllowed( $logRestrictions[$type] )
) {
return false;
}
@ -668,7 +658,6 @@ class LogEventsList extends ContextSource {
0,
$services->getLinkBatchFactory(),
$services->getDBLoadBalancer(),
$services->getPermissionManager(),
$services->getActorMigration()
);
if ( !$useRequestParams ) {
@ -787,14 +776,14 @@ class LogEventsList extends ContextSource {
*
* @param IDatabase $db
* @param string $audience Public/user
* @param User|null $user User to check, required when audience isn't public
* @param Authority|null $performer User to check, required when audience isn't public
* @return string|bool String on success, false on failure.
* @throws InvalidArgumentException
*/
public static function getExcludeClause( $db, $audience = 'public', User $user = null ) {
public static function getExcludeClause( $db, $audience = 'public', Authority $performer = null ) {
global $wgLogRestrictions;
if ( $audience != 'public' && $user === null ) {
if ( $audience != 'public' && $performer === null ) {
throw new InvalidArgumentException(
'A User object must be given when checking for a user audience.'
);
@ -805,9 +794,7 @@ class LogEventsList extends ContextSource {
// Don't show private logs to unprivileged users
foreach ( $wgLogRestrictions as $logType => $right ) {
if ( $audience == 'public' || !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $user, $right )
if ( $audience == 'public' || !$performer->isAllowed( $right )
) {
$hiddenLogs[] = $logType;
}

View file

@ -172,9 +172,7 @@ class LogFormatter {
$logRestrictions = $this->context->getConfig()->get( 'LogRestrictions' );
$type = $this->entry->getType();
return !isset( $logRestrictions[$type] )
|| MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), $logRestrictions[$type] );
|| $this->context->getAuthority()->isAllowed( $logRestrictions[$type] );
}
/**

View file

@ -25,7 +25,6 @@
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Permissions\PermissionManager;
use Wikimedia\Rdbms\ILoadBalancer;
/**
@ -68,9 +67,6 @@ class LogPager extends ReverseChronologicalPager {
/** @var LinkBatchFactory */
private $linkBatchFactory;
/** @var PermissionManager */
private $permissionManager;
/** @var ActorMigration */
private $actorMigration;
@ -89,7 +85,6 @@ class LogPager extends ReverseChronologicalPager {
* @param int $logId Log entry ID, to limit to a single log entry.
* @param LinkBatchFactory|null $linkBatchFactory
* @param ILoadBalancer|null $loadBalancer
* @param PermissionManager|null $permissionManager
* @param ActorMigration|null $actorMigration
*/
public function __construct( $list, $types = [], $performer = '', $title = '',
@ -97,7 +92,6 @@ class LogPager extends ReverseChronologicalPager {
$tagFilter = '', $action = '', $logId = 0,
LinkBatchFactory $linkBatchFactory = null,
ILoadBalancer $loadBalancer = null,
PermissionManager $permissionManager = null,
ActorMigration $actorMigration = null
) {
$services = MediaWikiServices::getInstance();
@ -111,7 +105,6 @@ class LogPager extends ReverseChronologicalPager {
// Class is used directly in extensions - T266480
$this->linkBatchFactory = $linkBatchFactory ?? $services->getLinkBatchFactory();
$this->permissionManager = $permissionManager ?? $services->getPermissionManager();
$this->actorMigration = $actorMigration ?? $services->getActorMigration();
$this->limitLogId( $logId ); // set before types per T269761
@ -186,7 +179,7 @@ class LogPager extends ReverseChronologicalPager {
$needReindex = false;
foreach ( $types as $type ) {
if ( isset( $restrictions[$type] )
&& !$this->permissionManager->userHasRight( $user, $restrictions[$type] )
&& !$this->getAuthority()->isAllowed( $restrictions[$type] )
) {
$needReindex = true;
$types = array_diff( $types, [ $type ] );
@ -511,10 +504,9 @@ class LogPager extends ReverseChronologicalPager {
return;
}
$this->actionRestrictionsEnforced = true;
$user = $this->getUser();
if ( !$this->permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
} elseif ( !$this->permissionManager->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' ) ) {
} elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
' != ' . LogPage::SUPPRESSED_USER;
}
@ -529,10 +521,9 @@ class LogPager extends ReverseChronologicalPager {
return;
}
$this->performerRestrictionsEnforced = true;
$user = $this->getUser();
if ( !$this->permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
if ( !$this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
} elseif ( !$this->permissionManager->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' ) ) {
} elseif ( !$this->getAuthority()->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
' != ' . LogPage::SUPPRESSED_ACTION;
}

View file

@ -22,8 +22,6 @@
* @since 1.25
*/
use MediaWiki\MediaWikiServices;
/**
* This class formats merge log entries.
*
@ -49,9 +47,7 @@ class MergeLogFormatter extends LogFormatter {
public function getActionLinks() {
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'mergehistory' )
|| !$this->context->getAuthority()->isAllowed( 'mergehistory' )
) {
return '';
}

View file

@ -23,8 +23,6 @@
* @since 1.22
*/
use MediaWiki\MediaWikiServices;
/**
* This class formats move log entries.
*
@ -62,9 +60,7 @@ class MoveLogFormatter extends LogFormatter {
public function getActionLinks() {
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| $this->entry->getSubtype() !== 'move'
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'move' )
|| !$this->context->getAuthority()->isAllowed( 'move' )
) {
return '';
}

View file

@ -102,10 +102,7 @@ class ProtectLogFormatter extends LogFormatter {
}
// Show change protection link
if ( MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'protect' )
) {
if ( $this->context->getAuthority()->isAllowed( 'protect' ) ) {
$links[] = $linkRenderer->makeKnownLink(
$title,
$this->msg( 'protect_change' )->text(),

View file

@ -248,7 +248,6 @@ class SpecialLog extends SpecialPage {
$opts->getValue( 'logid' ),
$this->linkBatchFactory,
$this->loadBalancer,
$this->permissionManager,
$this->actorMigration
);