jenkins-bot has submitted this change and it was merged.

Change subject: Improve error handling for "Editor not available"
......................................................................


Improve error handling for "Editor not available"

Instead of always show a toast, that the page is protected:
* Show "page is protected" when the page can't be edited by the current user
  (maybe because he/she doesn't have the proper right)
* Show a "you're blocked" error toast with information who blocked the user for
  what reason.
This doesn't affect editing for not-logged in users.

Bug: T96352
Change-Id: I27d970be19b754c2531a3cd077fb3c3fe5542118
---
M i18n/en.json
M i18n/qqq.json
M includes/Resources.php
M includes/skins/SkinMinerva.php
M javascripts/Page.js
M javascripts/modules/editor/init.js
M javascripts/user.js
M less/toast.less
8 files changed, 69 insertions(+), 5 deletions(-)

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



diff --git a/i18n/en.json b/i18n/en.json
index 4d03f1d..f9ee337 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -62,6 +62,7 @@
        "mobile-frontend-editor-anon": "Edit without logging in",
        "mobile-frontend-editor-anonwarning": "<strong>Warning</strong>: You 
are not logged in. Your IP address will be publicly visible if you make any 
edits. If you <strong>log in</strong> or <strong>create an account</strong>, 
your edits will be attributed to your username, along with other benefits.",
        "mobile-frontend-editor-blocked": "Your account is blocked from 
editing.",
+       "mobile-frontend-editor-blocked-info-loggedin": "Your account is 
blocked from editing. The block was made by {{GENDER:$2|$2}} for the following 
reason: $1",
        "mobile-frontend-editor-cancel": "Cancel",
        "mobile-frontend-editor-cancel-confirm": "Do you really want to abandon 
your edit?",
        "mobile-frontend-editor-captcha-try-again": "Wrong code, try again.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 76b6e5e..998d38c 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -90,6 +90,7 @@
        "mobile-frontend-editor-anon": "Title for link to edit a page without 
logging in.",
        "mobile-frontend-editor-anonwarning": "Warning message, when user want 
to edit without logging in.",
        "mobile-frontend-editor-blocked": "Toast message that appears when a 
user is unable to edit a page due to being blocked and clicks edit icon.",
+       "mobile-frontend-editor-blocked-info-loggedin": "Toast message for 
logged in users that appears (before the user see the editor) when a user tries 
to edit a page, but is blocked from editing with reason and blocked by 
information.\n\nParameters:\n* $1 - blocked by information (Username of the 
user who crated this block)\n* $2 - Reason for this block, if any",
        "mobile-frontend-editor-cancel": "Caption for cancel button on edit 
form.\n{{Identical|Cancel}}",
        "mobile-frontend-editor-cancel-confirm": "Question asking user if they 
are positive about abandoning unsaved edit.",
        "mobile-frontend-editor-captcha-try-again": "A message shown when user 
enters wrong CAPTCHA and a new one is displayed.",
diff --git a/includes/Resources.php b/includes/Resources.php
index 93a60a6..ce81f46 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -401,7 +401,7 @@
                'group' => 'user',
        ),
 
