* handle the "o" format character for PHP 5.1.0+, older versions need emulation
authorDanny B <danny_b@users.mediawiki.org>
Tue, 30 Dec 2008 22:51:05 +0000 (22:51 +0000)
committerDanny B <danny_b@users.mediawiki.org>
Tue, 30 Dec 2008 22:51:05 +0000 (22:51 +0000)
languages/Language.php

index b7c9efc..6502aa0 100644 (file)
@@ -535,9 +535,10 @@ class Language {
         * 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 @@ class Language {
         *    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 @@ class Language {
         * @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 @@ class Language {
                                        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;