Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/204831

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/modules/editor/init.js
M javascripts/user.js
6 files changed, 46 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/31/204831/1

diff --git a/i18n/en.json b/i18n/en.json
index 165164a..12b8eb2 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -63,6 +63,7 @@
        "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": "Your account or IP address is 
blocked from editing. The block was made by <i>$2</i> with the following 
reason: <i>$1</i>. You'll not be able to safe your edit.",
+       "mobile-frontend-editor-blocked-info-loggedin": "Your account is 
blocked from editing. The block was made by <i>$2</i> with the following 
reason: <i>$1</i>.",
        "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 4fa1820..a59031f 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -90,7 +90,8 @@
        "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": "Toast message that appears 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-blocked-info": "Toast message that appears when 
a user tries to edit a page (while the editor is visible), 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-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\n\nSee 
{{msg-msg|mobile-frontend-editor-blocked-info}}",
        "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 0e12de0..a29f789 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -418,6 +418,7 @@
                        'mobile-frontend-editor-uploadenable',
                        'mobile-frontend-editor-blocked',
                        'mobile-frontend-editor-blocked-info',
+                       'mobile-frontend-editor-blocked-info-loggedin',
                        '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..afc58f7 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -860,7 +860,17 @@
                );
 
                if ( $this->isAuthenticatedUser() ) {
-                       $vars['wgMFIsLoggedInUserBlockedFromPage'] = 
$user->isBlockedFrom( $title, true );
+                       $blockInfo = false;
+                       if ( $user->isBlockedFrom( $title, true ) ) {
+                               $block = $user->getBlock();
+                               $blockInfo = array(
+                                       'blockedBy' => $block->getByName(),
+                                       // check, if a reason for this block is 
saved, otherwise use "no reason given" msg
+                                       'blockReason' => $block->mReason
+                                               ? $block->mReason : $this->msg( 
'blockednoreason' )->text(),
+                               );
+                       }
+                       $vars['wgMFIsLoggedInUserBlockedFromPage'] = $blockInfo;
                        $vars['wgMFExperiments'] = $config->get( 
'MFExperiments' );
                }
 
diff --git a/javascripts/modules/editor/init.js 
b/javascripts/modules/editor/init.js
index 2523c16..41d0c55 100644
--- a/javascripts/modules/editor/init.js
+++ b/javascripts/modules/editor/init.js
@@ -231,8 +231,25 @@
                if ( currentPage.isEditable( user ) ) {
                        setupEditor( currentPage );
                } else {
-                       $caEdit.removeClass( 'hidden' );
-                       showSorryToast( 'mobile-frontend-editor-disabled' );
+                       var blockInfo = user.getBlock();
+                       if ( blockInfo ) {
+                               $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..775c556 100644
--- a/javascripts/user.js
+++ b/javascripts/user.js
@@ -54,6 +54,18 @@
                },
 
                /**
+                * Returns information, if the user is blocked, otherwise false.
+                * Always returns false for not-logged-in users!
+                * @return {Boolean|Object}
+                */
+               getBlock: function () {
+                       if ( mw.user.isAnon() || !mw.config.get( 
'wgMFIsLoggedInUserBlockedFromPage' ) ) {
+                               return false;
+                       }
+                       return mw.config.get( 
'wgMFIsLoggedInUserBlockedFromPage' );
+               },
+
+               /**
                * User Bucketing for A/B testing
                * (we want this to be the same everywhere)
                * @return {Boolean}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I27d970be19b754c2531a3cd077fb3c3fe5542118
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.wel...@t-online.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to