MediaWiki r6223 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r6222‎ | r6223 (on ViewVC)‎ | r6224 >
Date:00:07, 13 November 2004
Author:evanprodromou
Status:old
Tags:
Comment:
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.
Modified paths:

Diff [purge]

Index: trunk/phase3/skins/Amethyst.pt
@@ -9,7 +9,7 @@
1010 <!--[if IE]><style type="text/css" media="all">@import "${stylepath}/${stylename}/IEFixes.css";</style>
1111 <script type="text/javascript" src="${stylepath}/common/IEFixes.js"></script>
1212 <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
13 - <script type="text/javascript" tal:attributes="src jsvarurl"></script>
 13+ <script tal:condition="jsvarurl" type="text/javascript" tal:attributes="src jsvarurl"></script>
1414 <script type="text/javascript" src="${stylepath}/common/wikibits.js"></script>
1515 <style tal:condition="usercss" type="text/css">/*<![CDATA[*/ ${usercss} /*]]>*/</style>
1616 <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs"></script><script
Index: trunk/phase3/skins/Chick.pt
@@ -5,7 +5,7 @@
66 <div tal:replace="structure headlinks"></div>
77 <title tal:content="pagetitle">Exciting xhtml slimfast</title>
88 <style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "${stylepath}/${stylename}/main.css"; /*]]>*/</style>
9 - <script type="text/javascript" tal:attributes="src jsvarurl"></script>
 9+ <script tal:condition="jsvarurl" type="text/javascript" tal:attributes="src jsvarurl"></script>
1010 <script type="text/javascript" src="${stylepath}/common/wikibits.js"></script>
1111 <style tal:condition="usercss" tal:content="structure usercss" type="text/css"></style>
1212 <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs"></script><script
Index: trunk/phase3/skins/MonoBook.pt
@@ -9,7 +9,7 @@
1010 <!--[if IE]><style type="text/css" media="all">@import "${stylepath}/${stylename}/IEFixes.css";</style>
1111 <script type="text/javascript" src="${stylepath}/common/IEFixes.js"></script>
1212 <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
13 - <script type="text/javascript" tal:attributes="src jsvarurl"></script>
 13+ <script tal:condition="jsvarurl" type="text/javascript" tal:attributes="src jsvarurl"></script>
1414 <script type="text/javascript" src="${stylepath}/common/wikibits.js"></script>
1515 <style tal:condition="usercss" tal:content="structure usercss" type="text/css"></style>
1616 <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs"></script><script
Index: trunk/phase3/skins/WikimediaWiki.pt
@@ -9,7 +9,7 @@
1010 <!--[if IE]><style type="text/css" media="all">@import "${stylepath}/${stylename}/common/IEFixes.css";</style>
1111 <script type="text/javascript" src="${stylepath}/IEFixes.js"></script>
1212 <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
13 - <script type="text/javascript" tal:attributes="src jsvarurl"></script>
 13+ <script tal:condition="jsvarurl" type="text/javascript" tal:attributes="src jsvarurl"></script>
1414 <script type="text/javascript" src="${stylepath}/common/wikibits.js"></script>
1515 <style tal:condition="usercss" type="text/css">/*<![CDATA[*/ ${usercss} /*]]>*/</style>
1616 <script tal:condition="userjs" type="text/javascript" tal:attributes="src userjs"></script><script
Index: trunk/phase3/includes/SkinPHPTal.php
@@ -159,8 +159,8 @@
160160 $this->userpageUrlDetails = $this->makeUrlDetails($this->userpage);
161161
162162 $this->usercss = $this->userjs = $this->userjsprev = false;
163 - $this->setupUserCssJs();
164 -
 163+ $this->setupUserCss();
 164+ $this->setupUserJs();
