r74043 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74042‎ | r74043 | r74044 >
Date:21:20, 30 September 2010
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
* 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 (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/ResourceLoaderModule.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1957,6 +1957,13 @@
19581958 define( 'TS_DB2', 8 );
19591959
19601960 /**
 1961+ * ISO 8601 basic format with no timezone: 19860209T200000Z
 1962+ *
 1963+ * This is used by ResourceLoader
 1964+ */
 1965+define( 'TS_ISO_8601_BASIC', 9 );
 1966+
 1967+/**
19611968 * @param $outputtype Mixed: A timestamp in one of the supported formats, the
19621969 * function will autodetect which format is supplied and act
19631970 * accordingly.
@@ -1983,6 +1990,8 @@
19841991 str_replace( '+00:00', 'UTC', $ts ) ) );
19851992 } elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
19861993 # TS_ISO_8601
 1994+ } elseif ( preg_match( '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?\.*\d*)?Z$/', $ts, $da ) ) {
 1995+ #TS_ISO_8601_BASIC
19871996 } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) {
19881997 # TS_POSTGRES
19891998 } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) {
@@ -2014,6 +2023,8 @@
20152024 return gmdate( 'Y-m-d H:i:s', $uts );
20162025 case TS_ISO_8601:
20172026 return gmdate( 'Y-m-d\TH:i:s\Z', $uts );
 2027+ case TS_ISO_8601_BASIC:
 2028+ return gmdate( 'Ymd\THis\Z', $uts );
20182029 // This shouldn't ever be used, but is included for completeness
20192030 case TS_EXIF:
20202031 return gmdate( 'Y:m:d H:i:s', $uts );
Index: trunk/phase3/includes/OutputPage.php
@@ -2343,12 +2343,12 @@
23442344 // Create a fake request based on the one we are about to make so modules return correct times
23452345 $context = new ResourceLoaderContext( $this->mResourceLoader, new FauxRequest( $query ) );
23462346 // Get the maximum timestamp
2347 - $timestamp = 0;
 2347+ $timestamp = 1;
23482348 foreach ( $modules as $module ) {
23492349 $timestamp = max( $timestamp, $module->getModifiedTime( $context ) );
23502350 }
23512351 // Add a version parameter so cache will break when things change
2352 - $query['version'] = wfTimestamp( TS_ISO_8601, round( $timestamp, -2 ) );
 2352+ $query['version'] = wfTimestamp( TS_ISO_8601_BASIC, round( $timestamp, -2 ) );
23532353 }
23542354 // Make queries uniform in order
23552355 ksort( $query );
Index: trunk/phase3/includes/ResourceLoaderModule.php
@@ -1062,7 +1062,7 @@
10631063 if ( ( $loader = $module->getLoaderScript() ) !== false ) {
10641064 $deps = FormatJson::encode( $module->getDependencies() );
10651065 $group = FormatJson::encode( $module->getGroup() );
1066 - $version = wfTimestamp( TS_ISO_8601, round( $module->getModifiedTime( $context ), -2 ) );
 1066+ $version = wfTimestamp( TS_ISO_8601_BASIC, round( $module->getModifiedTime( $context ), -2 ) );
10671067 $out .= ResourceLoader::makeCustomLoaderScript( $name, $version, $deps, $group, $loader );
10681068 }
10691069 // Automatically register module
@@ -1106,7 +1106,7 @@
11071107 'lang' => $context->getLanguage(),
11081108 'skin' => $context->getSkin(),
11091109 'debug' => $context->getDebug() ? 'true' : 'false',
1110 - 'version' => wfTimestamp( TS_ISO_8601, round( max(
 1110+ 'version' => wfTimestamp( TS_ISO_8601_BASIC, round( max(
11111111 $context->getResourceLoader()->getModule( 'jquery' )->getModifiedTime( $context ),
11121112 $context->getResourceLoader()->getModule( 'mediawiki' )->getModifiedTime( $context )
11131113 ), -2 ) )
Index: trunk/phase3/RELEASE-NOTES
@@ -168,6 +168,7 @@
169169 * Special:Version now displays whether a SQLite database supports full-text
170170 search.
171171 * (bug 24343) New parser hook {{linkurl:}}, same as {{localurl:}} with fragment
 172+* TS_ISO_8691_BASIC was added as a time format, which is used by ResourceLoader for versioning
172173
173174 === Bug fixes in 1.17 ===
174175 * (bug 17560) Half-broken deletion moved image files to deletion archive
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -230,24 +230,18 @@
231231 /* Private Methods */
232232
233233 /**
234 - * Generates an ISO8601 string from a UNIX timestamp
 234+ * Generates an ISO8601 "basic" string from a UNIX timestamp
235235 */
236236 function formatVersionNumber( timestamp ) {
237 - var date = new Date();
238 - date.setTime( timestamp * 1000 );
239 - function pad1( n ) {
240 - return n < 10 ? '0' + n : n
 237+ function pad( a, b, c ) {
 238+ return [a < 10 ? '0' + a : a, b < 10 ? '0' + b : b, c < 10 ? '0' + c : c].join();
241239 }
242 - function pad2( n ) {
243 - return n < 10 ? '00' + n : ( n < 100 ? '0' + n : n );
244 - }
245 - return date.getUTCFullYear() + '-' +
246 - pad1( date.getUTCMonth() + 1 ) + '-' +
247 - pad1( date.getUTCDate() ) + 'T' +
248 - pad1( date.getUTCHours() ) + ':' +
249 - pad1( date.getUTCMinutes() ) + ':' +
250 - pad1( date.getUTCSeconds() ) +
251 - 'Z';
 240+ var d = new Date()
 241+ d.setTime( timestamp * 1000 );
 242+ return [
 243+ pad( d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate() ), 'T',
 244+ pad( d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds() ), 'Z'
 245+ ].join();
252246 }
253247
254248 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r74045Fixed bug in r74043 where a : was left out of a regex for matching timestamps...tparscal21:32, 30 September 2010
r74046Added tests for new TS_ISO_8601_BASIC timestamp format added in r74043 (and f...tparscal21:58, 30 September 2010

Comments

#Comment by Raymond (talk | contribs)   21:31, 30 September 2010

PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Compilation failed: unrecognized character after (? or (?- at offset 46 in /www/w/includes/GlobalFunctions.php on line 1993

Status & tagging log