jenkins-bot has submitted this change and it was merged.
Change subject: Use mediawiki.api.watch for watching/unwatching pages
......................................................................
Use mediawiki.api.watch for watching/unwatching pages
Also fix action=watch and action=unwatch, and use tokens when creating
links to them (see r88522 and r89545)
Bug: 45329
Change-Id: I3659ae24decdd82723d78e9b9862068f59f660d0
---
M LiquidThreads.php
M classes/View.php
M lqt.js
M pages/ThreadWatchView.php
4 files changed, 30 insertions(+), 38 deletions(-)
Approvals:
Siebrand: Looks good to me, approved
Esanders: Looks good to me, but someone else must approve
Nischayn22: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/LiquidThreads.php b/LiquidThreads.php
index 0b125c1..8448a89 100644
--- a/LiquidThreads.php
+++ b/LiquidThreads.php
@@ -83,7 +83,7 @@
'jquery.ui.dialog',
'jquery.ui.droppable',
'mediawiki.action.edit.preview',
- 'user.tokens',
+ 'mediawiki.api.watch',
),
'messages' => $lqtMessages
);
diff --git a/classes/View.php b/classes/View.php
index 3a1232d..4dca7c7 100644
--- a/classes/View.php
+++ b/classes/View.php
@@ -1340,13 +1340,19 @@
if ( !$this->user->isAnon() &&
!$thread->title()->userIsWatching() ) {
$commands['watch'] = array(
'label' => wfMessage( 'watch' )->parse(),
- 'href' => self::permalinkUrlWithQuery( $thread,
'action=watch' ),
+ 'href' => self::permalinkUrlWithQuery(
+ $thread,
+ array( 'action' => 'watch', 'token' =>
WatchAction::getWatchToken( $thread->title(), $this->user, 'watch' ) )
+ ),
'enabled' => true
);
} elseif ( !$this->user->isAnon() ) {
$commands['unwatch'] = array(
'label' => wfMessage( 'unwatch' )->parse(),
- 'href' => self::permalinkUrlWithQuery( $thread,
'action=unwatch' ),
+ 'href' => self::permalinkUrlWithQuery(
+ $thread,
+ array( 'action' => 'unwatch', 'token'
=> WatchAction::getWatchToken( $thread->title(), $this->user, 'unwatch' ) )
+ ),
'enabled' => true
);
}
diff --git a/lqt.js b/lqt.js
index dfa164a..597045b 100644
--- a/lqt.js
+++ b/lqt.js
@@ -778,45 +778,27 @@
$(this).remove();
},
- 'asyncWatch' : function(e) {
- var button = $(this);
- var tlcOffset = "lqt-threadlevel-commands-".length;
-
- // Find the title of the thread
- var threadLevelCommands =
button.closest('.lqt_threadlevel_commands');
- var threadID = threadLevelCommands.attr('id').substring(
tlcOffset );
- var title = $('#lqt-thread-title-'+threadID).val();
-
- // Check if we're watching or unwatching.
- var action = '';
- if ( button.hasClass( 'lqt-command-watch' ) ) {
- button.removeClass( 'lqt-command-watch' );
- action = 'watch';
- } else if ( button.hasClass( 'lqt-command-unwatch' ) ) {
- button.removeClass( 'lqt-command-unwatch' );
- action = 'unwatch';
- }
+ 'asyncWatch' : function ( e ) {
+ var button = $( this ),
+ oldButton = $( this ).clone(),
+ tlcOffset = 'lqt-threadlevel-commands-'.length,
+ // Find the title of the thread
+ threadLevelCommands = button.closest(
'.lqt_threadlevel_commands' ),
+ title = $( '#lqt-thread-title-' +
threadLevelCommands.attr( 'id' ).substring( tlcOffset ) ).val();
// Replace the watch link with a spinner
button.empty().addClass( 'mw-small-spinner' );
- // Do the AJAX call.
- var apiParams = {
- 'action': 'watch',
- 'title' : title,
- 'format': 'json',
- 'token' : mw.user.tokens.get( 'watchToken' )
- };
-
- if (action === 'unwatch') {
- apiParams.unwatch = 'yes';
+ // Check if we're watching or unwatching.
+ var api = new mw.Api(),
+ success = function () {
+ threadLevelCommands.load( window.location.href
+ ' #' + threadLevelCommands.attr( 'id' ) + ' > *' );
+ };
+ if ( oldButton.hasClass( 'lqt-command-unwatch' ) ) {
+ api.unwatch( title ).done( success );
+ } else if ( oldButton.hasClass( 'lqt-command-watch' ) ) {
+ api.watch( title ).done( success );
}
-
- $.post( mw.util.wikiScript( 'api' ), apiParams,
- function () {
- threadLevelCommands.load(
window.location.href+' '+
-
'#'+threadLevelCommands.attr('id')+' > *' );
- }, 'json' );
e.preventDefault();
},
diff --git a/pages/ThreadWatchView.php b/pages/ThreadWatchView.php
index 555ee56..00aa1fb 100644
--- a/pages/ThreadWatchView.php
+++ b/pages/ThreadWatchView.php
@@ -1,5 +1,9 @@
<?php
if ( !defined( 'MEDIAWIKI' ) ) die;
-class ThreadWatchView extends ThreadPermalinkView {
+class ThreadWatchView extends LqtView {
+ function show() {
+ // Don't override core action=watch and action=unwatch.
+ return true;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/50636
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3659ae24decdd82723d78e9b9862068f59f660d0
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/LiquidThreads
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Helder.wiki <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Nischayn22 <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits