Load the module mediawiki.page.watch.ajax only when needed
authorFomafix <fomafix@googlemail.com>
Thu, 17 Sep 2015 05:35:29 +0000 (05:35 +0000)
committerUmherirrender <umherirrender_de.wp@web.de>
Thu, 17 Sep 2015 19:46:27 +0000 (19:46 +0000)
Load the module mediawiki.page.watch.ajax only when there is
a watch button on the page.

This change uses the same checks as buildContentNavigationUrls() in SkinTemplate.php.

Also combine two if checks.

Bug: T112523
Change-Id: I78895ffea1290f8c1d90630851d0d3d443800d66

includes/skins/Skin.php

index 53af3e7..be08e4c 100644 (file)
@@ -200,16 +200,15 @@ abstract class Skin extends ContextSource {
                );
 
                // Add various resources if required
-               if ( $wgUseAjax ) {
-                       if ( $wgEnableAPI ) {
-                               if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
-                                       && $user->isAllowed( 'writeapi' )
-                               ) {
-                                       $modules['watch'][] = 'mediawiki.page.watch.ajax';
-                               }
-
-                               $modules['search'][] = 'mediawiki.searchSuggest';
+               if ( $wgUseAjax && $wgEnableAPI ) {
+                       if ( $wgEnableWriteAPI && $wgAjaxWatch && $user->isLoggedIn()
+                               && $user->isAllowedAll( 'writeapi', 'viewmywatchlist', 'editmywatchlist' )
+                               && $this->getRelevantTitle()->canExist()
+                       ) {
+                               $modules['watch'][] = 'mediawiki.page.watch.ajax';
                        }
+
+                       $modules['search'][] = 'mediawiki.searchSuggest';
                }
 
                if ( $user->getBoolOption( 'editsectiononrightclick' ) ) {