From b0a75622d3872e6cde6020a1b0f8775a19be3b23 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Wed, 6 Feb 2019 22:22:01 +0100 Subject: [PATCH] Move upload stash related exceptions to own files Change-Id: I23e81af2f1bf73f5cd78a01bcc2fcebb4c4ea038 --- .phpcs.xml | 2 - autoload.php | 24 +++---- includes/specials/SpecialUploadStash.php | 7 -- .../SpecialUploadStashTooLargeException.php | 28 ++++++++ includes/upload/UploadFromChunks.php | 15 ---- includes/upload/UploadStash.php | 69 ------------------- .../exception/UploadChunkFileException.php | 25 +++++++ .../UploadChunkVerificationException.php | 31 +++++++++ .../UploadChunkZeroLengthFileException.php | 25 +++++++ .../exception/UploadStashBadPathException.php | 27 ++++++++ .../upload/exception/UploadStashException.php | 48 +++++++++++++ .../exception/UploadStashFileException.php | 27 ++++++++ .../UploadStashFileNotFoundException.php | 27 ++++++++ .../UploadStashNoSuchKeyException.php | 27 ++++++++ .../UploadStashNotLoggedInException.php | 27 ++++++++ .../UploadStashWrongOwnerException.php | 27 ++++++++ .../UploadStashZeroLengthFileException.php | 27 ++++++++ 17 files changed, 358 insertions(+), 105 deletions(-) create mode 100644 includes/specials/exception/SpecialUploadStashTooLargeException.php create mode 100644 includes/upload/exception/UploadChunkFileException.php create mode 100644 includes/upload/exception/UploadChunkVerificationException.php create mode 100644 includes/upload/exception/UploadChunkZeroLengthFileException.php create mode 100644 includes/upload/exception/UploadStashBadPathException.php create mode 100644 includes/upload/exception/UploadStashException.php create mode 100644 includes/upload/exception/UploadStashFileException.php create mode 100644 includes/upload/exception/UploadStashFileNotFoundException.php create mode 100644 includes/upload/exception/UploadStashNoSuchKeyException.php create mode 100644 includes/upload/exception/UploadStashNotLoggedInException.php create mode 100644 includes/upload/exception/UploadStashWrongOwnerException.php create mode 100644 includes/upload/exception/UploadStashZeroLengthFileException.php diff --git a/.phpcs.xml b/.phpcs.xml index b8e35d4e65..6e031f6c85 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -244,9 +244,7 @@ */includes/specials/forms/PreferencesFormLegacy\.php */includes/specials/SpecialListusers\.php */includes/specials/SpecialMyRedirectPages\.php - */includes/specials/SpecialUploadStash\.php */includes/StubObject\.php - */includes/upload/UploadFromChunks\.php */includes/upload/UploadStash\.php */includes/utils/AutoloadGenerator\.php */includes/WebResponse\.php diff --git a/autoload.php b/autoload.php index 3b04dfc172..cde24e2e62 100644 --- a/autoload.php +++ b/autoload.php @@ -1434,7 +1434,7 @@ $wgAutoloadLocalClasses = [ 'SpecialUnlockdb' => __DIR__ . '/includes/specials/SpecialUnlockdb.php', 'SpecialUpload' => __DIR__ . '/includes/specials/SpecialUpload.php', 'SpecialUploadStash' => __DIR__ . '/includes/specials/SpecialUploadStash.php', - 'SpecialUploadStashTooLargeException' => __DIR__ . '/includes/specials/SpecialUploadStash.php', + 'SpecialUploadStashTooLargeException' => __DIR__ . '/includes/specials/exception/SpecialUploadStashTooLargeException.php', 'SpecialUserLogin' => __DIR__ . '/includes/specials/SpecialUserLogin.php', 'SpecialUserLogout' => __DIR__ . '/includes/specials/SpecialUserLogout.php', 'SpecialVersion' => __DIR__ . '/includes/specials/SpecialVersion.php', @@ -1534,9 +1534,9 @@ $wgAutoloadLocalClasses = [ 'UpdateSearchIndex' => __DIR__ . '/maintenance/updateSearchIndex.php', 'UpdateSpecialPages' => __DIR__ . '/maintenance/updateSpecialPages.php', 'UploadBase' => __DIR__ . '/includes/upload/UploadBase.php', - 'UploadChunkFileException' => __DIR__ . '/includes/upload/UploadFromChunks.php', - 'UploadChunkVerificationException' => __DIR__ . '/includes/upload/UploadFromChunks.php', - 'UploadChunkZeroLengthFileException' => __DIR__ . '/includes/upload/UploadFromChunks.php', + 'UploadChunkFileException' => __DIR__ . '/includes/upload/exception/UploadChunkFileException.php', + 'UploadChunkVerificationException' => __DIR__ . '/includes/upload/exception/UploadChunkVerificationException.php', + 'UploadChunkZeroLengthFileException' => __DIR__ . '/includes/upload/exception/UploadChunkZeroLengthFileException.php', 'UploadForm' => __DIR__ . '/includes/specials/forms/UploadForm.php', 'UploadFromChunks' => __DIR__ . '/includes/upload/UploadFromChunks.php', 'UploadFromFile' => __DIR__ . '/includes/upload/UploadFromFile.php', @@ -1547,15 +1547,15 @@ $wgAutoloadLocalClasses = [ 'UploadSourceAdapter' => __DIR__ . '/includes/import/UploadSourceAdapter.php', 'UploadSourceField' => __DIR__ . '/includes/specials/formfields/UploadSourceField.php', 'UploadStash' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashBadPathException' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashException' => __DIR__ . '/includes/upload/UploadStash.php', + 'UploadStashBadPathException' => __DIR__ . '/includes/upload/exception/UploadStashBadPathException.php', + 'UploadStashException' => __DIR__ . '/includes/upload/exception/UploadStashException.php', 'UploadStashFile' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashFileException' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashFileNotFoundException' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashNoSuchKeyException' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashNotLoggedInException' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashWrongOwnerException' => __DIR__ . '/includes/upload/UploadStash.php', - 'UploadStashZeroLengthFileException' => __DIR__ . '/includes/upload/UploadStash.php', + 'UploadStashFileException' => __DIR__ . '/includes/upload/exception/UploadStashFileException.php', + 'UploadStashFileNotFoundException' => __DIR__ . '/includes/upload/exception/UploadStashFileNotFoundException.php', + 'UploadStashNoSuchKeyException' => __DIR__ . '/includes/upload/exception/UploadStashNoSuchKeyException.php', + 'UploadStashNotLoggedInException' => __DIR__ . '/includes/upload/exception/UploadStashNotLoggedInException.php', + 'UploadStashWrongOwnerException' => __DIR__ . '/includes/upload/exception/UploadStashWrongOwnerException.php', + 'UploadStashZeroLengthFileException' => __DIR__ . '/includes/upload/exception/UploadStashZeroLengthFileException.php', 'UppercaseCollation' => __DIR__ . '/includes/collation/UppercaseCollation.php', 'User' => __DIR__ . '/includes/user/User.php', 'UserArray' => __DIR__ . '/includes/user/UserArray.php', diff --git a/includes/specials/SpecialUploadStash.php b/includes/specials/SpecialUploadStash.php index a00b031c9c..2da9a41a6b 100644 --- a/includes/specials/SpecialUploadStash.php +++ b/includes/specials/SpecialUploadStash.php @@ -447,10 +447,3 @@ class SpecialUploadStash extends UnlistedSpecialPage { return true; } } - -/** - * @ingroup SpecialPage - * @ingroup Upload - */ -class SpecialUploadStashTooLargeException extends UploadStashException { -} diff --git a/includes/specials/exception/SpecialUploadStashTooLargeException.php b/includes/specials/exception/SpecialUploadStashTooLargeException.php new file mode 100644 index 0000000000..6c2e730697 --- /dev/null +++ b/includes/specials/exception/SpecialUploadStashTooLargeException.php @@ -0,0 +1,28 @@ +msg = wfMessage( ...$res ); - parent::__construct( wfMessage( ...$res ) - ->inLanguage( 'en' )->useDatabase( false )->text() ); - } -} diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index babbe3aee1..aa31a5b689 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -766,72 +766,3 @@ class UploadStashFile extends UnregisteredLocalFile { return $this->repo->fileExists( $this->path ); } } - -/** - * @ingroup Upload - */ -class UploadStashException extends MWException implements ILocalizedException { - /** @var string|array|MessageSpecifier */ - protected $messageSpec; - - /** - * @param string|array|MessageSpecifier $messageSpec See Message::newFromSpecifier - * @param int $code Exception code - * @param Exception|Throwable|null $previous The previous exception used for the exception - * chaining. - */ - public function __construct( $messageSpec, $code = 0, $previous = null ) { - $this->messageSpec = $messageSpec; - - $msg = $this->getMessageObject()->text(); - $msg = preg_replace( '!!', '"', $msg ); - $msg = Sanitizer::stripAllTags( $msg ); - parent::__construct( $msg, $code, $previous ); - } - - public function getMessageObject() { - return Message::newFromSpecifier( $this->messageSpec ); - } -} - -/** - * @ingroup Upload - */ -class UploadStashFileNotFoundException extends UploadStashException { -} - -/** - * @ingroup Upload - */ -class UploadStashBadPathException extends UploadStashException { -} - -/** - * @ingroup Upload - */ -class UploadStashFileException extends UploadStashException { -} - -/** - * @ingroup Upload - */ -class UploadStashZeroLengthFileException extends UploadStashException { -} - -/** - * @ingroup Upload - */ -class UploadStashNotLoggedInException extends UploadStashException { -} - -/** - * @ingroup Upload - */ -class UploadStashWrongOwnerException extends UploadStashException { -} - -/** - * @ingroup Upload - */ -class UploadStashNoSuchKeyException extends UploadStashException { -} diff --git a/includes/upload/exception/UploadChunkFileException.php b/includes/upload/exception/UploadChunkFileException.php new file mode 100644 index 0000000000..066b38c3e6 --- /dev/null +++ b/includes/upload/exception/UploadChunkFileException.php @@ -0,0 +1,25 @@ +msg = wfMessage( ...$res ); + parent::__construct( wfMessage( ...$res ) + ->inLanguage( 'en' )->useDatabase( false )->text() ); + } +} diff --git a/includes/upload/exception/UploadChunkZeroLengthFileException.php b/includes/upload/exception/UploadChunkZeroLengthFileException.php new file mode 100644 index 0000000000..9b937b2111 --- /dev/null +++ b/includes/upload/exception/UploadChunkZeroLengthFileException.php @@ -0,0 +1,25 @@ +messageSpec = $messageSpec; + + $msg = $this->getMessageObject()->text(); + $msg = preg_replace( '!!', '"', $msg ); + $msg = Sanitizer::stripAllTags( $msg ); + parent::__construct( $msg, $code, $previous ); + } + + public function getMessageObject() { + return Message::newFromSpecifier( $this->messageSpec ); + } +} diff --git a/includes/upload/exception/UploadStashFileException.php b/includes/upload/exception/UploadStashFileException.php new file mode 100644 index 0000000000..0c6e9ddd55 --- /dev/null +++ b/includes/upload/exception/UploadStashFileException.php @@ -0,0 +1,27 @@ +