From 12a9f0564d1af1325b49efa255167f899b62dea7 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 3 Apr 2013 22:50:08 +0200 Subject: [PATCH] ResourceLoader: Honor $wgAllow* settings in site/user modules Bug: 46858 Change-Id: I17b3a2c1df5d52458f92c715242003b34111432c --- .../ResourceLoaderSiteModule.php | 20 +++--- .../ResourceLoaderUserCSSPrefsModule.php | 67 ++++++++++--------- .../ResourceLoaderUserGroupsModule.php | 13 +++- .../ResourceLoaderUserModule.php | 21 +++--- 4 files changed, 69 insertions(+), 52 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderSiteModule.php b/includes/resourceloader/ResourceLoaderSiteModule.php index 1cc5c1a982..340d7dfed5 100644 --- a/includes/resourceloader/ResourceLoaderSiteModule.php +++ b/includes/resourceloader/ResourceLoaderSiteModule.php @@ -37,15 +37,19 @@ class ResourceLoaderSiteModule extends ResourceLoaderWikiModule { * @return Array: List of pages */ protected function getPages( ResourceLoaderContext $context ) { - global $wgHandheldStyle; + global $wgUseSiteJs, $wgUseSiteCss, $wgHandheldStyle; - $pages = array( - 'MediaWiki:Common.js' => array( 'type' => 'script' ), - 'MediaWiki:Common.css' => array( 'type' => 'style' ), - 'MediaWiki:' . ucfirst( $context->getSkin() ) . '.js' => array( 'type' => 'script' ), - 'MediaWiki:' . ucfirst( $context->getSkin() ) . '.css' => array( 'type' => 'style' ), - 'MediaWiki:Print.css' => array( 'type' => 'style', 'media' => 'print' ), - ); + $pages = array(); + if ( $wgUseSiteJs ) { + $pages['MediaWiki:Common.js'] = array( 'type' => 'script' ); + $pages['MediaWiki:' . ucfirst( $context->getSkin() ) . '.js'] = array( 'type' => 'script' ); + } + if ( $wgUseSiteCss ) { + $pages['MediaWiki:Common.css'] = array( 'type' => 'style' ); + $pages['MediaWiki:' . ucfirst( $context->getSkin() ) . '.css'] = array( 'type' => 'style' ); + + } + $pages['MediaWiki:Print.css'] = array( 'type' => 'style', 'media' => 'print' ); if ( $wgHandheldStyle ) { $pages['MediaWiki:Handheld.css'] = array( 'type' => 'style', diff --git a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php index bdb240e052..9795cd05f0 100644 --- a/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php +++ b/includes/resourceloader/ResourceLoaderUserCSSPrefsModule.php @@ -56,43 +56,44 @@ class ResourceLoaderUserCSSPrefsModule extends ResourceLoaderModule { public function getStyles( ResourceLoaderContext $context ) { global $wgAllowUserCssPrefs, $wgUser; - if ( $wgAllowUserCssPrefs ) { - $options = $wgUser->getOptions(); + if ( !$wgAllowUserCssPrefs ) { + return array(); + } - // Build CSS rules - $rules = array(); + $options = $wgUser->getOptions(); - // Underline: 2 = browser default, 1 = always, 0 = never - if ( $options['underline'] < 2 ) { - $rules[] = "a { text-decoration: " . - ( $options['underline'] ? 'underline' : 'none' ) . "; }"; - } else { - # The scripts of these languages are very hard to read with underlines - $rules[] = 'a:lang(ar), a:lang(ckb), a:lang(fa),a:lang(kk-arab), ' . - 'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }'; - } - if ( $options['justify'] ) { - $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n"; - } - if ( !$options['showtoc'] ) { - $rules[] = "#toc { display: none; }\n"; - } - if ( !$options['editsection'] ) { - $rules[] = ".editsection { display: none; }\n"; - } - if ( $options['editfont'] !== 'default' ) { - // Double-check that $options['editfont'] consists of safe characters only - if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) { - $rules[] = "textarea { font-family: {$options['editfont']}; }\n"; - } - } - $style = implode( "\n", $rules ); - if ( $this->getFlip( $context ) ) { - $style = CSSJanus::transform( $style, true, false ); + // Build CSS rules + $rules = array(); + + // Underline: 2 = browser default, 1 = always, 0 = never + if ( $options['underline'] < 2 ) { + $rules[] = "a { text-decoration: " . + ( $options['underline'] ? 'underline' : 'none' ) . "; }"; + } else { + # The scripts of these languages are very hard to read with underlines + $rules[] = 'a:lang(ar), a:lang(ckb), a:lang(fa),a:lang(kk-arab), ' . + 'a:lang(mzn), a:lang(ps), a:lang(ur) { text-decoration: none; }'; + } + if ( $options['justify'] ) { + $rules[] = "#article, #bodyContent, #mw_content { text-align: justify; }\n"; + } + if ( !$options['showtoc'] ) { + $rules[] = "#toc { display: none; }\n"; + } + if ( !$options['editsection'] ) { + $rules[] = ".editsection { display: none; }\n"; + } + if ( $options['editfont'] !== 'default' ) { + // Double-check that $options['editfont'] consists of safe characters only + if ( preg_match( '/^[a-zA-Z0-9_, -]+$/', $options['editfont'] ) ) { + $rules[] = "textarea { font-family: {$options['editfont']}; }\n"; } - return array( 'all' => $style ); } - return array(); + $style = implode( "\n", $rules ); + if ( $this->getFlip( $context ) ) { + $style = CSSJanus::transform( $style, true, false ); + } + return array( 'all' => $style ); } /** diff --git a/includes/resourceloader/ResourceLoaderUserGroupsModule.php b/includes/resourceloader/ResourceLoaderUserGroupsModule.php index 1316f42348..7586bb7fac 100644 --- a/includes/resourceloader/ResourceLoaderUserGroupsModule.php +++ b/includes/resourceloader/ResourceLoaderUserGroupsModule.php @@ -33,12 +33,15 @@ class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule { * @return array */ protected function getPages( ResourceLoaderContext $context ) { - global $wgUser; + global $wgUser, $wgUseSiteJs, $wgUseSiteCss; $userName = $context->getUser(); if ( $userName === null ) { return array(); } + if ( !$wgUseSiteJs && !$wgUseSiteCss ) { + return array(); + } // Use $wgUser is possible; allows to skip a lot of code if ( is_object( $wgUser ) && $wgUser->getName() == $userName ) { @@ -55,8 +58,12 @@ class ResourceLoaderUserGroupsModule extends ResourceLoaderWikiModule { if ( in_array( $group, array( '*', 'user' ) ) ) { continue; } - $pages["MediaWiki:Group-$group.js"] = array( 'type' => 'script' ); - $pages["MediaWiki:Group-$group.css"] = array( 'type' => 'style' ); + if ( $wgUseSiteJs ) { + $pages["MediaWiki:Group-$group.js"] = array( 'type' => 'script' ); + } + if ( $wgUseSiteCss ) { + $pages["MediaWiki:Group-$group.css"] = array( 'type' => 'style' ); + } } return $pages; } diff --git a/includes/resourceloader/ResourceLoaderUserModule.php b/includes/resourceloader/ResourceLoaderUserModule.php index 177302c5b7..7a04e473f1 100644 --- a/includes/resourceloader/ResourceLoaderUserModule.php +++ b/includes/resourceloader/ResourceLoaderUserModule.php @@ -35,11 +35,15 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule { * @return array */ protected function getPages( ResourceLoaderContext $context ) { + global $wgAllowUserJs, $wgAllowUserCss; $username = $context->getUser(); if ( $username === null ) { return array(); } + if ( !$wgAllowUserJs && !$wgAllowUserCss ) { + return array(); + } // Get the normalized title of the user's user page $userpageTitle = Title::makeTitleSafe( NS_USER, $username ); @@ -50,14 +54,15 @@ class ResourceLoaderUserModule extends ResourceLoaderWikiModule { $userpage = $userpageTitle->getPrefixedDBkey(); // Needed so $excludepages works - $pages = array( - "$userpage/common.js" => array( 'type' => 'script' ), - "$userpage/" . $context->getSkin() . '.js' => - array( 'type' => 'script' ), - "$userpage/common.css" => array( 'type' => 'style' ), - "$userpage/" . $context->getSkin() . '.css' => - array( 'type' => 'style' ), - ); + $pages = array(); + if ( $wgAllowUserJs ) { + $pages["$userpage/common.js"] = array( 'type' => 'script' ); + $pages["$userpage/" . $context->getSkin() . '.js'] = array( 'type' => 'script' ); + } + if ( $wgAllowUserCss ) { + $pages["$userpage/common.css"] = array( 'type' => 'style' ); + $pages["$userpage/" . $context->getSkin() . '.css'] = array( 'type' => 'style' ); + } // Hack for bug 26283: if we're on a preview page for a CSS/JS page, // we need to exclude that page from this module. In that case, the excludepage -- 2.20.1