From b9c8a8d03d6a842b1bea9aca989f66fed223f24d Mon Sep 17 00:00:00 2001 From: Geoffrey Mon Date: Fri, 9 Dec 2016 20:58:57 -0500 Subject: [PATCH] Move Special:Watchlist auto-reload check from PHP to JS This makes the watchlist js load all the time, instead of only if the auto-reload preference is set, so we can put other things in the same js module. Bug: T150045 Change-Id: Ib8acca39593fe3d2369dc3187a9a55413553843d --- includes/specials/SpecialWatchlist.php | 7 +------ resources/Resources.php | 3 +++ .../mediawiki.special.watchlist.js | 21 ++++++++++--------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 55400d3cc9..000eb3966c 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -52,6 +52,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { $this->addHelpLink( 'Help:Watching pages' ); $output->addModules( [ 'mediawiki.special.changeslist.visitedstatus', + 'mediawiki.special.watchlist', ] ); $mode = SpecialEditWatchlist::getMode( $request, $subpage ); @@ -421,12 +422,6 @@ class SpecialWatchlist extends ChangesListSpecialPage { $user = $this->getUser(); $out = $this->getOutput(); - // if the user wishes, that the watchlist is reloaded, whenever a filter changes, - // add the module for that - if ( $user->getBoolOption( 'watchlistreloadautomatically' ) ) { - $out->addModules( [ 'mediawiki.special.watchlist' ] ); - } - $out->addSubtitle( $this->msg( 'watchlistfor2', $user->getName() ) ->rawParams( SpecialEditWatchlist::buildTools( diff --git a/resources/Resources.php b/resources/Resources.php index 3927a05045..5c74186c57 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -2033,6 +2033,9 @@ return [ ], 'mediawiki.special.watchlist' => [ 'scripts' => 'resources/src/mediawiki.special/mediawiki.special.watchlist.js', + 'dependencies' => [ + 'user.options', + ] ], 'mediawiki.special.version' => [ 'styles' => 'resources/src/mediawiki.special/mediawiki.special.version.css', diff --git a/resources/src/mediawiki.special/mediawiki.special.watchlist.js b/resources/src/mediawiki.special/mediawiki.special.watchlist.js index a35f4d1064..0be13a65e6 100644 --- a/resources/src/mediawiki.special/mediawiki.special.watchlist.js +++ b/resources/src/mediawiki.special/mediawiki.special.watchlist.js @@ -1,15 +1,16 @@ /*! * JavaScript for Special:Watchlist - * - * This script is only loaded, if the user opt-in a setting in Special:Preferences, - * that the watchlist should be automatically reloaded, when a filter option is - * changed in the header form. */ -jQuery( function ( $ ) { - // add a listener on all form elements in the header form - $( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', function () { - // submit the form, when one of the input fields was changed - $( '#mw-watchlist-form' ).submit(); +( function ( mw, $ ) { + $( function () { + // if the user wishes to reload the watchlist whenever a filter changes + if ( mw.user.options.get( 'watchlistreloadautomatically' ) ) { + // add a listener on all form elements in the header form + $( '#mw-watchlist-form input, #mw-watchlist-form select' ).on( 'change', function () { + // submit the form when one of the input fields is modified + $( '#mw-watchlist-form' ).submit(); + } ); + } } ); -} ); +}( mediaWiki, jQuery ) ); -- 2.20.1