jenkins-bot has submitted this change and it was merged.
Change subject: Hygiene: Refactor schemas
......................................................................
Hygiene: Refactor schemas
Do not load schema files if EventLogging is not installed.
Bug: T122504
Change-Id: I6592463570f2cb48e882f8edbb155bab00eadd1f
---
M extension.json
M includes/Gather.hooks.php
M resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
M resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
M resources/ext.gather.collection.editor/CollectionEditOverlay.js
M resources/ext.gather.collection.flag/CollectionFlagOverlay.js
D resources/ext.gather.logging/SchemaGather.js
D resources/ext.gather.logging/SchemaGatherFlags.js
A resources/ext.gather.schema/schemaGatherClicks.js
A resources/ext.gather.schema/schemaGatherFlags.js
M resources/ext.gather.watchstar/CollectionsWatchstar.js
M resources/ext.gather.watchstar/WatchstarPageActionOverlay.js
M
tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
13 files changed, 112 insertions(+), 135 deletions(-)
Approvals:
Jhernandez: Looks good to me, approved
Jdlrobson: Looks good to me, but someone else must approve
Bmansurov: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index 931e63b..9293c8d 100644
--- a/extension.json
+++ b/extension.json
@@ -169,10 +169,6 @@
"mobile.startup",
"mobile.user",
"ext.gather.schema"
- ],
- "scripts": [
- "resources/ext.gather.logging/SchemaGather.js",
-
"resources/ext.gather.logging/SchemaGatherFlags.js"
]
},
"ext.gather.api": {
diff --git a/includes/Gather.hooks.php b/includes/Gather.hooks.php
index b808d7b..055b05a 100644
--- a/includes/Gather.hooks.php
+++ b/includes/Gather.hooks.php
@@ -36,22 +36,26 @@
* @return bool Always true
*/
public static function onResourceLoaderRegisterModules( ResourceLoader
&$resourceLoader ) {
- $dependencies = array();
+ $schema = array(
+ 'localBasePath' => dirname( __DIR__ ),
+ 'remoteExtPath' => 'Gather',
+ 'targets' => array( 'mobile', 'desktop' ),
+ );
if ( is_callable( 'EventLogging::logEvent' ) ) {
- $dependencies = array(
- 'schema.GatherClicks',
- 'schema.GatherFlags',
+ $schema += array(
+ 'dependencies' => array(
+ 'schema.GatherClicks',
+ 'schema.GatherFlags',
+ ),
+ 'scripts' => array(
+
"resources/ext.gather.schema/schemaGatherClicks.js",
+
"resources/ext.gather.schema/schemaGatherFlags.js"
+ )
);
}
- $resourceLoader->register( 'ext.gather.schema', array(
- 'dependencies' => $dependencies,
- 'targets' => array(
- 'desktop',
- 'mobile'
- ),
- ) );
+ $resourceLoader->register( 'ext.gather.schema', $schema );
return true;
}
diff --git
a/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
b/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
index 9e1159d..4579e07 100644
---
a/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
+++
b/resources/ext.gather.collection.contentOverlay/CollectionsContentOverlay.js
@@ -1,7 +1,5 @@
( function ( M, $ ) {
- var SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
- schema = new SchemaGather(),
- icons = M.require( 'mobile.startup/icons' ),
+ var icons = M.require( 'mobile.startup/icons' ),
toast = M.require( 'mobile.toast/toast' ),
user = M.require( 'mobile.user/user' ),
Icon = M.require( 'mobile.startup/Icon' ),
@@ -109,7 +107,7 @@
/** @inheritdoc */
hide: function () {
$( 'html' ).removeClass( 'gather-overlay-enabled' );
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'hide'
} );
return
CollectionsContentOverlayBase.prototype.hide.apply( this, arguments );
@@ -239,7 +237,7 @@
ev.preventDefault();
if ( this.isTitleValid( title ) ) {
this.addCollection( title, page );
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'new-collection'
} );
} else {
@@ -274,7 +272,7 @@
this.addToCollection( collection, page );
}
ev.stopPropagation();
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'select-collection'
} );
},
@@ -346,7 +344,7 @@
self._collectionStateChange( collection, false
);
self._notifyChanges( collection, false );
} ).fail( function ( errMsg ) {
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'remove-collection-error',
errorText: errMsg
} );
@@ -365,7 +363,7 @@
self._collectionStateChange( collection, true );
self._notifyChanges( collection, true );
} ).fail( function () {
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'add-collection-error'
} );
self.hideSpinner();
@@ -409,7 +407,7 @@
self.hide();
} );
} ).fail( function ( errMsg ) {
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'create-collection-error',
errorText: errMsg
} );
diff --git a/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
b/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
index 87c2e55..d2ad184 100644
--- a/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
+++ b/resources/ext.gather.collection.delete/CollectionDeleteOverlay.js
@@ -1,8 +1,6 @@
( function ( M, $ ) {
- var SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
- schema = new SchemaGather(),
- toast = M.require( 'mobile.toast/toast' ),
+ var toast = M.require( 'mobile.toast/toast' ),
CollectionsGateway = M.require(
'ext.gather.api/CollectionsGateway' ),
ConfirmationOverlay = M.require(
'ext.gather.collection.confirm/ConfirmationOverlay' );
@@ -44,22 +42,21 @@
// disable button and inputs
this.$( '.confirm, .cancel' ).prop( 'disabled', true );
this.gateway.removeCollection( this.id ).done( function
() {
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'delete-collection'
- } ).always( function () {
- self.$( '.spinner' ).hide();
- // Show toast after reloading
- toast.showOnPageReload(
self.options.deleteSuccessMsg, 'toast' );
- self.hide();
- // Go to the collections list page as
collection will no longer exist
- window.location.href = mw.util.getUrl(
'Special:Gather' );
} );
+ self.$( '.spinner' ).hide();
+ // Show toast after reloading
+ toast.showOnPageReload(
self.options.deleteSuccessMsg, 'toast' );
+ self.hide();
+ // Go to the collections list page as
collection will no longer exist
+ window.location.href = mw.util.getUrl(
'Special:Gather' );
} ).fail( function ( errMsg ) {
toast.show( self.options.deleteFailedError,
'toast error' );
self.hide();
// Make it possible to try again.
self.$( '.confirm, .cancel' ).prop( 'disabled',
false );
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'delete-collection-error',
errorText: errMsg
} );
diff --git a/resources/ext.gather.collection.editor/CollectionEditOverlay.js
b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
index 342a359..5d3f686 100644
--- a/resources/ext.gather.collection.editor/CollectionEditOverlay.js
+++ b/resources/ext.gather.collection.editor/CollectionEditOverlay.js
@@ -5,8 +5,6 @@
CollectionSearchPanel = M.require(
'ext.gather.page.search/CollectionSearchPanel' ),
Overlay = M.require( 'mobile.overlays/Overlay' ),
Icon = M.require( 'mobile.startup/Icon' ),
- SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
- schema = new SchemaGather(),
router = M.require( 'mobile.startup/router' ),
CollectionDeleteOverlay = M.require(
'ext.gather.collection.delete/CollectionDeleteOverlay' ),
RelatedPages = M.require(
'ext.gather.relatedpages/RelatedPages' ),
@@ -421,16 +419,15 @@
} );
}
self._populateTitleAndDescription();
- schema.log( eventParams ).always(
function () {
- self._switchToFirstPane();
- // Make sure when the user
leaves the overlay the page gets refreshed
- self._stateChanged = true;
- } );
+ mw.track( 'gather.schemaGatherClicks',
eventParams );
+ self._switchToFirstPane();
+ // Make sure when the user leaves the
overlay the page gets refreshed
+ self._stateChanged = true;
} ).fail( function ( errMsg ) {
toast.show(
self.options.editFailedError, 'toast error' );
// Make it possible to try again.
self.$( '.mw-ui-input,
.save-description' ).prop( 'disabled', false );
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName:
'edit-collection-error',
errorMessage: errMsg
} );
diff --git a/resources/ext.gather.collection.flag/CollectionFlagOverlay.js
b/resources/ext.gather.collection.flag/CollectionFlagOverlay.js
index f04faf8..857265a 100644
--- a/resources/ext.gather.collection.flag/CollectionFlagOverlay.js
+++ b/resources/ext.gather.collection.flag/CollectionFlagOverlay.js
@@ -1,8 +1,6 @@
( function ( M, $ ) {
var ConfirmationOverlay = M.require(
'ext.gather.collection.confirm/ConfirmationOverlay' ),
- SchemaGatherFlags = M.require(
'ext.gather.logging/SchemaGatherFlags' ),
- schema = new SchemaGatherFlags(),
toast = M.require( 'mobile.toast/toast' );
/**
@@ -35,13 +33,12 @@
this.showSpinner();
// disable buttons
this.$( '.confirm, .cancel' ).prop( 'disabled', true );
- schema.log( {
+ mw.track( 'gather.schemaGatherFlags', {
collectionId: self.id
- } ).always( function () {
- toast.show( self.options.flagSuccessMsg,
'toast' );
- self.emit( 'collection-flagged' );
- self.hide();
} );
+ toast.show( self.options.flagSuccessMsg, 'toast' );
+ self.emit( 'collection-flagged' );
+ self.hide();
},
/**
* Override Overlay:onExit function as this overlay is not
controlled by OverlayManager
diff --git a/resources/ext.gather.logging/SchemaGather.js
b/resources/ext.gather.logging/SchemaGather.js
deleted file mode 100644
index 4d92048..0000000
--- a/resources/ext.gather.logging/SchemaGather.js
+++ /dev/null
@@ -1,38 +0,0 @@
-( function ( M, $ ) {
- var skinName = mw.config.get( 'skin' ),
- context = M.require( 'mobile.context/context' ),
- mobileMode = context.getMode(),
- Schema = M.require( 'mobile.startup/Schema' ),
- user = M.require( 'mobile.user/user' );
-
- if ( mobileMode ) {
- skinName += '-' + mobileMode;
- }
- /**
- * @class SchemaGather
- * @extends Schema
- */
- function SchemaGather( options ) {
- Schema.call( this, options );
- }
-
- OO.mfExtend( SchemaGather, Schema, {
- /**
- * @inheritdoc
- */
- defaults: $.extend( {}, Schema.prototype.defaults, {
- skin: skinName,
- userId: mw.user.getId(),
- // FIXME: use mw.user when method available
- // Null when user is anon, set to 0
- userEditCount: user.getEditCount() || 0
- } ),
- /**
- * @inheritdoc
- */
- name: 'GatherClicks'
- } );
-
- M.define( 'ext.gather.logging/SchemaGather', SchemaGather );
-
-}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/ext.gather.logging/SchemaGatherFlags.js
b/resources/ext.gather.logging/SchemaGatherFlags.js
deleted file mode 100644
index 1615fc4..0000000
--- a/resources/ext.gather.logging/SchemaGatherFlags.js
+++ /dev/null
@@ -1,32 +0,0 @@
-( function ( M, $ ) {
- var Schema = M.require( 'mobile.startup/Schema' ),
- user = M.require( 'mobile.user/user' );
-
- /**
- * @class SchemaGatherFlags
- * @extends Schema
- */
- function SchemaGatherFlags( options ) {
- Schema.call( this, options );
- }
-
- OO.mfExtend( SchemaGatherFlags, Schema, {
- /**
- * @inheritdoc
- */
- defaults: $.extend( {}, Schema.prototype.defaults, {
- userId: mw.user.getId(),
- // FIXME: use mw.user when method available
- // Null when user is anon, set to 0
- userEditCount: user.getEditCount() || 0,
- userGroups: mw.config.get( 'wgUserGroups' ).join( ',' )
- } ),
- /**
- * @inheritdoc
- */
- name: 'GatherFlags'
- } );
-
- M.define( 'ext.gather.logging/SchemaGatherFlags', SchemaGatherFlags );
-
-}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/ext.gather.schema/schemaGatherClicks.js
b/resources/ext.gather.schema/schemaGatherClicks.js
new file mode 100644
index 0000000..1834ebe
--- /dev/null
+++ b/resources/ext.gather.schema/schemaGatherClicks.js
@@ -0,0 +1,35 @@
+( function ( M ) {
+ var skinName = mw.config.get( 'skin' ),
+ context = M.require( 'mobile.context/context' ),
+ mobileMode = context.getMode(),
+ user = M.require( 'mobile.user/user' ),
+ schemaGather;
+
+ if ( mobileMode ) {
+ skinName += '-' + mobileMode;
+ }
+
+ /**
+ * Gather schema
+ * https://meta.wikimedia.org/wiki/Schema:GatherClicks
+ *
+ * @class schemaGather
+ * @singleton
+ */
+ schemaGather = new mw.eventLog.Schema(
+ 'GatherClicks',
+ 0,
+ {
+ skin: skinName,
+ userId: mw.user.getId(),
+ // FIXME: use mw.user when method available
+ // Null when user is anon, set to 0
+ userEditCount: user.getEditCount() || 0
+ }
+ );
+
+ mw.trackSubscribe( 'gather.schemaGatherClicks', function ( topic, data
) {
+ schemaGather.log( data );
+ } );
+
+}( mw.mobileFrontend ) );
diff --git a/resources/ext.gather.schema/schemaGatherFlags.js
b/resources/ext.gather.schema/schemaGatherFlags.js
new file mode 100644
index 0000000..4f9a93e
--- /dev/null
+++ b/resources/ext.gather.schema/schemaGatherFlags.js
@@ -0,0 +1,28 @@
+( function ( M ) {
+ var schemaGatherFlags,
+ user = M.require( 'mobile.user/user' );
+
+ /**
+ * GatherFlags schema
+ * https://meta.wikimedia.org/wiki/Schema:GatherFlags
+ *
+ * @class schemaGatherFlags
+ * @singleton
+ */
+ schemaGatherFlags = new mw.eventLog.Schema(
+ 'GatherFlags',
+ 0,
+ {
+ userId: mw.user.getId(),
+ // FIXME: use mw.user when method available
+ // Null when user is anon, set to 0
+ userEditCount: user.getEditCount() || 0,
+ userGroups: mw.config.get( 'wgUserGroups' ).join( ',' )
+ }
+ );
+
+ mw.trackSubscribe( 'gather.schemaGatherFlags', function ( topic, data )
{
+ schemaGatherFlags.log( data );
+ } );
+
+}( mw.mobileFrontend ) );
diff --git a/resources/ext.gather.watchstar/CollectionsWatchstar.js
b/resources/ext.gather.watchstar/CollectionsWatchstar.js
index 01ec1df..3d3dd55 100644
--- a/resources/ext.gather.watchstar/CollectionsWatchstar.js
+++ b/resources/ext.gather.watchstar/CollectionsWatchstar.js
@@ -1,9 +1,7 @@
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
( function ( M ) {
- var SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
- schema = new SchemaGather(),
- CtaDrawer = M.require( 'mobile.drawers/CtaDrawer' ),
+ var CtaDrawer = M.require( 'mobile.drawers/CtaDrawer' ),
CollectionsContentOverlay = M.require(
'ext.gather.watchstar/CollectionsContentOverlay' ),
Icon = M.require( 'mobile.startup/Icon' ),
// FIXME: MobileFrontend code duplication
@@ -151,7 +149,7 @@
} else {
this.onStatusToggleUser.apply( this, arguments
);
}
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'click',
source: this.options.wasUserPrompted ?
'onboarding' : 'unknown'
} );
diff --git a/resources/ext.gather.watchstar/WatchstarPageActionOverlay.js
b/resources/ext.gather.watchstar/WatchstarPageActionOverlay.js
index 07ec224..64be5c3 100644
--- a/resources/ext.gather.watchstar/WatchstarPageActionOverlay.js
+++ b/resources/ext.gather.watchstar/WatchstarPageActionOverlay.js
@@ -1,8 +1,5 @@
( function ( M, $ ) {
- var
- SchemaGather = M.require( 'ext.gather.logging/SchemaGather' ),
- schema = new SchemaGather(),
- PageActionOverlay = M.require(
'mobile.contentOverlays/PointerOverlay' );
+ var PageActionOverlay = M.require(
'mobile.contentOverlays/PointerOverlay' );
/**
* @class WatchstarPageActionOverlay
@@ -34,7 +31,7 @@
* @event cancel
*/
this.emit( 'cancel' );
- schema.log( {
+ mw.track( 'gather.schemaGatherClicks', {
eventName: 'dismiss-onboarding'
} );
},
diff --git
a/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
b/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
index 51eb386..9f744e5 100644
---
a/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
+++
b/tests/qunit/ext.gather.collection.contentOverlay/test_CollectionsContentOverlay.js
@@ -6,16 +6,14 @@
( function ( M, $ ) {
var CollectionsGateway = M.require( 'ext.gather.api/CollectionsGateway'
),
Page = M.require( 'mobile.startup/Page' ),
- CollectionsContentOverlay = M.require(
'ext.gather.watchstar/CollectionsContentOverlay' ),
- Schema = M.require( 'mobile.startup/Schema' );
+ CollectionsContentOverlay = M.require(
'ext.gather.watchstar/CollectionsContentOverlay' );
QUnit.module( 'Gather: Add to collection overlay', {
setup: function () {
var d = $.Deferred().resolve( {
id: 2
} ),
- d2 = $.Deferred().resolve(),
- logResult = $.Deferred().reject( 'ACCESS
DENIED' );
+ d2 = $.Deferred().resolve();
this.page = new Page( {
title: 'Gather test'
@@ -35,7 +33,9 @@
titleInCollection: false
};
- this.sandbox.stub( Schema.prototype, 'log' ).returns(
logResult );
+ if ( mw.eventLog ) {
+ this.sandbox.stub(
mw.eventLog.Schema.prototype, 'log' );
+ }
}
} );
--
To view, visit https://gerrit.wikimedia.org/r/274115
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6592463570f2cb48e882f8edbb155bab00eadd1f
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Gather
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits