From: Evan Prodromou Date: Sat, 13 Nov 2004 00:07:35 +0000 (+0000) Subject: Let administrators disable extra hits for user CSS and Javascript pages, X-Git-Tag: 1.5.0alpha1~1364 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=56340665bbd2297630b9e68b147520f4d435a8c6;p=lhc%2Fweb%2Fwiklou.git Let administrators disable extra hits for user CSS and Javascript pages, and for site-wide CSS and Javascript settings. Can save 4 dynamic Web hits (modulo caching) by turning off these features. --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 6d89f1f44a..afabae98ab 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -721,6 +721,12 @@ $wgAllowUserJs = true; # Allow user Cascading Style Sheets (CSS)? $wgAllowUserCss = true; +# Use the site's Javascript page? +$wgUseSiteJs = true; + +# Use the site's Cascading Style Sheets (CSS)? +$wgUseSiteCss = true; + # Filter for Special:Randompage. Part of a WHERE clause $wgExtraRandompageSQL = false; diff --git a/includes/SkinPHPTal.php b/includes/SkinPHPTal.php index 82f2dbdc04..110707c392 100644 --- a/includes/SkinPHPTal.php +++ b/includes/SkinPHPTal.php @@ -159,8 +159,8 @@ class SkinPHPTal extends Skin { $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage); $this->usercss = $this->userjs = $this->userjsprev = false; - $this->setupUserCssJs(); - + $this->setupUserCss(); + $this->setupUserJs(); $this->titletxt = $wgTitle->getPrefixedText(); $tpl->set( 'title', $wgOut->getPageTitle() ); @@ -223,10 +223,15 @@ class SkinPHPTal extends Skin { $tpl->setRef( 'usercss', $this->usercss); $tpl->setRef( 'userjs', $this->userjs); $tpl->setRef( 'userjsprev', $this->userjsprev); - if($this->loggedin) { - $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') ); + global $wgUseSiteJs; + if ($wgUseSiteJs) { + if($this->loggedin) { + $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') ); + } else { + $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') ); + } } else { - $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') ); + $tpl->set('jsvarurl', false); } if( $wgUser->getNewtalk() ) { $usertitle = Title::newFromText( $this->userpage ); @@ -670,40 +675,63 @@ class SkinPHPTal extends Skin { } } - /** * @access private */ - function setupUserCssJs () { - global $wgRequest, $wgTitle; - $action = $wgRequest->getText('action'); - # generated css - $this->usercss = '@import "'.$this->makeUrl('-','action=raw&gen=css').'";'."\n"; + + function setupUserCss () { + + global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss; + + $sitecss = ""; + $usercss = ""; + $siteargs = ""; - if( $this->loggedin ) { + # Add user-specific code if this is a user and we allow that kind of thing + + if ( $wgAllowUserCss && $this->loggedin ) { + $action = $wgRequest->getText('action'); + + # if we're previewing the CSS page, use it if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) { - # generated css - $this->usercss = '@import "'.$this->makeUrl('-','action=raw&smaxage=0&maxage=0&gen=css').'";'."\n"; - // css preview - $this->usercss .= $wgRequest->getText('wpTextbox1'); + $siteargs .= "&smaxage=0&maxage=0"; + $usercss = $wgRequest->getText('wpTextbox1'); } else { - # generated css - $this->usercss .= '@import "'.$this->makeUrl('-','action=raw&smaxage=0&gen=css').'";'."\n"; - # import user stylesheet - $this->usercss .= '@import "'. - $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').'";'."\n"; + $siteargs .= "&maxage=0"; + $usercss = '@import "' . + $this->makeUrl($this->userpage . '/'.$this->skinname.'.css', + 'action=raw&ctype=text/css') . '";' ."\n"; } + } + + # If we use the site's dynamic CSS, throw that in, too + + if ( $wgUseSiteCss ) { + $sitecss = '@import "'.$this->makeUrl('-','action=raw&gen=css' . $siteargs).'";'."\n"; + } + + # If we use any dynamic CSS, make a little CDATA block out of it. + + if ( !empty($sitecss) || !empty($usercss) ) { + $this->usercss = '/**/'; + } + } + + /** + * @access private + */ + function setupUserJs () { + global $wgRequest, $wgTitle, $wgAllowUserJs; + $action = $wgRequest->getText('action'); + + if( $wgAllowUserJs && $this->loggedin ) { if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) { # XXX: additional security check/prompt? - $this->userjsprev = $wgRequest->getText('wpTextbox1'); + $this->userjsprev = '/*getText('wpTextbox1') . ' /*]]>*/'; } else { $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s'); } } - $this->usercss = '/*usercss . ' /*]]>*/'; - if( $this->userjsprev ) { - $this->userjsprev = '/*userjsprev . ' /*]]>*/'; - } } /** diff --git a/skins/Amethyst.pt b/skins/Amethyst.pt index f77b7db2bc..1cf115c765 100644 --- a/skins/Amethyst.pt +++ b/skins/Amethyst.pt @@ -9,7 +9,7 @@ - + + - + - +