Index: branches/wmf/1.18wmf1/extensions/Narayam/js/ext.narayam.core.js |
— | — | @@ -53,13 +53,19 @@ |
54 | 54 | var rules = currentScheme.extended_keyboard && useExtended ? |
55 | 55 | currentScheme.rules_x : currentScheme.rules; |
56 | 56 | for ( var i = 0; i < rules.length; i++ ) { |
57 | | - var keyBufferMatch = true; |
58 | | - if ( rules[i][1].length > 0 && rules[i][1].length <= keyBuffer.length ) { |
59 | | - // Try to match rules[i][1] at the end of the key buffer |
60 | | - keyBufferMatch = new RegExp( rules[i][1] + '$' ).test( keyBuffer ); |
61 | | - } |
62 | 57 | var regex = new RegExp( rules[i][0] + '$' ); |
63 | | - if ( keyBufferMatch && regex.test( str ) ) { |
| 58 | + if ( regex.test( str ) // Input string match |
| 59 | + && |
| 60 | + ( |
| 61 | + rules[i][1].length == 0 // Keybuffer match not required |
| 62 | + || |
| 63 | + ( // Keybuffer match specified, so it should be met |
| 64 | + rules[i][1].length > 0 |
| 65 | + && rules[i][1].length <= keyBuffer.length |
| 66 | + && new RegExp( rules[i][1] + '$' ).test( keyBuffer ) |
| 67 | + ) |
| 68 | + ) |
| 69 | + ) { |
64 | 70 | return str.replace( regex, rules[i][2] ); |
65 | 71 | } |
66 | 72 | } |
Index: branches/wmf/1.18wmf1/extensions/Narayam/js/ext.narayam.rules.ne.js |
— | — | @@ -12,7 +12,7 @@ |
13 | 13 | |
14 | 14 | ['([क-ह]़?)्a', '','$1'], |
15 | 15 | ['([क-ह]़?)्A', '','$1ा'], |
16 | | -['([क-ह]़?)a', '','$1ा'], |
| 16 | +['([क-ह]़?)्a', '','$1ा'], |
17 | 17 | ['([क-ह]़?)्i', '','$1ि'], |
18 | 18 | ['([क-ह]़?)(्I|िi|ेe)', '','$1ी'], |
19 | 19 | ['([क-ह]़?)्u', '','$1ु'], |
— | — | @@ -52,14 +52,14 @@ |
53 | 53 | ['ऒ\\^', '','ओ'], |
54 | 54 | ['अu', '','औ'], |
55 | 55 | ['र्र्r', '','र्'], |
56 | | -['ड़्h', '','ढ़्'], |
| 56 | +['ड़्h', '','ढ्'], |
57 | 57 | ['ऋR', '','ॠ'], |
58 | 58 | ['ळ्l', '','ऌ'], |
59 | 59 | ['ऌl', '','ॡ'], |
60 | 60 | ['ं\\^', '','ँ'], |
61 | 61 | ['ंM', '','ँ'], |
62 | 62 | ['ओM', '','ॐ'], |
63 | | -['ड्D', '','ड़्'], |
| 63 | +['ड्D', '','ड्'], |
64 | 64 | ['क्h', '','ख्'], |
65 | 65 | ['ग्h', '','घ्'], |
66 | 66 | ['G', '','ङ्'], |
— | — | @@ -72,22 +72,22 @@ |
73 | 73 | ['द्h', '','ध्'], |
74 | 74 | ['प्h', '','फ्'], |
75 | 75 | ['ब्h', '','भ्'], |
76 | | -['ऋa', '','ऱ'], |
77 | | -['ऋA', '','ऱा'], |
78 | | -['ऋi', '','ऱि'], |
79 | | -['ऋI', '','ऱी'], |
80 | | -['ऋu', '','ऱु'], |
81 | | -['ऋU', '','ऱू'], |
82 | | -['ऋ\\^', '','ऱॅ'], |
83 | | -['ऋe', '','ऱे'], |
84 | | -['ऋE', '','ऱे'], |
85 | | -['ऋo', '','ऱो'], |
86 | | -['ऋO', '','ऱो'], |
87 | | -['ऋ\\~', '','ऱ्'], |
| 76 | +['ऋa', '','र'], |
| 77 | +['ऋA', '','रा'], |
| 78 | +['ऋi', '','रि'], |
| 79 | +['ऋI', '','री'], |
| 80 | +['ऋu', '','रु'], |
| 81 | +['ऋU', '','रू'], |
| 82 | +['ऋ\\^', '','ऋ'], |
| 83 | +['ऋe', '','रे'], |
| 84 | +['ऋE', '','रे'], |
| 85 | +['ऋo', '','रो'], |
| 86 | +['ऋO', '','रो'], |
| 87 | +['ऋ\\~', '','र्'], |
88 | 88 | |
89 | 89 | ['स्h', '','श्'], |
90 | 90 | ['श्h', '','ष्'], |
91 | | -['क़्h', '','ख़्'], |
| 91 | +['क़्h', '','ख्'], |
92 | 92 | ['ज़्h', '','ऴ्'], |
93 | 93 | ['।\\.', '','॥'], |
94 | 94 | |
— | — | @@ -96,7 +96,7 @@ |
97 | 97 | ['c', '','क्'], |
98 | 98 | ['d', '','द्'], |
99 | 99 | ['e', '','ए'], |
100 | | -['(f|F)', '','फ़्'], |
| 100 | +['(f|F)', '','फ्'], |
101 | 101 | ['g', '','ग्'], |
102 | 102 | ['h', '','ह्'], |
103 | 103 | ['i', '','इ'], |
— | — | @@ -131,11 +131,12 @@ |
132 | 132 | ['N', '','ण्'], |
133 | 133 | ['O', '','ओ'], |
134 | 134 | ['P', '','प्प्'], |
| 135 | +['Q', '','अ'], |
135 | 136 | ['R', '','ऋ'], |
136 | 137 | ['S', '','श्'], |
137 | 138 | ['T', '','ट्'], |
138 | 139 | ['U', '','ऊ'], |
139 | | -['V', '','व्व्'], |
| 140 | +['V', '','झ्'], |
140 | 141 | ['W', '','औ'], |
141 | 142 | ['X', '','क्ष्'], |
142 | 143 | ['Y', '','य्य्'], |
— | — | @@ -151,7 +152,7 @@ |
152 | 153 | ['9', '','९'], |
153 | 154 | ['\\.', '','।'], |
154 | 155 | ['//', '','ऽ'], |
155 | | -['\\`', '','़'] |
| 156 | +['\\`', '','्'] |
156 | 157 | ]; |
157 | 158 | |
158 | 159 | jQuery.narayam.addScheme( 'ne', { |
Index: branches/wmf/1.18wmf1/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | 'mwe-upwiz-source-thirdparty-cases' => 'Now tell us why you are sure this site has the right to publish {{PLURAL:$1|this work|these works}}:', |
114 | 114 | 'mwe-upwiz-source-thirdparty-accept' => 'OK', |
115 | 115 | 'mwe-upwiz-source-custom' => 'Provide copyright information for each file individually on the next page.', |
116 | | - 'mwe-upwiz-more-options' => 'more options...', |
| 116 | + 'mwe-upwiz-more-options' => 'add categories and more information...', |
117 | 117 | 'mwe-upwiz-fewer-options' => 'fewer options...', |
118 | 118 | 'mwe-upwiz-desc' => 'Description', |
119 | 119 | 'mwe-upwiz-desc-add-n' => 'add a description in another language', |
Index: branches/wmf/1.18wmf1/extensions/Babel/Babel.class.php |
— | — | @@ -199,7 +199,7 @@ |
200 | 200 | */ |
201 | 201 | protected static function mGenerateBox( $code, $level ) { |
202 | 202 | $lang = wfBCP47( $code ); |
203 | | - $portal = wfMessage( 'babel-portal', $code )->plain(); |
| 203 | + $portal = wfMessage( 'babel-portal', $code )->inContentLanguage()->plain(); |
204 | 204 | if ( $portal !== '' ) { |
205 | 205 | $portal = "[[$portal|$lang]]"; |
206 | 206 | } else { |
Index: branches/wmf/1.18wmf1/tests/phpunit/languages/LanguageMlTest.php |
— | — | @@ -0,0 +1,30 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @author Santhosh Thottingal |
| 5 | + * @copyright Copyright © 2011, Santhosh Thottingal |
| 6 | + * @file |
| 7 | + */ |
| 8 | + |
| 9 | +/** Tests for MediaWiki languages/LanguageMl.php */ |
| 10 | +class LanguageMlTest extends MediaWikiTestCase { |
| 11 | + private $lang; |
| 12 | + |
| 13 | + function setUp() { |
| 14 | + $this->lang = Language::factory( 'Ml' ); |
| 15 | + } |
| 16 | + function tearDown() { |
| 17 | + unset( $this->lang ); |
| 18 | + } |
| 19 | + |
| 20 | + /** see bug 29495 */ |
| 21 | + function testFormatNum() { |
| 22 | + $this->assertEquals( '12,34,567', $this->lang->formatNum( '1234567' ) ); |
| 23 | + $this->assertEquals( '12,345', $this->lang->formatNum( '12345' ) ); |
| 24 | + $this->assertEquals( '1', $this->lang->formatNum( '1' ) ); |
| 25 | + $this->assertEquals( '123', $this->lang->formatNum( '123' ) ); |
| 26 | + $this->assertEquals( '1,234', $this->lang->formatNum( '1234' ) ); |
| 27 | + $this->assertEquals( '12,345.56', $this->lang->formatNum( '12345.56' ) ); |
| 28 | + $this->assertEquals( '12,34,56,79,81,23,45,678', $this->lang->formatNum( '12345679812345678' ) ); |
| 29 | + $this->assertEquals( '.12345', $this->lang->formatNum( '.12345' ) ); |
| 30 | + } |
| 31 | +} |
Property changes on: branches/wmf/1.18wmf1/tests/phpunit/languages/LanguageMlTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 32 | + native |
Index: branches/wmf/1.18wmf1/tests/phpunit/languages/LanguageNlTest.php |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * @author Santhosh Thottingal |
| 5 | + * @copyright Copyright © 2011, Santhosh Thottingal |
| 6 | + * @file |
| 7 | + */ |
| 8 | + |
| 9 | +/** Tests for MediaWiki languages/LanguageNl.php */ |
| 10 | +class LanguageNlTest extends MediaWikiTestCase { |
| 11 | + private $lang; |
| 12 | + |
| 13 | + function setUp() { |
| 14 | + $this->lang = Language::factory( 'Nl' ); |
| 15 | + } |
| 16 | + function tearDown() { |
| 17 | + unset( $this->lang ); |
| 18 | + } |
| 19 | + |
| 20 | + function testFormatNum() { |
| 21 | + $this->assertEquals( '1.234.567', $this->lang->formatNum( '1234567' ) ); |
| 22 | + $this->assertEquals( '12.345', $this->lang->formatNum( '12345' ) ); |
| 23 | + $this->assertEquals( '1', $this->lang->formatNum( '1' ) ); |
| 24 | + $this->assertEquals( '123', $this->lang->formatNum( '123' ) ); |
| 25 | + $this->assertEquals( '1.234', $this->lang->formatNum( '1234' ) ); |
| 26 | + $this->assertEquals( '12.345,56', $this->lang->formatNum( '12345.56' ) ); |
| 27 | + $this->assertEquals( ',1234556', $this->lang->formatNum( '.1234556' ) ); |
| 28 | + } |
| 29 | +} |
Property changes on: branches/wmf/1.18wmf1/tests/phpunit/languages/LanguageNlTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 30 | + native |
Index: branches/wmf/1.18wmf1/includes/LocalisationCache.php |
— | — | @@ -88,6 +88,7 @@ |
89 | 89 | 'dateFormats', 'datePreferences', 'datePreferenceMigrationMap', |
90 | 90 | 'defaultDateFormat', 'extraUserToggles', 'specialPageAliases', |
91 | 91 | 'imageFiles', 'preloadedMessages', 'namespaceGenderAliases', |
| 92 | + 'digitGroupingPattern' |
92 | 93 | ); |
93 | 94 | |
94 | 95 | /** |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesMr.php |
— | — | @@ -295,6 +295,8 @@ |
296 | 296 | |
297 | 297 | $linkTrail = "/^([\xE0\xA4\x80-\xE0\xA5\xA3\xE0\xA5\xB1-\xE0\xA5\xBF\xEF\xBB\xBF\xE2\x80\x8D]+)(.*)$/sDu"; |
298 | 298 | |
| 299 | +$digitGroupingPattern = "##,##,###"; |
| 300 | + |
299 | 301 | $messages = array( |
300 | 302 | # User preference toggles |
301 | 303 | 'tog-underline' => 'दुव्यांना अधोरेखित करा:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesHi.php |
— | — | @@ -68,6 +68,8 @@ |
69 | 69 | ); |
70 | 70 | $linkTrail = "/^([a-z]+)(.*)$/sD"; |
71 | 71 | |
| 72 | +$digitGroupingPattern = "##,##,###"; |
| 73 | + |
72 | 74 | $messages = array( |
73 | 75 | # User preference toggles |
74 | 76 | 'tog-underline' => 'कड़ियाँ अधोरेखन:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesKn.php |
— | — | @@ -52,6 +52,8 @@ |
53 | 53 | '9' => '೯', # ೯ |
54 | 54 | ); |
55 | 55 | |
| 56 | +$digitGroupingPattern = "##,##,###"; |
| 57 | + |
56 | 58 | $messages = array( |
57 | 59 | # User preference toggles |
58 | 60 | 'tog-underline' => 'ಲಿಂಕುಗಳ ಕೆಳಗೆ ಗೆರೆ ತೋರಿಸಿ', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesEn.php |
— | — | @@ -3648,10 +3648,15 @@ |
3649 | 3649 | |
3650 | 3650 | # Video information, used by Language::formatTimePeriod() to format lengths in the above messages |
3651 | 3651 | 'video-dims' => '$1, $2×$3', # only translate this message to other languages if you have to change it |
3652 | | -'seconds-abbrev' => 's', # only translate this message to other languages if you have to change it |
3653 | | -'minutes-abbrev' => 'm', # only translate this message to other languages if you have to change it |
3654 | | -'hours-abbrev' => 'h', # only translate this message to other languages if you have to change it |
3655 | | -'days-abbrev' => 'd', # only translate this message to other languages if you have to change it |
| 3652 | +'seconds-abbrev' => '$1s', # only translate this message to other languages if you have to change it |
| 3653 | +'minutes-abbrev' => '$1m', # only translate this message to other languages if you have to change it |
| 3654 | +'hours-abbrev' => '$1h', # only translate this message to other languages if you have to change it |
| 3655 | +'days-abbrev' => '$1d', # only translate this message to other languages if you have to change it |
| 3656 | +'seconds' => '{{PLURAL:$1|$1 second|$1 seconds}}', |
| 3657 | +'minutes' => '{{PLURAL:$1|$1 minute|$1 minutes}}', |
| 3658 | +'hours' => '{{PLURAL:$1|$1 hour|$1 hours}}', |
| 3659 | +'days' => '{{PLURAL:$1|$1 day|$1 days}}', |
| 3660 | +'ago' => '$1 ago', |
3656 | 3661 | |
3657 | 3662 | # Bad image list |
3658 | 3663 | 'bad_image_list' => 'The format is as follows: |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesAs.php |
— | — | @@ -108,6 +108,8 @@ |
109 | 109 | '9' => '৯', # ৯ |
110 | 110 | ); |
111 | 111 | |
| 112 | +$digitGroupingPattern = "##,##,###"; |
| 113 | + |
112 | 114 | $messages = array( |
113 | 115 | # User preference toggles |
114 | 116 | 'tog-underline' => 'সংযোগ সমূহ অধোৰেখিত কৰক:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesMl.php |
— | — | @@ -315,6 +315,8 @@ |
316 | 316 | 'url_query' => array( '0', 'ക്വറി', 'QUERY' ), |
317 | 317 | ); |
318 | 318 | |
| 319 | +$digitGroupingPattern = "##,##,###"; |
| 320 | + |
319 | 321 | $messages = array( |
320 | 322 | # User preference toggles |
321 | 323 | 'tog-underline' => 'കണ്ണികൾക്ക് അടിവരയിടുക:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesBn.php |
— | — | @@ -61,6 +61,8 @@ |
62 | 62 | '9' => '৯' |
63 | 63 | ); |
64 | 64 | |
| 65 | +$digitGroupingPattern = "##,##,###"; |
| 66 | + |
65 | 67 | $messages = array( |
66 | 68 | # User preference toggles |
67 | 69 | 'tog-underline' => 'সংযোগগুলির নিচে দাগ দেখানো হোক:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesSa.php |
— | — | @@ -267,6 +267,8 @@ |
268 | 268 | 'protectionlevel' => array( '1', 'रक्षास्तर', 'PROTECTIONLEVEL' ), |
269 | 269 | ); |
270 | 270 | |
| 271 | +$digitGroupingPattern = "##,##,###"; |
| 272 | + |
271 | 273 | $messages = array( |
272 | 274 | # User preference toggles |
273 | 275 | 'tog-underline' => 'संबंधनानि अधोरेखितानि करोतु', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesOr.php |
— | — | @@ -241,6 +241,8 @@ |
242 | 242 | 'url_query' => array( '0', 'ପ୍ରଶ୍ନ', 'QUERY' ), |
243 | 243 | ); |
244 | 244 | |
| 245 | +$digitGroupingPattern = "##,##,###"; |
| 246 | + |
245 | 247 | $messages = array( |
246 | 248 | # User preference toggles |
247 | 249 | 'tog-underline' => 'ତଳେ ଥିବା ଲିଙ୍କ:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesPa.php |
— | — | @@ -48,6 +48,8 @@ |
49 | 49 | ); |
50 | 50 | $linkTrail = '/^([ਁਂਃਅਆਇਈਉਊਏਐਓਔਕਖਗਘਙਚਛਜਝਞਟਠਡਢਣਤਥਦਧਨਪਫਬਭਮਯਰਲਲ਼ਵਸ਼ਸਹ਼ਾਿੀੁੂੇੈੋੌ੍ਖ਼ਗ਼ਜ਼ੜਫ਼ੰੱੲੳa-z]+)(.*)$/sDu'; |
51 | 51 | |
| 52 | +$digitGroupingPattern = "##,##,###"; |
| 53 | + |
52 | 54 | $messages = array( |
53 | 55 | # User preference toggles |
54 | 56 | 'tog-underline' => 'ਅੰਡਰ-ਲਾਈਨ ਲਿੰਕ:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesGu.php |
— | — | @@ -134,6 +134,8 @@ |
135 | 135 | '9' => '૯', # ૯ |
136 | 136 | ); |
137 | 137 | |
| 138 | +$digitGroupingPattern = "##,##,###"; |
| 139 | + |
138 | 140 | $messages = array( |
139 | 141 | # User preference toggles |
140 | 142 | 'tog-underline' => 'કડીઓની નીચે લીટી (અંડરલાઇન) ઉમેરો:', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesTa.php |
— | — | @@ -68,6 +68,8 @@ |
69 | 69 | |
70 | 70 | $linkTrail = "/^([\xE0\xAE\x80-\xE0\xAF\xBF]+)(.*)$/sDu"; |
71 | 71 | |
| 72 | +$digitGroupingPattern = "##,##,###"; |
| 73 | + |
72 | 74 | $messages = array( |
73 | 75 | # User preference toggles |
74 | 76 | 'tog-underline' => 'இணைப்புகளுக்கு அடிக்கோடிடு', |
Index: branches/wmf/1.18wmf1/languages/messages/MessagesTe.php |
— | — | @@ -138,6 +138,8 @@ |
139 | 139 | |
140 | 140 | $linkTrail = "/^([\xE0\xB0\x81-\xE0\xB1\xAF]+)(.*)$/sDu"; |
141 | 141 | |
| 142 | +$digitGroupingPattern = "##,##,###"; |
| 143 | + |
142 | 144 | $messages = array( |
143 | 145 | # User preference toggles |
144 | 146 | 'tog-underline' => 'లంకె క్రీగీత:', |
Index: branches/wmf/1.18wmf1/languages/Language.php |
— | — | @@ -2560,13 +2560,57 @@ |
2561 | 2561 | |
2562 | 2562 | /** |
2563 | 2563 | * Adds commas to a given number |
2564 | | - * |
| 2564 | + * @since 1.19 |
2565 | 2565 | * @param $_ mixed |
2566 | 2566 | * @return string |
2567 | 2567 | */ |
2568 | 2568 | function commafy( $_ ) { |
2569 | | - return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); |
| 2569 | + $digitGroupingPattern = $this->digitGroupingPattern(); |
| 2570 | + |
| 2571 | + if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) { |
| 2572 | + //default grouping is at thousands, use the same for ###,###,### pattern too. |
| 2573 | + return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); |
| 2574 | + } |
| 2575 | + else { |
| 2576 | + // Ref: http://cldr.unicode.org/translation/number-patterns |
| 2577 | + $numberpart = array(); |
| 2578 | + $decimalpart = array(); |
| 2579 | + $numMatches = preg_match_all( "/(#+)/", $digitGroupingPattern, $matches ); |
| 2580 | + preg_match( "/\d+/", $_, $numberpart ); |
| 2581 | + preg_match( "/\.\d*/", $_, $decimalpart ); |
| 2582 | + $groupedNumber = ( count( $decimalpart ) > 0 ) ? $decimalpart[0]:""; |
| 2583 | + if ( $groupedNumber === $_){ |
| 2584 | + //the string does not have any number part. Eg: .12345 |
| 2585 | + return $groupedNumber; |
| 2586 | + } |
| 2587 | + $start = $end = strlen( $numberpart[0] ); |
| 2588 | + while ( $start > 0 ) |
| 2589 | + { |
| 2590 | + $match = $matches[0][$numMatches -1] ; |
| 2591 | + $matchLen = strlen( $match ); |
| 2592 | + $start = $end - $matchLen; |
| 2593 | + if ( $start < 0 ) { |
| 2594 | + $start = 0; |
| 2595 | + } |
| 2596 | + $groupedNumber = substr( $_ , $start, $end -$start ) . $groupedNumber ; |
| 2597 | + $end = $start; |
| 2598 | + if ( $numMatches > 1 ) { |
| 2599 | + // use the last pattern for the rest of the number |
| 2600 | + $numMatches--; |
| 2601 | + } |
| 2602 | + if ( $start > 0 ) { |
| 2603 | + $groupedNumber = "," . $groupedNumber; |
| 2604 | + } |
| 2605 | + } |
| 2606 | + return $groupedNumber; |
| 2607 | + } |
2570 | 2608 | } |
| 2609 | + /** |
| 2610 | + * @return String |
| 2611 | + */ |
| 2612 | + function digitGroupingPattern() { |
| 2613 | + return self::$dataCache->getItem( $this->mCode, 'digitGroupingPattern' ); |
| 2614 | + } |
2571 | 2615 | |
2572 | 2616 | /** |
2573 | 2617 | * @return array |
— | — | @@ -3427,18 +3471,34 @@ |
3428 | 3472 | /** |
3429 | 3473 | * @todo Document |
3430 | 3474 | * @param $seconds int|float |
3431 | | - * @param $format String Optional, one of ("avoidseconds","avoidminutes"): |
3432 | | - * "avoidseconds" - don't mention seconds if $seconds >= 1 hour |
3433 | | - * "avoidminutes" - don't mention seconds/minutes if $seconds > 48 hours |
| 3475 | + * @param $format Array Optional |
| 3476 | + * If $format['avoid'] == 'avoidseconds' - don't mention seconds if $seconds >= 1 hour |
| 3477 | + * If $format['avoid'] == 'avoidminutes' - don't mention seconds/minutes if $seconds > 48 hours |
| 3478 | + * If $format['noabbrevs'] is true - use 'seconds' and friends instead of 'seconds-abbrev' and friends |
| 3479 | + * For backwards compatibility, $format may also be one of the strings 'avoidseconds' or 'avoidminutes' |
3434 | 3480 | * @return string |
3435 | 3481 | */ |
3436 | | - function formatTimePeriod( $seconds, $format = false ) { |
| 3482 | + function formatTimePeriod( $seconds, $format = array() ) { |
| 3483 | + if ( !is_array( $format ) ) { |
| 3484 | + $format = array( 'avoid' => $format, 'noabbrevs' => false ); // For backwards compatibility |
| 3485 | + } |
| 3486 | + if ( !isset( $format['avoid'] ) ) { |
| 3487 | + $format['avoid'] = false; |
| 3488 | + } |
| 3489 | + if ( !isset( $format['noabbrevs' ] ) ) { |
| 3490 | + $format['noabbrevs'] = false; |
| 3491 | + } |
| 3492 | + $secondsMsg = wfMessage( $format['noabbrevs'] ? 'seconds' : 'seconds-abbrev' )->inLanguage( $this ); |
| 3493 | + $minutesMsg = wfMessage( $format['noabbrevs'] ? 'minutes' : 'minutes-abbrev' )->inLanguage( $this ); |
| 3494 | + $hoursMsg = wfMessage( $format['noabbrevs'] ? 'hours' : 'hours-abbrev' )->inLanguage( $this ); |
| 3495 | + $daysMsg = wfMessage( $format['noabbrevs'] ? 'days' : 'days-abbrev' )->inLanguage( $this ); |
| 3496 | + |
3437 | 3497 | if ( round( $seconds * 10 ) < 100 ) { |
3438 | 3498 | $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ); |
3439 | | - $s .= $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3499 | + $s = $secondsMsg->params( $s )->text(); |
3440 | 3500 | } elseif ( round( $seconds ) < 60 ) { |
3441 | 3501 | $s = $this->formatNum( round( $seconds ) ); |
3442 | | - $s .= $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3502 | + $s = $secondsMsg->params( $s )->text(); |
3443 | 3503 | } elseif ( round( $seconds ) < 3600 ) { |
3444 | 3504 | $minutes = floor( $seconds / 60 ); |
3445 | 3505 | $secondsPart = round( fmod( $seconds, 60 ) ); |
— | — | @@ -3446,9 +3506,9 @@ |
3447 | 3507 | $secondsPart = 0; |
3448 | 3508 | $minutes++; |
3449 | 3509 | } |
3450 | | - $s = $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
| 3510 | + $s = $minutesMsg->params( $this->formatNum( $minutes ) )->text(); |
3451 | 3511 | $s .= ' '; |
3452 | | - $s .= $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3512 | + $s .= $secondsMsg->params( $this->formatNum( $secondsPart ) )->text(); |
3453 | 3513 | } elseif ( round( $seconds ) <= 2*86400 ) { |
3454 | 3514 | $hours = floor( $seconds / 3600 ); |
3455 | 3515 | $minutes = floor( ( $seconds - $hours * 3600 ) / 60 ); |
— | — | @@ -3461,25 +3521,24 @@ |
3462 | 3522 | $minutes = 0; |
3463 | 3523 | $hours++; |
3464 | 3524 | } |
3465 | | - $s = $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3525 | + $s = $hoursMsg->params( $this->formatNum( $hours ) )->text(); |
3466 | 3526 | $s .= ' '; |
3467 | | - $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
3468 | | - if ( !in_array( $format, array( 'avoidseconds', 'avoidminutes' ) ) ) { |
3469 | | - $s .= ' ' . $this->formatNum( $secondsPart ) . |
3470 | | - $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3527 | + $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text(); |
| 3528 | + if ( !in_array( $format['avoid'], array( 'avoidseconds', 'avoidminutes' ) ) ) { |
| 3529 | + $s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text(); |
3471 | 3530 | } |
3472 | 3531 | } else { |
3473 | 3532 | $days = floor( $seconds / 86400 ); |
3474 | | - if ( $format === 'avoidminutes' ) { |
| 3533 | + if ( $format['avoid'] === 'avoidminutes' ) { |
3475 | 3534 | $hours = round( ( $seconds - $days * 86400 ) / 3600 ); |
3476 | 3535 | if ( $hours == 24 ) { |
3477 | 3536 | $hours = 0; |
3478 | 3537 | $days++; |
3479 | 3538 | } |
3480 | | - $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3539 | + $s = $daysMsg->params( $this->formatNum( $days ) )->text(); |
3481 | 3540 | $s .= ' '; |
3482 | | - $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
3483 | | - } elseif ( $format === 'avoidseconds' ) { |
| 3541 | + $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text(); |
| 3542 | + } elseif ( $format['avoid'] === 'avoidseconds' ) { |
3484 | 3543 | $hours = floor( ( $seconds - $days * 86400 ) / 3600 ); |
3485 | 3544 | $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 ); |
3486 | 3545 | if ( $minutes == 60 ) { |
— | — | @@ -3490,13 +3549,13 @@ |
3491 | 3550 | $hours = 0; |
3492 | 3551 | $days++; |
3493 | 3552 | } |
3494 | | - $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3553 | + $s = $daysMsg->params( $this->formatNum( $days ) )->text(); |
3495 | 3554 | $s .= ' '; |
3496 | | - $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3555 | + $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text(); |
3497 | 3556 | $s .= ' '; |
3498 | | - $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
| 3557 | + $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text(); |
3499 | 3558 | } else { |
3500 | | - $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3559 | + $s = $daysMsg->params( $this->formatNum( $days ) )->text(); |
3501 | 3560 | $s .= ' '; |
3502 | 3561 | $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format ); |
3503 | 3562 | } |