Pass a user to ArchivedFile::userCan in UploadBase

Bug: T251357
Change-Id: Iba9a47c4c4e7d34fee7cd31c605d2461612fe522
This commit is contained in:
DannyS712 2020-04-28 23:41:39 +00:00
parent 977ee0730e
commit 05a04ef54a
5 changed files with 26 additions and 11 deletions

View file

@ -749,6 +749,8 @@ because of Phabricator reports.
- WikiPage::getCreator - WikiPage::getCreator
- WikiPage::getUser - WikiPage::getUser
- WikiPage::getUserText - WikiPage::getUserText
* UploadBase::checkWarnings now accepts a User parameter; not providing a
user is soft deprecated.
* Article::insertProtectNullRevision and WikiPage::insertProtectNullRevision * Article::insertProtectNullRevision and WikiPage::insertProtectNullRevision
were hard deprecated. Instead, use WikiPage::insertNullProtectionRevision. were hard deprecated. Instead, use WikiPage::insertNullProtectionRevision.
* Article::doDeleteArticle, Article::doDeleteArticleReal, and * Article::doDeleteArticle, Article::doDeleteArticleReal, and

View file

@ -661,7 +661,9 @@ class ApiUpload extends ApiBase {
* @return array * @return array
*/ */
protected function getApiWarnings() { protected function getApiWarnings() {
$warnings = UploadBase::makeWarningsSerializable( $this->mUpload->checkWarnings() ); $warnings = UploadBase::makeWarningsSerializable(
$this->mUpload->checkWarnings( $this->getUser() )
);
return $this->transformWarnings( $warnings ); return $this->transformWarnings( $warnings );
} }

View file

@ -77,7 +77,9 @@ class AssembleUploadChunksJob extends Job {
// We can only get warnings like 'duplicate' after concatenating the chunks // We can only get warnings like 'duplicate' after concatenating the chunks
$status = Status::newGood(); $status = Status::newGood();
$status->value = [ $status->value = [
'warnings' => UploadBase::makeWarningsSerializable( $upload->checkWarnings() ) 'warnings' => UploadBase::makeWarningsSerializable(
$upload->checkWarnings( $user )
)
]; ];
// We have a new filekey for the fully concatenated file // We have a new filekey for the fully concatenated file

View file

@ -525,7 +525,8 @@ class SpecialUpload extends SpecialPage {
} }
// Verify permissions for this title // Verify permissions for this title
$permErrors = $this->mUpload->verifyTitlePermissions( $this->getUser() ); $user = $this->getUser();
$permErrors = $this->mUpload->verifyTitlePermissions( $user );
if ( $permErrors !== true ) { if ( $permErrors !== true ) {
$code = array_shift( $permErrors[0] ); $code = array_shift( $permErrors[0] );
$this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() ); $this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() );
@ -537,14 +538,14 @@ class SpecialUpload extends SpecialPage {
// Check warnings if necessary // Check warnings if necessary
if ( !$this->mIgnoreWarning ) { if ( !$this->mIgnoreWarning ) {
$warnings = $this->mUpload->checkWarnings(); $warnings = $this->mUpload->checkWarnings( $user );
if ( $this->showUploadWarning( $warnings ) ) { if ( $this->showUploadWarning( $warnings ) ) {
return; return;
} }
} }
// This is as late as we can throttle, after expected issues have been handled // This is as late as we can throttle, after expected issues have been handled
if ( UploadBase::isThrottled( $this->getUser() ) ) { if ( UploadBase::isThrottled( $user ) ) {
$this->showRecoverableUploadError( $this->showRecoverableUploadError(
$this->msg( 'actionthrottledtext' )->escaped() $this->msg( 'actionthrottledtext' )->escaped()
); );
@ -568,7 +569,7 @@ class SpecialUpload extends SpecialPage {
if ( $changeTags ) { if ( $changeTags ) {
$changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange( $changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
$changeTags, $this->getUser() ); $changeTags, $user );
if ( !$changeTagsStatus->isOK() ) { if ( !$changeTagsStatus->isOK() ) {
$this->showUploadError( $this->getOutput()->parseAsInterface( $this->showUploadError( $this->getOutput()->parseAsInterface(
$changeTagsStatus->getWikiText( false, false, $this->getLanguage() ) $changeTagsStatus->getWikiText( false, false, $this->getLanguage() )
@ -582,7 +583,7 @@ class SpecialUpload extends SpecialPage {
$this->mComment, $this->mComment,
$pageText, $pageText,
$this->mWatchthis, $this->mWatchthis,
$this->getUser(), $user,
$changeTags $changeTags
); );

View file

@ -665,9 +665,16 @@ abstract class UploadBase {
* *
* This should not assume that mTempPath is set. * This should not assume that mTempPath is set.
* *
* @param User|null $user Accepted since 1.35
*
* @return mixed[] Array of warnings * @return mixed[] Array of warnings
*/ */
public function checkWarnings() { public function checkWarnings( $user = null ) {
if ( $user === null ) {
// TODO check uses and hard deprecate
$user = RequestContext::getMain()->getUser();
}
$warnings = []; $warnings = [];
$localFile = $this->getLocalFile(); $localFile = $this->getLocalFile();
@ -707,7 +714,7 @@ abstract class UploadBase {
$warnings['duplicate'] = $dupes; $warnings['duplicate'] = $dupes;
} }
$archivedDupes = $this->checkAgainstArchiveDupes( $hash ); $archivedDupes = $this->checkAgainstArchiveDupes( $hash, $user );
if ( $archivedDupes !== null ) { if ( $archivedDupes !== null ) {
$warnings['duplicate-archive'] = $archivedDupes; $warnings['duplicate-archive'] = $archivedDupes;
} }
@ -866,14 +873,15 @@ abstract class UploadBase {
/** /**
* @param string $hash sha1 hash of the file to check * @param string $hash sha1 hash of the file to check
* @param User $user
* *
* @return string|null Name of the dupe or empty string if discovered (depending on visibility) * @return string|null Name of the dupe or empty string if discovered (depending on visibility)
* null if the check discovered no dupes. * null if the check discovered no dupes.
*/ */
private function checkAgainstArchiveDupes( $hash ) { private function checkAgainstArchiveDupes( $hash, User $user ) {
$archivedFile = new ArchivedFile( null, 0, '', $hash ); $archivedFile = new ArchivedFile( null, 0, '', $hash );
if ( $archivedFile->getID() > 0 ) { if ( $archivedFile->getID() > 0 ) {
if ( $archivedFile->userCan( File::DELETED_FILE ) ) { if ( $archivedFile->userCan( File::DELETED_FILE, $user ) ) {
return $archivedFile->getName(); return $archivedFile->getName();
} else { } else {
return ''; return '';