r28221 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28220‎ | r28221 | r28222 >
Date:20:14, 6 December 2007
Author:raymond
Status:old
Tags:
Comment:
* (bug 11657) Support for Thai solar calendar
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesTh.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/messages/MessagesTh.php
@@ -29,6 +29,54 @@
3030 NS_CATEGORY_TALK => 'คุยเรื่องหมวดหมู่',
3131 );
3232
 33+/**
 34+ * A list of date format preference keys which can be selected in user
 35+ * preferences. New preference keys can be added, provided they are supported
 36+ * by the language class's timeanddate(). Only the 5 keys listed below are
 37+ * supported by the wikitext converter (DateFormatter.php).
 38+ *
 39+ * The special key "default" is an alias for either dmy or mdy depending on
 40+ * $wgAmericanDates
 41+ */
 42+$datePreferences = array(
 43+ 'default',
 44+ 'thai',
 45+ 'mdy',
 46+ 'dmy',
 47+ 'ymd',
 48+ 'ISO 8601',
 49+);
 50+
 51+/**
 52+ * These are formats for dates generated by MediaWiki (as opposed to the wikitext
 53+ * DateFormatter). Documentation for the format string can be found in
 54+ * Language.php, search for sprintfDate.
 55+ *
 56+ * This array is automatically inherited by all subclasses. Individual keys can be
 57+ * overridden.
 58+ */
 59+$dateFormats = array(
 60+ 'thai time' => 'H:i',
 61+ 'thai date' => 'j F xkY',
 62+ 'thai both' => 'H:i, j F xkY',
 63+
 64+ 'mdy time' => 'H:i',
 65+ 'mdy date' => 'F j, Y',
 66+ 'mdy both' => 'H:i, F j, Y',
 67+
 68+ 'dmy time' => 'H:i',
 69+ 'dmy date' => 'j F Y',
 70+ 'dmy both' => 'H:i, j F Y',
 71+
 72+ 'ymd time' => 'H:i',
 73+ 'ymd date' => 'Y F j',
 74+ 'ymd both' => 'H:i, Y F j',
 75+
 76+ 'ISO 8601 time' => 'xnH:xni:xns',
 77+ 'ISO 8601 date' => 'xnY-xnm-xnd',
 78+ 'ISO 8601 both' => 'xnY-xnm-xnd"T"xnH:xni:xns',
 79+);
 80+
3381 $linkTrail = '/^([a-z]+)(.*)\$/sD';
3482
3583 $messages = array(
Index: trunk/phase3/languages/Language.php
@@ -513,6 +513,9 @@
514514 * xjn n (month number) in Hebrew calendar
515515 * xjY Y (full year) in Hebrew calendar
516516 *
 517+ * xkY Y (full year) in Thai solar calendar. Months and days are
 518+ * identical to the Gregorian calendar
 519+ *
517520 * Characters enclosed in double quotes will be considered literal (with
518521 * the quotes themselves removed). Unmatched quotes will be considered
519522 * literal quotes. Example:
@@ -539,6 +542,7 @@
540543 $rawToggle = false;
541544 $iranian = false;
542545 $hebrew = false;
 546+ $thai = false;
543547 for ( $p = 0; $p < strlen( $format ); $p++ ) {
544548 $num = false;
545549 $code = $format[$p];
@@ -546,7 +550,7 @@
547551 $code .= $format[++$p];
548552 }
549553
550 - if ( ( $code === 'xi' || $code == 'xj' ) && $p < strlen( $format ) - 1 ) {
 554+ if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' ) && $p < strlen( $format ) - 1 ) {
551555 $code .= $format[++$p];
552556 }
553557
@@ -659,6 +663,10 @@
660664 if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts );
661665 $num = $hebrew[0];
662666 break;
 667+ case 'xkY':
 668+ if ( !$thai ) $thai = self::tsToThai( $ts );
 669+ $num = $thai[0];
 670+ break;
663671 case 'y':
664672 $num = substr( $ts, 2, 2 );
665673 break;
@@ -914,6 +922,27 @@
915923 }
916924
917925 /**
 926+ * Algorithm to convert Gregorian dates to Thai solar dates.
 927+ *
 928+ * Link: http://en.wikipedia.org/wiki/Thai_solar_calendar
 929+ *
 930+ * @param string $ts 14-character timestamp
 931+ * @return array converted year, month, day
 932+ */
 933+ private static function tsToThai( $ts ) {
 934+ $gy = substr( $ts, 0, 4 );
 935+ $gm = substr( $ts, 4, 2 );
 936+ $gd = substr( $ts, 6, 2 );
 937+
 938+ # Add 543 years to the Gregorian calendar
 939+ # Months and days are identical
 940+ $gy_thai = $gy + 543;
 941+
 942+ return array( $gy_thai, $gm, $gd );
 943+ }
 944+
 945+
 946+ /**
918947 * Based on Carl Friedrich Gauss algorithm for finding Easter date.
919948 * Used for Hebrew date.
920949 */
Index: trunk/phase3/RELEASE-NOTES
@@ -91,6 +91,7 @@
9292 * (bug 8396) Ignore out-of-date serialised message caches
9393 * (bug 12195) Undeleting pages now requires 'undelete' permission
9494 * (bug 11810) Localize displayed semicolons
 95+* (bug 11657) Support for Thai solar calendar
9596
9697 === Bug fixes in 1.12 ===
9798

Status & tagging log