Florianschmidtwelzow has uploaded a new change for review.

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

Change subject: Backlog: Show Watchstar only for logged in users
......................................................................

Backlog: Show Watchstar only for logged in users

Change-Id: I2d795152929deba0a09ab6a3c4f8aea96356a3f2
---
M i18n/en.json
M includes/Resources.php
M includes/skins/SkinMinerva.php
M javascripts/modules/watchstar/Watchstar.js
M javascripts/modules/watchstar/init.js
M tests/qunit/modules/watchstar/test_Watchstar.js
6 files changed, 39 insertions(+), 65 deletions(-)


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

diff --git a/i18n/en.json b/i18n/en.json
index 3abef62..d817720 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -302,7 +302,6 @@
        "mobile-frontend-watchlist-a-z-empty-howto-alt": "Click the star at the 
top of the page",
        "mobile-frontend-watchlist-add": "Added $1 to your watchlist",
        "mobile-frontend-watchlist-back-home": "Back home",
-       "mobile-frontend-watchlist-cta": "Keep track of this page and all 
changes to it.",
        "mobile-frontend-watchlist-cta-button-login": "Log in",
        "mobile-frontend-watchlist-cta-button-signup": "Sign up",
        "mobile-frontend-watchlist-feed": "Modified",
diff --git a/includes/Resources.php b/includes/Resources.php
index 7fe6233..965ef74 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -748,10 +748,10 @@
                'messages' => array(
                        'watchthispage',
                        'unwatchthispage',
-                       // mf-watchstar.js
+                       // Watchstar.js
                        'mobile-frontend-watchlist-add',
                        'mobile-frontend-watchlist-removed',
-                       'mobile-frontend-watchlist-cta',
+                       'mobile-frontend-watchlist-error',
                ),
        ),
 
diff --git a/includes/skins/SkinMinerva.php b/includes/skins/SkinMinerva.php
index b1a0134..4d28e7a 100644
--- a/includes/skins/SkinMinerva.php
+++ b/includes/skins/SkinMinerva.php
@@ -705,6 +705,7 @@
                $menu = array();
                $namespaces = $tpl->data['content_navigation']['namespaces'];
                $actions = $tpl->data['content_navigation']['actions'];
+               $user = $this->getUser();
 
                // empty placeholder for edit and photos which both require js
                if ( $this->isAllowedPageAction( 'edit' ) ) {
@@ -745,7 +746,7 @@
                        unset( $menu['talk']['context'] );
                }
 
