http://www.mediawiki.org/wiki/Special:Code/MediaWiki/74043

Revision: 74043
Author:   tparscal
Date:     2010-09-30 21:20:09 +0000 (Thu, 30 Sep 2010)

Log Message:
-----------
* 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

Modified Paths:
--------------
    trunk/phase3/RELEASE-NOTES
    trunk/phase3/includes/GlobalFunctions.php
    trunk/phase3/includes/OutputPage.php
    trunk/phase3/includes/ResourceLoaderModule.php
    trunk/phase3/resources/mediawiki/mediawiki.js

Modified: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES  2010-09-30 21:11:11 UTC (rev 74042)
+++ trunk/phase3/RELEASE-NOTES  2010-09-30 21:20:09 UTC (rev 74043)
@@ -168,6 +168,7 @@
 * 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

Modified: trunk/phase3/includes/GlobalFunctions.php
===================================================================
--- trunk/phase3/includes/GlobalFunctions.php   2010-09-30 21:11:11 UTC (rev 
74042)
+++ trunk/phase3/includes/GlobalFunctions.php   2010-09-30 21:20:09 UTC (rev 
74043)
@@ -1957,6 +1957,13 @@
 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
  *                    accordingly.
@@ -1983,6 +1990,8 @@
                                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 @@
                        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 );

Modified: trunk/phase3/includes/OutputPage.php
===================================================================
--- trunk/phase3/includes/OutputPage.php        2010-09-30 21:11:11 UTC (rev 
74042)
+++ trunk/phase3/includes/OutputPage.php        2010-09-30 21:20:09 UTC (rev 
74043)
@@ -2343,12 +2343,12 @@
                                // 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 );

Modified: trunk/phase3/includes/ResourceLoaderModule.php
===================================================================
--- trunk/phase3/includes/ResourceLoaderModule.php      2010-09-30 21:11:11 UTC 
(rev 74042)
+++ trunk/phase3/includes/ResourceLoaderModule.php      2010-09-30 21:20:09 UTC 
(rev 74043)
@@ -1062,7 +1062,7 @@
                        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 @@
                                '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 ) )

Modified: trunk/phase3/resources/mediawiki/mediawiki.js
===================================================================
--- trunk/phase3/resources/mediawiki/mediawiki.js       2010-09-30 21:11:11 UTC 
(rev 74042)
+++ trunk/phase3/resources/mediawiki/mediawiki.js       2010-09-30 21:20:09 UTC 
(rev 74043)
@@ -230,24 +230,18 @@
                /* 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 pad( a, b, c ) {
+                               return [a < 10 ? '0' + a : a, b < 10 ? '0' + b 
: b, c < 10 ? '0' + c : c].join();
                        }
-                       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';
+                       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();
                }
                
                /**



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to