EditPage: Show EditFilterMergedContent hook errors in an errorbox
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 13 Oct 2016 18:39:07 +0000 (11:39 -0700)
committerTim Starling <tstarling@wikimedia.org>
Sat, 15 Oct 2016 05:59:47 +0000 (05:59 +0000)
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
languages/i18n/en.json
languages/i18n/qqq.json

index 8226da5..95d11c4 100644 (file)
@@ -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 <<<ERROR
+<div class="errorbox">
+{$errmsg}
+</div>
+<br clear="all" />
+ERROR;
+       }
+
        /**
         * Return the summary to be used for a new section.
         *
index 30adf58..4107b9e 100644 (file)
        "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<br><code>0.0.0.0/0</code><br><code>::/0</code>"
+       "restrictionsfield-help": "One IP address or CIDR range per line. To enable everything, use<br><code>0.0.0.0/0</code><br><code>::/0</code>",
+       "edit-error-short": "Error: $1",
+       "edit-error-long": "Errors:\n\n$1"
 }
index 235bf1e..27fa6e8 100644 (file)
        "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}}"
 }