* Added support for basic version of ISO_8601 timestamp format (see http://en.wikiped...
authorTrevor Parscal <tparscal@users.mediawiki.org>
Thu, 30 Sep 2010 21:20:09 +0000 (21:20 +0000)
committerTrevor Parscal <tparscal@users.mediawiki.org>
Thu, 30 Sep 2010 21:20:09 +0000 (21:20 +0000)
* Made use of ISO_8601 basic for ResourceLoader

RELEASE-NOTES
includes/GlobalFunctions.php
includes/OutputPage.php
includes/ResourceLoaderModule.php
resources/mediawiki/mediawiki.js

index 2fbc279..2713487 100644 (file)
@@ -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
index cc27ab2..93dd56b 100644 (file)
@@ -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 );
index 94edee8..99a9b8c 100644 (file)
@@ -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 );
index 41a363e..2f12c65 100644 (file)
@@ -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 ) )
index 1848917..2fcb5f7 100644 (file)
@@ -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();
                }
                
                /**