Catrope has uploaded a new change for review.

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

Change subject: Handle API errors when refetching the edit token
......................................................................

Handle API errors when refetching the edit token

This can happen when the user gets logged out on a private wiki.
We get a badtoken error, so we try to refetch the token, which
itself returns an error. Token refetches didn't have error handling
at all and got the save dialog stuck in the pending state.

We can't offer the user to proceed with a different identity here,
because we encountered an error while trying to figure out what their
current identity is. The best we can do is encourage them to
log back in in a different tab.

Bug: T128934
Change-Id: I17d4452f688ec22631dbd12af223731635004d66
---
M extension.json
M modules/ve-mw/i18n/en.json
M modules/ve-mw/i18n/qqq.json
M modules/ve-mw/init/ve.init.mw.ArticleTarget.js
4 files changed, 31 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/48/275148/1

diff --git a/extension.json b/extension.json
index 118674a..0136e19 100644
--- a/extension.json
+++ b/extension.json
@@ -364,6 +364,7 @@
                                "visualeditor-loadwarning",
                                "visualeditor-loadwarning-token",
                                "visualeditor-savedialog-identify-anon",
+                               "visualeditor-savedialog-identify-trylogin",
                                "visualeditor-savedialog-identify-user",
                                "visualeditor-timeout"
                        ]
diff --git a/modules/ve-mw/i18n/en.json b/modules/ve-mw/i18n/en.json
index b00bfa5..5980698 100644
--- a/modules/ve-mw/i18n/en.json
+++ b/modules/ve-mw/i18n/en.json
@@ -287,6 +287,7 @@
        "visualeditor-recreate": "The page has been deleted since you started 
editing. Press \"$1\" to recreate it.",
        "visualeditor-savedialog-error-badtoken": "We could not process your 
edit because the session was no longer valid.",
        "visualeditor-savedialog-identify-anon": "Do you want to save this page 
as an anonymous user instead? Your IP address will be recorded in this page's 
edit history.",
+       "visualeditor-savedialog-identify-trylogin": "It appears you are no 
longer logged in. Try logging back in in a different tab and try again.",
        "visualeditor-savedialog-identify-user": "You are now logged in as 
[[User:$1|$1]]. Your edit will be associated with this account if you save this 
edit.",
        "visualeditor-savedialog-label-create": "Create page",
        "visualeditor-savedialog-label-error": "Error",
diff --git a/modules/ve-mw/i18n/qqq.json b/modules/ve-mw/i18n/qqq.json
index 1178e53..f9a2f37 100644
--- a/modules/ve-mw/i18n/qqq.json
+++ b/modules/ve-mw/i18n/qqq.json
@@ -298,6 +298,7 @@
        "visualeditor-recreate": "Text shown when the editor fails to save the 
page due to it having been deleted since they opened VE. $1 is the message 
{{msg-mw|ooui-dialog-process-continue}}.",
        "visualeditor-savedialog-error-badtoken": "Error displayed in the save 
dialog if saving the edit failed due to an invalid edit token (likely due to 
the user having logged out in a separate window, or logged in again)",
        "visualeditor-savedialog-identify-anon": "Displayed in the save dialog 
if saving failed because the session expired and the session is now an 
anonymous user. Warning about IP address being recorded is based on 
{{msg-mw|anoneditwarning}}.\n\n{{format|jquerymsg}}",
+       "visualeditor-savedialog-identify-trylogin": "Displayd in the save 
dialog if saving failed because the session expired and we encountered an error 
while trying to figure out which user the current session is for. This is 
usually due to the user getting logged out on a private wiki.",
        "visualeditor-savedialog-identify-user": "Displayed in the save dialog 
if saving failed because the session expired and the session is now for a 
different user account.\n{{format|jquerymsg}}\nParameters:\n* $1 - username",
        "visualeditor-savedialog-label-create": "Label text for save button 
when the user is creating a new page\n{{Identical|Create page}}",
        "visualeditor-savedialog-label-error": "Label in front of a save dialog 
error sentence, separated by {{msg-mw|colon-separator}}.\n{{Identical|Error}}",
diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js 
b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
index 8a6e234..d95ea1a 100644
--- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
+++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js
@@ -104,8 +104,9 @@
 
 /**
  * @event saveErrorBadToken
- * Fired on save if we have to fetch a new edit token
- *  this is mainly for analytical purposes.
+ * @param {boolean} willRetry Whether an automatic retry will occur
+ * Fired on save if we have to fetch a new edit token.
+ * This is mainly for analytical purposes.
  */
 
 /**
@@ -423,9 +424,6 @@
                        indexpageids: '',
                        intoken: 'edit'
                } )
-                       .always( function () {
-                               target.saveErrorBadToken();
-                       } )
                        .done( function ( data ) {
                                var
                                        userInfo = data.query && 
data.query.userinfo,
@@ -443,7 +441,8 @@
                                                        // normalisation and 
against case where the user got renamed.
                                                        mw.config.get( 
'wgUserId' ) === userInfo.id
                                        ) {
-                                               // New session is the same user 
still
+                                               // New session is the same user 
still; retry
+                                               target.emit( 
'saveErrorBadToken', true );
                                                target.save( doc, saveData );
                                        } else {
                                                // The now current session is a 
different user
@@ -456,14 +455,17 @@
                                                                // functions 
like mw.user.isAnon rely on this.
                                                                wgUserName: null
                                                        } );
-                                                       
target.saveErrorNewUser( null );
+                                                       
target.saveErrorBadToken( null, false );
                                                } else {
                                                        // New session is a 
different user
                                                        mw.config.set( { 
wgUserId: userInfo.id, wgUserName: userInfo.name } );
-                                                       
target.saveErrorNewUser( userInfo.name );
+                                                       
target.saveErrorBadToken( userInfo.name, false );
                                                }
                                        }
                                }
+                       } )
+                       .fail( function () {
+                               target.saveErrorBadToken( null, true );
                        } );
                return;
        } else if ( data.error && data.error.code === 'editconflict' ) {
@@ -629,24 +631,31 @@
 };
 
 /**
- * Handle token fetch indicating another user is logged in
+ * Handle token fetch indicating another user is logged in, and token fetch 
errors.
  *
  * @method
  * @param {string|null} username Name of newly logged-in user, or null if 
anonymous
+ * @param {boolean} [error=false] Whether there was an error trying to figure 
out who we're logged in as
+ * @fires saveErrorBadToken
  * @fires saveErrorNewUser
  */
-ve.init.mw.ArticleTarget.prototype.saveErrorNewUser = function ( username ) {
-       var badToken, userMsg;
-       badToken = document.createTextNode( mw.msg( 
'visualeditor-savedialog-error-badtoken' ) + ' ' );
-       if ( username === null ) {
-               userMsg = 'visualeditor-savedialog-identify-anon';
+ve.init.mw.ArticleTarget.prototype.saveErrorBadToken = function ( username, 
error ) {
+       var userMsg,
+               $msg = $( document.createTextNode( mw.msg( 
'visualeditor-savedialog-error-badtoken' ) + ' ' ) );
+
+       if ( error ) {
+               this.emit( 'saveErrorBadToken', false );
+               $msg = $msg.add( document.createTextNode( mw.msg( 
'visualeditor-savedialog-identify-trylogin' ) ) );
        } else {
-               userMsg = 'visualeditor-savedialog-identify-user';
+               this.emit( 'saveErrorNewUser' );
+               if ( username === null ) {
+                       userMsg = 'visualeditor-savedialog-identify-anon';
+               } else {
+                       userMsg = 'visualeditor-savedialog-identify-user';
+               }
+               $msg = $msg.add( $.parseHTML( mw.message( userMsg, username 
).parse() ) );
        }
-       this.showSaveError(
-               $( badToken ).add( $.parseHTML( mw.message( userMsg, username 
).parse() ) )
-       );
-       this.emit( 'saveErrorNewUser' );
+       this.showSaveError( $msg );
 };
 
 /**
@@ -669,16 +678,6 @@
                false // prevents reapply
        );
        this.emit( 'saveErrorUnknown', errorMsg );
-};
-
-/**
- * Handle a bad token
- *
- * @method
- * @fires saveErrorBadToken
- */
-ve.init.mw.ArticleTarget.prototype.saveErrorBadToken = function () {
-       this.emit( 'saveErrorBadToken' );
 };
 
 /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I17d4452f688ec22631dbd12af223731635004d66
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>

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

Reply via email to