Bmansurov has uploaded a new change for review. https://gerrit.wikimedia.org/r/272921
Change subject: Hygiene: make Edit schema inherit from mw.eventLog.Schema ...................................................................... Hygiene: make Edit schema inherit from mw.eventLog.Schema Also load the schema file only when needed and not bundle it with other schema files. Bug: T122504 Change-Id: I7a09bd36b9cbfa4e214c62a3cfa886cf0feb931b --- M extension.json M includes/MobileFrontend.hooks.php M resources/mobile.editor.common/EditorOverlayBase.js D resources/mobile.loggingSchemas/SchemaEdit.js A resources/mobile.loggingSchemas/schemaEdit.js M resources/skins.minerva.editor/init.js 6 files changed, 85 insertions(+), 87 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/21/272921/1 diff --git a/extension.json b/extension.json index fd7e954..a96e1d5 100644 --- a/extension.json +++ b/extension.json @@ -1685,7 +1685,8 @@ "mobile.toast", "skins.minerva.toggling", "mobile.overlays", - "mediawiki.jqueryMsg" + "mediawiki.jqueryMsg", + "mobile.loggingSchemas.edit" ], "messages": { "0": "mobile-frontend-editor-disabled", diff --git a/includes/MobileFrontend.hooks.php b/includes/MobileFrontend.hooks.php index 5240b33..cb5cbac 100644 --- a/includes/MobileFrontend.hooks.php +++ b/includes/MobileFrontend.hooks.php @@ -1152,6 +1152,8 @@ */ public static function onEventLoggingRegisterSchemas( &$schemas ) { $schemas += self::getEventLoggingSchemas(); + // FIXME: should we not register the Edit schema reversion here? + // https://meta.wikimedia.org/wiki/Schema:Edit return true; } @@ -1169,7 +1171,6 @@ ); $scripts = array( - 'resources/mobile.loggingSchemas/SchemaEdit.js', 'resources/mobile.loggingSchemas/SchemaMobileWeb.js', 'resources/mobile.loggingSchemas/SchemaMobileWebClickTracking.js', 'resources/mobile.loggingSchemas/schemaMobileWebLanguageSwitcher.js', @@ -1179,12 +1180,24 @@ ); $schemaModules = array(); + $schemaEdit = $mfResourceFileModuleBoilerplate; + if ( class_exists( 'EventLogging' ) ) { $schemaModules = array_map( function ( $schema ) { return "schema.{$schema}"; }, array_keys( self::getEventLoggingSchemas() ) + ); + + $schemaEdit += array( + 'dependencies' => array( + 'ext.eventLogging.subscriber', + 'mobile.user' + ), + 'scripts' => array( + 'resources/mobile.loggingSchemas/schemaEdit.js', + ) ); } @@ -1199,6 +1212,7 @@ ); $resourceLoader->register( array( 'mobile.loggingSchemas' => $loggingSchemasModule ) ); + $resourceLoader->register( array( 'mobile.loggingSchemas.edit' => $schemaEdit ) ); } /** diff --git a/resources/mobile.editor.common/EditorOverlayBase.js b/resources/mobile.editor.common/EditorOverlayBase.js index 4ed104d..e31ff83 100644 --- a/resources/mobile.editor.common/EditorOverlayBase.js +++ b/resources/mobile.editor.common/EditorOverlayBase.js @@ -104,7 +104,6 @@ * 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, @@ -147,10 +146,12 @@ * @param {Object} data */ log: function ( data ) { - return this.schema.log( $.extend( data, { - editor: this.editor, - editingSessionId: this.sessionId - } ) ); + if ( this.schema ) { + this.schema.log( $.extend( data, { + editor: this.editor, + editingSessionId: this.sessionId + } ) ); + } }, /** diff --git a/resources/mobile.loggingSchemas/SchemaEdit.js b/resources/mobile.loggingSchemas/SchemaEdit.js deleted file mode 100644 index ebbcc2b..0000000 --- a/resources/mobile.loggingSchemas/SchemaEdit.js +++ /dev/null @@ -1,71 +0,0 @@ -( function ( M, $ ) { - var Schema = M.require( 'mobile.startup/Schema' ), - user = M.require( 'mobile.user/user' ); - - /** - * @class SchemaEdit - * @extends Schema - */ - function SchemaEdit() { - Schema.apply( this, arguments ); - } - - OO.mfExtend( SchemaEdit, Schema, { - /** - * https://meta.wikimedia.org/wiki/Schema:Edit - * @inheritdoc - **/ - name: 'Edit', - /** - * @inheritdoc - */ - isSampled: true, - /** - * @inheritdoc - */ - samplingRate: mw.config.get( 'wgMFSchemaEditSampleRate' ), - /** - * @inheritdoc - * @cfg {Object} defaults The options hash. - */ - defaults: $.extend( {}, Schema.prototype.defaults, { - 'page.id': mw.config.get( 'wgArticleId' ), - 'page.revid': mw.config.get( 'wgRevisionId' ), - 'page.title': mw.config.get( 'wgPageName' ), - 'page.ns': mw.config.get( 'wgNamespaceNumber' ), - 'user.id': user.getId(), - 'user.class': user.isAnon() ? 'IP' : undefined, - 'user.editCount': mw.config.get( 'wgUserEditCount', 0 ), - 'mediawiki.version': mw.config.get( 'wgVersion' ), - platform: 'phone', - integration: 'page', - version: 1 - } ), - /** - * @inheritdoc - */ - log: function ( data ) { - if ( mw.loader.getState( 'schema.Edit' ) === null ) { - // Only route any events into the Edit schema if the module is actually available. - // It won't be if EventLogging is installed but WikimediaEvents is not. - return $.Deferred().reject( 'schema.Edit not loaded.' ); - } else if ( this.isUserInBucket() ) { - data['action.' + data.action + '.type'] = data.type; - delete data.type; - data['action.' + data.action + '.mechanism'] = data.mechanism; - delete data.mechanism; - // data['action.' + data.action + '.timing'] = Math.round( computeDuration( ... ) ); - data['action.' + data.action + '.message'] = data.message; - delete data.message; - - mw.track( 'event.Edit', $.extend( {}, this.defaults, data ) ); - return $.Deferred().resolve(); - } - - return $.Deferred().reject( 'User not in the experimental condition.' ); - } - } ); - - M.define( 'mobile.loggingSchemas/SchemaEdit', SchemaEdit ); - -} )( mw.mobileFrontend, jQuery ); diff --git a/resources/mobile.loggingSchemas/schemaEdit.js b/resources/mobile.loggingSchemas/schemaEdit.js new file mode 100644 index 0000000..841ad22 --- /dev/null +++ b/resources/mobile.loggingSchemas/schemaEdit.js @@ -0,0 +1,47 @@ +( function ( M ) { + var user = M.require( 'mobile.user/user' ), + /** + * Edit schema + * https://meta.wikimedia.org/wiki/Schema:Edit + * + * @class schemaEdit + * @singleton + */ + schemaEdit = new mw.eventLog.Schema( + 'Edit', + mw.config.get( 'wgMFSchemaEditSampleRate' ), + { + 'page.id': mw.config.get( 'wgArticleId' ), + 'page.revid': mw.config.get( 'wgRevisionId' ), + 'page.title': mw.config.get( 'wgPageName' ), + 'page.ns': mw.config.get( 'wgNamespaceNumber' ), + 'user.id': user.getId(), + 'user.class': user.isAnon() ? 'IP' : undefined, + 'user.editCount': mw.config.get( 'wgUserEditCount', 0 ), + 'mediawiki.version': mw.config.get( 'wgVersion' ), + platform: 'phone', + integration: 'page', + version: 1 + } + ); + + /** + * Log an event + * + * @param {Object} data Data to log + */ + schemaEdit.log = function ( data ) { + data['action.' + data.action + '.type'] = data.type; + delete data.type; + data['action.' + data.action + '.mechanism'] = data.mechanism; + delete data.mechanism; + // data['action.' + data.action + '.timing'] = Math.round( computeDuration( ... ) ); + data['action.' + data.action + '.message'] = data.message; + delete data.message; + + mw.eventLog.Schema.prototype.log.call( this, data ); + }; + + M.define( 'mobile.loggingSchemas.edit/schemaEdit', schemaEdit ); + +} )( mw.mobileFrontend ); diff --git a/resources/skins.minerva.editor/init.js b/resources/skins.minerva.editor/init.js index cd474a2..27a891c 100644 --- a/resources/skins.minerva.editor/init.js +++ b/resources/skins.minerva.editor/init.js @@ -39,7 +39,11 @@ CtaDrawer = M.require( 'mobile.drawers/CtaDrawer' ), drawer, $caEdit = $( '#ca-edit' ), - SchemaEdit = M.require( 'mobile.loggingSchemas/SchemaEdit' ); + schemaEdit; + + if ( mw.eventLog ) { + schemaEdit = M.require( 'mobile.loggingSchemas.edit/schemaEdit' ); + } if ( user.isAnon() ) { blockInfo = false; @@ -155,7 +159,7 @@ contentLang: $content.attr( 'lang' ), contentDir: $content.attr( 'dir' ), sessionId: mw.user.generateRandomSessionId(), - editSchema: new SchemaEdit + editSchema: schemaEdit }, visualEditorNamespaces = veConfig && veConfig.namespaces, initMechanism = mw.util.getParamValue( 'redlink' ) ? 'new' : 'click'; @@ -170,13 +174,15 @@ * @method */ function logInit( editor ) { - editorOptions.editSchema.log( { - action: 'init', - type: 'section', - mechanism: initMechanism, - editor: editor, - editingSessionId: editorOptions.sessionId - } ); + if ( editorOptions.editSchema ) { + editorOptions.editSchema.log( { + action: 'init', + type: 'section', + mechanism: initMechanism, + editor: editor, + editingSessionId: editorOptions.sessionId + } ); + } } /** * Load source editor -- To view, visit https://gerrit.wikimedia.org/r/272921 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7a09bd36b9cbfa4e214c62a3cfa886cf0feb931b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits