Pass a user to ArchivedFile::userCan in UploadBase
Bug: T251357 Change-Id: Iba9a47c4c4e7d34fee7cd31c605d2461612fe522
This commit is contained in:
parent
977ee0730e
commit
05a04ef54a
5 changed files with 26 additions and 11 deletions
|
|
@ -749,6 +749,8 @@ because of Phabricator reports.
|
|||
- WikiPage::getCreator
|
||||
- WikiPage::getUser
|
||||
- WikiPage::getUserText
|
||||
* UploadBase::checkWarnings now accepts a User parameter; not providing a
|
||||
user is soft deprecated.
|
||||
* Article::insertProtectNullRevision and WikiPage::insertProtectNullRevision
|
||||
were hard deprecated. Instead, use WikiPage::insertNullProtectionRevision.
|
||||
* Article::doDeleteArticle, Article::doDeleteArticleReal, and
|
||||
|
|
|
|||
|
|
@ -661,7 +661,9 @@ class ApiUpload extends ApiBase {
|
|||
* @return array
|
||||
*/
|
||||
protected function getApiWarnings() {
|
||||
$warnings = UploadBase::makeWarningsSerializable( $this->mUpload->checkWarnings() );
|
||||
$warnings = UploadBase::makeWarningsSerializable(
|
||||
$this->mUpload->checkWarnings( $this->getUser() )
|
||||
);
|
||||
|
||||
return $this->transformWarnings( $warnings );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ class AssembleUploadChunksJob extends Job {
|
|||
// We can only get warnings like 'duplicate' after concatenating the chunks
|
||||
$status = Status::newGood();
|
||||
$status->value = [
|
||||
'warnings' => UploadBase::makeWarningsSerializable( $upload->checkWarnings() )
|
||||
'warnings' => UploadBase::makeWarningsSerializable(
|
||||
$upload->checkWarnings( $user )
|
||||
)
|
||||
];
|
||||
|
||||
// We have a new filekey for the fully concatenated file
|
||||
|
|
|
|||
|
|
@ -525,7 +525,8 @@ class SpecialUpload extends SpecialPage {
|
|||
}
|
||||
|
||||
// Verify permissions for this title
|
||||
$permErrors = $this->mUpload->verifyTitlePermissions( $this->getUser() );
|
||||
$user = $this->getUser();
|
||||
$permErrors = $this->mUpload->verifyTitlePermissions( $user );
|
||||
if ( $permErrors !== true ) {
|
||||
$code = array_shift( $permErrors[0] );
|
||||
$this->showRecoverableUploadError( $this->msg( $code, $permErrors[0] )->parse() );
|
||||
|
|
@ -537,14 +538,14 @@ class SpecialUpload extends SpecialPage {
|
|||
|
||||
// Check warnings if necessary
|
||||
if ( !$this->mIgnoreWarning ) {
|
||||
$warnings = $this->mUpload->checkWarnings();
|
||||
$warnings = $this->mUpload->checkWarnings( $user );
|
||||
if ( $this->showUploadWarning( $warnings ) ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 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->msg( 'actionthrottledtext' )->escaped()
|
||||
);
|
||||
|
|
@ -568,7 +569,7 @@ class SpecialUpload extends SpecialPage {
|
|||
|
||||
if ( $changeTags ) {
|
||||
$changeTagsStatus = ChangeTags::canAddTagsAccompanyingChange(
|
||||
$changeTags, $this->getUser() );
|
||||
$changeTags, $user );
|
||||
if ( !$changeTagsStatus->isOK() ) {
|
||||
$this->showUploadError( $this->getOutput()->parseAsInterface(
|
||||
$changeTagsStatus->getWikiText( false, false, $this->getLanguage() )
|
||||
|
|
@ -582,7 +583,7 @@ class SpecialUpload extends SpecialPage {
|
|||
$this->mComment,
|
||||
$pageText,
|
||||
$this->mWatchthis,
|
||||
$this->getUser(),
|
||||
$user,
|
||||
$changeTags
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -665,9 +665,16 @@ abstract class UploadBase {
|
|||
*
|
||||
* This should not assume that mTempPath is set.
|
||||
*
|
||||
* @param User|null $user Accepted since 1.35
|
||||
*
|
||||
* @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 = [];
|
||||
|
||||
$localFile = $this->getLocalFile();
|
||||
|
|
@ -707,7 +714,7 @@ abstract class UploadBase {
|
|||
$warnings['duplicate'] = $dupes;
|
||||
}
|
||||
|
||||
$archivedDupes = $this->checkAgainstArchiveDupes( $hash );
|
||||
$archivedDupes = $this->checkAgainstArchiveDupes( $hash, $user );
|
||||
if ( $archivedDupes !== null ) {
|
||||
$warnings['duplicate-archive'] = $archivedDupes;
|
||||
}
|
||||
|
|
@ -866,14 +873,15 @@ abstract class UploadBase {
|
|||
|
||||
/**
|
||||
* @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)
|
||||
* null if the check discovered no dupes.
|
||||
*/
|
||||
private function checkAgainstArchiveDupes( $hash ) {
|
||||
private function checkAgainstArchiveDupes( $hash, User $user ) {
|
||||
$archivedFile = new ArchivedFile( null, 0, '', $hash );
|
||||
if ( $archivedFile->getID() > 0 ) {
|
||||
if ( $archivedFile->userCan( File::DELETED_FILE ) ) {
|
||||
if ( $archivedFile->userCan( File::DELETED_FILE, $user ) ) {
|
||||
return $archivedFile->getName();
|
||||
} else {
|
||||
return '';
|
||||
|
|
|
|||
Loading…
Reference in a new issue