Jdlrobson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/372077 )
Change subject: User always passed in as an argument to classes ...................................................................... User always passed in as an argument to classes Depends-On: To be written Bug: T172455 Change-Id: I34be76d6cdb5cbd6d624b92ed6575c31bbf6da52 --- M resources/mobile.betaoptin/BetaOptinPanel.js M resources/mobile.editor.common/EditorOverlayBase.js M resources/mobile.pagelist.scripts/WatchstarPageList.js M resources/mobile.search/MobileWebSearchLogger.js M resources/mobile.talk.overlays/TalkOverlay.js M resources/mobile.talk.overlays/TalkOverlayBase.js M resources/mobile.talk.overlays/TalkSectionOverlay.js M resources/mobile.watchstar/Watchstar.js M tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js M tests/qunit/mobile.talk.overlays/test_TalkSectionOverlay.js M tests/qunit/mobile.watchlist/test_WatchList.js M tests/qunit/mobile.watchstar/test_Watchstar.js 12 files changed, 41 insertions(+), 31 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/77/372077/1 diff --git a/resources/mobile.betaoptin/BetaOptinPanel.js b/resources/mobile.betaoptin/BetaOptinPanel.js index a1d506c..0b21e3b 100644 --- a/resources/mobile.betaoptin/BetaOptinPanel.js +++ b/resources/mobile.betaoptin/BetaOptinPanel.js @@ -6,8 +6,11 @@ /** * @class BetaOptinPanel * @extends Panel + * @param {Object} options + * @param {User} user */ - function BetaOptinPanel() { + function BetaOptinPanel( options, user ) { + this.user = user; Panel.apply( this, arguments ); } @@ -19,7 +22,7 @@ template: mw.template.get( 'mobile.betaoptin', 'Panel.hogan' ), defaults: $.extend( {}, Panel.prototype.defaults, { postUrl: undefined, - editToken: mw.user.tokens.get( 'editToken' ), + editToken: user.tokens.get( 'editToken' ), text: mw.msg( 'mobile-frontend-panel-betaoptin-msg' ), buttons: [ new Button( { diff --git a/resources/mobile.editor.common/EditorOverlayBase.js b/resources/mobile.editor.common/EditorOverlayBase.js index ebb2f9f..8dbd16f 100644 --- a/resources/mobile.editor.common/EditorOverlayBase.js +++ b/resources/mobile.editor.common/EditorOverlayBase.js @@ -3,8 +3,7 @@ PageGateway = M.require( 'mobile.startup/PageGateway' ), browser = M.require( 'mobile.startup/Browser' ).getSingleton(), Icon = M.require( 'mobile.startup/Icon' ), - toast = M.require( 'mobile.startup/toast' ), - user = M.require( 'mobile.startup/user' ); + toast = M.require( 'mobile.startup/toast' ); /** * 'Edit' button @@ -41,19 +40,20 @@ * @class EditorOverlayBase * @extends Overlay * @uses Icon - * @uses user * @param {Object} options Configuration options + * @param {User} user current user */ - function EditorOverlayBase( options ) { + function EditorOverlayBase( options, user ) { var self = this; if ( options.isNewPage ) { - options.placeholder = mw.msg( 'mobile-frontend-editor-placeholder-new-page', mw.user ); + options.placeholder = mw.msg( 'mobile-frontend-editor-placeholder-new-page', user ); } // change the message to request a summary when not in article namespace if ( mw.config.get( 'wgNamespaceNumber' ) !== 0 ) { options.summaryRequestMsg = mw.msg( 'mobile-frontend-editor-summary' ); } + this.user = user; this.pageGateway = new PageGateway( options.api ); this.editCount = user.getEditCount(); this.isNewPage = options.isNewPage; @@ -162,7 +162,7 @@ if ( this.isNewPage && // TODO: Replace with an OOUI dialog // eslint-disable-next-line no-alert - !window.confirm( mw.msg( 'mobile-frontend-editor-new-page-confirm', mw.user ) ) + !window.confirm( mw.msg( 'mobile-frontend-editor-new-page-confirm', this.user ) ) ) { return false; } else { diff --git a/resources/mobile.pagelist.scripts/WatchstarPageList.js b/resources/mobile.pagelist.scripts/WatchstarPageList.js index ab41157..9666e3d 100644 --- a/resources/mobile.pagelist.scripts/WatchstarPageList.js +++ b/resources/mobile.pagelist.scripts/WatchstarPageList.js @@ -2,7 +2,6 @@ var PageList = M.require( 'mobile.startup/PageList' ), Watchstar = M.require( 'mobile.watchstar/Watchstar' ), - user = M.require( 'mobile.startup/user' ), Page = M.require( 'mobile.startup/Page' ), WatchstarGateway = M.require( 'mobile.watchstar/WatchstarGateway' ); @@ -16,9 +15,11 @@ * * @constructor * @param {Object} options Configuration options + * @param {User} user */ - function WatchstarPageList( options ) { + function WatchstarPageList( options, user ) { this.wsGateway = new WatchstarGateway( options.api ); + this.user = user; PageList.apply( this, arguments ); } @@ -44,6 +45,7 @@ postRender: function () { var $li, self = this, + user = this.user, pages = [], gateway = this.wsGateway; diff --git a/resources/mobile.search/MobileWebSearchLogger.js b/resources/mobile.search/MobileWebSearchLogger.js index f73ff6f..4d08e2e 100644 --- a/resources/mobile.search/MobileWebSearchLogger.js +++ b/resources/mobile.search/MobileWebSearchLogger.js @@ -4,10 +4,12 @@ * Implements schema defined at https://meta.wikimedia.org/wiki/Schema:MobileWebSearch * * @class + * @param {User} user */ - function MobileWebSearchLogger() { + function MobileWebSearchLogger( user ) { this.userSessionToken = null; this.searchSessionToken = null; + this.user = user; } MobileWebSearchLogger.prototype = { @@ -18,7 +20,7 @@ * @private */ _newUserSession: function () { - this.userSessionToken = mw.user.generateRandomSessionId(); + this.userSessionToken = this.user.generateRandomSessionId(); }, /** @@ -28,7 +30,7 @@ * @private */ _newSearchSession: function () { - this.searchSessionToken = mw.user.generateRandomSessionId(); + this.searchSessionToken = this.user.generateRandomSessionId(); this.searchSessionCreatedAt = new Date().getTime(); }, diff --git a/resources/mobile.talk.overlays/TalkOverlay.js b/resources/mobile.talk.overlays/TalkOverlay.js index f0c4cdb..7a0c96f 100644 --- a/resources/mobile.talk.overlays/TalkOverlay.js +++ b/resources/mobile.talk.overlays/TalkOverlay.js @@ -1,8 +1,7 @@ ( function ( M, $ ) { var TalkOverlayBase = M.require( 'mobile.talk.overlays/TalkOverlayBase' ), Page = M.require( 'mobile.startup/Page' ), - Anchor = M.require( 'mobile.startup/Anchor' ), - user = M.require( 'mobile.startup/user' ); + Anchor = M.require( 'mobile.startup/Anchor' ); /** * Overlay for talk page * @extends Overlay @@ -32,6 +31,7 @@ * @cfg {Array} defaults.headerButtons Objects that will be used as defaults for * generating header buttons. Default list includes an 'add' button, which opens * a new talk overlay. + * @cfg {User} defaults.user who is using the overlay */ defaults: $.extend( {}, TalkOverlayBase.prototype.defaults, { headings: undefined, @@ -143,7 +143,8 @@ * @private */ _setupAddDiscussionButton: function () { - var $add = this.$( '.header-action .add' ); + var user = this.options.user, + $add = this.$( '.header-action .add' ); M.on( 'talk-discussion-added', $.proxy( this, '_loadContent', this.options ) ); if ( !user.isAnon() ) { $add.removeClass( 'hidden' ); diff --git a/resources/mobile.talk.overlays/TalkOverlayBase.js b/resources/mobile.talk.overlays/TalkOverlayBase.js index fd12da2..fdade6e 100644 --- a/resources/mobile.talk.overlays/TalkOverlayBase.js +++ b/resources/mobile.talk.overlays/TalkOverlayBase.js @@ -11,11 +11,13 @@ * * @constructor * @param {Object} options Configuration options + * @param {User} user */ - function TalkOverlayBase( options ) { + function TalkOverlayBase( options, user ) { this.pageGateway = new PageGateway( options.api ); // FIXME: This should be using a gateway e.g. TalkGateway, PageGateway or EditorGateway this.editorApi = options.api; + this.user = user; Overlay.apply( this, arguments ); } OO.mfExtend( TalkOverlayBase, Overlay, { diff --git a/resources/mobile.talk.overlays/TalkSectionOverlay.js b/resources/mobile.talk.overlays/TalkSectionOverlay.js index d1c4f49..e27f4cc 100644 --- a/resources/mobile.talk.overlays/TalkSectionOverlay.js +++ b/resources/mobile.talk.overlays/TalkSectionOverlay.js @@ -1,7 +1,6 @@ ( function ( M, $ ) { var TalkOverlayBase = M.require( 'mobile.talk.overlays/TalkOverlayBase' ), popup = M.require( 'mobile.startup/toast' ), - user = M.require( 'mobile.startup/user' ), Page = M.require( 'mobile.startup/Page' ), Button = M.require( 'mobile.startup/Button' ); @@ -69,7 +68,7 @@ */ _enableComments: function () { this.$commentBox = this.$( '.comment' ); - if ( user.isAnon() ) { + if ( this.user.isAnon() ) { this.$commentBox.remove(); } else { this.$textarea = this.$commentBox.find( 'textarea' ); diff --git a/resources/mobile.watchstar/Watchstar.js b/resources/mobile.watchstar/Watchstar.js index 8e962c7..1bfb971 100644 --- a/resources/mobile.watchstar/Watchstar.js +++ b/resources/mobile.watchstar/Watchstar.js @@ -12,7 +12,6 @@ additionalClassNames: 'watch-this-article watched' } ), toast = M.require( 'mobile.startup/toast' ), - user = M.require( 'mobile.startup/user' ), CtaDrawer = M.require( 'mobile.startup/CtaDrawer' ); /** @@ -26,15 +25,17 @@ * * @constructor * @param {Object} options Configuration options + * @param {User} user */ - function Watchstar( options ) { + function Watchstar( options, user ) { var self = this, _super = View, page = options.page; this.gateway = new WatchstarGateway( options.api ); + this.user = user; - if ( user.isAnon() ) { + if ( this.user.isAnon() ) { _super.call( self, options ); } else if ( options.isWatched === undefined ) { this.gateway.loadWatchStatus( page.getId() ).done( function () { @@ -91,7 +92,7 @@ this.gateway = new WatchstarGateway( options.api ); - if ( user.isAnon() ) { + if ( this.user.isAnon() ) { _super.call( self, options ); } else if ( options.isWatched === undefined ) { this.gateway.loadWatchStatus( page.getId() ).done( function () { @@ -120,7 +121,7 @@ this.$el.attr( 'title', self.options.tooltip ); // Add watched class if necessary - if ( !user.isAnon() && gateway.isWatchedPage( page ) ) { + if ( !this.user.isAnon() && gateway.isWatchedPage( page ) ) { $el.addClass( watchedClass ).removeClass( unwatchedClass ); } else { $el.addClass( unwatchedClass ).removeClass( watchedClass ); @@ -194,7 +195,7 @@ * @method */ onStatusToggle: function () { - if ( user.isAnon() ) { + if ( this.user.isAnon() ) { this.onStatusToggleAnon.apply( this, arguments ); } else { this.onStatusToggleUser.apply( this, arguments ); diff --git a/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js b/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js index d3c618e..87c2c6b 100644 --- a/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js +++ b/tests/qunit/mobile.pagelist.scripts/test_WatchstarPageList.js @@ -35,7 +35,7 @@ }, { id: 50 } ] - } ); + }, user ); assert.ok( this.spy.calledOnce, 'run callback once' ); assert.ok( this.spy.calledWith( { action: 'query', diff --git a/tests/qunit/mobile.talk.overlays/test_TalkSectionOverlay.js b/tests/qunit/mobile.talk.overlays/test_TalkSectionOverlay.js index 3eb3d2c..f385275 100644 --- a/tests/qunit/mobile.talk.overlays/test_TalkSectionOverlay.js +++ b/tests/qunit/mobile.talk.overlays/test_TalkSectionOverlay.js @@ -19,7 +19,7 @@ new TalkSectionOverlay( { api: this.api, section: 'Testtext' - } ); + }, user ); assert.strictEqual( renderFromApiSpy.callCount, 0, 'Section requested from api, if no section given.' ); diff --git a/tests/qunit/mobile.watchlist/test_WatchList.js b/tests/qunit/mobile.watchlist/test_WatchList.js index 428a89e..f0ea9e1 100644 --- a/tests/qunit/mobile.watchlist/test_WatchList.js +++ b/tests/qunit/mobile.watchlist/test_WatchList.js @@ -36,7 +36,7 @@ }, { id: 60 } ] - } ); + }, user ); // Avoid API requests due to scroll events (https://phabricator.wikimedia.org/T116258) pl.infiniteScroll.disable(); assert.ok( this.spy.notCalled, 'Callback avoided' ); diff --git a/tests/qunit/mobile.watchstar/test_Watchstar.js b/tests/qunit/mobile.watchstar/test_Watchstar.js index 41195227..051be87 100644 --- a/tests/qunit/mobile.watchstar/test_Watchstar.js +++ b/tests/qunit/mobile.watchstar/test_Watchstar.js @@ -27,7 +27,7 @@ page: new Page( { id: 10 } ) - } ); + }, user ); $el.trigger( 'click' ); // position-fixed class may not have loaded and without it the toast is not visible so use @@ -59,7 +59,7 @@ page: new Page( { id: 42 } ) - } ), + }, user ), $el = w.$el; $el.trigger( 'click' ); @@ -80,7 +80,7 @@ page: new Page( { id: 42 } ) - } ), + }, user ), $el = w.$el; $el.trigger( 'click' ); -- To view, visit https://gerrit.wikimedia.org/r/372077 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I34be76d6cdb5cbd6d624b92ed6575c31bbf6da52 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits