jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/356878 )

Change subject: Error the official mediawiki way
......................................................................


Error the official mediawiki way

Don't confuse users by showing a non-styled 404 page.

Additional changes:
* Boxes generated via PHP no longer output an empty h2 tag
* The errorBox and messageBox methods now take a heading parameter
* Introduce ContentBox mustache template

Bug: T155149
Change-Id: Iea9a8d737df97d7b4e574645e19fb18ec8481603
---
M i18n/en.json
M i18n/qqq.json
A includes/ContentBox.mustache
M includes/MobileUI.php
M includes/specials/MobileSpecialPage.php
M includes/specials/SpecialMobileContributions.php
M includes/specials/SpecialMobileHistory.php
M resources/mobile.messageBox/MessageBox.js
M resources/mobile.messageBox/MessageBox.mustache
M resources/mobile.nearby/Nearby.js
10 files changed, 64 insertions(+), 21 deletions(-)

Approvals:
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index 52eda71..b8f52de 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -56,6 +56,8 @@
        "mobile-frontend-cite-error": "A problem occurred while attempting to 
load citations due to a bad revision identifier.",
        "mobile-frontend-cite-none-available": "There are no citations 
available for this page.",
        "mobile-frontend-clear-search": "Clear",
+       "mobile-frontend-contributions-404-desc": "Cannot look for 
contributions without a user or with a user that does not exist.",
+       "mobile-frontend-contributions-404-title": "Bad username given",
        "mobile-frontend-cookies-required": "Cookies are required to switch 
view modes. Please enable them and try again.",
        "mobile-frontend-copyright": "Content is available under $1 unless 
otherwise noted.",
        "mobile-frontend-desc": "Mobile Frontend",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 06a36d4..bbb0dc9 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -139,6 +139,8 @@
        "mobile-frontend-generic-login-new": "Combined message visible on 
[[Special:UserLogin]] to remind users how {{SITENAME}} relies on contributions 
and call to action that follows {{msg-mw|mobile-frontend-generic-login}} asking 
them to login.\n\nSee also:\n* {{msg-mw|mobile-frontend-generic-login}}* 
{{msg-mw|mobile-frontend-generic-login-action}}",
        "mobile-frontend-history": "Used as label for the link which points to 
the \"Edit history\" page.\n\nThis is shown on the Main Page in place of a last 
modified label to avoid confusion caused by transclusions.\n\nIf not the Main 
Page, the following message is used:\n* 
{{msg-mw|Mobile-frontend-last-modified-date}}",
        "mobile-frontend-history-404-desc": "Explain the reasons why the user 
may have arrived on {{msg-mw|mobile-frontend-history-404-title}}",
+       "mobile-frontend-contributions-404-title": "Title of the 404 error page 
shown when navigate to [[Special:Contributions/Title of username that does not 
exist]]",
+       "mobile-frontend-contributions-404-desc": "Explain the reasons why the 
user may have arrived on {{msg-mw|mobile-frontend-contributions-404-title}}",
        "mobile-frontend-history-404-title": "Title of the 404 error page shown 
when navigate to [[Special:History/Title of page that does not exist]]",
        "mobile-frontend-history-no-results": "Error shown when there are no 
history entires for a given/invalid filter.",
        "mobile-frontend-home-button": "This is the label of one of the buttons 
that appear if you click the wiki logo near the search box.\n\nThis buttons 
takes the user to the home page.\n{{Identical|Home}}",
diff --git a/includes/ContentBox.mustache b/includes/ContentBox.mustache
new file mode 100644
index 0000000..e0eeff1
--- /dev/null
+++ b/includes/ContentBox.mustache
@@ -0,0 +1,3 @@
+<div class="content {{className}}">
+       {{{html}}}
+</div>
diff --git a/includes/MobileUI.php b/includes/MobileUI.php
index d690430..fe7f204 100644
--- a/includes/MobileUI.php
+++ b/includes/MobileUI.php
@@ -66,15 +66,23 @@
         * Return a message box.
         * @param string $html of contents of box
         * @param string $className corresponding to box
+        * @param string $heading (optional)
         * @return string of html representing a box.
         */
-       public static function messageBox( $html, $className ) {
+       public static function messageBox( $html, $className, $heading = '' ) {
                $templateParser = new TemplateParser( __DIR__ . 
'/../resources/mobile.messageBox/' );
 
-               return $templateParser->processTemplate( 'MessageBox', [
+               $templateOptions = [
                        'className' => $className,
                        'msg' => $html
-               ] );
+               ];
+               if ( $heading ) {
+                       $templateOptions += [
+                               'heading' => $heading,
+                               'hasHeading' => true,
+                       ];
+               }
+               return $templateParser->processTemplate( 'MessageBox', 
$templateOptions );
        }
 
        /**
@@ -89,10 +97,11 @@
        /**
         * Return an error box.
         * @param string $html of contents of error box
+        * @param string $heading (optional)
         * @return string of html representing an error box.
         */
-       public static function errorBox( $html ) {
-               return self::messageBox( $html, 'errorbox' );
+       public static function errorBox( $html, $heading = '' ) {
+               return self::messageBox( $html, 'errorbox', $heading );
        }
 
        /**
@@ -111,8 +120,10 @@
         * @return string of html
         */
        public static function contentElement( $html, $className = '' ) {
-               $className .= ' content ';
-               return Html::openElement( 'div', [ 'class' => $className ] ) . 
$html .
-                       Html::closeElement( 'div' );
+               $templateParser = new TemplateParser( __DIR__ );
+               return $templateParser->processTemplate( 'ContentBox', [
+                       'className' => $className,
+                       'html' => $html,
+               ] );
        }
 }
diff --git a/includes/specials/MobileSpecialPage.php 
b/includes/specials/MobileSpecialPage.php
index c514d6b..641ba95 100644
--- a/includes/specials/MobileSpecialPage.php
+++ b/includes/specials/MobileSpecialPage.php
@@ -17,6 +17,10 @@
        protected $unstyledContent = true;
        /** @var Config MobileFrontend's config object */
        protected $config = null;
+       /** @var string a message key for the error message heading that should 
be shown on a 404 */
+       protected $errorNotFoundTitleMsg = 'mobile-frontend-generic-404-title';
+       /** @var string a message key for the error message description that 
should be shown on a 404 */
+       protected $errorNotFoundDescriptionMsg = 
'mobile-frontend-generic-404-desc';
 
        /**
         * Wrapper for MobileContext::getMFConfig
@@ -116,8 +120,15 @@
         * Render mobile specific error page, when special page can not be found
         */
        protected function showPageNotFound() {
-               wfHttpError( 404, $this->msg( 
'mobile-frontend-generic-404-title' )->text(),
-                       $this->msg( 'mobile-frontend-generic-404-desc' 
)->text() );
+               $this->getOutput()->setStatusCode( 404 );
+               $this->getOutput()->addHTML(
+                       MobileUI::contentElement(
+                               MobileUI::errorBox(
+                                       $this->msg( 
$this->errorNotFoundDescriptionMsg )->text(),
+                                       $this->msg( 
$this->errorNotFoundTitleMsg )->text()
+                               )
+                       )
+               );
        }
 
        /**
diff --git a/includes/specials/SpecialMobileContributions.php 
b/includes/specials/SpecialMobileContributions.php
index 7656258..83d0014 100644
--- a/includes/specials/SpecialMobileContributions.php
+++ b/includes/specials/SpecialMobileContributions.php
@@ -25,6 +25,10 @@
        protected $showUsername = false;
        /** @var array Lengths of previous revisions */
        protected $prevLengths = [];
+       /** @var string a message key for the error message heading that should 
be shown on a 404 */
+       protected $errorNotFoundTitleMsg = 
'mobile-frontend-contributions-404-title';
+       /** @var string a message key for the error message description that 
should be shown on a 404 */
+       protected $errorNotFoundDescriptionMsg = 
'mobile-frontend-contributions-404-desc';
 
        /**
         * Gets HTML to place in the header bar. Title should always refer to a 
logged in user
diff --git a/includes/specials/SpecialMobileHistory.php 
b/includes/specials/SpecialMobileHistory.php
index b13be53..be4375e 100644
--- a/includes/specials/SpecialMobileHistory.php
+++ b/includes/specials/SpecialMobileHistory.php
@@ -20,6 +20,11 @@
        /** @var Title|null $title Null if no title passed */
        protected $title;
 
+       /** @var string a message key for the error message heading that should 
be shown on a 404 */
+       protected $errorNotFoundTitleMsg = 'mobile-frontend-history-404-title';
+       /** @var string a message key for the error message description that 
should be shown on a 404 */
+       protected $errorNotFoundDescriptionMsg = 
'mobile-frontend-history-404-desc';
+
        /**
         * Construct function
         */
@@ -76,15 +81,6 @@
                                $headerTitle .
                                Html::closeElement( 'h2' ) .
                        Html::closeElement( 'div' )
-               );
-       }
-
-       /**
-        * Show an error page, if page not found
-        */
-       protected function showPageNotFound() {
-               wfHttpError( 404, $this->msg( 
'mobile-frontend-history-404-title' )->text(),
-                       $this->msg( 'mobile-frontend-history-404-desc' )->text()
                );
        }
 
