Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/169616

Change subject: Introduce WatchList class
......................................................................

Introduce WatchList class

Introduce new class that extends PageList
Move logic over there.

Also:
* Fix event logging for Watchlist schema watch and unwatch actions.
* Correctly identify watchlist A-Z actions as being on watchlist page

Change-Id: I1839d19de55633f1a99f7bfd06a4e8e2ceaba93c
---
M includes/Resources.php
M javascripts/modules/PageList.js
A javascripts/modules/watchlist/Watchlist.js
M javascripts/modules/watchstar/Watchstar.js
M javascripts/specials/watchlist.js
5 files changed, 69 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/16/169616/1

diff --git a/includes/Resources.php b/includes/Resources.php
index bf4ac15..36fe297 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -1125,6 +1125,7 @@
                        'mobile.pagelist.scripts',
                ),
                'scripts' => array(
+                       'javascripts/modules/watchlist/Watchlist.js',
                        'javascripts/specials/watchlist.js',
                ),
        ),
diff --git a/javascripts/modules/PageList.js b/javascripts/modules/PageList.js
index 73afecd..7008bd1 100644
--- a/javascripts/modules/PageList.js
+++ b/javascripts/modules/PageList.js
@@ -21,6 +21,11 @@
                        enhance: false
                },
                /**
+                * Whether all pages contained in the PageList are known to be 
watched
+                * @type Boolean
+                */
+               isWatchList: false,
+               /**
                 * Render page images for the existing page list. Assumes no 
page images have been loaded.
                 * Only load when wgImagesDisabled has not been activated via 
Special:MobileOptions.
                 *
@@ -68,15 +73,22 @@
                        if ( options.enhance ) {
                                this.template = false;
                        }
+                       if ( options.isWatchList ) {
+                               this.isWatchList = true;
+                       }
 
                        this.api = new WatchstarApi( options );
                        View.prototype.initialize.apply( this, arguments );
                },
                template: M.template.get( 'modules/PageList.hogan' ),
-               postRender: function ( options ) {
-                       View.prototype.postRender.apply( this, arguments );
-                       var pages = [], $li = this.$( 'li' ),
+               postRender: function () {
+                       var $li,
+                               self = this,
+                               pages = [],
                                api = this.api;
+
+                       View.prototype.postRender.apply( this, arguments );
+                       $li = this.$( 'li' );
 
                        // Check what we have in the page list
                        $li.each( function () {
@@ -85,21 +97,24 @@
 
                        // Create watch stars for each entry in list
                        if ( !user.isAnon() && pages.length > 0 ) {
-                               api.load( pages, options.isWatchList ).done( 
function () {
+                               api.load( pages, this.isWatchList ).done( 
function () {
                                        $li.each( function () {
-                                               var page = new Page( {
-                                                       // FIXME: Set sections 
so we don't hit the api (hacky)
-                                                       sections: [],
-                                                       title: $( this ).attr( 
'title' ),
-                                                       id: $( this ).data( 
'id' )
-                                               } );
+                                               var watchstar,
+                                                       page = new Page( {
+                                                               // FIXME: Set 
sections so we don't hit the api (hacky)
+                                                               sections: [],
+                                                               title: $( this 
).attr( 'title' ),
+                                                               id: $( this 
).data( 'id' )
+                                                       } );
 
-                                               new Watchstar( {
+                                               watchstar = new Watchstar( {
                                                        isAnon: false,
                                                        isWatched: 
api.isWatchedPage( page ),
                                                        page: page,
                                                        el: $( '<div>' 
).appendTo( this )
                                                } );
+                                               watchstar.on( 'watch', $.proxy( 
self, 'emit', 'watch' ) );
+                                               watchstar.on( 'unwatch', 
$.proxy( self, 'emit', 'unwatch' ) );
                                        } );
                                } );
                        }
diff --git a/javascripts/modules/watchlist/Watchlist.js 
b/javascripts/modules/watchlist/Watchlist.js
new file mode 100644
index 0000000..3162e07
--- /dev/null
+++ b/javascripts/modules/watchlist/Watchlist.js
@@ -0,0 +1,29 @@
+( function ( M, $ ) {
+       var WatchList,
+               PageList = M.require( 'modules/PageList' );
+
+       /**
+        * @extends PageList
+        * @class WatchList
+        */
+       WatchList = PageList.extend( {
+               /**
+                * @inheritdoc
+                */
+               isWatchList: true,
+               /**
+                * Also sets a watch uploads funnel.
+                * @inheritdoc
+                */
+               postRender: function () {
+                       PageList.prototype.postRender.apply( this, arguments );
+                       this.$el.find( 'a.title' ).on( 'mousedown', function () 
{
+                               // name funnel for watchlists to catch 
subsequent uploads
+                               $.cookie( 'mwUploadsFunnel', 'watchlist', { 
expires: new Date( new Date().getTime() + 60000 ) } );
+                       } );
+               }
+       } );
+
+       M.define( 'modules/watchlist/WatchList', WatchList );
+
+}( mw.mobileFrontend, jQuery ) );
diff --git a/javascripts/modules/watchstar/Watchstar.js 
b/javascripts/modules/watchstar/Watchstar.js
index 5b4b4f7..a5ed15a 100644
--- a/javascripts/modules/watchstar/Watchstar.js
+++ b/javascripts/modules/watchstar/Watchstar.js
@@ -73,9 +73,11 @@
                                                if ( api.isWatchedPage( page ) 
) {
                                                        options.isWatched = 
true;
                                                        self.render( options );
+                                                       self.emit( 'watch' );
                                                        toast.show( mw.msg( 
'mobile-frontend-watchlist-add', page.title ) );
                                                } else {
                                                        options.isWatched = 
false;
+                                                       self.emit( 'unwatch' );
                                                        self.render( options );
                                                        toast.show( mw.msg( 
'mobile-frontend-watchlist-removed', page.title ) );
                                                }
