Jdlrobson has uploaded a new change for review.

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

Change subject: Allow watching of missing pages
......................................................................

Allow watching of missing pages

This also avoids an api lookup on the watchlist page.
Fallback to using title for watching when id = 0
Add tests.

Bug: 70078
Change-Id: I49e62bb447b7ca5c6ade335a0cb85acc06b16267
---
M javascripts/Page.js
M javascripts/modules/PageList.js
M javascripts/modules/watchstar/WatchstarApi.js
M javascripts/specials/watchlist.js
M tests/qunit/modules/test_PageList.js
5 files changed, 44 insertions(+), 15 deletions(-)


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

diff --git a/javascripts/Page.js b/javascripts/Page.js
index 8ed4e25..f11026a 100644
--- a/javascripts/Page.js
+++ b/javascripts/Page.js
@@ -123,6 +123,14 @@
 
                /**
                 * @method
+                * @return {string}
+                */
+               getTitle: function() {
+                       return this.options.title;
+               },
+
+               /**
+                * @method
                 * @return {Number}
                 */
                getId: function() {
diff --git a/javascripts/modules/PageList.js b/javascripts/modules/PageList.js
index e91ad93..3c999b3 100644
--- a/javascripts/modules/PageList.js
+++ b/javascripts/modules/PageList.js
@@ -22,7 +22,7 @@
                        View.prototype.initialize.apply( this, arguments );
                },
                template: M.template.get( 'articleList.hogan' ),
-               postRender: function() {
+               postRender: function( options ) {
                        View.prototype.postRender.apply( this, arguments );
                        var pages = [], $li = this.$( 'li' ),
                                api = this.api;
@@ -34,7 +34,7 @@
 
                        // Create watch stars for each entry in list
                        if ( !user.isAnon() && pages.length > 0 ) {
-                               api.load( pages ).done( function() {
+                               api.load( pages, options.isWatchList ).done( 
function() {
                                        $li.each( function() {
                                                var page = new Page( {
                                                        // FIXME: Set sections 
so we don't hit the api (hacky)
diff --git a/javascripts/modules/watchstar/WatchstarApi.js 
b/javascripts/modules/watchstar/WatchstarApi.js
index 3d7eda7..62a2780 100644
--- a/javascripts/modules/watchstar/WatchstarApi.js
+++ b/javascripts/modules/watchstar/WatchstarApi.js
@@ -22,19 +22,27 @@
                 * Loads the watch status for a given list of page ids in bulk
                 * @method
                 * @param {array} ids A list of page ids
+                * @param {boolean} markAsAllWatched When true will assume all 
given ids are watched without a lookup.
                 * @return {jQuery.Deferred}
                 */
-               load: function( ids ) {
+               load: function( ids, markAsAllWatched ) {
                        var result = new $.Deferred(), self = this;
-                       this.get( {
-                               action: 'query',
-                               prop: 'info',
-                               inprop: 'watched',
-                               pageids: ids
-                       } ).done( function( resp ) {
-                               self._loadIntoCache( resp );
+                       if ( markAsAllWatched ) {
+                               $.each( ids, function ( i, id ) {
+                                       self._cache[ id ] = true;
+                               } );
                                result.resolve();
-                       } );
+                       } else {
+                               this.get( {
+                                       action: 'query',
+                                       prop: 'info',
+                                       inprop: 'watched',
+                                       pageids: ids
+                               } ).done( function( resp ) {
+                                       self._loadIntoCache( resp );
+                                       result.resolve();
+                               } );
+                       }
                        return result;
                },
 
@@ -71,11 +79,17 @@
                 * @return {jQuery.Deferred}
                 */
                toggleStatus: function( page ) {
-                       var self = this, data;
+                       var self = this, data,
+                               id = page.getId();
                        data = {
-                               action: 'watch',
-                               pageids: page.getId()
+                               action: 'watch'
                        };
+                       if ( id !== 0 ) {
+                               data.pageids = id;
+                       } else {
+                               // it's a new page use title instead
+                               data.title = page.getTitle();
+                       }
 
                        if ( this.isWatchedPage( page ) ) {
                                data.unwatch = true;
diff --git a/javascripts/specials/watchlist.js 
b/javascripts/specials/watchlist.js
index 60da3fb..f5df5be 100644
--- a/javascripts/specials/watchlist.js
+++ b/javascripts/specials/watchlist.js
@@ -10,7 +10,7 @@
 
                // 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 } );
+                       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 ) } );
diff --git a/tests/qunit/modules/test_PageList.js 
b/tests/qunit/modules/test_PageList.js
index 7247d25..e264607 100644
--- a/tests/qunit/modules/test_PageList.js
+++ b/tests/qunit/modules/test_PageList.js
@@ -27,4 +27,11 @@
                assert.strictEqual( pl.$el.find( '.watched' ).length, 1, "1 of 
articles is marked as watched" );
        } );
 
+       QUnit.test( 'In watched mode', 3, function( assert ) {
+               var pl = new PageList( { pages: [ { id: 30 }, { id: 50 }, { id: 
60 } ], isWatchList: true } );
+               assert.ok( this.spy.notCalled, 'Callback avoided' );
+               assert.strictEqual( pl.$el.find( '.watch-this-article' 
).length, 3, "3 articles have watch stars..." );
+               assert.strictEqual( pl.$el.find( '.watched' ).length, 3, 
"...and all are marked as watched." );
+       } );
+
 }( jQuery, mw.mobileFrontend ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I49e62bb447b7ca5c6ade335a0cb85acc06b16267
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