-               if ( $this->isAllowedPageAction( 'watch' ) ) {
+               if ( $user->isLoggedIn() && $this->isAllowedPageAction( 'watch' 
) ) {
                        $watchTemplate = array(
                                'id' => 'ca-watch',
                                'class' => MobileUI::iconClass( 'watch', 
'element', 'icon-32px watch-this-article' ),
diff --git a/javascripts/modules/watchstar/Watchstar.js 
b/javascripts/modules/watchstar/Watchstar.js
index d1df115..0b11d94 100644
--- a/javascripts/modules/watchstar/Watchstar.js
+++ b/javascripts/modules/watchstar/Watchstar.js
@@ -6,9 +6,7 @@
                watchIcon = new Icon( { name: 'watch', additionalClassNames: 
'icon-32px watch-this-article' } ),
                watchedIcon = new Icon( { name: 'watched', 
additionalClassNames: 'icon-32px watch-this-article' } ),
                toast = M.require( 'toast' ),
-               user = M.require( 'user' ),
-               api = new WatchstarApi(),
-               CtaDrawer = M.require( 'CtaDrawer' );
+               api = new WatchstarApi();
 
        /**
         * A clickable watchstar
@@ -26,17 +24,7 @@
                        var self = this, _super = View.prototype.initialize,
                                page = options.page;
 
-                       this.drawer = new CtaDrawer( {
-                               content: mw.msg( 
'mobile-frontend-watchlist-cta' ),
-                               queryParams: {
-                                       campaign: 'mobile_watchPageActionCta',
-                                       returntoquery: 'article_action=watch'
-                               }
-                       } );
-
-                       if ( user.isAnon() ) {
-                               _super.call( self, options );
-                       } else if ( options.isWatched === undefined ) {
+                       if ( options.isWatched === undefined ) {
                                api.load( page.getId() ).done( function () {
                                        options.isWatched = api.isWatchedPage( 
page );
                                        _super.call( self, options );
@@ -61,40 +49,35 @@
                        this.$el.attr('title', options.tooltip);
 
                        callback = function () {
-                               if ( user.isAnon() ) {
-                                       self.drawer.show();
-                               } else {
-                                       checker = setInterval( function () {
-                                               toast.show( mw.msg( 
'mobile-frontend-watchlist-please-wait' ) );
-                                       }, 1000 );
-                                       api.toggleStatus( page ).always( 
function () {
-                                               clearInterval( checker );
-                                       } ).done( function () {
-                                               if ( api.isWatchedPage( page ) 
) {
-                                                       options.isWatched = 
true;
-                                                       self.render( options );
-                                                       /**
-                                                        * @event watch
-                                                        * Fired when the watch 
star is changed to watched status
-                                                        */
-                                                       self.emit( 'watch' );
-                                                       toast.show( mw.msg( 
'mobile-frontend-watchlist-add', page.title ) );
-                                               } else {
-                                                       options.isWatched = 
false;
-                                                       /**
-                                                        * @event unwatch
-                                                        * Fired when the watch 
star is changed to unwatched status
-                                                        */
-                                                       self.emit( 'unwatch' );
-                                                       self.render( options );
-                                                       toast.show( mw.msg( 
'mobile-frontend-watchlist-removed', page.title ) );
-                                               }
-                                       } ).fail( function () {
-                                               toast.show( 
'mobile-frontend-watchlist-error', 'error' );
-                                       } );
-                               }
+                               checker = setInterval( function () {
+                                       toast.show( mw.msg( 
'mobile-frontend-watchlist-please-wait' ) );
+                               }, 1000 );
+                               api.toggleStatus( page ).always( function () {
+                                       clearInterval( checker );
+                               } ).done( function () {
+                                       if ( api.isWatchedPage( page ) ) {
+                                               options.isWatched = true;
+                                               self.render( options );
+                                               /**
+                                                * @event watch
+                                                * Fired when the watch star is 
changed to watched status
+                                                */
+                                               self.emit( 'watch' );
+                                               toast.show( mw.msg( 
'mobile-frontend-watchlist-add', page.title ) );
+                                       } else {
+                                               options.isWatched = false;
+                                               /**
+                                                * @event unwatch
+                                                * Fired when the watch star is 
changed to unwatched status
+                                                */
+                                               self.emit( 'unwatch' );
+                                               self.render( options );
+                                               toast.show( mw.msg( 
'mobile-frontend-watchlist-removed', page.title ) );
+                                       }
+                               } ).fail( function () {
+                                       toast.show( 
'mobile-frontend-watchlist-error', 'error' );
+                               } );
                        };
-
                        if ( !this._initialised ) {
                                this.$el.on( 'click', callback );
                                this._initialised = true;
@@ -106,7 +89,7 @@
                        } );
 
                        // Add watched class if necessary
-                       if ( !user.isAnon() && api.isWatchedPage( page ) ) {
+                       if ( api.isWatchedPage( page ) ) {
                                $el.addClass( watchedClass ).removeClass( 
unwatchedClass );
                        } else {
                                $el.addClass( unwatchedClass ).removeClass( 
watchedClass );
diff --git a/javascripts/modules/watchstar/init.js 
b/javascripts/modules/watchstar/init.js
index 8202b1a..271a5e4 100644
--- a/javascripts/modules/watchstar/init.js
+++ b/javascripts/modules/watchstar/init.js
@@ -14,11 +14,12 @@
                        new Watchstar( {
                                el: $container,
                                isWatched: page.isWatched,
-                               page: page,
-                               isAnon: user.isAnon()
+                               page: page
                        } );
                }
        }
-       init( M.getCurrentPage() );
+       if ( !user.isAnon() ) {
+               init( M.getCurrentPage() );
+       }
 
 }( mw.mobileFrontend, jQuery ) );
diff --git a/tests/qunit/modules/watchstar/test_Watchstar.js 
b/tests/qunit/modules/watchstar/test_Watchstar.js
index 705b857..8da63da 100644
--- a/tests/qunit/modules/watchstar/test_Watchstar.js
+++ b/tests/qunit/modules/watchstar/test_Watchstar.js
@@ -16,16 +16,6 @@
        }
 } );
 
-QUnit.test( 'Anonymous user opens drawer', 1, function( assert ) {
-       var $el = $( '<div>' );
-
-       new Watchstar( { el: $el, page: new Page( { id: 10 } ) } );
-       $el.trigger( 'click' );
-
-       // Note due to the fact isVisible uses a timeout we cannot easily test 
this
-       assert.ok( this.spy.called, 'We checked if the drawer was visible 
before displaying it' );
-} );
-
 QUnit.module( 'MobileFrontend: Watchstar.js', {
        setup: function() {
                this.spy = this.sandbox.stub( WatchstarApi.prototype, 
'postWithToken' ).

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

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

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

Reply via email to