diff --git a/resources/mobile.messageBox/MessageBox.js 
b/resources/mobile.messageBox/MessageBox.js
index 7fbeb6c..847872c 100644
--- a/resources/mobile.messageBox/MessageBox.js
+++ b/resources/mobile.messageBox/MessageBox.js
@@ -19,7 +19,12 @@
                 * @cfg {string} defaults.className either errorbox, warningbox 
or successbox
                 */
                defaults: {},
-               template: mw.template.get( 'mobile.messageBox', 
'MessageBox.hogan' )
+               template: mw.template.get( 'mobile.messageBox', 
'MessageBox.hogan' ),
+               preRender: function () {
+                       // Mustache (serverside) only allows truthy block tags.
+                       // In case a dev added a heading but not hasHeading we 
set its value here.
+                       this.options.hasHeading = Boolean( this.options.heading 
);
+               }
        } );
 
        M.define( 'mobile.messageBox/MessageBox', MessageBox );
diff --git a/resources/mobile.messageBox/MessageBox.mustache 
b/resources/mobile.messageBox/MessageBox.mustache
index 188a76c..650fbca 100644
--- a/resources/mobile.messageBox/MessageBox.mustache
+++ b/resources/mobile.messageBox/MessageBox.mustache
@@ -1,4 +1,8 @@
 <div class="{{className}}">
-       {{#heading}}<h2>{{heading}}</h2>{{/heading}}
+       {{!
+               See T143847 - Mustache and Hogan work differently with regards 
to block rendering so we
+               need to use both hasHeading and heading. this template operates 
in both js and php
+       }}
+       {{#hasHeading}}<h2>{{heading}}</h2>{{/hasHeading}}
        {{{msg}}}
 </div>
diff --git a/resources/mobile.nearby/Nearby.js 
b/resources/mobile.nearby/Nearby.js
index a3f39a2..f1ca150 100644
--- a/resources/mobile.nearby/Nearby.js
+++ b/resources/mobile.nearby/Nearby.js
@@ -36,22 +36,27 @@
                errorMessages: {
                        empty: {
                                heading: mw.msg( 
'mobile-frontend-nearby-noresults' ),
+                               hasHeading: true,
                                msg: mw.msg( 
'mobile-frontend-nearby-noresults-guidance' )
                        },
                        locating: {
                                heading: mw.msg( 
'mobile-frontend-nearby-lookup-ui-error' ),
+                               hasHeading: true,
                                msg: mw.msg( 
'mobile-frontend-nearby-lookup-ui-error-guidance' )
                        },
                        permission: {
                                heading: mw.msg( 
'mobile-frontend-nearby-permission' ),
+                               hasHeading: true,
                                msg: mw.msg( 
'mobile-frontend-nearby-permission-guidance' )
                        },
                        http: {
                                heading: mw.msg( 'mobile-frontend-nearby-error' 
),
+                               hasHeading: true,
                                msg: mw.msg( 
'mobile-frontend-nearby-error-guidance' )
                        },
                        incompatible: {
                                heading: mw.msg( 
'mobile-frontend-nearby-requirements' ),
+                               hasHeading: true,
                                msg: mw.msg( 
'mobile-frontend-nearby-requirements-guidance' )
                        }
                },

-- 
To view, visit https://gerrit.wikimedia.org/r/356878
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iea9a8d737df97d7b4e574645e19fb18ec8481603
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: TheDJ <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to