Skip to content

Commit

Permalink
Replace usages of deprecated User::isAllowed. Step 2.
Browse files Browse the repository at this point in the history
Bug: T220191
Depends-On: I509cd88355cfd0cc074f4135ec86399b4075f89f
Change-Id: I2341e6f1d108c92924620fba3c64ec090cb09918
  • Loading branch information
Pchelolo committed Sep 11, 2019
1 parent f379b3f commit 7b4eafd
Show file tree
Hide file tree
Showing 68 changed files with 497 additions and 212 deletions.
2 changes: 0 additions & 2 deletions includes/Revision/RevisionRecord.php
Expand Up @@ -531,8 +531,6 @@ public static function userCanBitfield( $bitfield, $field, User $user, Title $ti
$text = $title->getPrefixedText();
wfDebug( "Checking for $permissionlist on $text due to $field match on $bitfield\n" );

$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();

foreach ( $permissions as $perm ) {
if ( $permissionManager->userCan( $perm, $user, $title ) ) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion includes/Storage/DerivedPageDataUpdater.php
Expand Up @@ -1531,7 +1531,9 @@ function () {
if ( $this->options['changed']
&& $title->getNamespace() == NS_USER_TALK
&& $shortTitle != $legacyUser->getTitleKey()
&& !( $this->revision->isMinor() && $legacyUser->isAllowed( 'nominornewtalk' ) )
&& !( $this->revision->isMinor() && MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $legacyUser, 'nominornewtalk' ) )
) {
$recipient = User::newFromName( $shortTitle, false );
if ( !$recipient ) {
Expand Down
8 changes: 3 additions & 5 deletions includes/actions/InfoAction.php
Expand Up @@ -280,11 +280,10 @@ protected function pageInfo() {
// Language in which the page content is (supposed to be) written
$pageLang = $title->getPageLanguage()->getCode();

$permissionManager = $services->getPermissionManager();

$pageLangHtml = $pageLang . ' - ' .
Language::fetchLanguageName( $pageLang, $lang->getCode() );
// Link to Special:PageLanguage with pre-filled page title if user has permissions
$permissionManager = $services->getPermissionManager();
if ( $config->get( 'PageLanguageUseDB' )
&& $permissionManager->userCan( 'pagelang', $user, $title )
) {
Expand Down Expand Up @@ -344,8 +343,7 @@ protected function pageInfo() {
];

$unwatchedPageThreshold = $config->get( 'UnwatchedPageThreshold' );
if (
$services->getPermissionManager()->userHasRight( $user, 'unwatchedpages' ) ||
if ( $permissionManager->userHasRight( $user, 'unwatchedpages' ) ||
( $unwatchedPageThreshold !== false &&
$pageCounts['watchers'] >= $unwatchedPageThreshold )
) {
Expand All @@ -360,7 +358,7 @@ protected function pageInfo() {
) {
$minToDisclose = $config->get( 'UnwatchedPageSecret' );
if ( $pageCounts['visitingWatchers'] > $minToDisclose ||
$services->getPermissionManager()->userHasRight( $user, 'unwatchedpages' ) ) {
$permissionManager->userHasRight( $user, 'unwatchedpages' ) ) {
$pageInfo['header-basic'][] = [
$this->msg( 'pageinfo-visiting-watchers' ),
$lang->formatNum( $pageCounts['visitingWatchers'] )
Expand Down
7 changes: 6 additions & 1 deletion includes/api/ApiResetPassword.php
Expand Up @@ -21,6 +21,7 @@
*/

use MediaWiki\Auth\AuthManager;
use MediaWiki\MediaWikiServices;

/**
* Reset password, with AuthManager
Expand Down Expand Up @@ -63,7 +64,11 @@ public function execute() {

$this->requireOnlyOneParameter( $params, 'user', 'email' );

$passwordReset = new PasswordReset( $this->getConfig(), AuthManager::singleton() );
$passwordReset = new PasswordReset(
$this->getConfig(),
AuthManager::singleton(),
MediaWikiServices::getInstance()->getPermissionManager()
);

$status = $passwordReset->isAllowed( $this->getUser() );
if ( !$status->isOK() ) {
Expand Down
6 changes: 5 additions & 1 deletion includes/logging/BlockLogFormatter.php
Expand Up @@ -22,6 +22,8 @@
* @since 1.25
*/

use MediaWiki\MediaWikiServices;

/**
* This class formats block log entries.
*
Expand Down Expand Up @@ -138,7 +140,9 @@ public function getActionLinks() {
$linkRenderer = $this->getLinkRenderer();
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| !( $subtype === 'block' || $subtype === 'reblock' )
|| !$this->context->getUser()->isAllowed( 'block' )
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'block' )
) {
return '';
}
Expand Down
6 changes: 5 additions & 1 deletion includes/logging/ContentModelLogFormatter.php
@@ -1,5 +1,7 @@
<?php

use MediaWiki\MediaWikiServices;

class ContentModelLogFormatter extends LogFormatter {
protected function getMessageParameters() {
$lang = $this->context->getLanguage();
Expand All @@ -12,7 +14,9 @@ protected function getMessageParameters() {
public function getActionLinks() {
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| $this->entry->getSubtype() !== 'change'
|| !$this->context->getUser()->isAllowed( 'editcontentmodel' )
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'editcontentmodel' )
) {
return '';
}
Expand Down
6 changes: 4 additions & 2 deletions includes/logging/DeleteLogFormatter.php
Expand Up @@ -23,6 +23,7 @@
* @since 1.22
*/

use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\RevisionRecord;

/**
Expand Down Expand Up @@ -136,7 +137,8 @@ protected function parseBitField( $string ) {
public function getActionLinks() {
$user = $this->context->getUser();
$linkRenderer = $this->getLinkRenderer();
if ( !$user->isAllowed( 'deletedhistory' )
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ( !$permissionManager->userHasRight( $user, 'deletedhistory' )
|| $this->entry->isDeleted( LogPage::DELETED_ACTION )
) {
return '';
Expand All @@ -145,7 +147,7 @@ public function getActionLinks() {
switch ( $this->entry->getSubtype() ) {
case 'delete': // Show undelete link
case 'delete_redir':
if ( $user->isAllowed( 'undelete' ) ) {
if ( $permissionManager->userHasRight( $user, 'undelete' ) ) {
$message = 'undeletelink';
} else {
$message = 'undeleteviewlink';
Expand Down
28 changes: 20 additions & 8 deletions includes/logging/LogEventsList.php
Expand Up @@ -233,7 +233,10 @@ private function getTypeMenuDesc( $queryTypes ) {
foreach ( LogPage::validTypes() as $type ) {
$page = new LogPage( $type );
$restriction = $page->getRestriction();
if ( $this->getUser()->isAllowed( $restriction ) ) {
if ( MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->getUser(), $restriction )
) {
$typesByName[$type] = $page->getName()->text();
}
}
Expand Down Expand Up @@ -450,11 +453,12 @@ private function getShowHideLinks( $row ) {
}

$del = '';
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
// Don't show useless checkbox to people who cannot hide log entries
if ( $user->isAllowed( 'deletedhistory' ) ) {
$canHide = $user->isAllowed( 'deletelogentry' );
$canViewSuppressedOnly = $user->isAllowed( 'viewsuppressed' ) &&
!$user->isAllowed( 'suppressrevision' );
if ( $permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
$canHide = $permissionManager->userHasRight( $user, 'deletelogentry' );
$canViewSuppressedOnly = $permissionManager->userHasRight( $user, 'viewsuppressed' ) &&
!$permissionManager->userHasRight( $user, 'suppressrevision' );
$entryIsSuppressed = self::isDeleted( $row, LogPage::DELETED_RESTRICTED );
$canViewThisSuppressedEntry = $canViewSuppressedOnly && $entryIsSuppressed;
if ( $row->log_deleted || $canHide ) {
Expand Down Expand Up @@ -508,7 +512,9 @@ public static function typeAction( $row, $type, $action, $right = '' ) {
in_array( $row->log_action, $action ) : $row->log_action == $action;
if ( $match && $right ) {
global $wgUser;
$match = $wgUser->isAllowed( $right );
$match = MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $wgUser, $right );
}
}

Expand Down Expand Up @@ -572,7 +578,10 @@ public static function userCanViewLogType( $type, User $user = null ) {
$user = $wgUser;
}
$logRestrictions = MediaWikiServices::getInstance()->getMainConfig()->get( 'LogRestrictions' );
if ( isset( $logRestrictions[$type] ) && !$user->isAllowed( $logRestrictions[$type] ) ) {
if ( isset( $logRestrictions[$type] ) && !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $user, $logRestrictions[$type] )
) {
return false;
}
return true;
Expand Down Expand Up @@ -783,7 +792,10 @@ public static function getExcludeClause( $db, $audience = 'public', User $user =

// Don't show private logs to unprivileged users
foreach ( $wgLogRestrictions as $logType => $right ) {
if ( $audience == 'public' || !$user->isAllowed( $right ) ) {
if ( $audience == 'public' || !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $user, $right )
) {
$hiddenLogs[] = $logType;
}
}
Expand Down
4 changes: 3 additions & 1 deletion includes/logging/LogFormatter.php
Expand Up @@ -163,7 +163,9 @@ public function canViewLogType() {
$logRestrictions = $this->context->getConfig()->get( 'LogRestrictions' );
$type = $this->entry->getType();
return !isset( $logRestrictions[$type] )
|| $this->context->getUser()->isAllowed( $logRestrictions[$type] );
|| MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), $logRestrictions[$type] );
}

/**
Expand Down
20 changes: 9 additions & 11 deletions includes/logging/LogPager.php
Expand Up @@ -146,7 +146,9 @@ private function limitType( $types ) {
$needReindex = false;
foreach ( $types as $type ) {
if ( isset( $wgLogRestrictions[$type] )
&& !$user->isAllowed( $wgLogRestrictions[$type] )
&& !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $user, $wgLogRestrictions[$type] )
) {
$needReindex = true;
$types = array_diff( $types, [ $type ] );
Expand Down Expand Up @@ -462,12 +464,10 @@ private function enforceActionRestrictions() {
}
$this->actionRestrictionsEnforced = true;
$user = $this->getUser();
if ( !$user->isAllowed( 'deletedhistory' ) ) {
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ( !$permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_ACTION ) . ' = 0';
} elseif ( !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
) {
} elseif ( !$permissionManager->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_ACTION ) .
' != ' . LogPage::SUPPRESSED_USER;
}
Expand All @@ -483,12 +483,10 @@ private function enforcePerformerRestrictions() {
}
$this->performerRestrictionsEnforced = true;
$user = $this->getUser();
if ( !$user->isAllowed( 'deletedhistory' ) ) {
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ( !$permissionManager->userHasRight( $user, 'deletedhistory' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::DELETED_USER ) . ' = 0';
} elseif ( !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' )
) {
} elseif ( !$permissionManager->userHasAnyRight( $user, 'suppressrevision', 'viewsuppressed' ) ) {
$this->mConds[] = $this->mDb->bitAnd( 'log_deleted', LogPage::SUPPRESSED_USER ) .
' != ' . LogPage::SUPPRESSED_ACTION;
}
Expand Down
6 changes: 5 additions & 1 deletion includes/logging/MergeLogFormatter.php
Expand Up @@ -22,6 +22,8 @@
* @since 1.25
*/

use MediaWiki\MediaWikiServices;

/**
* This class formats merge log entries.
*
Expand All @@ -47,7 +49,9 @@ protected function getMessageParameters() {

public function getActionLinks() {
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| !$this->context->getUser()->isAllowed( 'mergehistory' )
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'mergehistory' )
) {
return '';
}
Expand Down
6 changes: 5 additions & 1 deletion includes/logging/MoveLogFormatter.php
Expand Up @@ -23,6 +23,8 @@
* @since 1.22
*/

use MediaWiki\MediaWikiServices;

/**
* This class formats move log entries.
*
Expand Down Expand Up @@ -60,7 +62,9 @@ protected function getMessageParameters() {
public function getActionLinks() {
if ( $this->entry->isDeleted( LogPage::DELETED_ACTION ) // Action is hidden
|| $this->entry->getSubtype() !== 'move'
|| !$this->context->getUser()->isAllowed( 'move' )
|| !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'move' )
) {
return '';
}
Expand Down
5 changes: 4 additions & 1 deletion includes/logging/ProtectLogFormatter.php
Expand Up @@ -101,7 +101,10 @@ public function getActionLinks() {
];

// Show change protection link
if ( $this->context->getUser()->isAllowed( 'protect' ) ) {
if ( !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $this->context->getUser(), 'protect' )
) {
$links[] = $linkRenderer->makeKnownLink(
$title,
$this->msg( 'protect_change' )->text(),
Expand Down
10 changes: 8 additions & 2 deletions includes/mail/EmailNotification.php
Expand Up @@ -129,7 +129,10 @@ public function notifyOnPageChange( $editor, $title, $timestamp, $summary,
if ( $watchers === [] && !count( $wgUsersNotifiedOnAllChanges ) ) {
$sendEmail = false;
// Only send notification for non minor edits, unless $wgEnotifMinorEdits
if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
if ( !$minorEdit || ( $wgEnotifMinorEdits && !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $editor, 'nominornewtalk' ) )
) {
$isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
if ( $wgEnotifUserTalk
&& $isUserTalkPage
Expand Down Expand Up @@ -214,7 +217,10 @@ public function actuallyNotifyOnPageChange(

$userTalkId = false;

if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
if ( !$minorEdit || ( $wgEnotifMinorEdits && !MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $editor, 'nominornewtalk' ) )
) {
if ( $wgEnotifUserTalk
&& $isUserTalkPage
&& $this->canSendUserTalkEmail( $editor, $title, $minorEdit )
Expand Down
16 changes: 11 additions & 5 deletions includes/page/Article.php
Expand Up @@ -1310,7 +1310,10 @@ public function showPatrolFooter() {
}

$outputPage->preventClickjacking();
if ( $user->isAllowed( 'writeapi' ) ) {
if ( MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $user, 'writeapi' )
) {
$outputPage->addModules( 'mediawiki.page.patrol.ajax' );
}

Expand Down Expand Up @@ -1827,7 +1830,10 @@ public function delete() {
[ 'delete', $this->getTitle()->getPrefixedText() ] )
) {
# Flag to hide all contents of the archived revisions
$suppress = $request->getCheck( 'wpSuppress' ) && $user->isAllowed( 'suppressrevision' );

$suppress = $request->getCheck( 'wpSuppress' ) && MediaWikiServices::getInstance()
->getPermissionManager()
->userHasRight( $user, 'suppressrevision' );

$this->doDelete( $reason, $suppress );

Expand Down Expand Up @@ -1986,8 +1992,8 @@ public function confirmDelete( $reason ) {
]
);
}

if ( $user->isAllowed( 'suppressrevision' ) ) {
$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
if ( $permissionManager->userHasRight( $user, 'suppressrevision' ) ) {
$fields[] = new OOUI\FieldLayout(
new OOUI\CheckboxInputWidget( [
'name' => 'wpSuppress',
Expand Down Expand Up @@ -2045,7 +2051,7 @@ public function confirmDelete( $reason ) {
] )
);

if ( $user->isAllowed( 'editinterface' ) ) {
if ( $permissionManager->userHasRight( $user, 'editinterface' ) ) {
$link = Linker::linkKnown(
$ctx->msg( 'deletereason-dropdown' )->inContentLanguage()->getTitle(),
wfMessage( 'delete-edit-reasonlist' )->escaped(),
Expand Down

0 comments on commit 7b4eafd

Please sign in to comment.