-       'mobile.editor' => $wgMFResourceFileModuleBoilerplate + array(
+       'mobile.editor' => $wgMFResourceParsedMessageModuleBoilerplate + array(
                'dependencies' => array(
                        'mobile.startup',
                        'mobile.drawers',
@@ -419,6 +419,7 @@
                        'mobile-frontend-editor-unavailable',
                        'mobile-frontend-editor-uploadenable',
                        'mobile-frontend-editor-blocked',
+                       'mobile-frontend-editor-blocked-info-loggedin' => 
array( 'parse' ),
                        'mobile-frontend-editor-cta',
                        'mobile-frontend-editor-anon',
                        'mobile-frontend-editor-undo-unsupported',
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index 403e530..91615c7 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -843,6 +843,7 @@
                $title = $this->getTitle();
                $user = $this->getUser();
                $config = $this->getMFConfig();
+               $out = $this->getOutput();
 
                $vars = array(
                        'wgMFEnableJSConsoleRecruitment' => $config->get( 
'MFEnableJSConsoleRecruitment' ),
@@ -860,7 +861,18 @@
                );
 
                if ( $this->isAuthenticatedUser() ) {
-                       $vars['wgMFIsLoggedInUserBlockedFromPage'] = 
$user->isBlockedFrom( $title, true );
+                       $blockInfo = false;
+                       if ( $user->isBlockedFrom( $title, true ) ) {
+                               $block = $user->getBlock();
+                               $blockReason = $block->mReason ?
+                                       $out->parseinline( $block->mReason ) : 
$this->msg( 'blockednoreason' )->text();
+                               $blockInfo = array(
+                                       'blockedBy' => $block->getByName(),
+                                       // check, if a reason for this block is 
saved, otherwise use "no reason given" msg
+                                       'blockReason' => $blockReason,
+                               );
+                       }
+                       $vars['wgMFUserBlockInfo'] = $blockInfo;
                        $vars['wgMFExperiments'] = $config->get( 
'MFExperiments' );
                }
 
diff --git a/javascripts/Page.js b/javascripts/Page.js
index ab3ed2e..6951ce8 100644
--- a/javascripts/Page.js
+++ b/javascripts/Page.js
@@ -111,7 +111,7 @@
 
                        // for logged in users check if they are blocked from 
editing this page
                        if ( editable && !user.isAnon() ) {
-                               editable = !mw.config.get( 
'wgMFIsLoggedInUserBlockedFromPage' );
+                               editable = !mw.config.get( 'wgMFUserBlockInfo' 
);
                        }
 
                        return editable;
diff --git a/javascripts/modules/editor/init.js 
b/javascripts/modules/editor/init.js
index 2523c16..5df4e2c 100644
--- a/javascripts/modules/editor/init.js
+++ b/javascripts/modules/editor/init.js
@@ -228,11 +228,31 @@
         * @ignore
         */
        function init() {
+               var blockInfo;
+
                if ( currentPage.isEditable( user ) ) {
                        setupEditor( currentPage );
                } else {
-                       $caEdit.removeClass( 'hidden' );
-                       showSorryToast( 'mobile-frontend-editor-disabled' );
+                       if ( user.isBlocked() ) {
+                               blockInfo = user.getBlockInfo();
+
+                               $caEdit.removeClass( 'hidden' );
+                               $( '#ca-edit' ).on( 'click', function ( ev ) {
+                                       popup.show(
+                                               mw.msg(
+                                                       
'mobile-frontend-editor-blocked-info-loggedin',
+                                                       blockInfo.blockReason,
+                                                       blockInfo.blockedBy
+                                               ),
+                                               'toast'
+                                       );
+                                       ev.preventDefault();
+                               } );
+                               $( '.edit-page' ).detach();
+                       } else {
+                               $caEdit.removeClass( 'hidden' );
+                               showSorryToast( 
'mobile-frontend-editor-disabled' );
+                       }
                }
        }
 
diff --git a/javascripts/user.js b/javascripts/user.js
index 76e84be..0a377d7 100644
--- a/javascripts/user.js
+++ b/javascripts/user.js
@@ -54,6 +54,27 @@
                },
 
                /**
+                * Returns false, if the user isn't logged in or is blocked,
+                * otherwise true.
+                * @return {Boolean}
+                */
+               isBlocked: function () {
+                       return this.getBlockInfo() !== false;
+               },
+
+               /**
+                * Returns information about the block of this user, otherwise 
false.
+                * Always returns false for not-logged-in users!
+                * @return {Boolean|Object}
+                */
+               getBlockInfo: function () {
+                       if ( mw.user.isAnon() || !mw.config.get( 
'wgMFUserBlockInfo' ) ) {
+                               return false;
+                       }
+                       return mw.config.get( 'wgMFUserBlockInfo' );
+               },
+
+               /**
                * User Bucketing for A/B testing
                * (we want this to be the same everywhere)
                * @return {Boolean}
diff --git a/less/toast.less b/less/toast.less
index e5a5e6a..afcc229 100644
--- a/less/toast.less
+++ b/less/toast.less
@@ -104,4 +104,12 @@
                width: 75%;
                border: none; // FIXME: this is needed because a global .error 
adds border
        }
+
+       a {
+               color: @colorProgressive;
+
+               &.new {
+                       color: @colorDestructive;
+               }
+       }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I27d970be19b754c2531a3cd077fb3c3fe5542118
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to