jenkins-bot has submitted this change and it was merged.

Change subject: Hygiene: WatchlistApi -> WatchlistGateway
......................................................................


Hygiene: WatchlistApi -> WatchlistGateway

Bug: T110718
Change-Id: I15e6da3aca197ad586de6e7852d746c84d9c2099
---
M includes/Resources.php
M resources/mobile.watchlist/WatchList.js
R resources/mobile.watchlist/WatchListGateway.js
M resources/skins.minerva.special.watchlist.scripts/watchlist.js
M tests/qunit/mobile.watchlist/test_WatchList.js
R tests/qunit/mobile.watchlist/test_WatchListGateway.js
6 files changed, 47 insertions(+), 55 deletions(-)

Approvals:
  Phuedx: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Resources.php b/includes/Resources.php
index 846b206..7243649 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -366,7 +366,7 @@
                        'mobile.modifiedBar',
                ),
                'scripts' => array(
-                       'resources/mobile.watchlist/WatchListApi.js',
+                       'resources/mobile.watchlist/WatchListGateway.js',
                        'resources/mobile.watchlist/WatchList.js',
                ),
        ),
diff --git a/resources/mobile.watchlist/WatchList.js 
b/resources/mobile.watchlist/WatchList.js
index cdabd16..1712d1a 100644
--- a/resources/mobile.watchlist/WatchList.js
+++ b/resources/mobile.watchlist/WatchList.js
@@ -2,7 +2,7 @@
        var WatchList,
                WatchstarPageList = M.require( 
'mobile.pagelist.scripts/WatchstarPageList' ),
                InfiniteScroll = M.require( 
'mobile.infiniteScroll/InfiniteScroll' ),
-               WatchListApi = M.require( 'mobile.watchlist/WatchListApi' );
+               WatchListGateway = M.require( 
'mobile.watchlist/WatchListGateway' );
 
        /**
         * An extension of the PageList which preloads pages as all being 
watched.
@@ -25,8 +25,7 @@
                        if ( options.el ) {
                                lastTitle = this.getLastTitle( options.el );
                        }
-                       // `api` is used in the parent...
-                       this.watchlistApi = new WatchListApi( lastTitle );
+                       this.gateway = new WatchListGateway( options.api, 
lastTitle );
 
                        WatchstarPageList.prototype.initialize.apply( this, 
arguments );
                },
@@ -68,7 +67,7 @@
                 */
                _loadPages: function () {
                        var self = this;
-                       this.watchlistApi.load().done( function ( pages ) {
+                       this.gateway.load().done( function ( pages ) {
                                $.each( pages, function ( i, page ) {
                                        self.appendPage( page );
                                } );
diff --git a/resources/mobile.watchlist/WatchListApi.js 
b/resources/mobile.watchlist/WatchListGateway.js
similarity index 75%
rename from resources/mobile.watchlist/WatchListApi.js
rename to resources/mobile.watchlist/WatchListGateway.js
index 228600e..963719e 100644
--- a/resources/mobile.watchlist/WatchListApi.js
+++ b/resources/mobile.watchlist/WatchListGateway.js
@@ -1,40 +1,33 @@
-/**
- * API for WatchList
- * @extends Api
- * @class WatchListApi
- */
 ( function ( M, $ ) {
-
-       var WatchListApi,
-               time = M.require( 'mobile.modifiedBar/time' ),
-               Api = M.require( 'mobile.startup/api' ).Api;
+       var time = M.require( 'modules/lastEdited/time' );
 
        /**
-        * @class WatchListApi
-        * @extends Api
+        * @class WatchListGateway
+        * @param {mw.Api} api
+        * @param {String} lastTitle of page listed in Watchlist to be used as 
a continuation parameter
         */
-       WatchListApi = Api.extend( {
-               /** @inheritdoc */
-               initialize: function ( lastTitle ) {
-                       Api.prototype.initialize.apply( this, arguments );
-                       // Try to keep it in sync with 
SpecialMobileWatchlist::LIMIT (php)
-                       this.limit = 50;
+       function WatchListGateway( api, lastTitle ) {
+               this.api = api;
+               // Try to keep it in sync with SpecialMobileWatchlist::LIMIT 
(php)
+               this.limit = 50;
 
-                       if ( lastTitle ) {
-                               this.continueParams = {
-                                       continue: 'gwrcontinue||',
-                                       gwrcontinue: '0|' + lastTitle.replace( 
/ /g, '_' )
-                               };
-                               this.shouldSkipFirstTitle = true;
-                       } else {
-                               this.continueParams = {
-                                       continue: ''
-                               };
-                               this.shouldSkipFirstTitle = false;
-                       }
+               if ( lastTitle ) {
+                       this.continueParams = {
+                               continue: 'gwrcontinue||',
+                               gwrcontinue: '0|' + lastTitle.replace( / /g, 
'_' )
+                       };
+                       this.shouldSkipFirstTitle = true;
+               } else {
+                       this.continueParams = {
+                               continue: ''
+                       };
+                       this.shouldSkipFirstTitle = false;
+               }
 
-                       this.canContinue = true;
-               },
+               this.canContinue = true;
+       }
+
+       WatchListGateway.prototype = {
                /**
                 * Load the list of items on the watchlist
                 * @returns {jQuery.Deferred}
@@ -66,7 +59,7 @@
                                params.gwrlimit += 1;
                                params.pilimit += 1;
                        }
-                       return this.get( params, {
+                       return this.api.get( params, {
                                url: this.apiUrl
                        } ).then( function ( data ) {
                                if ( data.hasOwnProperty( 'continue' ) ) {
@@ -137,9 +130,8 @@
                        } );
                }
 
-       } );
+       };
 
-       M.define( 'mobile.watchlist/WatchListApi', WatchListApi )
-               .deprecate( 'modules/watchlist/WatchListApi' );
+       M.define( 'mobile.watchlist/WatchListGateway', WatchListGateway );
 
 }( mw.mobileFrontend, jQuery ) );
diff --git a/resources/skins.minerva.special.watchlist.scripts/watchlist.js 
b/resources/skins.minerva.special.watchlist.scripts/watchlist.js
index 6c52659..9098908 100644
--- a/resources/skins.minerva.special.watchlist.scripts/watchlist.js
+++ b/resources/skins.minerva.special.watchlist.scripts/watchlist.js
@@ -19,6 +19,7 @@
                // FIXME: find more elegant way to not show watchlist stars on 
recent changes
                if ( $( '.mw-mf-watchlist-selector' ).length === 0 ) {
                        watchlist = new WatchList( {
+                               api: new mw.Api(),
                                el: $watchlist,
                                funnel: 'watchlist',
                                enhance: true
diff --git a/tests/qunit/mobile.watchlist/test_WatchList.js 
b/tests/qunit/mobile.watchlist/test_WatchList.js
index 05d1b34..4734399 100644
--- a/tests/qunit/mobile.watchlist/test_WatchList.js
+++ b/tests/qunit/mobile.watchlist/test_WatchList.js
@@ -5,8 +5,7 @@
                Icon = M.require( 'mobile.startup/Icon' ),
                watchIcon = new Icon( {
                        name: 'watched'
-               } ),
-               WatchstarApi = M.require( 'mobile.watchstar/WatchstarApi' );
+               } );
 
        QUnit.module( 'MobileFrontend modules/WatchList', {
                setup: function () {
@@ -21,7 +20,7 @@
                                }
                        };
 
-                       this.spy = this.sandbox.stub( WatchstarApi.prototype, 
'get' )
+                       this.spy = this.sandbox.stub( mw.Api.prototype, 'get' )
                                .returns( $.Deferred().resolve( resp ) );
                        this.sandbox.stub( user, 'isAnon' ).returns( false );
                }
@@ -29,6 +28,7 @@
 
        QUnit.test( 'In watched mode', 3, function ( assert ) {
                var pl = new WatchList( {
+                       api: new mw.Api(),
                        pages: [ {
                                id: 30
                        }, {
diff --git a/tests/qunit/mobile.watchlist/test_WatchListApi.js 
b/tests/qunit/mobile.watchlist/test_WatchListGateway.js
similarity index 86%
rename from tests/qunit/mobile.watchlist/test_WatchListApi.js
rename to tests/qunit/mobile.watchlist/test_WatchListGateway.js
index 29cedd7..f352f85 100644
--- a/tests/qunit/mobile.watchlist/test_WatchListApi.js
+++ b/tests/qunit/mobile.watchlist/test_WatchListGateway.js
@@ -1,6 +1,6 @@
 ( function ( $, M ) {
 
-       var WatchListApi = M.require( 'mobile.watchlist/WatchListApi' ),
+       var WatchListGateway = M.require( 'mobile.watchlist/WatchListGateway' ),
                response = {
                        continue: {
                                pageimages: {
@@ -87,16 +87,16 @@
                        }
                };
 
-       QUnit.module( 'MobileFrontend: WatchListApi', {} );
+       QUnit.module( 'MobileFrontend: WatchListGateway', {} );
 
        QUnit.test( 'load results from the first page', 3, function ( assert ) {
-               var api = new WatchListApi();
+               var api = new WatchListGateway( new mw.Api() );
 
-               this.sandbox.stub( WatchListApi.prototype, 'get' )
+               this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( response ) );
 
                api.load().done( function ( pages ) {
-                       var params = 
WatchListApi.prototype.get.firstCall.args[0];
+                       var params = mw.Api.prototype.get.firstCall.args[0];
 
                        assert.strictEqual( params.continue, '', 'It should set 
the continue parameter' );
 
@@ -107,7 +107,7 @@
 
        QUnit.test( 'load results from the second page from last item of 
first', 6, function ( assert ) {
                var lastTitle = 'Albert Einstein',
-                       api = new WatchListApi( lastTitle ),
+                       api = new WatchListGateway( new mw.Api(), lastTitle ),
                        response1 = $.extend( {}, response, {
                                'continue': {
                                        watchlistraw: {
@@ -118,11 +118,11 @@
                        stub;
 
                // First time we call the API for the second page
-               stub = this.sandbox.stub( WatchListApi.prototype, 'get' )
+               stub = this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( response1 ) );
 
                api.load().done( function ( pages ) {
-                       var params = 
WatchListApi.prototype.get.firstCall.args[0];
+                       var params = mw.Api.prototype.get.firstCall.args[0];
 
                        assert.strictEqual( params.continue, 'gwrcontinue||', 
'It should set the continue parameter' );
                        assert.strictEqual( params.gwrcontinue, 
'0|Albert_Einstein', 'It should set the watchlistraw-specific continue 
parameter' );
@@ -144,9 +144,9 @@
        } );
 
        QUnit.test( 'it doesn\'t throw an error when no pages are returned', 1, 
function ( assert ) {
-               var api = new WatchListApi();
+               var api = new WatchListGateway( new mw.Api() );
 
-               this.sandbox.stub( WatchListApi.prototype, 'get' )
+               this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( {
                                batchcomplete: ''
                        } ) );
@@ -159,10 +159,10 @@
        QUnit.test( 'it should mark pages as new if necessary', 2, function ( 
assert ) {
                var api;
 
-               this.sandbox.stub( WatchListApi.prototype, 'get' )
+               this.sandbox.stub( mw.Api.prototype, 'get' )
                        .returns( $.Deferred().resolve( response ) );
 
-               api = new WatchListApi();
+               api = new WatchListGateway( new mw.Api() );
 
                api.load().done( function ( pages ) {
                        assert.equal( pages[0].isMissing, false, 'Albert 
Einstein page isn\'t marked as new' );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I15e6da3aca197ad586de6e7852d746c84d9c2099
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to