From fc106bf474aa1146fcd5dd9d15e2f14d29cc60f8 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Thu, 30 Sep 2010 21:20:09 +0000 Subject: [PATCH] * Added support for basic version of ISO_8601 timestamp format (see http://en.wikipedia.org/wiki/ISO_8601) * Made use of ISO_8601 basic for ResourceLoader --- RELEASE-NOTES | 1 + includes/GlobalFunctions.php | 11 +++++++++++ includes/OutputPage.php | 4 ++-- includes/ResourceLoaderModule.php | 4 ++-- resources/mediawiki/mediawiki.js | 26 ++++++++++---------------- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2fbc279bf3..2713487a65 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -168,6 +168,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Special:Version now displays whether a SQLite database supports full-text search. * (bug 24343) New parser hook {{linkurl:}}, same as {{localurl:}} with fragment +* TS_ISO_8691_BASIC was added as a time format, which is used by ResourceLoader for versioning === Bug fixes in 1.17 === * (bug 17560) Half-broken deletion moved image files to deletion archive diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index cc27ab2981..93dd56b385 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1956,6 +1956,13 @@ define( 'TS_POSTGRES', 7 ); */ define( 'TS_DB2', 8 ); +/** + * ISO 8601 basic format with no timezone: 19860209T200000Z + * + * This is used by ResourceLoader + */ +define( 'TS_ISO_8601_BASIC', 9 ); + /** * @param $outputtype Mixed: A timestamp in one of the supported formats, the * function will autodetect which format is supplied and act @@ -1983,6 +1990,8 @@ function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) { str_replace( '+00:00', 'UTC', $ts ) ) ); } elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) { # TS_ISO_8601 + } elseif ( preg_match( '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?\.*\d*)?Z$/', $ts, $da ) ) { + #TS_ISO_8601_BASIC } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) { # TS_POSTGRES } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) { @@ -2014,6 +2023,8 @@ function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) { return gmdate( 'Y-m-d H:i:s', $uts ); case TS_ISO_8601: return gmdate( 'Y-m-d\TH:i:s\Z', $uts ); + case TS_ISO_8601_BASIC: + return gmdate( 'Ymd\THis\Z', $uts ); // This shouldn't ever be used, but is included for completeness case TS_EXIF: return gmdate( 'Y:m:d H:i:s', $uts ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 94edee8a01..99a9b8c40d 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2343,12 +2343,12 @@ class OutputPage { // Create a fake request based on the one we are about to make so modules return correct times $context = new ResourceLoaderContext( $this->mResourceLoader, new FauxRequest( $query ) ); // Get the maximum timestamp - $timestamp = 0; + $timestamp = 1; foreach ( $modules as $module ) { $timestamp = max( $timestamp, $module->getModifiedTime( $context ) ); } // Add a version parameter so cache will break when things change - $query['version'] = wfTimestamp( TS_ISO_8601, round( $timestamp, -2 ) ); + $query['version'] = wfTimestamp( TS_ISO_8601_BASIC, round( $timestamp, -2 ) ); } // Make queries uniform in order ksort( $query ); diff --git a/includes/ResourceLoaderModule.php b/includes/ResourceLoaderModule.php index 41a363eda5..2f12c6564f 100644 --- a/includes/ResourceLoaderModule.php +++ b/includes/ResourceLoaderModule.php @@ -1062,7 +1062,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { if ( ( $loader = $module->getLoaderScript() ) !== false ) { $deps = FormatJson::encode( $module->getDependencies() ); $group = FormatJson::encode( $module->getGroup() ); - $version = wfTimestamp( TS_ISO_8601, round( $module->getModifiedTime( $context ), -2 ) ); + $version = wfTimestamp( TS_ISO_8601_BASIC, round( $module->getModifiedTime( $context ), -2 ) ); $out .= ResourceLoader::makeCustomLoaderScript( $name, $version, $deps, $group, $loader ); } // Automatically register module @@ -1106,7 +1106,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { 'lang' => $context->getLanguage(), 'skin' => $context->getSkin(), 'debug' => $context->getDebug() ? 'true' : 'false', - 'version' => wfTimestamp( TS_ISO_8601, round( max( + 'version' => wfTimestamp( TS_ISO_8601_BASIC, round( max( $context->getResourceLoader()->getModule( 'jquery' )->getModifiedTime( $context ), $context->getResourceLoader()->getModule( 'mediawiki' )->getModifiedTime( $context ) ), -2 ) ) diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 1848917750..2fcb5f758f 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -230,24 +230,18 @@ window.mediaWiki = new ( function( $ ) { /* Private Methods */ /** - * Generates an ISO8601 string from a UNIX timestamp + * Generates an ISO8601 "basic" string from a UNIX timestamp */ function formatVersionNumber( timestamp ) { - var date = new Date(); - date.setTime( timestamp * 1000 ); - function pad1( n ) { - return n < 10 ? '0' + n : n - } - function pad2( n ) { - return n < 10 ? '00' + n : ( n < 100 ? '0' + n : n ); - } - return date.getUTCFullYear() + '-' + - pad1( date.getUTCMonth() + 1 ) + '-' + - pad1( date.getUTCDate() ) + 'T' + - pad1( date.getUTCHours() ) + ':' + - pad1( date.getUTCMinutes() ) + ':' + - pad1( date.getUTCSeconds() ) + - 'Z'; + function pad( a, b, c ) { + return [a < 10 ? '0' + a : a, b < 10 ? '0' + b : b, c < 10 ? '0' + c : c].join(); + } + var d = new Date() + d.setTime( timestamp * 1000 ); + return [ + pad( d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate() ), 'T', + pad( d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds() ), 'Z' + ].join(); } /** -- 2.20.1