Index: trunk/phase3/languages/Language.php |
— | — | @@ -13,18 +13,18 @@ |
14 | 14 | |
15 | 15 | # Read language names |
16 | 16 | global $wgLanguageNames; |
17 | | -require_once( dirname(__FILE__) . '/Names.php' ) ; |
| 17 | +require_once( dirname( __FILE__ ) . '/Names.php' ); |
18 | 18 | |
19 | 19 | global $wgInputEncoding, $wgOutputEncoding; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * These are always UTF-8, they exist only for backwards compatibility |
23 | 23 | */ |
24 | | -$wgInputEncoding = "UTF-8"; |
25 | | -$wgOutputEncoding = "UTF-8"; |
| 24 | +$wgInputEncoding = 'UTF-8'; |
| 25 | +$wgOutputEncoding = 'UTF-8'; |
26 | 26 | |
27 | 27 | if( function_exists( 'mb_strtoupper' ) ) { |
28 | | - mb_internal_encoding('UTF-8'); |
| 28 | + mb_internal_encoding( 'UTF-8' ); |
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
— | — | @@ -34,19 +34,19 @@ |
35 | 35 | */ |
36 | 36 | class FakeConverter { |
37 | 37 | var $mLang; |
38 | | - function FakeConverter($langobj) {$this->mLang = $langobj;} |
39 | | - function autoConvertToAllVariants($text) {return $text;} |
40 | | - function convert($t, $i) {return $t;} |
| 38 | + function FakeConverter( $langobj ) { $this->mLang = $langobj; } |
| 39 | + function autoConvertToAllVariants( $text ) { return $text; } |
| 40 | + function convert( $t, $i ) { return $t; } |
41 | 41 | function getVariants() { return array( $this->mLang->getCode() ); } |
42 | 42 | function getPreferredVariant() { return $this->mLang->getCode(); } |
43 | 43 | function getConvRuleTitle() { return false; } |
44 | | - function findVariantLink(&$l, &$n, $ignoreOtherCond = false) {} |
45 | | - function getExtraHashOptions() {return '';} |
46 | | - function getParsedTitle() {return '';} |
47 | | - function markNoConversion($text, $noParse=false) {return $text;} |
48 | | - function convertCategoryKey( $key ) {return $key; } |
49 | | - function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); } |
50 | | - function armourMath($text){ return $text; } |
| 44 | + function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) {} |
| 45 | + function getExtraHashOptions() { return ''; } |
| 46 | + function getParsedTitle() { return ''; } |
| 47 | + function markNoConversion( $text, $noParse = false ) { return $text; } |
| 48 | + function convertCategoryKey( $key ) { return $key; } |
| 49 | + function convertLinkToAllVariants( $text ) { return array( $this->mLang->getCode() => $text ); } |
| 50 | + function armourMath( $text ) { return $text; } |
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
— | — | @@ -149,10 +149,10 @@ |
150 | 150 | $class = 'Language' . str_replace( '-', '_', ucfirst( $code ) ); |
151 | 151 | // Preload base classes to work around APC/PHP5 bug |
152 | 152 | if ( file_exists( "$IP/languages/classes/$class.deps.php" ) ) { |
153 | | - include_once("$IP/languages/classes/$class.deps.php"); |
| 153 | + include_once( "$IP/languages/classes/$class.deps.php" ); |
154 | 154 | } |
155 | 155 | if ( file_exists( "$IP/languages/classes/$class.php" ) ) { |
156 | | - include_once("$IP/languages/classes/$class.php"); |
| 156 | + include_once( "$IP/languages/classes/$class.php" ); |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
— | — | @@ -160,7 +160,7 @@ |
161 | 161 | throw new MWException( "Language fallback loop detected when creating class $class\n" ); |
162 | 162 | } |
163 | 163 | |
164 | | - if( ! class_exists( $class ) ) { |
| 164 | + if( !class_exists( $class ) ) { |
165 | 165 | $fallback = Language::getFallbackFor( $code ); |
166 | 166 | ++$recursionLevel; |
167 | 167 | $lang = Language::newFromCode( $fallback ); |
— | — | @@ -185,7 +185,7 @@ |
186 | 186 | } |
187 | 187 | |
188 | 188 | function __construct() { |
189 | | - $this->mConverter = new FakeConverter($this); |
| 189 | + $this->mConverter = new FakeConverter( $this ); |
190 | 190 | // Set the code to the name of the descendant |
191 | 191 | if ( get_class( $this ) == 'Language' ) { |
192 | 192 | $this->mCode = 'en'; |
— | — | @@ -273,8 +273,8 @@ |
274 | 274 | */ |
275 | 275 | function getFormattedNamespaces() { |
276 | 276 | $ns = $this->getNamespaces(); |
277 | | - foreach($ns as $k => $v) { |
278 | | - $ns[$k] = strtr($v, '_', ' '); |
| 277 | + foreach( $ns as $k => $v ) { |
| 278 | + $ns[$k] = strtr( $v, '_', ' ' ); |
279 | 279 | } |
280 | 280 | return $ns; |
281 | 281 | } |
— | — | @@ -303,7 +303,7 @@ |
304 | 304 | */ |
305 | 305 | function getFormattedNsText( $index ) { |
306 | 306 | $ns = $this->getNsText( $index ); |
307 | | - return strtr($ns, '_', ' '); |
| 307 | + return strtr( $ns, '_', ' ' ); |
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
— | — | @@ -315,7 +315,7 @@ |
316 | 316 | * @return mixed An integer if $text is a valid value otherwise false |
317 | 317 | */ |
318 | 318 | function getLocalNsIndex( $text ) { |
319 | | - $lctext = $this->lc($text); |
| 319 | + $lctext = $this->lc( $text ); |
320 | 320 | $ids = $this->getNamespaceIds(); |
321 | 321 | return isset( $ids[$lctext] ) ? $ids[$lctext] : false; |
322 | 322 | } |
— | — | @@ -348,14 +348,14 @@ |
349 | 349 | # class-specific fixup hasn't been done. |
350 | 350 | $this->mNamespaceIds = array(); |
351 | 351 | foreach ( $this->getNamespaces() as $index => $name ) { |
352 | | - $this->mNamespaceIds[$this->lc($name)] = $index; |
| 352 | + $this->mNamespaceIds[$this->lc( $name )] = $index; |
353 | 353 | } |
354 | 354 | foreach ( $this->getNamespaceAliases() as $name => $index ) { |
355 | | - $this->mNamespaceIds[$this->lc($name)] = $index; |
| 355 | + $this->mNamespaceIds[$this->lc( $name )] = $index; |
356 | 356 | } |
357 | 357 | if ( $wgNamespaceAliases ) { |
358 | 358 | foreach ( $wgNamespaceAliases as $name => $index ) { |
359 | | - $this->mNamespaceIds[$this->lc($name)] = $index; |
| 359 | + $this->mNamespaceIds[$this->lc( $name )] = $index; |
360 | 360 | } |
361 | 361 | } |
362 | 362 | } |
— | — | @@ -371,7 +371,7 @@ |
372 | 372 | * @return mixed An integer if $text is a valid value otherwise false |
373 | 373 | */ |
374 | 374 | function getNsIndex( $text ) { |
375 | | - $lctext = $this->lc($text); |
| 375 | + $lctext = $this->lc( $text ); |
376 | 376 | if ( ( $ns = MWNamespace::getCanonicalIndex( $lctext ) ) !== null ) { |
377 | 377 | return $ns; |
378 | 378 | } |
— | — | @@ -492,39 +492,39 @@ |
493 | 493 | } |
494 | 494 | |
495 | 495 | function getMonthName( $key ) { |
496 | | - return $this->getMessageFromDB( self::$mMonthMsgs[$key-1] ); |
| 496 | + return $this->getMessageFromDB( self::$mMonthMsgs[$key - 1] ); |
497 | 497 | } |
498 | 498 | |
499 | 499 | function getMonthNameGen( $key ) { |
500 | | - return $this->getMessageFromDB( self::$mMonthGenMsgs[$key-1] ); |
| 500 | + return $this->getMessageFromDB( self::$mMonthGenMsgs[$key - 1] ); |
501 | 501 | } |
502 | 502 | |
503 | 503 | function getMonthAbbreviation( $key ) { |
504 | | - return $this->getMessageFromDB( self::$mMonthAbbrevMsgs[$key-1] ); |
| 504 | + return $this->getMessageFromDB( self::$mMonthAbbrevMsgs[$key - 1] ); |
505 | 505 | } |
506 | 506 | |
507 | 507 | function getWeekdayName( $key ) { |
508 | | - return $this->getMessageFromDB( self::$mWeekdayMsgs[$key-1] ); |
| 508 | + return $this->getMessageFromDB( self::$mWeekdayMsgs[$key - 1] ); |
509 | 509 | } |
510 | 510 | |
511 | 511 | function getWeekdayAbbreviation( $key ) { |
512 | | - return $this->getMessageFromDB( self::$mWeekdayAbbrevMsgs[$key-1] ); |
| 512 | + return $this->getMessageFromDB( self::$mWeekdayAbbrevMsgs[$key - 1] ); |
513 | 513 | } |
514 | 514 | |
515 | 515 | function getIranianCalendarMonthName( $key ) { |
516 | | - return $this->getMessageFromDB( self::$mIranianCalendarMonthMsgs[$key-1] ); |
| 516 | + return $this->getMessageFromDB( self::$mIranianCalendarMonthMsgs[$key - 1] ); |
517 | 517 | } |
518 | 518 | |
519 | 519 | function getHebrewCalendarMonthName( $key ) { |
520 | | - return $this->getMessageFromDB( self::$mHebrewCalendarMonthMsgs[$key-1] ); |
| 520 | + return $this->getMessageFromDB( self::$mHebrewCalendarMonthMsgs[$key - 1] ); |
521 | 521 | } |
522 | 522 | |
523 | 523 | function getHebrewCalendarMonthNameGen( $key ) { |
524 | | - return $this->getMessageFromDB( self::$mHebrewCalendarMonthGenMsgs[$key-1] ); |
| 524 | + return $this->getMessageFromDB( self::$mHebrewCalendarMonthGenMsgs[$key - 1] ); |
525 | 525 | } |
526 | 526 | |
527 | 527 | function getHijriCalendarMonthName( $key ) { |
528 | | - return $this->getMessageFromDB( self::$mHijriCalendarMonthMsgs[$key-1] ); |
| 528 | + return $this->getMessageFromDB( self::$mHijriCalendarMonthMsgs[$key - 1] ); |
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
— | — | @@ -558,7 +558,9 @@ |
559 | 559 | $minDiff = 0; |
560 | 560 | if ( $data[0] == 'System' || $tz == '' ) { |
561 | 561 | # Global offset in minutes. |
562 | | - if( isset($wgLocalTZoffset) ) $minDiff = $wgLocalTZoffset; |
| 562 | + if( isset( $wgLocalTZoffset ) ) { |
| 563 | + $minDiff = $wgLocalTZoffset; |
| 564 | + } |
563 | 565 | } else if ( $data[0] == 'Offset' ) { |
564 | 566 | $minDiff = intval( $data[1] ); |
565 | 567 | } else { |
— | — | @@ -567,14 +569,18 @@ |
568 | 570 | $data[0] = intval( $data[0] ); |
569 | 571 | $data[1] = intval( $data[1] ); |
570 | 572 | $minDiff = abs( $data[0] ) * 60 + $data[1]; |
571 | | - if ( $data[0] < 0 ) $minDiff = -$minDiff; |
| 573 | + if ( $data[0] < 0 ) { |
| 574 | + $minDiff = -$minDiff; |
| 575 | + } |
572 | 576 | } else { |
573 | 577 | $minDiff = intval( $data[0] ) * 60; |
574 | 578 | } |
575 | 579 | } |
576 | 580 | |
577 | 581 | # No difference ? Return time unchanged |
578 | | - if ( 0 == $minDiff ) return $ts; |
| 582 | + if ( 0 == $minDiff ) { |
| 583 | + return $ts; |
| 584 | + } |
579 | 585 | |
580 | 586 | wfSuppressWarnings(); // E_STRICT system time bitching |
581 | 587 | # Generate an adjusted date; take advantage of the fact that mktime |
— | — | @@ -713,51 +719,73 @@ |
714 | 720 | $num = intval( substr( $ts, 6, 2 ) ); |
715 | 721 | break; |
716 | 722 | case 'xij': |
717 | | - if ( !$iranian ) $iranian = self::tsToIranian( $ts ); |
| 723 | + if ( !$iranian ) { |
| 724 | + $iranian = self::tsToIranian( $ts ); |
| 725 | + } |
718 | 726 | $num = $iranian[2]; |
719 | 727 | break; |
720 | 728 | case 'xmj': |
721 | | - if ( !$hijri ) $hijri = self::tsToHijri( $ts ); |
| 729 | + if ( !$hijri ) { |
| 730 | + $hijri = self::tsToHijri( $ts ); |
| 731 | + } |
722 | 732 | $num = $hijri[2]; |
723 | 733 | break; |
724 | 734 | case 'xjj': |
725 | | - if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts ); |
| 735 | + if ( !$hebrew ) { |
| 736 | + $hebrew = self::tsToHebrew( $ts ); |
| 737 | + } |
726 | 738 | $num = $hebrew[2]; |
727 | 739 | break; |
728 | 740 | case 'l': |
729 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 741 | + if ( !$unix ) { |
| 742 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 743 | + } |
730 | 744 | $s .= $this->getWeekdayName( gmdate( 'w', $unix ) + 1 ); |
731 | 745 | break; |
732 | 746 | case 'N': |
733 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 747 | + if ( !$unix ) { |
| 748 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 749 | + } |
734 | 750 | $w = gmdate( 'w', $unix ); |
735 | 751 | $num = $w ? $w : 7; |
736 | 752 | break; |
737 | 753 | case 'w': |
738 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 754 | + if ( !$unix ) { |
| 755 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 756 | + } |
739 | 757 | $num = gmdate( 'w', $unix ); |
740 | 758 | break; |
741 | 759 | case 'z': |
742 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 760 | + if ( !$unix ) { |
| 761 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 762 | + } |
743 | 763 | $num = gmdate( 'z', $unix ); |
744 | 764 | break; |
745 | 765 | case 'W': |
746 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 766 | + if ( !$unix ) { |
| 767 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 768 | + } |
747 | 769 | $num = gmdate( 'W', $unix ); |
748 | 770 | break; |
749 | 771 | case 'F': |
750 | 772 | $s .= $this->getMonthName( substr( $ts, 4, 2 ) ); |
751 | 773 | break; |
752 | 774 | case 'xiF': |
753 | | - if ( !$iranian ) $iranian = self::tsToIranian( $ts ); |
| 775 | + if ( !$iranian ) { |
| 776 | + $iranian = self::tsToIranian( $ts ); |
| 777 | + } |
754 | 778 | $s .= $this->getIranianCalendarMonthName( $iranian[1] ); |
755 | 779 | break; |
756 | 780 | case 'xmF': |
757 | | - if ( !$hijri ) $hijri = self::tsToHijri( $ts ); |
| 781 | + if ( !$hijri ) { |
| 782 | + $hijri = self::tsToHijri( $ts ); |
| 783 | + } |
758 | 784 | $s .= $this->getHijriCalendarMonthName( $hijri[1] ); |
759 | 785 | break; |
760 | 786 | case 'xjF': |
761 | | - if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts ); |
| 787 | + if ( !$hebrew ) { |
| 788 | + $hebrew = self::tsToHebrew( $ts ); |
| 789 | + } |
762 | 790 | $s .= $this->getHebrewCalendarMonthName( $hebrew[1] ); |
763 | 791 | break; |
764 | 792 | case 'm': |
— | — | @@ -770,64 +798,91 @@ |
771 | 799 | $num = intval( substr( $ts, 4, 2 ) ); |
772 | 800 | break; |
773 | 801 | case 'xin': |
774 | | - if ( !$iranian ) $iranian = self::tsToIranian( $ts ); |
| 802 | + if ( !$iranian ) { |
| 803 | + $iranian = self::tsToIranian( $ts ); |
| 804 | + } |
775 | 805 | $num = $iranian[1]; |
776 | 806 | break; |
777 | 807 | case 'xmn': |
778 | | - if ( !$hijri ) $hijri = self::tsToHijri ( $ts ); |
| 808 | + if ( !$hijri ) { |
| 809 | + $hijri = self::tsToHijri ( $ts ); |
| 810 | + } |
779 | 811 | $num = $hijri[1]; |
780 | 812 | break; |
781 | 813 | case 'xjn': |
782 | | - if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts ); |
| 814 | + if ( !$hebrew ) { |
| 815 | + $hebrew = self::tsToHebrew( $ts ); |
| 816 | + } |
783 | 817 | $num = $hebrew[1]; |
784 | 818 | break; |
785 | 819 | case 't': |
786 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 820 | + if ( !$unix ) { |
| 821 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 822 | + } |
787 | 823 | $num = gmdate( 't', $unix ); |
788 | 824 | break; |
789 | 825 | case 'xjt': |
790 | | - if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts ); |
| 826 | + if ( !$hebrew ) { |
| 827 | + $hebrew = self::tsToHebrew( $ts ); |
| 828 | + } |
791 | 829 | $num = $hebrew[3]; |
792 | 830 | break; |
793 | 831 | case 'L': |
794 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 832 | + if ( !$unix ) { |
| 833 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 834 | + } |
795 | 835 | $num = gmdate( 'L', $unix ); |
796 | 836 | break; |
797 | 837 | # 'o' is supported since PHP 5.1.0 |
798 | 838 | # return literal if not supported |
799 | 839 | # TODO: emulation for pre 5.1.0 versions |
800 | 840 | case 'o': |
801 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
802 | | - if ( version_compare(PHP_VERSION, '5.1.0') === 1 ) |
| 841 | + if ( !$unix ) { |
| 842 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 843 | + } |
| 844 | + if ( version_compare( PHP_VERSION, '5.1.0' ) === 1 ) { |
803 | 845 | $num = date( 'o', $unix ); |
804 | | - else |
| 846 | + } else { |
805 | 847 | $s .= 'o'; |
| 848 | + } |
806 | 849 | break; |
807 | 850 | case 'Y': |
808 | 851 | $num = substr( $ts, 0, 4 ); |
809 | 852 | break; |
810 | 853 | case 'xiY': |
811 | | - if ( !$iranian ) $iranian = self::tsToIranian( $ts ); |
| 854 | + if ( !$iranian ) { |
| 855 | + $iranian = self::tsToIranian( $ts ); |
| 856 | + } |
812 | 857 | $num = $iranian[0]; |
813 | 858 | break; |
814 | 859 | case 'xmY': |
815 | | - if ( !$hijri ) $hijri = self::tsToHijri( $ts ); |
| 860 | + if ( !$hijri ) { |
| 861 | + $hijri = self::tsToHijri( $ts ); |
| 862 | + } |
816 | 863 | $num = $hijri[0]; |
817 | 864 | break; |
818 | 865 | case 'xjY': |
819 | | - if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts ); |
| 866 | + if ( !$hebrew ) { |
| 867 | + $hebrew = self::tsToHebrew( $ts ); |
| 868 | + } |
820 | 869 | $num = $hebrew[0]; |
821 | 870 | break; |
822 | 871 | case 'xkY': |
823 | | - if ( !$thai ) $thai = self::tsToYear( $ts, 'thai' ); |
| 872 | + if ( !$thai ) { |
| 873 | + $thai = self::tsToYear( $ts, 'thai' ); |
| 874 | + } |
824 | 875 | $num = $thai[0]; |
825 | 876 | break; |
826 | 877 | case 'xoY': |
827 | | - if ( !$minguo ) $minguo = self::tsToYear( $ts, 'minguo' ); |
| 878 | + if ( !$minguo ) { |
| 879 | + $minguo = self::tsToYear( $ts, 'minguo' ); |
| 880 | + } |
828 | 881 | $num = $minguo[0]; |
829 | 882 | break; |
830 | 883 | case 'xtY': |
831 | | - if ( !$tenno ) $tenno = self::tsToYear( $ts, 'tenno' ); |
| 884 | + if ( !$tenno ) { |
| 885 | + $tenno = self::tsToYear( $ts, 'tenno' ); |
| 886 | + } |
832 | 887 | $num = $tenno[0]; |
833 | 888 | break; |
834 | 889 | case 'y': |
— | — | @@ -860,15 +915,21 @@ |
861 | 916 | $num = substr( $ts, 12, 2 ); |
862 | 917 | break; |
863 | 918 | case 'c': |
864 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 919 | + if ( !$unix ) { |
| 920 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 921 | + } |
865 | 922 | $s .= gmdate( 'c', $unix ); |
866 | 923 | break; |
867 | 924 | case 'r': |
868 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 925 | + if ( !$unix ) { |
| 926 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 927 | + } |
869 | 928 | $s .= gmdate( 'r', $unix ); |
870 | 929 | break; |
871 | 930 | case 'U': |
872 | | - if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
| 931 | + if ( !$unix ) { |
| 932 | + $unix = wfTimestamp( TS_UNIX, $ts ); |
| 933 | + } |
873 | 934 | $num = $unix; |
874 | 935 | break; |
875 | 936 | case '\\': |
— | — | @@ -933,10 +994,10 @@ |
934 | 995 | $gd = substr( $ts, 6, 2 ) -1; |
935 | 996 | |
936 | 997 | # Days passed from the beginning (including leap years) |
937 | | - $gDayNo = 365*$gy |
938 | | - + floor(($gy+3) / 4) |
939 | | - - floor(($gy+99) / 100) |
940 | | - + floor(($gy+399) / 400); |
| 998 | + $gDayNo = 365 * $gy |
| 999 | + + floor( ( $gy + 3 ) / 4 ) |
| 1000 | + - floor( ( $gy + 99 ) / 100 ) |
| 1001 | + + floor( ( $gy + 399 ) / 400 ); |
941 | 1002 | |
942 | 1003 | |
943 | 1004 | // Add days of the past months of this year |
— | — | @@ -945,7 +1006,7 @@ |
946 | 1007 | } |
947 | 1008 | |
948 | 1009 | // Leap years |
949 | | - if ( $gm > 1 && (($gy%4===0 && $gy%100!==0 || ($gy%400==0)))) { |
| 1010 | + if ( $gm > 1 && ( ( $gy%4 === 0 && $gy%100 !== 0 || ( $gy%400 == 0 ) ) ) ) { |
950 | 1011 | $gDayNo++; |
951 | 1012 | } |
952 | 1013 | |
— | — | @@ -954,26 +1015,27 @@ |
955 | 1016 | |
956 | 1017 | $jDayNo = $gDayNo - 79; |
957 | 1018 | |
958 | | - $jNp = floor($jDayNo / 12053); |
| 1019 | + $jNp = floor( $jDayNo / 12053 ); |
959 | 1020 | $jDayNo %= 12053; |
960 | 1021 | |
961 | | - $jy = 979 + 33*$jNp + 4*floor($jDayNo/1461); |
| 1022 | + $jy = 979 + 33 * $jNp + 4 * floor( $jDayNo / 1461 ); |
962 | 1023 | $jDayNo %= 1461; |
963 | 1024 | |
964 | 1025 | if ( $jDayNo >= 366 ) { |
965 | | - $jy += floor(($jDayNo-1)/365); |
966 | | - $jDayNo = floor(($jDayNo-1)%365); |
| 1026 | + $jy += floor( ( $jDayNo - 1 ) / 365 ); |
| 1027 | + $jDayNo = floor( ( $jDayNo - 1 ) % 365 ); |
967 | 1028 | } |
968 | 1029 | |
969 | 1030 | for ( $i = 0; $i < 11 && $jDayNo >= self::$IRANIAN_DAYS[$i]; $i++ ) { |
970 | 1031 | $jDayNo -= self::$IRANIAN_DAYS[$i]; |
971 | 1032 | } |
972 | 1033 | |
973 | | - $jm= $i+1; |
974 | | - $jd= $jDayNo+1; |
| 1034 | + $jm = $i + 1; |
| 1035 | + $jd = $jDayNo + 1; |
975 | 1036 | |
976 | | - return array($jy, $jm, $jd); |
| 1037 | + return array( $jy, $jm, $jd ); |
977 | 1038 | } |
| 1039 | + |
978 | 1040 | /** |
979 | 1041 | * Converting Gregorian dates to Hijri dates. |
980 | 1042 | * |
— | — | @@ -981,39 +1043,40 @@ |
982 | 1044 | * |
983 | 1045 | * @link http://phpnuke.org/modules.php?name=News&file=article&sid=8234&mode=thread&order=0&thold=0 |
984 | 1046 | */ |
985 | | - private static function tsToHijri ( $ts ) { |
| 1047 | + private static function tsToHijri( $ts ) { |
986 | 1048 | $year = substr( $ts, 0, 4 ); |
987 | 1049 | $month = substr( $ts, 4, 2 ); |
988 | 1050 | $day = substr( $ts, 6, 2 ); |
989 | 1051 | |
990 | 1052 | $zyr = $year; |
991 | | - $zd=$day; |
992 | | - $zm=$month; |
993 | | - $zy=$zyr; |
| 1053 | + $zd = $day; |
| 1054 | + $zm = $month; |
| 1055 | + $zy = $zyr; |
994 | 1056 | |
| 1057 | + if ( |
| 1058 | + ( $zy > 1582 ) || ( ( $zy == 1582 ) && ( $zm > 10 ) ) || |
| 1059 | + ( ( $zy == 1582 ) && ( $zm == 10 ) && ( $zd > 14 ) ) |
| 1060 | + ) |
| 1061 | + { |
| 1062 | + $zjd = (int)( ( 1461 * ( $zy + 4800 + (int)( ( $zm - 14 ) / 12 ) ) ) / 4 ) + |
| 1063 | + (int)( ( 367 * ( $zm - 2 - 12 * ( (int)( ( $zm - 14 ) / 12 ) ) ) ) / 12 ) - |
| 1064 | + (int)( ( 3 * (int)( ( ( $zy + 4900 + (int)( ( $zm - 14 ) / 12 ) ) / 100 ) ) ) / 4 ) + |
| 1065 | + $zd - 32075; |
| 1066 | + } else { |
| 1067 | + $zjd = 367 * $zy - (int)( ( 7 * ( $zy + 5001 + (int)( ( $zm - 9 ) / 7 ) ) ) / 4 ) + |
| 1068 | + (int)( ( 275 * $zm ) / 9 ) + $zd + 1729777; |
| 1069 | + } |
995 | 1070 | |
| 1071 | + $zl = $zjd-1948440 + 10632; |
| 1072 | + $zn = (int)( ( $zl - 1 ) / 10631 ); |
| 1073 | + $zl = $zl - 10631 * $zn + 354; |
| 1074 | + $zj = ( (int)( ( 10985 - $zl ) / 5316 ) ) * ((int)( ( 50 * $zl ) / 17719 ) ) + ( (int)( $zl / 5670 ) ) * ( (int)( ( 43 * $zl ) / 15238 ) ); |
| 1075 | + $zl = $zl - ( (int)( ( 30 - $zj ) / 15 ) ) * ((int)( ( 17719 * $zj ) / 50 ) ) - ( (int)( $zj / 16 ) ) * ( (int)( ( 15238 * $zj ) / 43 ) ) + 29; |
| 1076 | + $zm = (int)( ( 24 * $zl ) / 709 ); |
| 1077 | + $zd = $zl - (int)( ( 709 * $zm ) / 24 ); |
| 1078 | + $zy = 30 * $zn + $zj - 30; |
996 | 1079 | |
997 | | - if (($zy>1582)||(($zy==1582)&&($zm>10))||(($zy==1582)&&($zm==10)&&($zd>14))) |
998 | | - { |
999 | | - |
1000 | | - |
1001 | | - $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; |
1002 | | - } |
1003 | | - else |
1004 | | - { |
1005 | | - $zjd = 367*$zy-(int)((7*($zy+5001+(int)(($zm-9)/7)))/4)+(int)((275*$zm)/9)+$zd+1729777; |
1006 | | - } |
1007 | | - |
1008 | | - $zl=$zjd-1948440+10632; |
1009 | | - $zn=(int)(($zl-1)/10631); |
1010 | | - $zl=$zl-10631*$zn+354; |
1011 | | - $zj=((int)((10985-$zl)/5316))*((int)((50*$zl)/17719))+((int)($zl/5670))*((int)((43*$zl)/15238)); |
1012 | | - $zl=$zl-((int)((30-$zj)/15))*((int)((17719*$zj)/50))-((int)($zj/16))*((int)((15238*$zj)/43))+29; |
1013 | | - $zm=(int)((24*$zl)/709); |
1014 | | - $zd=$zl-(int)((709*$zm)/24); |
1015 | | - $zy=30*$zn+$zj-30; |
1016 | | - |
1017 | | - return array ($zy, $zm, $zd); |
| 1080 | + return array( $zy, $zm, $zd ); |
1018 | 1081 | } |
1019 | 1082 | |
1020 | 1083 | /** |
— | — | @@ -1207,49 +1270,65 @@ |
1208 | 1271 | $gm = substr( $ts, 4, 2 ); |
1209 | 1272 | $gd = substr( $ts, 6, 2 ); |
1210 | 1273 | |
1211 | | - if (!strcmp($cName,'thai')) { |
| 1274 | + if ( !strcmp( $cName, 'thai' ) ) { |
1212 | 1275 | # Thai solar dates |
1213 | 1276 | # Add 543 years to the Gregorian calendar |
1214 | 1277 | # Months and days are identical |
1215 | 1278 | $gy_offset = $gy + 543; |
1216 | | - } else if ((!strcmp($cName,'minguo')) || !strcmp($cName,'juche')) { |
| 1279 | + } else if ( ( !strcmp( $cName, 'minguo' ) ) || !strcmp( $cName, 'juche' ) ) { |
1217 | 1280 | # Minguo dates |
1218 | 1281 | # Deduct 1911 years from the Gregorian calendar |
1219 | 1282 | # Months and days are identical |
1220 | 1283 | $gy_offset = $gy - 1911; |
1221 | | - } else if (!strcmp($cName,'tenno')) { |
| 1284 | + } else if ( !strcmp( $cName, 'tenno' ) ) { |
1222 | 1285 | # Nengō dates up to Meiji period |
1223 | 1286 | # Deduct years from the Gregorian calendar |
1224 | 1287 | # depending on the nengo periods |
1225 | 1288 | # Months and days are identical |
1226 | | - if (($gy < 1912) || (($gy == 1912) && ($gm < 7)) || (($gy == 1912) && ($gm == 7) && ($gd < 31))) { |
| 1289 | + if ( ( $gy < 1912 ) || ( ( $gy == 1912 ) && ( $gm < 7 ) ) || ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd < 31 ) ) ) { |
1227 | 1290 | # Meiji period |
1228 | 1291 | $gy_gannen = $gy - 1868 + 1; |
1229 | 1292 | $gy_offset = $gy_gannen; |
1230 | | - if ($gy_gannen == 1) |
| 1293 | + if ( $gy_gannen == 1 ) { |
1231 | 1294 | $gy_offset = '元'; |
1232 | | - $gy_offset = '明治'.$gy_offset; |
1233 | | - } else if ((($gy == 1912) && ($gm == 7) && ($gd == 31)) || (($gy == 1912) && ($gm >= 8)) || (($gy > 1912) && ($gy < 1926)) || (($gy == 1926) && ($gm < 12)) || (($gy == 1926) && ($gm == 12) && ($gd < 26))) { |
| 1295 | + } |
| 1296 | + $gy_offset = '明治' . $gy_offset; |
| 1297 | + } else if ( |
| 1298 | + ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd == 31 ) ) || |
| 1299 | + ( ( $gy == 1912 ) && ( $gm >= 8 ) ) || |
| 1300 | + ( ( $gy > 1912 ) && ( $gy < 1926 ) ) || |
| 1301 | + ( ( $gy == 1926 ) && ( $gm < 12 ) ) || |
| 1302 | + ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd < 26 ) ) |
| 1303 | + ) |
| 1304 | + { |
1234 | 1305 | # Taishō period |
1235 | 1306 | $gy_gannen = $gy - 1912 + 1; |
1236 | 1307 | $gy_offset = $gy_gannen; |
1237 | | - if ($gy_gannen == 1) |
| 1308 | + if ( $gy_gannen == 1 ) { |
1238 | 1309 | $gy_offset = '元'; |
1239 | | - $gy_offset = '大正'.$gy_offset; |
1240 | | - } else if ((($gy == 1926) && ($gm == 12) && ($gd >= 26)) || (($gy > 1926) && ($gy < 1989)) || (($gy == 1989) && ($gm == 1) && ($gd < 8))) { |
| 1310 | + } |
| 1311 | + $gy_offset = '大正' . $gy_offset; |
| 1312 | + } else if ( |
| 1313 | + ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd >= 26 ) ) || |
| 1314 | + ( ( $gy > 1926 ) && ( $gy < 1989 ) ) || |
| 1315 | + ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd < 8 ) ) |
| 1316 | + ) |
| 1317 | + { |
1241 | 1318 | # Shōwa period |
1242 | 1319 | $gy_gannen = $gy - 1926 + 1; |
1243 | 1320 | $gy_offset = $gy_gannen; |
1244 | | - if ($gy_gannen == 1) |
| 1321 | + if ( $gy_gannen == 1 ) { |
1245 | 1322 | $gy_offset = '元'; |
1246 | | - $gy_offset = '昭和'.$gy_offset; |
| 1323 | + } |
| 1324 | + $gy_offset = '昭和' . $gy_offset; |
1247 | 1325 | } else { |
1248 | 1326 | # Heisei period |
1249 | 1327 | $gy_gannen = $gy - 1989 + 1; |
1250 | 1328 | $gy_offset = $gy_gannen; |
1251 | | - if ($gy_gannen == 1) |
| 1329 | + if ( $gy_gannen == 1 ) { |
1252 | 1330 | $gy_offset = '元'; |
1253 | | - $gy_offset = '平成'.$gy_offset; |
| 1331 | + } |
| 1332 | + $gy_offset = '平成' . $gy_offset; |
1254 | 1333 | } |
1255 | 1334 | } else { |
1256 | 1335 | $gy_offset = $gy; |
— | — | @@ -1277,7 +1356,7 @@ |
1278 | 1357 | $s = ''; |
1279 | 1358 | for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) { |
1280 | 1359 | if ( $num >= $pow10 ) { |
1281 | | - $s .= $table[$i][floor($num / $pow10)]; |
| 1360 | + $s .= $table[$i][floor( $num / $pow10 )]; |
1282 | 1361 | } |
1283 | 1362 | $num = $num % $pow10; |
1284 | 1363 | } |
— | — | @@ -1482,29 +1561,29 @@ |
1483 | 1562 | } |
1484 | 1563 | |
1485 | 1564 | // callback functions for uc(), lc(), ucwords(), ucwordbreaks() |
1486 | | - function ucwordbreaksCallbackAscii($matches){ |
1487 | | - return $this->ucfirst($matches[1]); |
| 1565 | + function ucwordbreaksCallbackAscii( $matches ) { |
| 1566 | + return $this->ucfirst( $matches[1] ); |
1488 | 1567 | } |
1489 | 1568 | |
1490 | | - function ucwordbreaksCallbackMB($matches){ |
1491 | | - return mb_strtoupper($matches[0]); |
| 1569 | + function ucwordbreaksCallbackMB( $matches ) { |
| 1570 | + return mb_strtoupper( $matches[0] ); |
1492 | 1571 | } |
1493 | 1572 | |
1494 | | - function ucCallback($matches){ |
| 1573 | + function ucCallback( $matches ) { |
1495 | 1574 | list( $wikiUpperChars ) = self::getCaseMaps(); |
1496 | 1575 | return strtr( $matches[1], $wikiUpperChars ); |
1497 | 1576 | } |
1498 | 1577 | |
1499 | | - function lcCallback($matches){ |
| 1578 | + function lcCallback( $matches ) { |
1500 | 1579 | list( , $wikiLowerChars ) = self::getCaseMaps(); |
1501 | 1580 | return strtr( $matches[1], $wikiLowerChars ); |
1502 | 1581 | } |
1503 | 1582 | |
1504 | | - function ucwordsCallbackMB($matches){ |
1505 | | - return mb_strtoupper($matches[0]); |
| 1583 | + function ucwordsCallbackMB( $matches ) { |
| 1584 | + return mb_strtoupper( $matches[0] ); |
1506 | 1585 | } |
1507 | 1586 | |
1508 | | - function ucwordsCallbackWiki($matches){ |
| 1587 | + function ucwordsCallbackWiki( $matches ) { |
1509 | 1588 | list( $wikiUpperChars ) = self::getCaseMaps(); |
1510 | 1589 | return strtr( $matches[0], $wikiUpperChars ); |
1511 | 1590 | } |
— | — | @@ -1514,10 +1593,10 @@ |
1515 | 1594 | if ( $o < 96 ) { |
1516 | 1595 | return $str; |
1517 | 1596 | } elseif ( $o < 128 ) { |
1518 | | - return ucfirst($str); |
| 1597 | + return ucfirst( $str ); |
1519 | 1598 | } else { |
1520 | 1599 | // fall back to more complex logic in case of multibyte strings |
1521 | | - return self::uc($str,true); |
| 1600 | + return self::uc( $str, true ); |
1522 | 1601 | } |
1523 | 1602 | } |
1524 | 1603 | |
— | — | @@ -1538,7 +1617,7 @@ |
1539 | 1618 | $x = $first ? '^' : ''; |
1540 | 1619 | return preg_replace_callback( |
1541 | 1620 | "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/", |
1542 | | - array($this,"ucCallback"), |
| 1621 | + array( $this, 'ucCallback' ), |
1543 | 1622 | $str |
1544 | 1623 | ); |
1545 | 1624 | } else { |
— | — | @@ -1562,85 +1641,92 @@ |
1563 | 1642 | } |
1564 | 1643 | |
1565 | 1644 | function lc( $str, $first = false ) { |
1566 | | - if ( function_exists( 'mb_strtolower' ) ) |
1567 | | - if ( $first ) |
1568 | | - if ( self::isMultibyte( $str ) ) |
| 1645 | + if ( function_exists( 'mb_strtolower' ) ) { |
| 1646 | + if ( $first ) { |
| 1647 | + if ( self::isMultibyte( $str ) ) { |
1569 | 1648 | return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 ); |
1570 | | - else |
| 1649 | + } else { |
1571 | 1650 | return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 ); |
1572 | | - else |
| 1651 | + } |
| 1652 | + } else { |
1573 | 1653 | return self::isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str ); |
1574 | | - else |
| 1654 | + } |
| 1655 | + } else { |
1575 | 1656 | if ( self::isMultibyte( $str ) ) { |
1576 | 1657 | list( , $wikiLowerChars ) = self::getCaseMaps(); |
1577 | 1658 | $x = $first ? '^' : ''; |
1578 | 1659 | return preg_replace_callback( |
1579 | 1660 | "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/", |
1580 | | - array($this,"lcCallback"), |
| 1661 | + array( $this, 'lcCallback' ), |
1581 | 1662 | $str |
1582 | 1663 | ); |
1583 | | - } else |
| 1664 | + } else { |
1584 | 1665 | return $first ? strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 ) : strtolower( $str ); |
| 1666 | + } |
| 1667 | + } |
1585 | 1668 | } |
1586 | 1669 | |
1587 | 1670 | function isMultibyte( $str ) { |
1588 | 1671 | return (bool)preg_match( '/[\x80-\xff]/', $str ); |
1589 | 1672 | } |
1590 | 1673 | |
1591 | | - function ucwords($str) { |
| 1674 | + function ucwords( $str ) { |
1592 | 1675 | if ( self::isMultibyte( $str ) ) { |
1593 | | - $str = self::lc($str); |
| 1676 | + $str = self::lc( $str ); |
1594 | 1677 | |
1595 | 1678 | // regexp to find first letter in each word (i.e. after each space) |
1596 | 1679 | $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/"; |
1597 | 1680 | |
1598 | 1681 | // function to use to capitalize a single char |
1599 | | - if ( function_exists( 'mb_strtoupper' ) ) |
| 1682 | + if ( function_exists( 'mb_strtoupper' ) ) { |
1600 | 1683 | return preg_replace_callback( |
1601 | 1684 | $replaceRegexp, |
1602 | | - array($this,"ucwordsCallbackMB"), |
| 1685 | + array( $this, 'ucwordsCallbackMB' ), |
1603 | 1686 | $str |
1604 | 1687 | ); |
1605 | | - else |
| 1688 | + } else { |
1606 | 1689 | return preg_replace_callback( |
1607 | 1690 | $replaceRegexp, |
1608 | | - array($this,"ucwordsCallbackWiki"), |
| 1691 | + array( $this, 'ucwordsCallbackWiki' ), |
1609 | 1692 | $str |
1610 | 1693 | ); |
| 1694 | + } |
| 1695 | + } else { |
| 1696 | + return ucwords( strtolower( $str ) ); |
1611 | 1697 | } |
1612 | | - else |
1613 | | - return ucwords( strtolower( $str ) ); |
1614 | 1698 | } |
1615 | 1699 | |
1616 | | - # capitalize words at word breaks |
1617 | | - function ucwordbreaks($str){ |
1618 | | - if (self::isMultibyte( $str ) ) { |
1619 | | - $str = self::lc($str); |
| 1700 | + # capitalize words at word breaks |
| 1701 | + function ucwordbreaks( $str ) { |
| 1702 | + if ( self::isMultibyte( $str ) ) { |
| 1703 | + $str = self::lc( $str ); |
1620 | 1704 | |
1621 | 1705 | // since \b doesn't work for UTF-8, we explicitely define word break chars |
1622 | | - $breaks= "[ \-\(\)\}\{\.,\?!]"; |
| 1706 | + $breaks = "[ \-\(\)\}\{\.,\?!]"; |
1623 | 1707 | |
1624 | 1708 | // find first letter after word break |
1625 | 1709 | $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/"; |
1626 | 1710 | |
1627 | | - if ( function_exists( 'mb_strtoupper' ) ) |
| 1711 | + if ( function_exists( 'mb_strtoupper' ) ) { |
1628 | 1712 | return preg_replace_callback( |
1629 | 1713 | $replaceRegexp, |
1630 | | - array($this,"ucwordbreaksCallbackMB"), |
| 1714 | + array( $this, 'ucwordbreaksCallbackMB' ), |
1631 | 1715 | $str |
1632 | 1716 | ); |
1633 | | - else |
| 1717 | + } else { |
1634 | 1718 | return preg_replace_callback( |
1635 | 1719 | $replaceRegexp, |
1636 | | - array($this,"ucwordsCallbackWiki"), |
| 1720 | + array( $this, 'ucwordsCallbackWiki' ), |
1637 | 1721 | $str |
1638 | 1722 | ); |
| 1723 | + } |
| 1724 | + } else { |
| 1725 | + return preg_replace_callback( |
| 1726 | + '/\b([\w\x80-\xff]+)\b/', |
| 1727 | + array( $this, 'ucwordbreaksCallbackAscii' ), |
| 1728 | + $str |
| 1729 | + ); |
1639 | 1730 | } |
1640 | | - else |
1641 | | - return preg_replace_callback( |
1642 | | - '/\b([\w\x80-\xff]+)\b/', |
1643 | | - array($this,"ucwordbreaksCallbackAscii"), |
1644 | | - $str ); |
1645 | 1731 | } |
1646 | 1732 | |
1647 | 1733 | /** |
— | — | @@ -1664,13 +1750,17 @@ |
1665 | 1751 | } |
1666 | 1752 | # Check for non-UTF-8 URLs |
1667 | 1753 | $ishigh = preg_match( '/[\x80-\xff]/', $s); |
1668 | | - if(!$ishigh) return $s; |
| 1754 | + if( !$ishigh ) { |
| 1755 | + return $s; |
| 1756 | + } |
1669 | 1757 | |
1670 | 1758 | $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' . |
1671 | 1759 | '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); |
1672 | | - if( $isutf8 ) return $s; |
| 1760 | + if( $isutf8 ) { |
| 1761 | + return $s; |
| 1762 | + } |
1673 | 1763 | |
1674 | | - return $this->iconv( $this->fallback8bitEncoding(), "utf-8", $s ); |
| 1764 | + return $this->iconv( $this->fallback8bitEncoding(), 'utf-8', $s ); |
1675 | 1765 | } |
1676 | 1766 | |
1677 | 1767 | function fallback8bitEncoding() { |
— | — | @@ -1686,11 +1776,11 @@ |
1687 | 1777 | function hasWordBreaks() { |
1688 | 1778 | return true; |
1689 | 1779 | } |
1690 | | - |
| 1780 | + |
1691 | 1781 | /** |
1692 | 1782 | * Some languages such as Chinese require word segmentation, |
1693 | 1783 | * Specify such segmentation when overridden in derived class. |
1694 | | - * |
| 1784 | + * |
1695 | 1785 | * @param $string String |
1696 | 1786 | * @return String |
1697 | 1787 | */ |
— | — | @@ -1748,8 +1838,12 @@ |
1749 | 1839 | */ |
1750 | 1840 | function firstChar( $s ) { |
1751 | 1841 | $matches = array(); |
1752 | | - preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' . |
1753 | | - '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/', $s, $matches); |
| 1842 | + preg_match( |
| 1843 | + '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' . |
| 1844 | + '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/', |
| 1845 | + $s, |
| 1846 | + $matches |
| 1847 | + ); |
1754 | 1848 | |
1755 | 1849 | if ( isset( $matches[1] ) ) { |
1756 | 1850 | if ( strlen( $matches[1] ) != 3 ) { |
— | — | @@ -1758,7 +1852,7 @@ |
1759 | 1853 | |
1760 | 1854 | // Break down Hangul syllables to grab the first jamo |
1761 | 1855 | $code = utf8ToCodepoint( $matches[1] ); |
1762 | | - if ( $code < 0xac00 || 0xd7a4 <= $code) { |
| 1856 | + if ( $code < 0xac00 || 0xd7a4 <= $code ) { |
1763 | 1857 | return $matches[1]; |
1764 | 1858 | } elseif ( $code < 0xb098 ) { |
1765 | 1859 | return "\xe3\x84\xb1"; |
— | — | @@ -1790,7 +1884,7 @@ |
1791 | 1885 | return "\xe3\x85\x8e"; |
1792 | 1886 | } |
1793 | 1887 | } else { |
1794 | | - return ""; |
| 1888 | + return ''; |
1795 | 1889 | } |
1796 | 1890 | } |
1797 | 1891 | |
— | — | @@ -1809,8 +1903,7 @@ |
1810 | 1904 | # wgInputEncoding, this text will be further converted |
1811 | 1905 | # to wgOutputEncoding. |
1812 | 1906 | global $wgEditEncoding; |
1813 | | - if( $wgEditEncoding == '' or |
1814 | | - $wgEditEncoding == 'UTF-8' ) { |
| 1907 | + if( $wgEditEncoding == '' || $wgEditEncoding == 'UTF-8' ) { |
1815 | 1908 | return $s; |
1816 | 1909 | } else { |
1817 | 1910 | return $this->iconv( 'UTF-8', $wgEditEncoding, $s ); |
— | — | @@ -1820,7 +1913,7 @@ |
1821 | 1914 | function recodeInput( $s ) { |
1822 | 1915 | # Take the previous into account. |
1823 | 1916 | global $wgEditEncoding; |
1824 | | - if($wgEditEncoding != "") { |
| 1917 | + if( $wgEditEncoding != '' ) { |
1825 | 1918 | $enc = $wgEditEncoding; |
1826 | 1919 | } else { |
1827 | 1920 | $enc = 'UTF-8'; |
— | — | @@ -1855,7 +1948,7 @@ |
1856 | 1949 | if ( !isset( $this->transformData[$file] ) ) { |
1857 | 1950 | $data = wfGetPrecompiledData( $file ); |
1858 | 1951 | if ( $data === false ) { |
1859 | | - throw new MWException( __METHOD__.": The transformation file $file is missing" ); |
| 1952 | + throw new MWException( __METHOD__ . ": The transformation file $file is missing" ); |
1860 | 1953 | } |
1861 | 1954 | $this->transformData[$file] = new ReplacementArray( $data ); |
1862 | 1955 | } |
— | — | @@ -2039,15 +2132,19 @@ |
2040 | 2133 | */ |
2041 | 2134 | function formatNum( $number, $nocommafy = false ) { |
2042 | 2135 | global $wgTranslateNumerals; |
2043 | | - if (!$nocommafy) { |
2044 | | - $number = $this->commafy($number); |
| 2136 | + if ( !$nocommafy ) { |
| 2137 | + $number = $this->commafy( $number ); |
2045 | 2138 | $s = $this->separatorTransformTable(); |
2046 | | - if ($s) { $number = strtr($number, $s); } |
| 2139 | + if ( $s ) { |
| 2140 | + $number = strtr( $number, $s ); |
| 2141 | + } |
2047 | 2142 | } |
2048 | 2143 | |
2049 | | - if ($wgTranslateNumerals) { |
| 2144 | + if ( $wgTranslateNumerals ) { |
2050 | 2145 | $s = $this->digitTransformTable(); |
2051 | | - if ($s) { $number = strtr($number, $s); } |
| 2146 | + if ( $s ) { |
| 2147 | + $number = strtr( $number, $s ); |
| 2148 | + } |
2052 | 2149 | } |
2053 | 2150 | |
2054 | 2151 | return $number; |
— | — | @@ -2055,12 +2152,16 @@ |
2056 | 2153 | |
2057 | 2154 | function parseFormattedNumber( $number ) { |
2058 | 2155 | $s = $this->digitTransformTable(); |
2059 | | - if ($s) { $number = strtr($number, array_flip($s)); } |
| 2156 | + if ( $s ) { |
| 2157 | + $number = strtr( $number, array_flip( $s ) ); |
| 2158 | + } |
2060 | 2159 | |
2061 | 2160 | $s = $this->separatorTransformTable(); |
2062 | | - if ($s) { $number = strtr($number, array_flip($s)); } |
| 2161 | + if ( $s ) { |
| 2162 | + $number = strtr( $number, array_flip( $s ) ); |
| 2163 | + } |
2063 | 2164 | |
2064 | | - $number = strtr( $number, array (',' => '') ); |
| 2165 | + $number = strtr( $number, array( ',' => '' ) ); |
2065 | 2166 | return $number; |
2066 | 2167 | } |
2067 | 2168 | |
— | — | @@ -2071,7 +2172,7 @@ |
2072 | 2173 | * @return string |
2073 | 2174 | */ |
2074 | 2175 | function commafy($_) { |
2075 | | - return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_))); |
| 2176 | + return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); |
2076 | 2177 | } |
2077 | 2178 | |
2078 | 2179 | function digitTransformTable() { |
— | — | @@ -2082,7 +2183,6 @@ |
2083 | 2184 | return self::$dataCache->getItem( $this->mCode, 'separatorTransformTable' ); |
2084 | 2185 | } |
2085 | 2186 | |
2086 | | - |
2087 | 2187 | /** |
2088 | 2188 | * Take a list of strings and build a locale-friendly comma-separated |
2089 | 2189 | * list, using the local comma-separator message. |
— | — | @@ -2096,8 +2196,7 @@ |
2097 | 2197 | $m = count( $l ) - 1; |
2098 | 2198 | if( $m == 1 ) { |
2099 | 2199 | return $l[0] . $this->getMessageFromDB( 'and' ) . $this->getMessageFromDB( 'word-separator' ) . $l[1]; |
2100 | | - } |
2101 | | - else { |
| 2200 | + } else { |
2102 | 2201 | for ( $i = $m; $i >= 0; $i-- ) { |
2103 | 2202 | if ( $i == $m ) { |
2104 | 2203 | $s = $l[$i]; |
— | — | @@ -2120,7 +2219,11 @@ |
2121 | 2220 | function commaList( $list ) { |
2122 | 2221 | return implode( |
2123 | 2222 | $list, |
2124 | | - wfMsgExt( 'comma-separator', array( 'parsemag', 'escapenoentities', 'language' => $this ) ) ); |
| 2223 | + wfMsgExt( |
| 2224 | + 'comma-separator', |
| 2225 | + array( 'parsemag', 'escapenoentities', 'language' => $this ) |
| 2226 | + ) |
| 2227 | + ); |
2125 | 2228 | } |
2126 | 2229 | |
2127 | 2230 | /** |
— | — | @@ -2132,7 +2235,11 @@ |
2133 | 2236 | function semicolonList( $list ) { |
2134 | 2237 | return implode( |
2135 | 2238 | $list, |
2136 | | - wfMsgExt( 'semicolon-separator', array( 'parsemag', 'escapenoentities', 'language' => $this ) ) ); |
| 2239 | + wfMsgExt( |
| 2240 | + 'semicolon-separator', |
| 2241 | + array( 'parsemag', 'escapenoentities', 'language' => $this ) |
| 2242 | + ) |
| 2243 | + ); |
2137 | 2244 | } |
2138 | 2245 | |
2139 | 2246 | /** |
— | — | @@ -2143,7 +2250,11 @@ |
2144 | 2251 | function pipeList( $list ) { |
2145 | 2252 | return implode( |
2146 | 2253 | $list, |
2147 | | - wfMsgExt( 'pipe-separator', array( 'escapenoentities', 'language' => $this ) ) ); |
| 2254 | + wfMsgExt( |
| 2255 | + 'pipe-separator', |
| 2256 | + array( 'escapenoentities', 'language' => $this ) |
| 2257 | + ) |
| 2258 | + ); |
2148 | 2259 | } |
2149 | 2260 | |
2150 | 2261 | /** |
— | — | @@ -2251,7 +2362,7 @@ |
2252 | 2363 | # Check if there is no need to truncate |
2253 | 2364 | if ( $length <= 0 ) { |
2254 | 2365 | return $ellipsis; // no text shown, nothing to format |
2255 | | - } elseif ( strlen($text) <= $length ) { |
| 2366 | + } elseif ( strlen( $text ) <= $length ) { |
2256 | 2367 | return $text; // string short enough even *with* HTML |
2257 | 2368 | } |
2258 | 2369 | $text = MWTidy::tidy( $text ); // fix tags |
— | — | @@ -2265,7 +2376,7 @@ |
2266 | 2377 | $textLen = strlen($text); |
2267 | 2378 | for( $pos = 0; $pos < $textLen; ++$pos ) { |
2268 | 2379 | $ch = $text[$pos]; |
2269 | | - $lastCh = $pos ? $text[$pos-1] : ''; |
| 2380 | + $lastCh = $pos ? $text[$pos - 1] : ''; |
2270 | 2381 | $ret .= $ch; // add to result string |
2271 | 2382 | if ( $ch == '<' ) { |
2272 | 2383 | $this->truncate_endBracket( $tag, $tagType, $lastCh, $openTags ); // for bad HTML |
— | — | @@ -2318,7 +2429,7 @@ |
2319 | 2430 | # the ellipsis actually makes the string longer. |
2320 | 2431 | $pOpenTags = $openTags; // save state |
2321 | 2432 | $pRet = $ret; // save state |
2322 | | - } elseif ( $displayLen > ($length + strlen($ellipsis)) ) { |
| 2433 | + } elseif ( $displayLen > ( $length + strlen( $ellipsis ) ) ) { |
2323 | 2434 | # Ellipsis won't make string longer/equal, the truncation point was OK. |
2324 | 2435 | $openTags = $pOpenTags; // reload state |
2325 | 2436 | $ret = $this->removeBadCharLast( $pRet ); // reload state, multi-byte char fix |
— | — | @@ -2330,7 +2441,7 @@ |
2331 | 2442 | if ( $displayLen == 0 ) { |
2332 | 2443 | return ''; // no text shown, nothing to format |
2333 | 2444 | } |
2334 | | - $this->truncate_endBracket( $tag, $text[$textLen-1], $tagType, $openTags ); // for bad HTML |
| 2445 | + $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags ); // for bad HTML |
2335 | 2446 | while ( count( $openTags ) > 0 ) { |
2336 | 2447 | $ret .= '</' . array_pop( $openTags ) . '>'; // close open tags |
2337 | 2448 | } |
— | — | @@ -2341,7 +2452,7 @@ |
2342 | 2453 | // like strcspn() but adds the skipped chars to $ret |
2343 | 2454 | private function truncate_skip( &$ret, $text, $search, $start, $len = -1 ) { |
2344 | 2455 | $skipCount = 0; |
2345 | | - if( $start < strlen($text) ) { |
| 2456 | + if( $start < strlen( $text ) ) { |
2346 | 2457 | $skipCount = strcspn( $text, $search, $start, $len ); |
2347 | 2458 | $ret .= substr( $text, $start, $skipCount ); |
2348 | 2459 | } |
— | — | @@ -2357,7 +2468,7 @@ |
2358 | 2469 | if( $tagType == 0 && $lastCh != '/' ) { |
2359 | 2470 | $openTags[] = $tag; // tag opened (didn't close itself) |
2360 | 2471 | } else if( $tagType == 1 ) { |
2361 | | - if( $openTags && $tag == $openTags[count($openTags)-1] ) { |
| 2472 | + if( $openTags && $tag == $openTags[count( $openTags ) - 1] ) { |
2362 | 2473 | array_pop( $openTags ); // tag closed |
2363 | 2474 | } |
2364 | 2475 | } |
— | — | @@ -2375,7 +2486,7 @@ |
2376 | 2487 | */ |
2377 | 2488 | function convertGrammar( $word, $case ) { |
2378 | 2489 | global $wgGrammarForms; |
2379 | | - if ( isset($wgGrammarForms[$this->getCode()][$case][$word]) ) { |
| 2490 | + if ( isset( $wgGrammarForms[$this->getCode()][$case][$word] ) ) { |
2380 | 2491 | return $wgGrammarForms[$this->getCode()][$case][$word]; |
2381 | 2492 | } |
2382 | 2493 | return $word; |
— | — | @@ -2390,11 +2501,17 @@ |
2391 | 2502 | * These details may be overriden per language. |
2392 | 2503 | */ |
2393 | 2504 | function gender( $gender, $forms ) { |
2394 | | - if ( !count($forms) ) { return ''; } |
| 2505 | + if ( !count( $forms ) ) { |
| 2506 | + return ''; |
| 2507 | + } |
2395 | 2508 | $forms = $this->preConvertPlural( $forms, 2 ); |
2396 | | - if ( $gender === 'male' ) return $forms[0]; |
2397 | | - if ( $gender === 'female' ) return $forms[1]; |
2398 | | - return isset($forms[2]) ? $forms[2] : $forms[0]; |
| 2509 | + if ( $gender === 'male' ) { |
| 2510 | + return $forms[0]; |
| 2511 | + } |
| 2512 | + if ( $gender === 'female' ) { |
| 2513 | + return $forms[1]; |
| 2514 | + } |
| 2515 | + return isset( $forms[2] ) ? $forms[2] : $forms[0]; |
2399 | 2516 | } |
2400 | 2517 | |
2401 | 2518 | /** |
— | — | @@ -2413,7 +2530,9 @@ |
2414 | 2531 | * @return string Correct form of plural for $count in this language |
2415 | 2532 | */ |
2416 | 2533 | function convertPlural( $count, $forms ) { |
2417 | | - if ( !count($forms) ) { return ''; } |
| 2534 | + if ( !count( $forms ) ) { |
| 2535 | + return ''; |
| 2536 | + } |
2418 | 2537 | $forms = $this->preConvertPlural( $forms, 2 ); |
2419 | 2538 | |
2420 | 2539 | return ( $count == 1 ) ? $forms[0] : $forms[1]; |
— | — | @@ -2428,31 +2547,31 @@ |
2429 | 2548 | * @return array Padded array of forms or an exception if not an array |
2430 | 2549 | */ |
2431 | 2550 | protected function preConvertPlural( /* Array */ $forms, $count ) { |
2432 | | - while ( count($forms) < $count ) { |
2433 | | - $forms[] = $forms[count($forms)-1]; |
| 2551 | + while ( count( $forms ) < $count ) { |
| 2552 | + $forms[] = $forms[count( $forms ) - 1]; |
2434 | 2553 | } |
2435 | 2554 | return $forms; |
2436 | 2555 | } |
2437 | 2556 | |
2438 | 2557 | /** |
2439 | | - * For translaing of expiry times |
| 2558 | + * For translating of expiry times |
2440 | 2559 | * @param $str String: the validated block time in English |
2441 | 2560 | * @return Somehow translated block time |
2442 | 2561 | * @see LanguageFi.php for example implementation |
2443 | 2562 | */ |
2444 | 2563 | function translateBlockExpiry( $str ) { |
2445 | | - |
2446 | 2564 | $scBlockExpiryOptions = $this->getMessageFromDB( 'ipboptions' ); |
2447 | 2565 | |
2448 | | - if ( $scBlockExpiryOptions == '-') { |
| 2566 | + if ( $scBlockExpiryOptions == '-' ) { |
2449 | 2567 | return $str; |
2450 | 2568 | } |
2451 | 2569 | |
2452 | | - foreach (explode(',', $scBlockExpiryOptions) as $option) { |
2453 | | - if ( strpos($option, ":") === false ) |
| 2570 | + foreach ( explode( ',', $scBlockExpiryOptions) as $option ) { |
| 2571 | + if ( strpos( $option, ':' ) === false ) { |
2454 | 2572 | continue; |
2455 | | - list($show, $value) = explode(":", $option); |
2456 | | - if ( strcmp ( $str, $value) == 0 ) { |
| 2573 | + } |
| 2574 | + list( $show, $value ) = explode( ':', $option ); |
| 2575 | + if ( strcmp( $str, $value ) == 0 ) { |
2457 | 2576 | return htmlspecialchars( trim( $show ) ); |
2458 | 2577 | } |
2459 | 2578 | } |
— | — | @@ -2482,26 +2601,25 @@ |
2483 | 2602 | } |
2484 | 2603 | |
2485 | 2604 | # convert text to all supported variants |
2486 | | - function autoConvertToAllVariants($text) { |
2487 | | - return $this->mConverter->autoConvertToAllVariants($text); |
| 2605 | + function autoConvertToAllVariants( $text ) { |
| 2606 | + return $this->mConverter->autoConvertToAllVariants( $text ); |
2488 | 2607 | } |
2489 | 2608 | |
2490 | 2609 | # convert text to different variants of a language. |
2491 | | - function convert( $text, $isTitle = false) { |
2492 | | - return $this->mConverter->convert($text, $isTitle); |
| 2610 | + function convert( $text, $isTitle = false ) { |
| 2611 | + return $this->mConverter->convert( $text, $isTitle ); |
2493 | 2612 | } |
2494 | 2613 | |
2495 | 2614 | # Check if this is a language with variants |
2496 | | - function hasVariants(){ |
2497 | | - return sizeof($this->getVariants())>1; |
| 2615 | + function hasVariants() { |
| 2616 | + return sizeof( $this->getVariants() ) > 1; |
2498 | 2617 | } |
2499 | 2618 | |
2500 | 2619 | # Put custom tags (e.g. -{ }-) around math to prevent conversion |
2501 | | - function armourMath($text){ |
2502 | | - return $this->mConverter->armourMath($text); |
| 2620 | + function armourMath( $text ) { |
| 2621 | + return $this->mConverter->armourMath( $text ); |
2503 | 2622 | } |
2504 | 2623 | |
2505 | | - |
2506 | 2624 | /** |
2507 | 2625 | * Perform output conversion on a string, and encode for safe HTML output. |
2508 | 2626 | * @param $text String text to be converted |
— | — | @@ -2518,7 +2636,7 @@ |
2519 | 2637 | } |
2520 | 2638 | |
2521 | 2639 | /** |
2522 | | - * get the list of variants supported by this langauge |
| 2640 | + * Get the list of variants supported by this langauge |
2523 | 2641 | * see sample implementation in LanguageZh.php |
2524 | 2642 | * |
2525 | 2643 | * @return array an array of language codes |
— | — | @@ -2527,13 +2645,12 @@ |
2528 | 2646 | return $this->mConverter->getVariants(); |
2529 | 2647 | } |
2530 | 2648 | |
2531 | | - |
2532 | 2649 | function getPreferredVariant( $fromUser = true, $fromHeader = false ) { |
2533 | 2650 | return $this->mConverter->getPreferredVariant( $fromUser, $fromHeader ); |
2534 | 2651 | } |
2535 | 2652 | |
2536 | 2653 | /** |
2537 | | - * if a language supports multiple variants, it is |
| 2654 | + * If a language supports multiple variants, it is |
2538 | 2655 | * possible that non-existing link in one variant |
2539 | 2656 | * actually exists in another variant. this function |
2540 | 2657 | * tries to find it. See e.g. LanguageZh.php |
— | — | @@ -2553,11 +2670,10 @@ |
2554 | 2671 | * into an array of all possible variants of the text: |
2555 | 2672 | * 'variant' => text in that variant |
2556 | 2673 | */ |
2557 | | - function convertLinkToAllVariants($text){ |
2558 | | - return $this->mConverter->convertLinkToAllVariants($text); |
| 2674 | + function convertLinkToAllVariants( $text ) { |
| 2675 | + return $this->mConverter->convertLinkToAllVariants( $text ); |
2559 | 2676 | } |
2560 | 2677 | |
2561 | | - |
2562 | 2678 | /** |
2563 | 2679 | * returns language specific options used by User::getPageRenderHash() |
2564 | 2680 | * for example, the preferred language variant |
— | — | @@ -2569,7 +2685,7 @@ |
2570 | 2686 | } |
2571 | 2687 | |
2572 | 2688 | /** |
2573 | | - * for languages that support multiple variants, the title of an |
| 2689 | + * For languages that support multiple variants, the title of an |
2574 | 2690 | * article may be displayed differently in different variants. this |
2575 | 2691 | * function returns the apporiate title defined in the body of the article. |
2576 | 2692 | * |
— | — | @@ -2587,7 +2703,7 @@ |
2588 | 2704 | * @param $noParse |
2589 | 2705 | * @return string the tagged text |
2590 | 2706 | */ |
2591 | | - function markNoConversion( $text, $noParse=false ) { |
| 2707 | + function markNoConversion( $text, $noParse = false ) { |
2592 | 2708 | return $this->mConverter->markNoConversion( $text, $noParse ); |
2593 | 2709 | } |
2594 | 2710 | |
— | — | @@ -2682,7 +2798,9 @@ |
2683 | 2799 | } |
2684 | 2800 | |
2685 | 2801 | function fixVariableInNamespace( $talk ) { |
2686 | | - if ( strpos( $talk, '$1' ) === false ) return $talk; |
| 2802 | + if ( strpos( $talk, '$1' ) === false ) { |
| 2803 | + return $talk; |
| 2804 | + } |
2687 | 2805 | |
2688 | 2806 | global $wgMetaNamespace; |
2689 | 2807 | $talk = str_replace( '$1', $wgMetaNamespace, $talk ); |