r16992 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r16991 | r16992 (on ViewVC) | r16993 >
Date:21:48, 13 October 2006
Author:brion
Status:new
Tags:
Comment:* Added global $wgStyleVersion to centralize bumping CSS and JS file versions
for cache-friendly style and script updating
Modified paths:

Diff [purge]

Index: trunk/phase3/skins/CologneBlue.php
===================================================================
--- trunk/phase3/skins/CologneBlue.php	(revision 16991)
+++ trunk/phase3/skins/CologneBlue.php	(revision 16992)
@@ -18,7 +18,7 @@
 class SkinCologneBlue extends Skin {
 
 	function getStylesheet() {
-		return "common/cologneblue.css?4";
+		return 'common/cologneblue.css';
 	}
 	function getSkinName() {
 		return "cologneblue";
Index: trunk/phase3/skins/Standard.php
===================================================================
--- trunk/phase3/skins/Standard.php	(revision 16991)
+++ trunk/phase3/skins/Standard.php	(revision 16992)
@@ -21,12 +21,12 @@
 	 *
 	 */
 	function getHeadScripts() {
-		global $wgStylePath, $wgJsMimeType;
+		global $wgStylePath, $wgJsMimeType, $wgStyleVersion;
 
 		$s = parent::getHeadScripts();
 		if ( 3 == $this->qbSetting() ) { # Floating left
 			$s .= "<script language='javascript' type='$wgJsMimeType' " .
-			  "src='{$wgStylePath}/common/sticky.js'></script>\n";
+			  "src='{$wgStylePath}/common/sticky.js?$wgStyleVersion'></script>\n";
 		}
 		return $s;
 	}
@@ -35,14 +35,14 @@
 	 *
 	 */
 	function getUserStyles() {
-		global $wgStylePath;
+		global $wgStylePath, $wgStyleVersion;
 		$s = '';
 		if ( 3 == $this->qbSetting() ) { # Floating left
 			$s .= "<style type='text/css'>\n" .
-			  "@import '{$wgStylePath}/common/quickbar.css';\n</style>\n";
+			  "@import '{$wgStylePath}/common/quickbar.css?$wgStyleVersion';\n</style>\n";
 		} else if ( 4 == $this->qbSetting() ) { # Floating right
 			$s .= "<style type='text/css'>\n" .
-			  "@import '{$wgStylePath}/common/quickbar-right.css';\n</style>\n";
+			  "@import '{$wgStylePath}/common/quickbar-right.css?$wgStyleVersion';\n</style>\n";
 		}
 		$s .= parent::getUserStyles();
 		return $s;
Index: trunk/phase3/skins/Nostalgia.php
===================================================================
--- trunk/phase3/skins/Nostalgia.php	(revision 16991)
+++ trunk/phase3/skins/Nostalgia.php	(revision 16992)
@@ -18,7 +18,7 @@
 class SkinNostalgia extends Skin {
 
 	function getStylesheet() {
-		return 'common/nostalgia.css?2';
+		return 'common/nostalgia.css';
 	}
 	function getSkinName() {
 		return "nostalgia";
Index: trunk/phase3/skins/MonoBook.php
===================================================================
--- trunk/phase3/skins/MonoBook.php	(revision 16991)
+++ trunk/phase3/skins/MonoBook.php	(revision 16992)
@@ -56,18 +56,18 @@
 		<meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
 		<?php $this->html('headlinks') ?>
 		<title><?php $this->text('pagetitle') ?></title>
-		<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/main.css?10"; /*]]>*/</style>
-		<link rel="stylesheet" type="text/css" <?php if(empty($this->data['printable']) ) { ?>media="print"<?php } ?> href="<?php $this->text('stylepath') ?>/common/commonPrint.css?1" />
-		<!--[if lt IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE50Fixes.css";</style><![endif]-->
-		<!--[if IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE55Fixes.css";</style><![endif]-->
-		<!--[if IE 6]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE60Fixes.css";</style><![endif]-->
-		<!--[if IE 7]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE70Fixes.css?1";</style><![endif]-->
-		<!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js"></script>
+		<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/main.css?<?php echo $GLOBALS['wgStyleVersion'] ?>"; /*]]>*/</style>
+		<link rel="stylesheet" type="text/css" <?php if(empty($this->data['printable']) ) { ?>media="print"<?php } ?> href="<?php $this->text('stylepath') ?>/common/commonPrint.css?<?php echo $GLOBALS['wgStyleVersion'] ?>" />
+		<!--[if lt IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE50Fixes.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";</style><![endif]-->
+		<!--[if IE 5.5000]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE55Fixes.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";</style><![endif]-->
+		<!--[if IE 6]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE60Fixes.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";</style><![endif]-->
+		<!--[if IE 7]><style type="text/css">@import "<?php $this->text('stylepath') ?>/<?php $this->text('stylename') ?>/IE70Fixes.css?<?php echo $GLOBALS['wgStyleVersion'] ?>";</style><![endif]-->
+		<!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"></script>
 		<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
 		
 		<?php print Skin::makeGlobalVariablesScript( $this->data ); ?>
                 
-		<script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?2"><!-- wikibits js --></script>
+		<script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"><!-- wikibits js --></script>
 <?php	if($this->data['jsvarurl'  ]) { ?>
 		<script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl'  ) ?>"><!-- site js --></script>
 <?php	} ?>
Index: trunk/phase3/includes/ProtectionForm.php
===================================================================
--- trunk/phase3/includes/ProtectionForm.php	(revision 16991)
+++ trunk/phase3/includes/ProtectionForm.php	(revision 16992)
@@ -212,9 +212,9 @@
 	}
 
 	function buildScript() {
-		global $wgStylePath;
+		global $wgStylePath, $wgStyleVersion;
 		return '<script type="text/javascript" src="' .
-			htmlspecialchars( $wgStylePath . "/common/protect.js" ) .
+			htmlspecialchars( $wgStylePath . "/common/protect.js?$wgStyleVersion" ) .
 			'"></script>';
 	}
 
Index: trunk/phase3/includes/ImagePage.php
===================================================================
--- trunk/phase3/includes/ImagePage.php	(revision 16991)
+++ trunk/phase3/includes/ImagePage.php	(revision 16992)
@@ -71,13 +71,13 @@
 			$this->imageHistory();
 			$this->imageLinks();
 			if( $exif ) {
-				global $wgStylePath;
+				global $wgStylePath, $wgStyleVersion;
 				$expand = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-expand' ) ) );
 				$collapse = htmlspecialchars( wfEscapeJsString( wfMsg( 'metadata-collapse' ) ) );
 				$wgOut->addHTML( "<h2 id=\"metadata\">" . wfMsgHtml( 'metadata' ) . "</h2>\n" );
 				$wgOut->addWikiText( $this->makeMetadataTable( $exif ) );
 				$wgOut->addHTML(
-					"<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js\"></script>\n" .
+					"<script type=\"text/javascript\" src=\"$wgStylePath/common/metadata.js?wgStyleVersion\"></script>\n" .
 					"<script type=\"text/javascript\">attachMetadataToggle('mw_metadata', '$expand', '$collapse');</script>\n" );
 			}
 		} else {
Index: trunk/phase3/includes/Feed.php
===================================================================
--- trunk/phase3/includes/Feed.php	(revision 16991)
+++ trunk/phase3/includes/Feed.php	(revision 16992)
@@ -149,12 +149,12 @@
 	 * @private
 	 */
 	function outXmlHeader() {
-		global $wgServer, $wgStylePath;
+		global $wgServer, $wgStylePath, $wgStyleVersion;
 
 		$this->httpHeaders();
 		echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
 		echo '<?xml-stylesheet type="text/css" href="' .
-			htmlspecialchars( "$wgServer$wgStylePath/common/feed.css" ) . '"?' . ">\n";
+			htmlspecialchars( "$wgServer$wgStylePath/common/feed.css?$wgStyleVersion" ) . '"?' . ">\n";
 	}
 }
 
Index: trunk/phase3/includes/EditPage.php
===================================================================
--- trunk/phase3/includes/EditPage.php	(revision 16991)
+++ trunk/phase3/includes/EditPage.php	(revision 16992)
@@ -1290,9 +1290,9 @@
 	 * of the preview button
 	 */
 	function doLivePreviewScript() {
-		global $wgStylePath, $wgJsMimeType, $wgOut, $wgTitle;
+		global $wgStylePath, $wgJsMimeType, $wgStyleVersion, $wgOut, $wgTitle;
 		$wgOut->addHTML( '<script type="'.$wgJsMimeType.'" src="' .
-			htmlspecialchars( $wgStylePath . '/common/preview.js' ) .
+			htmlspecialchars( "$wgStylePath/common/preview.js?$wgStyleVersion" ) .
 			'"></script>' . "\n" );
 		$liveAction = $wgTitle->getLocalUrl( 'action=submit&wpPreview=true&live=true' );
 		return "return !livePreview(" .
Index: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php	(revision 16991)
+++ trunk/phase3/includes/OutputPage.php	(revision 16992)
@@ -481,6 +481,7 @@
 		global $wgUser, $wgOutputEncoding, $wgRequest;
 		global $wgContLanguageCode, $wgDebugRedirects, $wgMimeType;
 		global $wgJsMimeType, $wgStylePath, $wgUseAjax, $wgAjaxSearch, $wgScriptPath, $wgServer;
+		global $wgStyleVersion;
 
 		if( $this->mDoNothing ){
 			return;
@@ -490,11 +491,11 @@
 		$sk = $wgUser->getSkin();
 
 		if ( $wgUseAjax ) {
-			$this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js\"></script>\n" );
+			$this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
 		}
 
 		if ( $wgUseAjax && $wgAjaxSearch ) {
-			$this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js\"></script>\n" );
+			$this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
 			$this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
 		}
 
@@ -969,7 +970,7 @@
 	 */
 	function headElement() {
 		global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
-		global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle;
+		global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle, $wgStyleVersion;
 
 		if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) {
 			$ret = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
@@ -995,7 +996,7 @@
 		} else {
 			$media = "media='print'";
 		}
-		$printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css" );
+		$printsheet = htmlspecialchars( "$wgStylePath/common/wikiprintable.css?$wgStyleVersion" );
 		$ret .= "<link rel='stylesheet' type='text/css' $media href='$printsheet' />\n";
 
 		$sk = $wgUser->getSkin();
Index: trunk/phase3/includes/SkinTemplate.php
===================================================================
--- trunk/phase3/includes/SkinTemplate.php	(revision 16991)
+++ trunk/phase3/includes/SkinTemplate.php	(revision 16992)
@@ -932,7 +932,10 @@
 			$siteargs .= '&ts=' . $wgUser->mTouched;
 		}
 
-		if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css?1";' . "\n";
+		if( $wgContLang->isRTL() ) {
+			global $wgStyleVersion;
+			$sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
+		}
 
 		# If we use the site's dynamic CSS, throw that in, too
 		if ( $wgUseSiteCss ) {
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 16991)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 16992)
@@ -1024,6 +1024,13 @@
  */
 $wgCacheEpoch = '20030516000000';
 
+/**
+ * Bump this number when changing the global style sheets and JavaScript.
+ * It should be appended in the query string of static CSS and JS includes,
+ * to ensure that client-side caches don't keep obsolete copies of global
+ * styles.
+ */
+$wgStyleVersion = '11';
 
 # Server-side caching:
 
Index: trunk/phase3/includes/Skin.php
===================================================================
--- trunk/phase3/includes/Skin.php	(revision 16991)
+++ trunk/phase3/includes/Skin.php	(revision 16992)
@@ -139,7 +139,7 @@
 
 	/** @return string path to the skin stylesheet */
 	function getStylesheet() {
-		return 'common/wikistandard.css?2';
+		return 'common/wikistandard.css';
 	}
 
 	/** @return string skin name */
@@ -296,7 +296,7 @@
 	}
 
 	function getHeadScripts() {
-		global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
+		global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
 		global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
 		global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
 
@@ -323,7 +323,7 @@
 
 		$r = self::makeGlobalVariablesScript( $vars );
 
-		$r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
+		$r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
 		if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
 			$userpage = $wgUser->getUserPage();
 			$userjs = htmlspecialchars( self::makeUrl(
@@ -360,10 +360,10 @@
 
 	# get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
 	function getUserStylesheet() {
-		global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
+		global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
 		$sheet = $this->getStylesheet();
 		$action = $wgRequest->getText('action');
-		$s = "@import \"$wgStylePath/$sheet\";\n";
+		$s = "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
 		if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?1\";\n";
 
 		$query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES	(revision 16991)
+++ trunk/phase3/RELEASE-NOTES	(revision 16992)
@@ -44,7 +44,10 @@
 * (bug 6868) Un-hardcode section edit link style
 * (bug 3205) Stop right floats from stacking horizontally in non-Monobook skins
 * (bug 2013) Inherit ratios and not computed values for line-height
+* Added global $wgStyleVersion to centralize bumping CSS and JS file versions
+  for cache-friendly style and script updating
 
+
 == Languages updated ==
 
 * Occitan (oc)
Views
Toolbox