Add support for Higri (Islamic) calendar
authorMeno25 <mfarag@users.mediawiki.org>
Thu, 19 Jun 2008 14:46:50 +0000 (14:46 +0000)
committerMeno25 <mfarag@users.mediawiki.org>
Thu, 19 Jun 2008 14:46:50 +0000 (14:46 +0000)
Patch by AhmadSherif

RELEASE-NOTES
languages/Language.php
languages/messages/MessagesAr.php
languages/messages/MessagesEn.php
maintenance/language/messageTypes.inc
maintenance/language/messages.inc

index 97f8acb..c806769 100644 (file)
@@ -160,6 +160,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 2889) MediaWiki:Print.css applies to the printable version
 * (bug 14558) New system message (emailuserfooter) is now added to the footer of 
   e-mails sent with Special:Emailuser
+* Add support for Higri (Islamic) calendar
   
 === Bug fixes in 1.13 ===
 
index 873967e..8769041 100644 (file)
@@ -119,6 +119,13 @@ class Language {
                'hebrew-calendar-m10-gen', 'hebrew-calendar-m11-gen', 'hebrew-calendar-m12-gen',
                'hebrew-calendar-m6a-gen', 'hebrew-calendar-m6b-gen'
        );
+       
+       static public $mHijriCalendarMonthMsgs = array(
+               'hijri-calendar-m1', 'hijri-calendar-m2', 'hijri-calendar-m3',
+               'hijri-calendar-m4', 'hijri-calendar-m5', 'hijri-calendar-m6',
+               'hijri-calendar-m7', 'hijri-calendar-m8', 'hijri-calendar-m9',
+               'hijri-calendar-m10', 'hijri-calendar-m11', 'hijri-calendar-m12'
+       );
 
        /**
         * Create a language object for a given language code
@@ -435,8 +442,11 @@ class Language {
        function getHebrewCalendarMonthNameGen( $key ) {
                return $this->getMessageFromDB( self::$mHebrewCalendarMonthGenMsgs[$key-1] );
        }
-
-
+       
+       function getHijriCalendarMonthName( $key ) {
+               return $this->getMessageFromDB( self::$mHijriCalendarMonthMsgs[$key-1] );
+       }
+       
        /**
         * Used by date() and time() to adjust the time output.
         *
@@ -521,6 +531,11 @@ 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
+        *
         *    xkY  Y (full year) in Thai solar calendar. Months and days are
         *                       identical to the Gregorian calendar
         *
@@ -550,6 +565,7 @@ class Language {
                $rawToggle = false;
                $iranian = false;
                $hebrew = false;
+               $hijri = false;
                $thai = false;
                for ( $p = 0; $p < strlen( $format ); $p++ ) {
                        $num = false;
@@ -559,6 +575,7 @@ class Language {
                        }
 
                        if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' ) && $p < strlen( $format ) - 1 ) {
+                       if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' || $code == 'xm' ) && $p < strlen( $format ) - 1 ) {
                                $code .= $format[++$p];
                        }
 
@@ -599,6 +616,10 @@ class Language {
                                        if ( !$iranian ) $iranian = self::tsToIranian( $ts );
                                        $num = $iranian[2];
                                        break;
+                               case 'xmj':
+                                       if ( !$hijri ) $hijri = self::tsToHijri( $ts );
+                                       $num = $hijri[2];
+                                       break;
                                case 'xjj':
                                        if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts );
                                        $num = $hebrew[2];
@@ -631,6 +652,10 @@ class Language {
                                        if ( !$iranian ) $iranian = self::tsToIranian( $ts );
                                        $s .= $this->getIranianCalendarMonthName( $iranian[1] );
                                        break;
+                               case 'xmF':
+                                       if ( !$hijri ) $hijri = self::tsToHijri( $ts );
+                                       $s .= $this->getHijriCalendarMonthName( $hijri[1] );
+                                       break;
                                case 'xjF':
                                        if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts );
                                        $s .= $this->getHebrewCalendarMonthName( $hebrew[1] );
@@ -648,6 +673,10 @@ class Language {
                                        if ( !$iranian ) $iranian = self::tsToIranian( $ts );
                                        $num = $iranian[1];
                                        break;
+                               case 'xmn':
+                                       if ( !$hijri ) $hijri = self::tsToHijri ( $ts );
+                                       $num = $hijri[1];
+                                       break;
                                case 'xjn':
                                        if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts );
                                        $num = $hebrew[1];
@@ -671,6 +700,10 @@ class Language {
                                        if ( !$iranian ) $iranian = self::tsToIranian( $ts );
                                        $num = $iranian[0];
                                        break;
+                               case 'xmY':
+                                       if ( !$hijri ) $hijri = self::tsToHijri( $ts );
+                                       $num = $hijri[0];
+                                       break;
                                case 'xjY':
                                        if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts );
                                        $num = $hebrew[0];
@@ -823,6 +856,47 @@ class Language {
 
                return array($jy, $jm, $jd);
        }
+       /**
+        * Converting Gregorian dates to Hijri dates.
+        *
+        * Based on a PHP-Nuke block by Sharjeel which is released under GNU/GPL license
+        *
+        * @link http://phpnuke.org/modules.php?name=News&file=article&sid=8234&mode=thread&order=0&thold=0
+        */
+       private static function tsToHijri ( $ts ) {
+               $year = substr( $ts, 0, 4 );
+               $month = substr( $ts, 4, 2 );
+               $day = substr( $ts, 6, 2 );
+               
+               $zyr = $year;
+               $zd=$day;
+               $zm=$month;
+               $zy=$zyr;
+
+
+
+               if (($zy>1582)||(($zy==1582)&&($zm>10))||(($zy==1582)&&($zm==10)&&($zd>14)))
+                       {
+       
+       
+                                   $zjd=(int)((1461*($zy + 4800 + (int)( ($zm-14) /12) ))/4) + (int)((367*($zm-2-12*((int)(($zm-14)/12))))/12)-(int)((3*(int)(( ($zy+4900+(int)(($zm-14)/12))/100)))/4)+$zd-32075;
+                                   }
+                else
+                       {
+                                   $zjd = 367*$zy-(int)((7*($zy+5001+(int)(($zm-9)/7)))/4)+(int)((275*$zm)/9)+$zd+1729777;
+                       }
+               
+               $zl=$zjd-1948440+10632;
+               $zn=(int)(($zl-1)/10631);
+               $zl=$zl-10631*$zn+354;
+               $zj=((int)((10985-$zl)/5316))*((int)((50*$zl)/17719))+((int)($zl/5670))*((int)((43*$zl)/15238));
+               $zl=$zl-((int)((30-$zj)/15))*((int)((17719*$zj)/50))-((int)($zj/16))*((int)((15238*$zj)/43))+29;
+               $zm=(int)((24*$zl)/709);
+               $zd=$zl-(int)((709*$zm)/24);
+               $zy=30*$zn+$zj-30;
+
+               return array ($zy, $zm, $zd);
+       }
 
        /**
         * Converting Gregorian dates to Hebrew dates.
index 4a053cc..66b51db 100644 (file)
@@ -47,6 +47,7 @@ $datePreferences = array(
        'mdy',
        'dmy',
        'ymd',
+       'hijri',
        'ISO 8601',
 );
 
@@ -89,6 +90,10 @@ $dateFormats = array(
        'ymd time' => 'H:i',
        'ymd date' => 'Y xg j',
        'ymd both' => 'H:i، Y xg j', # Arabic comma
+       
+       'hijri time' => 'H:i',
+       'hijri date' => 'xmj xmF xmY',
+       'hijri both' => 'H:i، xmj xmF xmY',
 
        'ISO 8601 time' => 'xnH:xni:xns',
        'ISO 8601 date' => 'xnY-xnm-xnd',
@@ -2871,6 +2876,20 @@ $1',
 'iranian-calendar-m11' => 'بهمن',
 'iranian-calendar-m12' => 'اسفند',
 
+#Higri month names
+'hijri-calendar-m1' => 'محرم',
+'hijri-calendar-m2' => 'صفر',
+'hijri-calendar-m3' => 'ربيع الأول',  
+'hijri-calendar-m4' => 'ربيع الثاني',
+'hijri-calendar-m5' => 'جمادى الأولى',
+'hijri-calendar-m6' => 'جمادى الثانية',
+'hijri-calendar-m7' => 'رجب',
+'hijri-calendar-m8' => 'شعبان',
+'hijri-calendar-m9' => 'رمضان',
+'hijri-calendar-m10' => 'شوال',
+'hijri-calendar-m11' => 'ذو القعدة',
+'hijri-calendar-m12' => 'ذو الحجة',
+
 # Hebrew month names
 'hebrew-calendar-m1'      => 'تيشري',
 'hebrew-calendar-m2'      => 'تيشفان',
index 2108bdb..c514aaf 100644 (file)
@@ -3333,6 +3333,20 @@ You can also [[Special:Watchlist/edit|use the standard editor]].',
 'iranian-calendar-m11' => 'Bahman', # only translate this message to other languages if you have to change it
 'iranian-calendar-m12' => 'Esfand', # only translate this message to other languages if you have to change it
 
+#Higri month names
++'hijri-calendar-m1' => 'Muharram', # only translate this message to other languages if you have to change it
++'hijri-calendar-m2' => 'Safar', # only translate this message to other languages if you have to change it
++'hijri-calendar-m3' => 'Rabi\' al-awwal', # only translate this message to other languages if you have to change it
++'hijri-calendar-m4' => 'Rabi\' al-thani', # only translate this message to other languages if you have to change it
++'hijri-calendar-m5' => 'Jumada al-awwal', # only translate this message to other languages if you have to change it
++'hijri-calendar-m6' => 'Jumada al-thani', # only translate this message to other languages if you have to change it
++'hijri-calendar-m7' => 'Rajab', # only translate this message to other languages if you have to change it
++'hijri-calendar-m8' => 'Sha\'aban', # only translate this message to other languages if you have to change it
++'hijri-calendar-m9' => 'Ramadan', # only translate this message to other languages if you have to change it
++'hijri-calendar-m10' => 'Shawwal', # only translate this message to other languages if you have to change it
++'hijri-calendar-m11' => 'Dhu al-Qi\'dah', # only translate this message to other languages if you have to change it
++'hijri-calendar-m12' => 'Dhu al-Hijjah', # only translate this message to other languages if you have to change it
+
 # Hebrew month names
 'hebrew-calendar-m1'      => 'Tishrei', # only translate this message to other languages if you have to change it
 'hebrew-calendar-m2'      => 'Cheshvan', # only translate this message to other languages if you have to change it
index ea92a3f..1ad2274 100644 (file)
@@ -265,6 +265,18 @@ $wgOptionalMessages = array(
        'iranian-calendar-m10',
        'iranian-calendar-m11',
        'iranian-calendar-m12',
+       'higri-calendar-m1',
+       'higri-calendar-m2',
+       'higri-calendar-m3',
+       'higri-calendar-m4',
+       'higri-calendar-m5',
+       'higri-calendar-m6',
+       'higri-calendar-m7',
+       'higri-calendar-m8',
+       'higri-calendar-m9',
+       'higri-calendar-m10',
+       'higri-calendar-m11',
+       'higri-calendar-m12',
        'hebrew-calendar-m1',
        'hebrew-calendar-m2',
        'hebrew-calendar-m3',
index d22e77c..e973c58 100644 (file)
@@ -2503,6 +2503,20 @@ $wgMessageStructure = array(
                'iranian-calendar-m11',
                'iranian-calendar-m12',
        ),
+       'higri-dates' => array(
+               'higri-calendar-m1',
+               'higri-calendar-m2',
+               'higri-calendar-m3',
+               'higri-calendar-m4',
+               'higri-calendar-m5',
+               'higri-calendar-m6',
+               'higri-calendar-m7',
+               'higri-calendar-m8',
+               'higri-calendar-m9',
+               'higri-calendar-m10',
+               'higri-calendar-m11',
+               'higri-calendar-m12',
+       ),
        'hebrew-dates' => array(
                'hebrew-calendar-m1',
                'hebrew-calendar-m2',