Skip to content

Commit

Permalink
Migrate from SchemaMobileWebEditing to SchemaEdit
Browse files Browse the repository at this point in the history
* Changes EditorOverlayWithToolbar to just identify as the 'wikitext' editor
* No longer use funnels

Bug: T110272
Change-Id: I50391ecef23c7189bdbe8f7619122cf2c948ce6c
  • Loading branch information
Alex Monk authored and Krenair committed Sep 10, 2015
1 parent 3ff0216 commit c0a8d30
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 94 deletions.
4 changes: 2 additions & 2 deletions includes/MobileFrontend.hooks.php
Expand Up @@ -921,9 +921,9 @@ public static function onResourceLoaderGetLessVars( &$lessVars ) {
*/
private static function getEventLoggingSchemas() {
return array(
'Edit' => 13457736,
'MobileWebBrowse' => 12119641,
'MobileWebDiffClickTracking' => 10720373,
'MobileWebEditing' => 8599025,
'MobileWebMainMenuClickTracking' => 11568715,
'MobileWebSearch' => 12054448,
'MobileWebUIClickTracking' => 10742159,
Expand Down Expand Up @@ -962,9 +962,9 @@ private static function registerMobileLoggingSchemasModule( $resourceLoader ) {
->getMFConfig()->get( 'MFResourceFileModuleBoilerplate' );

$scripts = array(
'resources/mobile.loggingSchemas/SchemaEdit.js',
'resources/mobile.loggingSchemas/SchemaMobileWeb.js',
'resources/mobile.loggingSchemas/SchemaMobileWebClickTracking.js',
'resources/mobile.loggingSchemas/SchemaMobileWebEditing.js',
'resources/mobile.loggingSchemas/SchemaMobileWebWatching.js',
'resources/mobile.loggingSchemas/SchemaMobileWebSearch.js',
'resources/mobile.loggingSchemas/SchemaMobileWebBrowse.js',
Expand Down
2 changes: 1 addition & 1 deletion includes/Resources.php
Expand Up @@ -528,6 +528,7 @@
// Route needs moduleLoader
'mobile.overlays',
'mediawiki.jqueryMsg',
'mobile.loggingSchemas',
),
'messages' => array(
// editor.js
Expand Down Expand Up @@ -585,7 +586,6 @@

'mobile.editor.common' => $wgMFResourceParsedMessageModuleBoilerplate + array(
'dependencies' => array(
'mobile.loggingSchemas',
'oojs-ui',
'mobile.overlays',
'mobile.editor.api',
Expand Down
70 changes: 39 additions & 31 deletions resources/mobile.editor.common/EditorOverlayBase.js
@@ -1,7 +1,6 @@
( function ( M, $ ) {
var Overlay = M.require( 'Overlay' ),
browser = M.require( 'browser' ),
SchemaMobileWebEditing = M.require( 'loggingSchemas/SchemaMobileWebEditing' ),
Icon = M.require( 'Icon' ),
toast = M.require( 'toast' ),
user = M.require( 'user' ),
Expand Down Expand Up @@ -65,6 +64,7 @@
* two different editing interfaces.
* @cfg {String} defaults.licenseMsg Text and link of the license, under which this contribution will be
* released to inform the user.
* @cfg {SchemaEdit} defaults.editSchema Schema to log events to.
*/
defaults: $.extend( {}, Overlay.prototype.defaults, {
hasToolbar: false,
Expand Down Expand Up @@ -102,25 +102,17 @@
'click .continue': 'onClickContinue',
'click .submit': 'onClickSubmit'
} ),

/**
* Logs an event to http://meta.wikimedia.org/wiki/Schema:MobileWebEditing
* @param {String} action name in workflow.
* @param {String} errorText error to report if applicable
* Logs an event to http://meta.wikimedia.org/wiki/Schema:Edit
* @param {Object} data
*/
log: function ( action, errorText ) {
var
data = {
action: action,
section: this.sectionId,
editor: this.editor,
funnel: this.funnel
};
if ( errorText ) {
data.errorText = errorText;
}
return this.schema.log( data );
log: function ( data ) {
return this.schema.log( $.extend( data, {
editor: this.editor,
editingSessionId: this.sessionId
} ) );
},

/**
* If this is a new article, require confirmation before saving.
* @method
Expand Down Expand Up @@ -158,7 +150,9 @@
toast.showOnPageReload( msg, 'success' );

// Ensure we don't lose this event when logging
this.log( 'success' ).always( function () {
this.log( {
action: 'saveSuccess'
} ).always( function () {
if ( self.sectionLine ) {
title = title + '#' + self.sectionLine;
}
Expand Down Expand Up @@ -188,9 +182,9 @@
this.isNewPage = options.isNewPage;
this.isNewEditor = options.isNewEditor;
this.sectionId = options.sectionId;
this.funnel = options.funnel;
this.schema = new SchemaMobileWebEditing();
this.schema = options.editSchema;
this.config = mw.config.get( 'wgMFEditorOptions' );
this.sessionId = options.sessionId;
this.allowCloseWindow = mw.confirmCloseWindow( {
/** Returns true, if content has changed, otherwise false */
test: function () {
Expand All @@ -207,14 +201,12 @@
Overlay.prototype.initialize.apply( this, arguments );
},
/**
* Report errors back to the user. Silently record the error using EventLogging.
* Report load errors back to the user. Silently record the error using EventLogging.
* @method
* @param {String} msg key of message to display to user
* @param {String} errorText to log to EventLogging
* @param {String} text Text of message to display to user
*/
reportError: function ( msg, errorText ) {
this.log( 'error', errorText );
toast.show( msg, 'toast error' );
reportError: function ( text ) {
toast.show( text, 'toast error' );
},
/**
* Prepares the penultimate screen before saving.
Expand All @@ -223,7 +215,9 @@
*/
onStageChanges: function () {
this.showHidden( '.save-header, .save-panel' );
this.log( 'save' );
this.log( {
action: 'saveIntent'
} );
// Scroll to the top of the page, so that the summary input is visible
// (even if overlay was scrolled down when editing) and weird iOS header
// problems are avoided (header position not updating to the top of the
Expand All @@ -242,7 +236,9 @@
this.confirmAborted = true;
return;
}
this.log( 'submit' );
this.log( {
action: 'saveAttempt'
} );
},
/** @inheritdoc **/
postRender: function () {
Expand All @@ -251,7 +247,9 @@
this.$el.addClass( 'android-2' );
}
// log edit attempt
this.log( 'attempt' );
this.log( {
action: 'ready'
} );

// decide what happens, when the user clicks the continue button
if ( this.config.skipPreview ) {
Expand All @@ -267,10 +265,20 @@
},
/**
* Back button click handler
* @method
*/
onClickBack: function () {
onClickBack: $.noop,
/**
* Exit handler
*/
onExit: function () {
Overlay.prototype.onExit.apply( this, arguments );
// log cancel attempt
this.log( 'cancel' );
this.log( {
action: 'abort',
mechanism: 'cancel',
type: this.hasChanged() ? 'abandon' : 'nochange'
} );
},
/**
* Submit button click handler
Expand Down
Expand Up @@ -12,7 +12,6 @@
templatePartials: $.extend( {}, EditorOverlay.prototype.templatePartials, {
footer: mw.template.get( 'mobile.editor.overlay.withtoolbar', 'editorFooter.hogan' )
} ),
editor: 'SourceEditorWithFormatting',
/** @inheritdoc **/
postRender: function () {
var self = this;
Expand Down
32 changes: 26 additions & 6 deletions resources/mobile.editor.overlay/EditorOverlay.js
Expand Up @@ -56,7 +56,7 @@
msg: mw.msg( 'mobile-frontend-editor-anonwarning' )
}
} ),
editor: 'SourceEditor',
editor: 'wikitext',
sectionLine: '',

/**
Expand Down Expand Up @@ -322,8 +322,8 @@
}
self.clearSpinner();
} )
.fail( function ( error ) {
self.reportError( mw.msg( 'mobile-frontend-editor-error-loading' ), error );
.fail( function () {
self.reportError( mw.msg( 'mobile-frontend-editor-error-loading' ) );
} );
},

Expand All @@ -336,7 +336,11 @@
*/
_switchToVisualEditor: function ( options ) {
var self = this;
this.log( 'switch' );
this.log( {
action: 'abort',
type: 'switchnochange',
mechanism: 'navigate'
} );
// Save a user setting indicating that this user prefers using the VisualEditor
settings.save( 'preferredEditor', 'VisualEditor', true );
// Load the VisualEditor and replace the SourceEditor overlay with it
Expand Down Expand Up @@ -419,11 +423,21 @@
'readonly',
'blocked',
'autoblocked'
];
],
key = response.error.code,
typeMap = {
'editconflict': 'editConflict',
'wasdeleted': 'editPageDeleted',
'abusefilter-disallowed': 'extensionAbuseFilter',
'captcha': 'extensionConfirmEdit',
'spamprotectiontext': 'extensionSpamBlacklist',
'titleblacklist-forbidden-edit': 'extensionTitleBlacklist'
};

if ( data.type === 'captcha' ) {
self.captchaId = data.details.id;
self.handleCaptcha( data.details );
key = 'captcha';
} else if ( data.type === 'abusefilter' ) {
self._showAbuseFilter( data.details.type, data.details.message );
} else {
Expand All @@ -438,9 +452,15 @@
msg = mw.msg( 'mobile-frontend-editor-error' );
}

self.reportError( msg, data.details );
self.reportError( msg );
self.showHidden( '.save-header, .save-panel' );
}

self.log( {
action: 'saveFailure',
message: msg,
type: typeMap[key] || 'responseUnknown'
} );
} );
},

Expand Down
8 changes: 6 additions & 2 deletions resources/mobile.editor.ve/VisualEditorOverlay.js
Expand Up @@ -19,7 +19,7 @@
} ),
/** @inheritdoc **/
className: 'overlay editor-overlay editor-overlay-ve',
editor: 'VisualEditor',
editor: 'visualeditor',
/**
* Set options that apply specifically to VisualEditorOverlay but not
* EditorOverlay so that an EditorOverlay instance can be created effortlessly.
Expand Down Expand Up @@ -113,7 +113,11 @@
*/
switchToSourceEditor: function () {
var self = this;
this.log( 'switch' );
this.log( {
action: 'abort',
type: 'switchnochange',
mechanism: 'navigate'
} );
// Save a user setting indicating that this user prefers using the SourceEditor
settings.save( 'preferredEditor', 'SourceEditor', true );
this.showSpinner();
Expand Down
Expand Up @@ -175,11 +175,11 @@ ve.init.mw.MobileFrontendArticleTarget.prototype.adjustContentPadding = function
/*
* FIXME: @inheritdoc once this file is in the right repo
*/
ve.init.mw.MobileFrontendArticleTarget.prototype.loadFail = function ( errorText ) {
ve.init.mw.MobileFrontendArticleTarget.prototype.loadFail = function ( key, text ) {
// Parent method
ve.init.mw.MobileFrontendArticleTarget.super.prototype.loadFail.apply( this, arguments );

this.overlay.reportError( errorText, 'visualeditor-load-error' );
this.overlay.reportError( text );
this.overlay.hide();
};

Expand Down
34 changes: 29 additions & 5 deletions resources/mobile.editor/init.js
Expand Up @@ -33,7 +33,8 @@
isVisualEditorEnabled = veConfig,
CtaDrawer = M.require( 'CtaDrawer' ),
drawer,
$caEdit = $( '#ca-edit' );
$caEdit = $( '#ca-edit' ),
SchemaEdit = M.require( 'loggingSchemas/SchemaEdit' );

/**
* Prepend an edit page button to the container
Expand Down Expand Up @@ -123,7 +124,7 @@
window.alert( mw.msg( 'mobile-frontend-editor-undo-unsupported' ) );
}

overlayManager.add( /^\/editor\/(\d+)\/?([^\/]*)$/, function ( sectionId, funnel ) {
overlayManager.add( /^\/editor\/(\d+)$/, function ( sectionId ) {
var
// FIXME: Clean up selector when cache has cleared.
$content = $( '#content #bodyContent, #content_wrapper #content' ),
Expand All @@ -136,12 +137,31 @@
isNewPage: isNewPage,
isNewEditor: user.getEditCount() === 0,
oldId: mw.util.getParamValue( 'oldid' ),
funnel: funnel || 'article',
contentLang: $content.attr( 'lang' ),
contentDir: $content.attr( 'dir' )
contentDir: $content.attr( 'dir' ),
sessionId: mw.user.generateRandomSessionId(),
editSchema: new SchemaEdit
},
visualEditorNamespaces = veConfig && veConfig.namespaces;
visualEditorNamespaces = veConfig && veConfig.namespaces,
initMechanism = mw.util.getParamValue( 'redlink' ) ? 'new' : 'click';

/**
* Log init event to edit schema.
* Need to log this from outside the Overlay object because that module
* won't have loaded yet.
* @private
* @ignore
* @method
*/
function logInit( editor ) {
editorOptions.editSchema.log( {
action: 'init',
type: 'section',
mechanism: initMechanism,
editor: editor,
editingSessionId: editorOptions.sessionId
} );
}
/**
* Load source editor
* @private
Expand All @@ -150,6 +170,9 @@
*/
function loadSourceEditor() {
var rlModuleName, moduleName;

logInit( 'wikitext' );

// use the new wikitexteditor with a basic toolbar as a test for beta users and users
// without an iphone (bottom toolbars doesn't work) - Bug T109224
// FIXME: Make this working with iOS8
Expand Down Expand Up @@ -184,6 +207,7 @@
// the VisualEditor is the default editor for this wiki
preferredEditor === 'VisualEditor'
) {
logInit( 'visualeditor' );
loader.loadModule( 'mobile.editor.ve' ).done( function () {
var VisualEditorOverlay = M.require( 'modules/editor/VisualEditorOverlay' );
result.resolve( new VisualEditorOverlay( editorOptions ) );
Expand Down

0 comments on commit c0a8d30

Please sign in to comment.