Call IContextSource::getAuthority instead of IContextSource::getUser

Change to use Authority object where possible
to use the interface instead of implementation

Change-Id: Ia7e9ce2a2f05ef2ae1cf981bf96faf48b04cf58d
This commit is contained in:
Umherirrender 2022-06-27 20:38:03 +02:00
parent 65dee01426
commit a5abaeba10
22 changed files with 50 additions and 52 deletions

View file

@ -3080,7 +3080,7 @@ class EditPage implements IEditObject {
private function showCustomIntro(): bool {
if ( $this->editintro ) {
$title = Title::newFromText( $this->editintro );
if ( $this->isPageExistingAndViewable( $title, $this->context->getUser() ) ) {
if ( $this->isPageExistingAndViewable( $title, $this->context->getAuthority() ) ) {
// Added using template syntax, to take <noinclude>'s into account.
$this->context->getOutput()->addWikiTextAsContent(
'<div class="mw-editintro">{{:' . $title->getFullText() . '}}</div>',

View file

@ -900,7 +900,7 @@ class MediaWiki {
}
// Do any stats increment/watchlist stuff, assuming user is viewing the
// latest revision (which should always be the case for file cache)
$this->context->getWikiPage()->doViewUpdates( $this->context->getUser() );
$this->context->getWikiPage()->doViewUpdates( $this->context->getAuthority() );
// Tell OutputPage that output is taken care of
$output->disable();

View file

@ -540,7 +540,7 @@ class HistoryPager extends ReverseChronologicalPager {
* @return string
*/
private function revLink( RevisionRecord $rev ) {
return ChangesList::revDateLink( $rev, $this->getUser(), $this->getLanguage(),
return ChangesList::revDateLink( $rev, $this->getAuthority(), $this->getLanguage(),
$this->getTitle() );
}

View file

@ -142,7 +142,7 @@ class ApiBlock extends ApiBase {
!$this->blockPermissionCheckerFactory
->newBlockPermissionChecker(
$target,
$this->getUser()
$this->getAuthority()
)
->checkEmailPermissions()
) {

View file

@ -461,7 +461,7 @@ class ApiComparePages extends ApiBase {
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable T240141
$newRev = MutableRevisionRecord::newFromParentRevision( $rev );
$content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER,
$this->getUser() );
$this->getAuthority() );
if ( !$content ) {
$this->dieWithError(
[ 'apierror-missingcontent-revid-role', $rev->getId(), SlotRecord::MAIN ], 'missingcontent'
@ -562,7 +562,7 @@ class ApiComparePages extends ApiBase {
if ( !$rev ) {
$this->dieWithError( "apierror-compare-no{$prefix}revision" );
}
$oldContent = $rev->getContent( $role, RevisionRecord::FOR_THIS_USER, $this->getUser() );
$oldContent = $rev->getContent( $role, RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
if ( !$oldContent ) {
$this->dieWithError(
[ 'apierror-missingcontent-revid-role', $rev->getId(), wfEscapeWikiText( $role ) ],
@ -642,7 +642,7 @@ class ApiComparePages extends ApiBase {
$anyHidden = true;
}
if ( isset( $this->props['user'] ) ) {
$user = $rev->getUser( RevisionRecord::FOR_THIS_USER, $this->getUser() );
$user = $rev->getUser( RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
if ( $user ) {
$vals["{$prefix}user"] = $user->getName();
$vals["{$prefix}userid"] = $user->getId();
@ -654,7 +654,7 @@ class ApiComparePages extends ApiBase {
$anyHidden = true;
}
if ( isset( $this->props['comment'] ) || isset( $this->props['parsedcomment'] ) ) {
$comment = $rev->getComment( RevisionRecord::FOR_THIS_USER, $this->getUser() );
$comment = $rev->getComment( RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
if ( $comment !== null ) {
if ( isset( $this->props['comment'] ) ) {
$vals["{$prefix}comment"] = $comment->text;

View file

@ -29,20 +29,20 @@ class ApiManageTags extends ApiBase {
public function execute() {
$params = $this->extractRequestParams();
$user = $this->getUser();
$authority = $this->getAuthority();
// make sure the user is allowed
if ( $params['operation'] !== 'delete'
&& !$this->getAuthority()->isAllowed( 'managechangetags' )
&& !$authority->isAllowed( 'managechangetags' )
) {
$this->dieWithError( 'tags-manage-no-permission', 'permissiondenied' );
} elseif ( !$this->getAuthority()->isAllowed( 'deletechangetags' ) ) {
} elseif ( !$authority->isAllowed( 'deletechangetags' ) ) {
$this->dieWithError( 'tags-delete-no-permission', 'permissiondenied' );
}
// Check if user can add the log entry tags which were requested
if ( $params['tags'] ) {
$ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $this->getAuthority() );
$ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $authority );
if ( !$ableToTag->isOK() ) {
$this->dieStatus( $ableToTag );
}
@ -55,16 +55,16 @@ class ApiManageTags extends ApiBase {
$tags = $params['tags'] ?: [];
switch ( $params['operation'] ) {
case 'create':
$status = ChangeTags::createTagWithChecks( $tag, $reason, $user, $ignoreWarnings, $tags );
$status = ChangeTags::createTagWithChecks( $tag, $reason, $authority, $ignoreWarnings, $tags );
break;
case 'delete':
$status = ChangeTags::deleteTagWithChecks( $tag, $reason, $user, $ignoreWarnings, $tags );
$status = ChangeTags::deleteTagWithChecks( $tag, $reason, $authority, $ignoreWarnings, $tags );
break;
case 'activate':
$status = ChangeTags::activateTagWithChecks( $tag, $reason, $user, $ignoreWarnings, $tags );
$status = ChangeTags::activateTagWithChecks( $tag, $reason, $authority, $ignoreWarnings, $tags );
break;
case 'deactivate':
$status = ChangeTags::deactivateTagWithChecks( $tag, $reason, $user, $ignoreWarnings, $tags );
$status = ChangeTags::deactivateTagWithChecks( $tag, $reason, $authority, $ignoreWarnings, $tags );
break;
default:
// unreachable

View file

@ -772,13 +772,13 @@ class ApiParse extends ApiBase {
if ( $getContent || $this->section !== false || $isDeleted ) {
if ( $rev ) {
$this->content = $rev->getContent(
SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $this->getUser()
SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $this->getAuthority()
);
if ( !$this->content ) {
$this->dieWithError( [ 'apierror-missingcontent-revid', $revId ] );
}
} else {
$this->content = $page->getContent( RevisionRecord::FOR_THIS_USER, $this->getUser() );
$this->content = $page->getContent( RevisionRecord::FOR_THIS_USER, $this->getAuthority() );
if ( !$this->content ) {
$this->dieWithError( [ 'apierror-missingcontent-pageid', $page->getId() ] );
}

View file

@ -92,7 +92,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
$this->fld_details = isset( $prop['details'] );
$this->fld_tags = isset( $prop['tags'] );
$hideLogs = LogEventsList::getExcludeClause( $db, 'user', $this->getUser() );
$hideLogs = LogEventsList::getExcludeClause( $db, 'user', $this->getAuthority() );
if ( $hideLogs !== false ) {
$this->addWhere( $hideLogs );
}
@ -316,7 +316,6 @@ class ApiQueryLogEvents extends ApiQueryBase {
ApiResult::META_TYPE => 'assoc',
];
$anyHidden = false;
$user = $this->getUser();
if ( $this->fld_ids ) {
$vals['logid'] = (int)$row->log_id;
@ -326,12 +325,13 @@ class ApiQueryLogEvents extends ApiQueryBase {
$title = Title::makeTitle( $row->log_namespace, $row->log_title );
}
$authority = $this->getAuthority();
if ( $this->fld_title || $this->fld_ids || $this->fld_details && $row->log_params !== '' ) {
if ( LogEventsList::isDeleted( $row, LogPage::DELETED_ACTION ) ) {
$vals['actionhidden'] = true;
$anyHidden = true;
}
if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $user ) ) {
if ( LogEventsList::userCan( $row, LogPage::DELETED_ACTION, $authority ) ) {
if ( $this->fld_title ) {
// @phan-suppress-next-next-line PhanTypeMismatchArgumentNullable,PhanPossiblyUndeclaredVariable
// title is set when used
@ -357,7 +357,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
$vals['userhidden'] = true;
$anyHidden = true;
}
if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $user ) ) {
if ( LogEventsList::userCan( $row, LogPage::DELETED_USER, $authority ) ) {
if ( $this->fld_user ) {
$vals['user'] = $row->actor_name;
}
@ -379,7 +379,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
$vals['commenthidden'] = true;
$anyHidden = true;
}
if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $user ) ) {
if ( LogEventsList::userCan( $row, LogPage::DELETED_COMMENT, $authority ) ) {
if ( $this->fld_comment ) {
$vals['comment'] = $this->commentStore->getComment( 'log_comment', $row )->text;
}
@ -426,7 +426,7 @@ class ApiQueryLogEvents extends ApiQueryBase {
if ( $params['prop'] !== null && in_array( 'parsedcomment', $params['prop'] ) ) {
// formatComment() calls wfMessage() among other things
return 'anon-public-user-private';
} elseif ( LogEventsList::getExcludeClause( $this->getDB(), 'user', $this->getUser() )
} elseif ( LogEventsList::getExcludeClause( $this->getDB(), 'user', $this->getAuthority() )
=== LogEventsList::getExcludeClause( $this->getDB(), 'public' )
) { // Output can only contain public data.
return 'public';

View file

@ -598,7 +598,7 @@ class ApiQueryUserContribs extends ApiQueryBase {
$userCanView = RevisionRecord::userCanBitfield(
$row->rev_deleted,
RevisionRecord::DELETED_COMMENT, $this->getUser()
RevisionRecord::DELETED_COMMENT, $this->getAuthority()
);
if ( $userCanView ) {

View file

@ -51,7 +51,7 @@ class ChangeTagsLogItem extends RevisionItemBase {
public function canView() {
return LogEventsList::userCan(
$this->row, RevisionRecord::SUPPRESSED_ALL, $this->list->getUser()
$this->row, RevisionRecord::SUPPRESSED_ALL, $this->list->getAuthority()
);
}

View file

@ -433,8 +433,6 @@ class LogEventsList extends ContextSource {
return '';
}
$user = $this->getUser();
// If change tag editing is available to this user, return the checkbox
if ( $this->flags & self::USE_CHECKBOXES && $this->showTagEditUI ) {
return Xml::check(
@ -450,18 +448,19 @@ class LogEventsList extends ContextSource {
}
$del = '';
$authority = $this->getAuthority();
// Don't show useless checkbox to people who cannot hide log entries
if ( $this->getAuthority()->isAllowed( 'deletedhistory' ) ) {
$canHide = $this->getAuthority()->isAllowed( 'deletelogentry' );
$canViewSuppressedOnly = $this->getAuthority()->isAllowed( 'viewsuppressed' ) &&
!$this->getAuthority()->isAllowed( 'suppressrevision' );
if ( $authority->isAllowed( 'deletedhistory' ) ) {
$canHide = $authority->isAllowed( 'deletelogentry' );
$canViewSuppressedOnly = $authority->isAllowed( 'viewsuppressed' ) &&
!$authority->isAllowed( 'suppressrevision' );
$entryIsSuppressed = self::isDeleted( $row, LogPage::DELETED_RESTRICTED );
$canViewThisSuppressedEntry = $canViewSuppressedOnly && $entryIsSuppressed;
if ( $row->log_deleted || $canHide ) {
// Show checkboxes instead of links.
if ( $canHide && $this->flags & self::USE_CHECKBOXES && !$canViewThisSuppressedEntry ) {
// If event was hidden from sysops
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $authority ) ) {
$del = Xml::check( 'deleterevisions', false, [ 'disabled' => 'disabled' ] );
} else {
$del = Xml::check(
@ -472,7 +471,7 @@ class LogEventsList extends ContextSource {
}
} else {
// If event was hidden from sysops
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $user ) ) {
if ( !self::userCan( $row, LogPage::DELETED_RESTRICTED, $authority ) ) {
$del = Linker::revDeleteLinkDisabled( $canHide );
} else {
$query = [

View file

@ -186,7 +186,7 @@ class LogFormatter {
protected function canView( $field ) {
if ( $this->audience == self::FOR_THIS_USER ) {
return LogEventsList::userCanBitfield(
$this->entry->getDeleted(), $field, $this->context->getUser() ) &&
$this->entry->getDeleted(), $field, $this->context->getAuthority() ) &&
self::canViewLogType();
} else {
return !$this->entry->isDeleted( $field ) && self::canViewLogType();

View file

@ -174,7 +174,6 @@ class LogPager extends ReverseChronologicalPager {
* empty string means no restriction
*/
private function limitType( $types ) {
$user = $this->getUser();
$restrictions = $this->getConfig()->get( MainConfigNames::LogRestrictions );
// If $types is not an array, make it an array
$types = ( $types === '' ) ? [] : (array)$types;
@ -200,7 +199,7 @@ class LogPager extends ReverseChronologicalPager {
// we don't require that "specific request" so that the links-in-logs feature
// works. See T269761
$audience = ( $types || $this->hasEqualsClause( 'log_id' ) ) ? 'user' : 'public';
$hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience, $user );
$hideLogs = LogEventsList::getExcludeClause( $this->mDb, $audience, $this->getAuthority() );
if ( $hideLogs !== false ) {
$this->mConds[] = $hideLogs;
}

View file

@ -133,7 +133,7 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager {
$file = $this->mHist[$i];
$comments[$i] = $file->getDescription(
File::FOR_THIS_USER,
$this->getUser()
$this->getAuthority()
) ?: '';
}
$formattedComments = MediaWikiServices::getInstance()

View file

@ -75,11 +75,11 @@ class RevDelFileItem extends RevDelItem {
}
public function canView() {
return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getUser() );
return $this->file->userCan( File::DELETED_RESTRICTED, $this->list->getAuthority() );
}
public function canViewContent() {
return $this->file->userCan( File::DELETED_FILE, $this->list->getUser() );
return $this->file->userCan( File::DELETED_FILE, $this->list->getAuthority() );
}
public function getBits() {
@ -189,7 +189,7 @@ class RevDelFileItem extends RevDelItem {
* @return string HTML
*/
protected function getComment() {
if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) {
if ( $this->file->userCan( File::DELETED_COMMENT, $this->list->getAuthority() ) ) {
$block = Linker::commentBlock( $this->file->getDescription() );
} else {
$block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped();

View file

@ -66,7 +66,7 @@ class RevDelLogItem extends RevDelItem {
public function canView() {
return LogEventsList::userCan(
$this->row, RevisionRecord::DELETED_RESTRICTED, $this->list->getUser()
$this->row, RevisionRecord::DELETED_RESTRICTED, $this->list->getAuthority()
);
}
@ -154,7 +154,7 @@ class RevDelLogItem extends RevDelItem {
public function getApiData( ApiResult $result ) {
$logEntry = DatabaseLogEntry::newFromRow( $this->row );
$user = $this->list->getUser();
$user = $this->list->getAuthority();
$ret = [
'id' => $logEntry->getId(),
'type' => $logEntry->getType(),

View file

@ -1343,7 +1343,7 @@ abstract class Skin extends ContextSource {
$nav_urls['mainpage'] = [ 'href' => self::makeMainPageUrl() ];
if ( $uploadNavigationUrl ) {
$nav_urls['upload'] = [ 'href' => $uploadNavigationUrl ];
} elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
} elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getAuthority() ) === true ) {
$nav_urls['upload'] = [ 'href' => self::makeSpecialUrl( 'Upload' ) ];
} else {
$nav_urls['upload'] = false;

View file

@ -400,7 +400,7 @@ class SpecialMergeHistory extends SpecialPage {
$mh = $this->mergeHistoryFactory->newMergeHistory( $targetTitle, $destTitle, $this->mTimestamp );
// Merge!
$mergeStatus = $mh->merge( $this->getUser(), $this->mComment );
$mergeStatus = $mh->merge( $this->getAuthority(), $this->mComment );
if ( !$mergeStatus->isOK() ) {
// Failed merge
$this->getOutput()->addWikiMsg( $mergeStatus->getMessage() );

View file

@ -295,7 +295,7 @@ class SpecialTags extends SpecialPage {
$tag = trim( strval( $data['Tag'] ) );
$ignoreWarnings = isset( $data['IgnoreWarnings'] ) && $data['IgnoreWarnings'] === '1';
$status = ChangeTags::createTagWithChecks( $tag, $data['Reason'],
$context->getUser(), $ignoreWarnings );
$context->getAuthority(), $ignoreWarnings );
if ( $status->isGood() ) {
$out->redirect( $this->getPageTitle()->getLocalURL() );

View file

@ -164,7 +164,7 @@ class UploadForm extends HTMLForm {
}
$canUploadByUrl = UploadFromUrl::isEnabled()
&& ( UploadFromUrl::isAllowed( $this->getUser() ) === true )
&& ( UploadFromUrl::isAllowed( $this->getAuthority() ) === true )
&& $this->getConfig()->get( MainConfigNames::CopyUploadsFromSpecialUpload );
$radio = $canUploadByUrl;
$selectedSourceType = strtolower( $this->getRequest()->getText( 'wpSourceType', 'File' ) );

View file

@ -685,7 +685,6 @@ class ContribsPager extends RangeChronologicalPager {
);
# Mark current revisions
$topmarktext = '';
$user = $this->getUser();
if ( $row->rev_id === $row->page_latest ) {
$topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
@ -763,7 +762,8 @@ class ContribsPager extends RangeChronologicalPager {
$comment = $lang->getDirMark() . $comment;
$d = ChangesList::revDateLink( $revRecord, $user, $lang, $page );
$authority = $this->getAuthority();
$d = ChangesList::revDateLink( $revRecord, $authority, $lang, $page );
# When querying for an IP range, we want to always show user and user talk links.
$userlink = '';
@ -788,7 +788,7 @@ class ContribsPager extends RangeChronologicalPager {
}
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable castFrom does not return null here
$del = Linker::getRevDeleteLink( $user, $revRecord, $page );
$del = Linker::getRevDeleteLink( $authority, $revRecord, $page );
if ( $del !== '' ) {
$del .= ' ';
}

View file

@ -231,7 +231,7 @@ class ProtectedPagesPager extends TablePager {
if ( LogEventsList::userCanBitfield(
$row->log_deleted,
LogPage::DELETED_USER,
$this->getUser()
$this->getAuthority()
) ) {
$formatted = Linker::userLink( (int)$value, $username )
. Linker::userToolLinks( (int)$value, $username );
@ -266,7 +266,7 @@ class ProtectedPagesPager extends TablePager {
if ( LogEventsList::userCanBitfield(
$row->log_deleted,
LogPage::DELETED_COMMENT,
$this->getUser()
$this->getAuthority()
) ) {
$formatted = $this->formattedComments[$this->getResultOffset()];
} else {