MediaWiki r45208 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r45207‎ | r45208 (on ViewVC)‎ | r45209 >
Date:22:51, 30 December 2008
Author:danny_b
Status:ok (Comments)
Tags:
Comment:
* handle the "o" format character for PHP 5.1.0+, older versions need emulation
Modified paths:

Diff [purge]

Index: trunk/phase3/languages/Language.php
===================================================================
--- trunk/phase3/languages/Language.php	(revision 45207)
+++ trunk/phase3/languages/Language.php	(revision 45208)
@@ -535,9 +535,10 @@
 	 * internationalisation, a reduced set of format characters, and a better 
 	 * escaping format.
 	 *
-	 * Supported format characters are dDjlNwzWFmMntLYyaAgGhHiscrU. See the 
-	 * PHP manual for definitions. There are a number of extensions, which 
-	 * start with "x":
+	 * Supported format characters are dDjlNwzWFmMntLoYyaAgGhHiscrU. See the 
+	 * PHP manual for definitions. "o" format character is supported since
+	 * PHP 5.1.0, previous versions return literal o.
+	 * There are a number of extensions, which start with "x":
 	 *
 	 *    xn   Do not translate digits of the next numeric format character
 	 *    xN   Toggle raw digit (xn) flag, stays set until explicitly unset
@@ -558,10 +559,10 @@
 	 *    xjn  n (month number) in Hebrew calendar
 	 *    xjY  Y (full year) in Hebrew calendar
 	 *
-	 *   xmj  j (day number) in Hijri calendar
-	 *   xmF  F (month name) in Hijri calendar
-	 *   xmn  n (month number) in Hijri calendar
-	 *   xmY  Y (full year) in Hijri calendar
+	 *    xmj  j (day number) in Hijri calendar
+	 *    xmF  F (month name) in Hijri calendar
+	 *    xmn  n (month number) in Hijri calendar
+	 *    xmY  Y (full year) in Hijri calendar
 	 *
 	 *    xkY  Y (full year) in Thai solar calendar. Months and days are
 	 *                       identical to the Gregorian calendar
@@ -582,6 +583,8 @@
 	 * @param $ts String: 14-character timestamp
 	 *      YYYYMMDDHHMMSS
 	 *      01234567890123
+	 * @todo emulation of "o" format character for PHP pre 5.1.0
+	 * @todo handling of "o" format character for Iranian, Hebrew, Hijri & Thai?
 	 */
 	function sprintfDate( $format, $ts ) {
 		$s = '';
@@ -719,6 +722,16 @@
 					if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
 					$num = gmdate( 'L', $unix );
 					break;
+				# 'o' is supported since PHP 5.1.0
+				# return literal if not supported
+				# TODO: emulation for pre 5.1.0 versions
+				case 'o':
+					if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
+					if ( version_compare(PHP_VERSION, '5.1.0') === 1 )
+						$num = date( 'o', $unix );
+					else
+						$s .= 'o';
+					break;
 				case 'Y':
 					$num = substr( $ts, 0, 4 );
 					break;

Follow-up revisions

Rev.Commit summaryAuthorDate
r107806(Half of bug 33454) The week based year number (format char 'o') was being ca...bawolff08:20, 2 January 2012

Comments

#Comment by Nikerabbit (Talk | contribs)   10:18, 23 February 2009

Shouldn't the check be version_compare(PHP_VERSION, '5.1.0') >= 0

Status & tagging log

Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox