diff options
-rw-r--r-- | includes/api/ApiEditPage.php | 5 | ||||
-rw-r--r-- | includes/api/ApiMessageTrait.php | 8 | ||||
-rw-r--r-- | includes/api/i18n/en.json | 1 | ||||
-rw-r--r-- | includes/api/i18n/qqq.json | 1 | ||||
-rw-r--r-- | includes/editpage/Constraint/PageSizeConstraint.php | 8 | ||||
-rw-r--r-- | includes/editpage/EditPage.php | 41 | ||||
-rw-r--r-- | languages/i18n/en.json | 2 | ||||
-rw-r--r-- | languages/i18n/qqq.json | 2 |
8 files changed, 28 insertions, 40 deletions
diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 3ed3cba5958c..cf4ce46b32de 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -641,11 +641,6 @@ class ApiEditPage extends ApiBase { case EditPage::AS_IMAGE_REDIRECT_LOGGED: $status->fatal( 'apierror-noimageredirect' ); break; - case EditPage::AS_CONTENT_TOO_BIG: - case EditPage::AS_MAX_ARTICLE_SIZE_EXCEEDED: - $status->fatal( 'apierror-contenttoobig', - $this->getConfig()->get( MainConfigNames::MaxArticleSize ) ); - break; case EditPage::AS_READ_ONLY_PAGE_ANON: $status->fatal( 'apierror-noedit-anon' ); break; diff --git a/includes/api/ApiMessageTrait.php b/includes/api/ApiMessageTrait.php index 3cc2a6720dc5..8f796101ce2b 100644 --- a/includes/api/ApiMessageTrait.php +++ b/includes/api/ApiMessageTrait.php @@ -35,6 +35,7 @@ trait ApiMessageTrait { * Compatibility code mappings for various MW messages. * @todo Ideally anything relying on this should be changed to use ApiMessage. * @var string[] + * @phpcs-require-sorted-array */ protected static $messageMap = [ 'actionthrottledtext' => 'ratelimited', @@ -54,14 +55,14 @@ trait ApiMessageTrait { 'cantrollback' => 'onlyauthor', 'confirmedittext' => 'confirmemail', 'content-not-allowed-here' => 'contentnotallowedhere', - 'deleteprotected' => 'cantedit', 'delete-toobig' => 'bigdelete', + 'deleteprotected' => 'cantedit', 'edit-conflict' => 'editconflict', 'imagenocrossnamespace' => 'nonfilenamespace', 'imagetypemismatch' => 'filetypemismatch', + 'import-noarticle' => 'badinterwiki', 'importbadinterwiki' => 'badinterwiki', 'importcantopen' => 'cantopenfile', - 'import-noarticle' => 'badinterwiki', 'importnofile' => 'nofile', 'importuploaderrorpartial' => 'partialupload', 'importuploaderrorsize' => 'filetoobig', @@ -71,6 +72,7 @@ trait ApiMessageTrait { 'ipb_cant_unblock' => 'cantunblock', 'ipb_expiry_invalid' => 'invalidexpiry', 'ip_range_invalid' => 'invalidrange', + 'longpageerror' => 'contenttoobig', 'mailnologin' => 'cantsend', 'markedaspatrollederror-noautopatrol' => 'noautopatrol', 'movenologintext' => 'cantmove-anon', @@ -94,8 +96,8 @@ trait ApiMessageTrait { 'systemblockedtext' => 'blocked', 'titleprotected' => 'protectedtitle', 'undo-failure' => 'undofailure', - 'userrights-nodatabase' => 'nosuchdatabase', 'userrights-no-interwiki' => 'nointerwikiuserrights', + 'userrights-nodatabase' => 'nosuchdatabase', ]; /** @var string|null */ diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index 8c14eab90bb2..6136df868f07 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1846,7 +1846,6 @@ "apierror-compare-relative-to-deleted": "Cannot use <kbd>torelative=$1</kbd> relative to a deleted revision.", "apierror-compare-relative-to-nothing": "No 'from' revision for <var>torelative</var> to be relative to.", "apierror-contentserializationexception": "Content serialization failed: $1", - "apierror-contenttoobig": "The content you supplied exceeds the page size limit of $1 {{PLURAL:$1|kibibyte|kibibytes}}.", "apierror-contentmodel-mismatch": "The content you supplied has <kbd>$1</kbd> content model, which differs from the current content model of the page <kbd>$2</kbd>.", "apierror-copyuploadbaddomain": "Uploads by URL are not allowed from this domain.", "apierror-copyuploadbadurl": "Upload not allowed from this URL.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index 99bcd16295e7..c433ab7db557 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1750,7 +1750,6 @@ "apierror-compare-relative-to-deleted": "{{doc-apierror}}", "apierror-compare-relative-to-nothing": "{{doc-apierror}}", "apierror-contentserializationexception": "{{doc-apierror}}\n\nParameters:\n* $1 - Exception text, may end with punctuation. Currently this is probably English, hopefully we'll fix that in the future.", - "apierror-contenttoobig": "{{doc-apierror}}\n\nParameters:\n* $1 - Maximum article size in kibibytes.", "apierror-contentmodel-mismatch": "{{doc-apierror}}\n\nParameters:\n* $1 content model of the old revision\n* $2 - content model of the current revision.", "apierror-copyuploadbaddomain": "{{doc-apierror}}", "apierror-copyuploadbadurl": "{{doc-apierror}}", diff --git a/includes/editpage/Constraint/PageSizeConstraint.php b/includes/editpage/Constraint/PageSizeConstraint.php index 0dbedfd0ef5e..b2aa4b7c92ec 100644 --- a/includes/editpage/Constraint/PageSizeConstraint.php +++ b/includes/editpage/Constraint/PageSizeConstraint.php @@ -22,6 +22,7 @@ namespace MediaWiki\EditPage\Constraint; use InvalidArgumentException; use StatusValue; +use Wikimedia\Message\MessageValue; /** * Verify the page isn't larger than the maximum @@ -48,7 +49,7 @@ class PageSizeConstraint implements IEditConstraint { private string $type; /** - * @param int $maxSize In kibibytes, from $wgMaxArticleSize + * @param int $maxSize In kilobytes, from $wgMaxArticleSize * @param int $contentSize * @param string $type */ @@ -57,7 +58,7 @@ class PageSizeConstraint implements IEditConstraint { int $contentSize, string $type ) { - $this->maxSize = $maxSize * 1024; // Convert from kibibytes + $this->maxSize = $maxSize * 1024; // Convert from kilobytes $this->contentSize = $contentSize; if ( $type === self::BEFORE_MERGE ) { @@ -83,6 +84,9 @@ class PageSizeConstraint implements IEditConstraint { // Either self::AS_CONTENT_TOO_BIG, if it was too big before merging, // or self::AS_MAX_ARTICLE_SIZE_EXCEEDED, if it was too big after merging $statusValue->setResult( false, $this->errorCode ); + $statusValue->fatal( MessageValue::new( 'longpageerror' ) + ->numParams( round( $this->contentSize / 1024, 3 ), $this->maxSize / 1024 ) + ); } return $statusValue; } diff --git a/includes/editpage/EditPage.php b/includes/editpage/EditPage.php index 4241952d0220..65ad16a08915 100644 --- a/includes/editpage/EditPage.php +++ b/includes/editpage/EditPage.php @@ -241,9 +241,6 @@ class EditPage implements IEditObject { private $incompleteForm = false; /** @var bool */ - private $tooBig = false; - - /** @var bool */ private $missingComment = false; /** @var bool */ @@ -1866,13 +1863,13 @@ class EditPage implements IEditObject { $extraQueryRedirect = $request->getVal( 'wpExtraQueryRedirect' ); switch ( $statusValue ) { + // Status codes for which the error/warning message is generated somewhere else in this class. + // They should be refactored to provide their own messages and handled below (T384399). case self::AS_HOOK_ERROR_EXPECTED: - case self::AS_CONTENT_TOO_BIG: case self::AS_ARTICLE_WAS_DELETED: case self::AS_CONFLICT_DETECTED: case self::AS_SUMMARY_NEEDED: case self::AS_TEXTBOX_EMPTY: - case self::AS_MAX_ARTICLE_SIZE_EXCEEDED: case self::AS_END: case self::AS_BLANK_ARTICLE: case self::AS_SELF_REDIRECT: @@ -1884,9 +1881,13 @@ class EditPage implements IEditObject { case self::AS_HOOK_ERROR: return false; + // Status codes that provide their own error/warning messages. Most error scenarios that don't + // need custom user interface (e.g. edit conflicts) should be handled here, one day (T384399). + case self::AS_CONTENT_TOO_BIG: + case self::AS_MAX_ARTICLE_SIZE_EXCEEDED: case self::AS_PARSE_ERROR: - case self::AS_UNICODE_NOT_SUPPORTED: case self::AS_UNABLE_TO_ACQUIRE_TEMP_ACCOUNT: + case self::AS_UNICODE_NOT_SUPPORTED: foreach ( $status->getMessages() as $msg ) { $out->addHTML( Html::errorBox( $this->context->msg( $msg )->parse() @@ -2618,10 +2619,7 @@ class EditPage implements IEditObject { * result from the backend. */ private function handleFailedConstraint( IEditConstraint $failed ): void { - if ( $failed instanceof PageSizeConstraint ) { - // Error will be displayed by showEditForm() - $this->tooBig = true; - } elseif ( $failed instanceof UserBlockConstraint ) { + if ( $failed instanceof UserBlockConstraint ) { // Auto-block user's IP if the account was "hard" blocked if ( !MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) { $this->context->getUser()->spreadAnyEditBlock(); @@ -4664,22 +4662,13 @@ class EditPage implements IEditObject { } $out = $this->context->getOutput(); - $maxArticleSize = $this->context->getConfig()->get( MainConfigNames::MaxArticleSize ); - if ( $this->tooBig || $this->contentLength > $maxArticleSize * 1024 ) { - $out->addHTML( "<div id='mw-edit-longpageerror'>" . Html::errorBox( - $this->context->msg( 'longpageerror' ) - ->numParams( round( $this->contentLength / 1024, 3 ), $maxArticleSize ) - ->parse() - ) . "</div>" ); - } else { - $longPageHint = $this->context->msg( 'longpage-hint' ); - if ( !$longPageHint->isDisabled() ) { - $msgText = trim( $longPageHint->sizeParams( $this->contentLength ) - ->params( $this->contentLength ) // Keep this unformatted for math inside message - ->parse() ); - if ( $msgText !== '' && $msgText !== '-' ) { - $out->addHTML( "<div id='mw-edit-longpage-hint'>\n$msgText\n</div>" ); - } + $longPageHint = $this->context->msg( 'longpage-hint' ); + if ( !$longPageHint->isDisabled() ) { + $msgText = trim( $longPageHint->sizeParams( $this->contentLength ) + ->params( $this->contentLength ) // Keep this unformatted for math inside message + ->parse() ); + if ( $msgText !== '' && $msgText !== '-' ) { + $out->addHTML( "<div id='mw-edit-longpage-hint'>\n$msgText\n</div>" ); } } } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 3ce54329e373..b01496fe6b48 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -678,7 +678,7 @@ "editpage-cannot-use-custom-model": "The content model of this page cannot be changed.", "editpage-code-message": "-", "longpage-hint": "-", - "longpageerror": "<strong>Error: The text you have submitted is {{PLURAL:$1|one kilobyte|$1 kilobytes}} long, which is longer than the maximum of {{PLURAL:$2|one kilobyte|$2 kilobytes}}.</strong>\nIt cannot be published.", + "longpageerror": "The text you have submitted is $1 {{PLURAL:$1|kilobyte|kilobytes}} long, which is more than the maximum of $2 {{PLURAL:$2|kilobyte|kilobytes}}.", "readonlywarning": "<strong>Warning: The database has been locked for maintenance, so you will not be able to publish your edits right now.</strong>\nYou may wish to copy and paste your text into a text file and save it for later.\n\nThe system administrator who locked it offered this explanation: $1", "protectedpagewarning": "<strong>Warning: This page has been protected so that only users with administrator privileges can edit it.</strong>\nThe latest log entry is provided below for reference:", "semiprotectedpagewarning": "<strong>Note:</strong> This page has been protected so that only autoconfirmed users can edit it.\nThe latest log entry is provided below for reference:", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 020e51033e85..4b66b066409c 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -945,7 +945,7 @@ "editpage-cannot-use-custom-model": "Error message shown if the database does not support changing the content model of a page.", "editpage-code-message": "{{notranslate}} Message that shows when editing code (E.g. CSS, JS or JSON). Should be configured on a site-level.", "longpage-hint": "{{notranslate}}\n* $1: Size of the textbox formatted for output, using an appropriate unit ({{msg-mw|size-bytes}}, {{msg-mw|size-kilobytes}}, {{msg-mw|size-megabytes}}, {{msg-mw|size-gigabytes}})\n* $2: Size of the textbox in bytes, not formatnum", - "longpageerror": "Warning displayed when trying to save a text larger than the maximum size allowed.\n\nParameters:\n* $1 - submitted size (in kilobytes)\n* $2 - maximum size (in kilobytes)", + "longpageerror": "Error displayed when trying to save a text larger than the maximum size allowed.\n\nParameters:\n* $1 - submitted size (in kilobytes)\n* $2 - maximum size (in kilobytes)", "readonlywarning": "Parameters:\n* $1 - reason", "protectedpagewarning": "{{Related|Semiprotectedpagewarning}}", "semiprotectedpagewarning": "{{Related|Semiprotectedpagewarning}}", |