165165 $this->titletxt = $wgTitle->getPrefixedText();
166166
167167 $tpl->set( 'title', $wgOut->getPageTitle() );
@@ -223,10 +223,15 @@
224224 $tpl->setRef( 'usercss', $this->usercss);
225225 $tpl->setRef( 'userjs', $this->userjs);
226226 $tpl->setRef( 'userjsprev', $this->userjsprev);
227 - if($this->loggedin) {
228 - $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
 227+ global $wgUseSiteJs;
 228+ if ($wgUseSiteJs) {
 229+ if($this->loggedin) {
 230+ $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&smaxage=0&gen=js') );
 231+ } else {
 232+ $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
 233+ }
229234 } else {
230 - $tpl->set( 'jsvarurl', $this->makeUrl('-','action=raw&gen=js') );
 235+ $tpl->set('jsvarurl', false);
231236 }
232237 if( $wgUser->getNewtalk() ) {
233238 $usertitle = Title::newFromText( $this->userpage );
@@ -670,40 +675,63 @@
671676 }
672677 }
673678
674 -
675679 /**
676680 * @access private
677681 */
678 - function setupUserCssJs () {
679 - global $wgRequest, $wgTitle;
680 - $action = $wgRequest->getText('action');
681 - # generated css
682 - $this->usercss = '@import "'.$this->makeUrl('-','action=raw&gen=css').'";'."\n";
 682+
 683+ function setupUserCss () {
 684+
 685+ global $wgRequest, $wgTitle, $wgAllowUserCss, $wgUseSiteCss;
683686
684 - if( $this->loggedin ) {
 687+ $sitecss = "";
 688+ $usercss = "";
 689+ $siteargs = "";
 690+
 691+ # Add user-specific code if this is a user and we allow that kind of thing
 692+
 693+ if ( $wgAllowUserCss && $this->loggedin ) {
 694+ $action = $wgRequest->getText('action');
 695+
 696+ # if we're previewing the CSS page, use it
685697 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
686 - # generated css
687 - $this->usercss = '@import "'.$this->makeUrl('-','action=raw&smaxage=0&maxage=0&gen=css').'";'."\n";
688 - // css preview
689 - $this->usercss .= $wgRequest->getText('wpTextbox1');
 698+ $siteargs .= "&smaxage=0&maxage=0";
 699+ $usercss = $wgRequest->getText('wpTextbox1');
690700 } else {
691 - # generated css
692 - $this->usercss .= '@import "'.$this->makeUrl('-','action=raw&smaxage=0&gen=css').'";'."\n";
693 - # import user stylesheet
694 - $this->usercss .= '@import "'.
695 - $this->makeUrl($this->userpage.'/'.$this->skinname.'.css', 'action=raw&ctype=text/css').'";'."\n";
 701+ $siteargs .= "&maxage=0";
 702+ $usercss = '@import "' .
 703+ $this->makeUrl($this->userpage . '/'.$this->skinname.'.css',
 704+ 'action=raw&ctype=text/css') . '";' ."\n";
696705 }
 706+ }
 707+
 708+ # If we use the site's dynamic CSS, throw that in, too
 709+
 710+ if ( $wgUseSiteCss ) {
 711+ $sitecss = '@import "'.$this->makeUrl('-','action=raw&gen=css' . $siteargs).'";'."\n";
 712+ }
 713+
 714+ # If we use any dynamic CSS, make a little CDATA block out of it.
 715+
 716+ if ( !empty($sitecss) || !empty($usercss) ) {
 717+ $this->usercss = '/*<![CDATA[*/ ' . $sitecss . ' ' . $usercss . ' /*]]>*/';
 718+ }
 719+ }
 720+
 721+ /**
 722+ * @access private
 723+ */
 724+ function setupUserJs () {
 725+ global $wgRequest, $wgTitle, $wgAllowUserJs;
 726+ $action = $wgRequest->getText('action');
 727+
 728+ if( $wgAllowUserJs && $this->loggedin ) {
697729 if($wgTitle->isJsSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
698730 # XXX: additional security check/prompt?
699 - $this->userjsprev = $wgRequest->getText('wpTextbox1');
 731+ $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
700732 } else {
701733 $this->userjs = $this->makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype=text/javascript&dontcountme=s');
702734 }
703735 }
704 - $this->usercss = '/*<![CDATA[*/ ' . $this->usercss . ' /*]]>*/';
705 - if( $this->userjsprev ) {
706 - $this->userjsprev = '/*<![CDATA[*/ ' . $this->userjsprev . ' /*]]>*/';
707 - }
708736 }
709737
710738 /**
Index: trunk/phase3/includes/DefaultSettings.php
@@ -721,6 +721,12 @@
722722 # Allow user Cascading Style Sheets (CSS)?
723723 $wgAllowUserCss = true;
724724
 725+# Use the site's Javascript page?
 726+$wgUseSiteJs = true;
 727+
 728+# Use the site's Cascading Style Sheets (CSS)?
 729+$wgUseSiteCss = true;
 730+
725731 # Filter for Special:Randompage. Part of a WHERE clause
726732 $wgExtraRandompageSQL = false;
727733

Status & tagging log

  • 15:00, 12 September 2011 Meno25 (talk | contribs) changed the status of r6223 [removed: ok added: old]
  • 13:54, 18 June 2009 ^demon (talk | contribs) changed the status of r6223 [removed: new added: ok]