Robmoen has uploaded a new change for review.

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


Change subject: Move save error tracking into target subclass
......................................................................

Move save error tracking into target subclass

Primary reasons for this change:
 * Fixes an error when handling saveErrors on mobile
 * Save errors on mobile are polluting desktop data
 * Simplification of target classes

Change-Id: I036e4f2129d929db0a3b9a4baa87c946a4b194a9
---
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
M modules/ve-mw/init/ve.init.mw.Target.js
2 files changed, 35 insertions(+), 19 deletions(-)


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

diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
index d9e5495..12e2d08 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -34,7 +34,7 @@
        this.saveDialog = null;
        this.onBeforeUnloadFallback = null;
        this.onBeforeUnloadHandler = null;
-       this.timings = {};
+       this.timings = { 'saveRetries': 0 };
        this.active = false;
        this.activating = false;
        this.deactivating = false;
@@ -75,6 +75,7 @@
                'saveAsyncComplete': 'onSaveAsyncComplete',
                'saveErrorSpamBlacklist': 'onSaveErrorSpamBlacklist',
                'saveErrorAbuseFilter': 'onSaveErrorAbuseFilter',
+               'saveErrorBadToken': 'onSaveErrorBadToken',
                'saveErrorNewUser': 'onSaveErrorNewUser',
                'saveErrorCaptcha': 'onSaveErrorCaptcha',
                'saveErrorUnknown': 'onSaveErrorUnknown',