diff --git a/javascripts/specials/watchlist.js 
b/javascripts/specials/watchlist.js
index 844058b..86f701d 100644
--- a/javascripts/specials/watchlist.js
+++ b/javascripts/specials/watchlist.js
@@ -1,7 +1,10 @@
 ( function ( M, $ ) {
-       var PageList = M.require( 'modules/PageList' ),
+       var watchlist,
+    WatchList = M.require( 'modules/watchlist/WatchList' ),
                schema = M.require( 'loggingSchemas/MobileWebClickTracking' ),
-               pageName = mw.config.get( 'wgCanonicalSpecialPageName' ) === 
'Watchlist' ? 'watchlist' : 'diff',
+               canonicalName = mw.config.get( 'wgCanonicalSpecialPageName' ),
+               pageName = canonicalName === 'EditWatchlist' || canonicalName 
=== 'Watchlist' ?
+                       'watchlist' : 'diff',
                subPageName = M.query.watchlistview || 'a-z';
 
        function init() {
@@ -10,10 +13,12 @@
 
                // FIXME: find more elegant way to not show watchlist stars on 
recent changes
                if ( $( '.mw-mf-watchlist-selector' ).length === 0 ) {
-                       new PageList( { el: $watchlist, enhance: true, 
isWatchList: true } );
-                       $watchlist.find( 'a.title' ).on( 'mousedown', function 
() {
-                               // name funnel for watchlists to catch 
subsequent uploads
-                               $.cookie( 'mwUploadsFunnel', 'watchlist', { 
expires: new Date( new Date().getTime() + 60000 ) } );
+                       watchlist = new WatchList( { el: $watchlist, enhance: 
true, isWatchList: true } );
+                       watchlist.on( 'unwatch', function () {
+                               schema.log( actionNamePrefix + 'unwatch' );
+                       } );
+                       watchlist.on( 'watch', function () {
+                               schema.log( actionNamePrefix + 'watch' );
                        } );
                }
 
@@ -22,11 +27,6 @@
                schema.hijackLink( '.mw-mf-watchlist-selector a', 
actionNamePrefix + 'filter' );
                schema.hijackLink( '.page-list .title', actionNamePrefix + 
'view' );
                schema.hijackLink( '.more', actionNamePrefix + 'more' );
-
-               M.on( 'watched', function ( page, isWatched ) {
-                       var action = isWatched ? 'watch' : 'unwatch';
-                       schema.log( actionNamePrefix + action );
-               } );
        }
 
        $( function () {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1839d19de55633f1a99f7bfd06a4e8e2ceaba93c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

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

Reply via email to