Move Special:Watchlist auto-reload check from PHP to JS
authorGeoffrey Mon <geofbot@gmail.com>
Sat, 10 Dec 2016 01:58:57 +0000 (20:58 -0500)
committerGeoffrey Mon <geofbot@gmail.com>
Sun, 11 Dec 2016 19:29:41 +0000 (14:29 -0500)
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
resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.watchlist.js

index 55400d3..000eb39 100644 (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(
index 3927a05..5c74186 100644 (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',
index a35f4d1..0be13a6 100644 (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 ) );