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
This commit is contained in:
Geoffrey Mon 2016-12-09 20:58:57 -05:00
parent 798ba89f17
commit b9c8a8d03d
3 changed files with 15 additions and 16 deletions

View file

@ -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(

View file

@ -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',

View file

@ -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 ) );