@@ -286,6 +287,7 @@
  */
 ve.init.mw.ViewPageTarget.prototype.onSave = function ( html, newid ) {
        ve.track( 'performance.user.saveComplete', { 'duration': ve.now() - 
this.timings.saveDialogSave } );
+       this.timings.saveRetries = 0;
        if ( !this.pageExists || this.restoring ) {
                // This is a page creation or restoration, refresh the page
                this.tearDownBeforeUnloadHandler();
@@ -361,6 +363,7 @@
 ve.init.mw.ViewPageTarget.prototype.onSaveErrorEmpty = function () {
        this.showSaveError( ve.msg( 'visualeditor-saveerror', 'Empty server 
response' ) );
        this.saveDialog.saveButton.setDisabled( true );
+       this.trackSaveError( 'empty' );
 };
 
 /**
@@ -375,6 +378,7 @@
                ve.msg( 'spamprotectiontext' ) + ' ' + ve.msg( 
'spamprotectionmatch', editApi.spamblacklist.split( '|' ).join( ', ' ) )
        );
        this.saveDialog.saveButton.setDisabled( true );
+       this.trackSaveError( 'spamblacklist' );
 };
 
 /**
@@ -388,6 +392,11 @@
        // Don't disable the save button. If the action is not disallowed the 
user may save the
        // edit by pressing Save again. The AbuseFilter API currently has no 
way to distinguish
        // between filter triggers that are and aren't disallowing the action.
+       this.trackSaveError( 'abusefilter' );
+};
+
+ve.init.mw.ViewPageTarget.prototype.onSaveErrorBadToken = function () {
+       this.trackSaveError( 'badtoken' );
 };
 
 /**
@@ -437,6 +446,7 @@
                        this.captcha.input.$element
                ), false
        );
+       this.trackSaveError( 'captcha' );
 };
 
 /**
@@ -457,6 +467,21 @@
                )
        );
        this.saveDialog.saveButton.setDisabled( true );
+       this.trackSaveError( 'unknown' );
+};
+
+/**
+ * Track a save error by type
+ *
+ * @method
+ * @param {string} type Text for error type
+ */
+ve.init.mw.viewPageTarget.prototype.trackSaveError = function ( type ) {
+       ve.track( 'performance.user.saveError', {
+               'duration': ve.now() - this.timings.saveDialogSave,
+               'retries': this.timings.saveRetries,
+               'type': type
+       } );
 };
 
 /**
@@ -707,7 +732,7 @@
  */
 ve.init.mw.ViewPageTarget.prototype.onSaveDialogSave = function () {
        this.timings.saveDialogSave = ve.now();
-       this.timings.saveRetries = 0;
+       this.timings.saveRetries++;
        ve.track( 'behavior.saveDialogOpenTillSave', {
                'duration': this.timings.saveDialogSave - 
this.timings.saveDialogOpen
        } );
diff --git a/modules/ve-mw/init/ve.init.mw.Target.js 
b/modules/ve-mw/init/ve.init.mw.Target.js
index 3b8ae6d..7e0bcc8 100644
--- a/modules/ve-mw/init/ve.init.mw.Target.js
+++ b/modules/ve-mw/init/ve.init.mw.Target.js
@@ -123,6 +123,11 @@
  */
 
 /**
+ * @event saveErrorBadToken
+ * Fired on save if the edit token is bad
+ */
+
+/**
  * @event saveErrorNewUser
  * Fired when user is logged in as a new user
  * @param {boolean|undefined} isAnon Is newly logged in user anonymous. If
@@ -383,24 +388,19 @@
  * @fires saveErrorEmpty
  * @fires saveErrorSpamBlacklist
  * @fires saveErrorAbuseFilter
+ * @fires saveErrorBadToken
  * @fires saveErrorNewUser
  * @fires saveErrorCaptcha
  * @fires saveErrorUnknown
  */
 ve.init.mw.Target.prototype.onSaveError = function ( jqXHR, status, data ) {
        var api, editApi,
-               trackData = {
-                       'duration': ve.now() - this.timings.saveDialogSave,
-                       'retries': this.timings.saveRetries
-               },
                viewPage = this;
        this.saving = false;
        this.emit( 'saveAsyncComplete' );
 
        // Handle empty response
        if ( !data ) {
-               trackData.type = 'empty';
-               ve.track( 'performance.user.saveError', trackData );
                this.emit( 'saveErrorEmpty' );
                return;
        }
@@ -408,8 +408,6 @@
 
        // Handle spam blacklist error (either from core or from 
Extension:SpamBlacklist)
        if ( editApi && editApi.spamblacklist ) {
-               trackData.type = 'spamblacklist';
-               ve.track( 'performance.user.saveError', trackData );
                this.emit( 'saveErrorSpamBlacklist', editApi );
                return;
        }
@@ -417,8 +415,6 @@
        // Handle warnings/errors from Extension:AbuseFilter
        // TODO: Move this to a plugin
        if ( editApi && editApi.info && editApi.info.indexOf( 'Hit 
AbuseFilter:' ) === 0 && editApi.warning ) {
-               trackData.type = 'abusefilter';
-               ve.track( 'performance.user.saveError', trackData );
                this.emit( 'saveErrorAbuseFilter', editApi );
                return;
        }
@@ -461,12 +457,10 @@
                                                        mw.config.get( 
'wgUserId' ) === userInfo.id
                                        ) {
                                                // New session is the same user 
still
-                                               this.timings.saveRetries++;
                                                viewPage.saveDocument();
                                        } else {
                                                // The now current session is a 
different user
-                                               trackData.type = 'badtoken';
-                                               ve.track( 
'performance.user.saveError', trackData );
+                                               viewPage.emit( 
'saveErrorBadToken' );
                                                if ( isAnon ) {
                                                        // New session is an 
anonymous user
                                                        mw.config.set( {
@@ -503,18 +497,15 @@
        // API for different things in the UI. At this point we only support 
the FancyCaptha which we
        // very intuitively detect by the presence of a "url" property.
        if ( editApi && editApi.captcha && editApi.captcha.url ) {
-               trackData.type = 'captcha';
-               ve.track( 'performance.user.saveError', trackData );
                this.emit( 'saveErrorCaptcha', editApi );
                return;
        }
 
        // Handle (other) unknown and/or unrecoverable errors
-       trackData.type = 'unknown';
-       ve.track( 'performance.user.saveError', trackData );
        this.emit( 'saveErrorUnknown', editApi, data );
 };
 
+
 /**
  * Handle a successful show changes request.
  *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I036e4f2129d929db0a3b9a4baa87c946a4b194a9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Robmoen <[email protected]>

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

Reply via email to