From a02a7ff8eab9d589d77c03d4b4c58fc4a05e65c8 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 13 Oct 2016 11:39:07 -0700 Subject: [PATCH] EditPage: Show EditFilterMergedContent hook errors in an errorbox Errors that go through the Status object of the EditFilterMergedContent hook have less control over how their errors are displayed, compared to the legacy EditFilterMerged hook. Notably, Scribunto wrapped its errors in an errorbox for increased visibility. That was a good idea in general, so let's do that for all errors. Change-Id: I1f0e463841298b8c59ed8bd898c8a4661c5e3aa4 --- includes/EditPage.php | 24 ++++++++++++++++++++++-- languages/i18n/en.json | 4 +++- languages/i18n/qqq.json | 4 +++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 8226da5a78..95d11c48e7 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1639,7 +1639,7 @@ class EditPage { // being set. This is used by ConfirmEdit to display a captcha // without any error message cruft. } else { - $this->hookError = $status->getWikiText(); + $this->hookError = $this->formatStatusErrors( $status ); } // Use the existing $status->value if the hook set it if ( !$status->value ) { @@ -1649,7 +1649,7 @@ class EditPage { } elseif ( !$status->isOK() ) { # ...or the hook could be expecting us to produce an error // FIXME this sucks, we should just use the Status object throughout - $this->hookError = $status->getWikiText(); + $this->hookError = $this->formatStatusErrors( $status ); $status->fatal( 'hookaborted' ); $status->value = self::AS_HOOK_ERROR_EXPECTED; return false; @@ -1658,6 +1658,26 @@ class EditPage { return true; } + /** + * Wrap status errors in an errorbox for increased visiblity + * + * @param Status $status + * @return string + */ + private function formatStatusErrors( Status $status ) { + $errmsg = $status->getHTML( + 'edit-error-short', + 'edit-error-long', + $this->context->getLanguage() + ); + return << +{$errmsg} + +
+ERROR; + } + /** * Return the summary to be used for a new section. * diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 30adf58f60..4107b9e67f 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -4227,5 +4227,7 @@ "usercssispublic": "Please note: CSS subpages should not contain confidential data as they are viewable by other users.", "restrictionsfield-badip": "Invalid IP address or range: $1", "restrictionsfield-label": "Allowed IP ranges:", - "restrictionsfield-help": "One IP address or CIDR range per line. To enable everything, use
0.0.0.0/0
::/0" + "restrictionsfield-help": "One IP address or CIDR range per line. To enable everything, use
0.0.0.0/0
::/0", + "edit-error-short": "Error: $1", + "edit-error-long": "Errors:\n\n$1" } diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 235bf1ef20..27fa6e85f1 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -4411,5 +4411,7 @@ "usercssispublic": "A reminder to users that CSS subpages are not preferences but normal pages, and thus can be viewed by other users and the general public. This message is shown to a user whenever they are editing a subpage in their own user-space that ends in .css. See also {{msg-mw|userjsispublic}}", "restrictionsfield-badip": "An error message shown when one entered an invalid IP address or range in a restrictions field (such as Special:BotPassword). $1 is the IP address.", "restrictionsfield-label": "Field label shown for restriction fields (e.g. on Special:BotPassword).", - "restrictionsfield-help": "Placeholder text displayed in restriction fields (e.g. on Special:BotPassword)." + "restrictionsfield-help": "Placeholder text displayed in restriction fields (e.g. on Special:BotPassword).", + "edit-error-short": "Error message. Parameters:\n* $1 - the error details\nSee also:\n* {{msg-mw|edit-error-long}}", + "edit-error-long": "Error message. Parameters:\n* $1 - the error details\nSee also:\n* {{msg-mw|edit-error-short}}" } -- 2.20.1