MediaWiki fundraising/REL1_35
Language.php
Go to the documentation of this file.
1<?php
25use CLDRPluralRuleParser\Evaluator;
33use Wikimedia\Assert\Assert;
34
41class Language {
47 public const AS_AUTONYMS = LanguageNameUtils::AUTONYMS;
48
54 public const ALL = LanguageNameUtils::ALL;
55
62 public const SUPPORTED = LanguageNameUtils::SUPPORTED;
63
71 public function __get( string $name ) {
72 if ( $name == "mConverter" ) {
74 'Access to Language::$mConverter was deprecated in MediaWiki 1.35',
75 '1.35' );
76 return $this->getConverter();
77 }
78 throw new RuntimeException( "Cannot get '$name' property." );
79 }
80
81 public $mCode;
82
86 public $mMagicExtensions = [];
87
88 private $mHtmlCode = null;
89
94 public $dateFormatStrings = [];
95
102
106
111 public $transformData = [];
112
115
118
121
124
129
134
138 private $hookRunner;
139
144 public static $mLangObjCache = [];
145
151 public const MESSAGES_FALLBACKS = LanguageFallback::MESSAGES;
152
158 public const STRICT_FALLBACKS = LanguageFallback::STRICT;
159
163 public const WEEKDAY_MESSAGES = [
164 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
165 'friday', 'saturday'
166 ];
167
171 public static $mWeekdayMsgs = self::WEEKDAY_MESSAGES;
172
177 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'
178 ];
179
183 public static $mWeekdayAbbrevMsgs = self::WEEKDAY_ABBREVIATED_MESSAGES;
184
188 public const MONTH_MESSAGES = [
189 'january', 'february', 'march', 'april', 'may_long', 'june',
190 'july', 'august', 'september', 'october', 'november',
191 'december'
192 ];
193
197 public static $mMonthMsgs = self::MONTH_MESSAGES;
198
202 public const MONTH_GENITIVE_MESSAGES = [
203 'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
204 'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen',
205 'december-gen'
206 ];
207
211 public static $mMonthGenMsgs = self::MONTH_GENITIVE_MESSAGES;
212
217 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
218 'sep', 'oct', 'nov', 'dec'
219 ];
220
224 public static $mMonthAbbrevMsgs = self::MONTH_ABBREVIATED_MESSAGES;
225
230 'iranian-calendar-m1', 'iranian-calendar-m2', 'iranian-calendar-m3',
231 'iranian-calendar-m4', 'iranian-calendar-m5', 'iranian-calendar-m6',
232 'iranian-calendar-m7', 'iranian-calendar-m8', 'iranian-calendar-m9',
233 'iranian-calendar-m10', 'iranian-calendar-m11', 'iranian-calendar-m12'
234 ];
235
239 public static $mIranianCalendarMonthMsgs = self::IRANIAN_CALENDAR_MONTHS_MESSAGES;
240
245 'hebrew-calendar-m1', 'hebrew-calendar-m2', 'hebrew-calendar-m3',
246 'hebrew-calendar-m4', 'hebrew-calendar-m5', 'hebrew-calendar-m6',
247 'hebrew-calendar-m7', 'hebrew-calendar-m8', 'hebrew-calendar-m9',
248 'hebrew-calendar-m10', 'hebrew-calendar-m11', 'hebrew-calendar-m12',
249 'hebrew-calendar-m6a', 'hebrew-calendar-m6b'
250 ];
251
255 public static $mHebrewCalendarMonthMsgs = self::HEBREW_CALENDAR_MONTHS_MESSAGES;
256
261 'hebrew-calendar-m1-gen', 'hebrew-calendar-m2-gen', 'hebrew-calendar-m3-gen',
262 'hebrew-calendar-m4-gen', 'hebrew-calendar-m5-gen', 'hebrew-calendar-m6-gen',
263 'hebrew-calendar-m7-gen', 'hebrew-calendar-m8-gen', 'hebrew-calendar-m9-gen',
264 'hebrew-calendar-m10-gen', 'hebrew-calendar-m11-gen', 'hebrew-calendar-m12-gen',
265 'hebrew-calendar-m6a-gen', 'hebrew-calendar-m6b-gen'
266 ];
267
271 public static $mHebrewCalendarMonthGenMsgs = self::HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES;
272
277 'hijri-calendar-m1', 'hijri-calendar-m2', 'hijri-calendar-m3',
278 'hijri-calendar-m4', 'hijri-calendar-m5', 'hijri-calendar-m6',
279 'hijri-calendar-m7', 'hijri-calendar-m8', 'hijri-calendar-m9',
280 'hijri-calendar-m10', 'hijri-calendar-m11', 'hijri-calendar-m12'
281 ];
282
286 public static $mHijriCalendarMonthMsgs = self::HIJRI_CALENDAR_MONTH_MESSAGES;
287
291 protected const DURATION_INTERVALS = [
292 'millennia' => 31556952000,
293 'centuries' => 3155695200,
294 'decades' => 315569520,
295 'years' => 31556952, // 86400 * ( 365 + ( 24 * 3 + 25 ) / 400 )
296 'weeks' => 604800,
297 'days' => 86400,
298 'hours' => 3600,
299 'minutes' => 60,
300 'seconds' => 1,
301 ];
302
308 public static $durationIntervals = self::DURATION_INTERVALS;
309
313 private const LRE = "\u{202A}"; // U+202A LEFT-TO-RIGHT EMBEDDING
314 private const RLE = "\u{202B}"; // U+202B RIGHT-TO-LEFT EMBEDDING
315 private const PDF = "\u{202C}"; // U+202C POP DIRECTIONAL FORMATTING
316
328 // @codeCoverageIgnoreStart
329 // phpcs:ignore Generic.Files.LineLength
330 private static $strongDirRegex = '/(?:([\x{41}-\x{5a}\x{61}-\x{7a}\x{aa}\x{b5}\x{ba}\x{c0}-\x{d6}\x{d8}-\x{f6}\x{f8}-\x{2b8}\x{2bb}-\x{2c1}\x{2d0}\x{2d1}\x{2e0}-\x{2e4}\x{2ee}\x{370}-\x{373}\x{376}\x{377}\x{37a}-\x{37d}\x{37f}\x{386}\x{388}-\x{38a}\x{38c}\x{38e}-\x{3a1}\x{3a3}-\x{3f5}\x{3f7}-\x{482}\x{48a}-\x{52f}\x{531}-\x{556}\x{559}-\x{55f}\x{561}-\x{587}\x{589}\x{903}-\x{939}\x{93b}\x{93d}-\x{940}\x{949}-\x{94c}\x{94e}-\x{950}\x{958}-\x{961}\x{964}-\x{980}\x{982}\x{983}\x{985}-\x{98c}\x{98f}\x{990}\x{993}-\x{9a8}\x{9aa}-\x{9b0}\x{9b2}\x{9b6}-\x{9b9}\x{9bd}-\x{9c0}\x{9c7}\x{9c8}\x{9cb}\x{9cc}\x{9ce}\x{9d7}\x{9dc}\x{9dd}\x{9df}-\x{9e1}\x{9e6}-\x{9f1}\x{9f4}-\x{9fa}\x{a03}\x{a05}-\x{a0a}\x{a0f}\x{a10}\x{a13}-\x{a28}\x{a2a}-\x{a30}\x{a32}\x{a33}\x{a35}\x{a36}\x{a38}\x{a39}\x{a3e}-\x{a40}\x{a59}-\x{a5c}\x{a5e}\x{a66}-\x{a6f}\x{a72}-\x{a74}\x{a83}\x{a85}-\x{a8d}\x{a8f}-\x{a91}\x{a93}-\x{aa8}\x{aaa}-\x{ab0}\x{ab2}\x{ab3}\x{ab5}-\x{ab9}\x{abd}-\x{ac0}\x{ac9}\x{acb}\x{acc}\x{ad0}\x{ae0}\x{ae1}\x{ae6}-\x{af0}\x{af9}\x{b02}\x{b03}\x{b05}-\x{b0c}\x{b0f}\x{b10}\x{b13}-\x{b28}\x{b2a}-\x{b30}\x{b32}\x{b33}\x{b35}-\x{b39}\x{b3d}\x{b3e}\x{b40}\x{b47}\x{b48}\x{b4b}\x{b4c}\x{b57}\x{b5c}\x{b5d}\x{b5f}-\x{b61}\x{b66}-\x{b77}\x{b83}\x{b85}-\x{b8a}\x{b8e}-\x{b90}\x{b92}-\x{b95}\x{b99}\x{b9a}\x{b9c}\x{b9e}\x{b9f}\x{ba3}\x{ba4}\x{ba8}-\x{baa}\x{bae}-\x{bb9}\x{bbe}\x{bbf}\x{bc1}\x{bc2}\x{bc6}-\x{bc8}\x{bca}-\x{bcc}\x{bd0}\x{bd7}\x{be6}-\x{bf2}\x{c01}-\x{c03}\x{c05}-\x{c0c}\x{c0e}-\x{c10}\x{c12}-\x{c28}\x{c2a}-\x{c39}\x{c3d}\x{c41}-\x{c44}\x{c58}-\x{c5a}\x{c60}\x{c61}\x{c66}-\x{c6f}\x{c7f}\x{c82}\x{c83}\x{c85}-\x{c8c}\x{c8e}-\x{c90}\x{c92}-\x{ca8}\x{caa}-\x{cb3}\x{cb5}-\x{cb9}\x{cbd}-\x{cc4}\x{cc6}-\x{cc8}\x{cca}\x{ccb}\x{cd5}\x{cd6}\x{cde}\x{ce0}\x{ce1}\x{ce6}-\x{cef}\x{cf1}\x{cf2}\x{d02}\x{d03}\x{d05}-\x{d0c}\x{d0e}-\x{d10}\x{d12}-\x{d3a}\x{d3d}-\x{d40}\x{d46}-\x{d48}\x{d4a}-\x{d4c}\x{d4e}\x{d57}\x{d5f}-\x{d61}\x{d66}-\x{d75}\x{d79}-\x{d7f}\x{d82}\x{d83}\x{d85}-\x{d96}\x{d9a}-\x{db1}\x{db3}-\x{dbb}\x{dbd}\x{dc0}-\x{dc6}\x{dcf}-\x{dd1}\x{dd8}-\x{ddf}\x{de6}-\x{def}\x{df2}-\x{df4}\x{e01}-\x{e30}\x{e32}\x{e33}\x{e40}-\x{e46}\x{e4f}-\x{e5b}\x{e81}\x{e82}\x{e84}\x{e87}\x{e88}\x{e8a}\x{e8d}\x{e94}-\x{e97}\x{e99}-\x{e9f}\x{ea1}-\x{ea3}\x{ea5}\x{ea7}\x{eaa}\x{eab}\x{ead}-\x{eb0}\x{eb2}\x{eb3}\x{ebd}\x{ec0}-\x{ec4}\x{ec6}\x{ed0}-\x{ed9}\x{edc}-\x{edf}\x{f00}-\x{f17}\x{f1a}-\x{f34}\x{f36}\x{f38}\x{f3e}-\x{f47}\x{f49}-\x{f6c}\x{f7f}\x{f85}\x{f88}-\x{f8c}\x{fbe}-\x{fc5}\x{fc7}-\x{fcc}\x{fce}-\x{fda}\x{1000}-\x{102c}\x{1031}\x{1038}\x{103b}\x{103c}\x{103f}-\x{1057}\x{105a}-\x{105d}\x{1061}-\x{1070}\x{1075}-\x{1081}\x{1083}\x{1084}\x{1087}-\x{108c}\x{108e}-\x{109c}\x{109e}-\x{10c5}\x{10c7}\x{10cd}\x{10d0}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1360}-\x{137c}\x{1380}-\x{138f}\x{13a0}-\x{13f5}\x{13f8}-\x{13fd}\x{1401}-\x{167f}\x{1681}-\x{169a}\x{16a0}-\x{16f8}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1735}\x{1736}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17b6}\x{17be}-\x{17c5}\x{17c7}\x{17c8}\x{17d4}-\x{17da}\x{17dc}\x{17e0}-\x{17e9}\x{1810}-\x{1819}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{18aa}\x{18b0}-\x{18f5}\x{1900}-\x{191e}\x{1923}-\x{1926}\x{1929}-\x{192b}\x{1930}\x{1931}\x{1933}-\x{1938}\x{1946}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19ab}\x{19b0}-\x{19c9}\x{19d0}-\x{19da}\x{1a00}-\x{1a16}\x{1a19}\x{1a1a}\x{1a1e}-\x{1a55}\x{1a57}\x{1a61}\x{1a63}\x{1a64}\x{1a6d}-\x{1a72}\x{1a80}-\x{1a89}\x{1a90}-\x{1a99}\x{1aa0}-\x{1aad}\x{1b04}-\x{1b33}\x{1b35}\x{1b3b}\x{1b3d}-\x{1b41}\x{1b43}-\x{1b4b}\x{1b50}-\x{1b6a}\x{1b74}-\x{1b7c}\x{1b82}-\x{1ba1}\x{1ba6}\x{1ba7}\x{1baa}\x{1bae}-\x{1be5}\x{1be7}\x{1bea}-\x{1bec}\x{1bee}\x{1bf2}\x{1bf3}\x{1bfc}-\x{1c2b}\x{1c34}\x{1c35}\x{1c3b}-\x{1c49}\x{1c4d}-\x{1c7f}\x{1cc0}-\x{1cc7}\x{1cd3}\x{1ce1}\x{1ce9}-\x{1cec}\x{1cee}-\x{1cf3}\x{1cf5}\x{1cf6}\x{1d00}-\x{1dbf}\x{1e00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{200e}\x{2071}\x{207f}\x{2090}-\x{209c}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{214e}\x{214f}\x{2160}-\x{2188}\x{2336}-\x{237a}\x{2395}\x{249c}-\x{24e9}\x{26ac}\x{2800}-\x{28ff}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c60}-\x{2ce4}\x{2ceb}-\x{2cee}\x{2cf2}\x{2cf3}\x{2d00}-\x{2d25}\x{2d27}\x{2d2d}\x{2d30}-\x{2d67}\x{2d6f}\x{2d70}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{302e}\x{302f}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312d}\x{3131}-\x{318e}\x{3190}-\x{31ba}\x{31f0}-\x{321c}\x{3220}-\x{324f}\x{3260}-\x{327b}\x{327f}-\x{32b0}\x{32c0}-\x{32cb}\x{32d0}-\x{32fe}\x{3300}-\x{3376}\x{337b}-\x{33dd}\x{33e0}-\x{33fe}\x{3400}-\x{4db5}\x{4e00}-\x{9fd5}\x{a000}-\x{a48c}\x{a4d0}-\x{a60c}\x{a610}-\x{a62b}\x{a640}-\x{a66e}\x{a680}-\x{a69d}\x{a6a0}-\x{a6ef}\x{a6f2}-\x{a6f7}\x{a722}-\x{a787}\x{a789}-\x{a7ad}\x{a7b0}-\x{a7b7}\x{a7f7}-\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a824}\x{a827}\x{a830}-\x{a837}\x{a840}-\x{a873}\x{a880}-\x{a8c3}\x{a8ce}-\x{a8d9}\x{a8f2}-\x{a8fd}\x{a900}-\x{a925}\x{a92e}-\x{a946}\x{a952}\x{a953}\x{a95f}-\x{a97c}\x{a983}-\x{a9b2}\x{a9b4}\x{a9b5}\x{a9ba}\x{a9bb}\x{a9bd}-\x{a9cd}\x{a9cf}-\x{a9d9}\x{a9de}-\x{a9e4}\x{a9e6}-\x{a9fe}\x{aa00}-\x{aa28}\x{aa2f}\x{aa30}\x{aa33}\x{aa34}\x{aa40}-\x{aa42}\x{aa44}-\x{aa4b}\x{aa4d}\x{aa50}-\x{aa59}\x{aa5c}-\x{aa7b}\x{aa7d}-\x{aaaf}\x{aab1}\x{aab5}\x{aab6}\x{aab9}-\x{aabd}\x{aac0}\x{aac2}\x{aadb}-\x{aaeb}\x{aaee}-\x{aaf5}\x{ab01}-\x{ab06}\x{ab09}-\x{ab0e}\x{ab11}-\x{ab16}\x{ab20}-\x{ab26}\x{ab28}-\x{ab2e}\x{ab30}-\x{ab65}\x{ab70}-\x{abe4}\x{abe6}\x{abe7}\x{abe9}-\x{abec}\x{abf0}-\x{abf9}\x{ac00}-\x{d7a3}\x{d7b0}-\x{d7c6}\x{d7cb}-\x{d7fb}\x{e000}-\x{fa6d}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}\x{10000}-\x{1000b}\x{1000d}-\x{10026}\x{10028}-\x{1003a}\x{1003c}\x{1003d}\x{1003f}-\x{1004d}\x{10050}-\x{1005d}\x{10080}-\x{100fa}\x{10100}\x{10102}\x{10107}-\x{10133}\x{10137}-\x{1013f}\x{101d0}-\x{101fc}\x{10280}-\x{1029c}\x{102a0}-\x{102d0}\x{10300}-\x{10323}\x{10330}-\x{1034a}\x{10350}-\x{10375}\x{10380}-\x{1039d}\x{1039f}-\x{103c3}\x{103c8}-\x{103d5}\x{10400}-\x{1049d}\x{104a0}-\x{104a9}\x{10500}-\x{10527}\x{10530}-\x{10563}\x{1056f}\x{10600}-\x{10736}\x{10740}-\x{10755}\x{10760}-\x{10767}\x{11000}\x{11002}-\x{11037}\x{11047}-\x{1104d}\x{11066}-\x{1106f}\x{11082}-\x{110b2}\x{110b7}\x{110b8}\x{110bb}-\x{110c1}\x{110d0}-\x{110e8}\x{110f0}-\x{110f9}\x{11103}-\x{11126}\x{1112c}\x{11136}-\x{11143}\x{11150}-\x{11172}\x{11174}-\x{11176}\x{11182}-\x{111b5}\x{111bf}-\x{111c9}\x{111cd}\x{111d0}-\x{111df}\x{111e1}-\x{111f4}\x{11200}-\x{11211}\x{11213}-\x{1122e}\x{11232}\x{11233}\x{11235}\x{11238}-\x{1123d}\x{11280}-\x{11286}\x{11288}\x{1128a}-\x{1128d}\x{1128f}-\x{1129d}\x{1129f}-\x{112a9}\x{112b0}-\x{112de}\x{112e0}-\x{112e2}\x{112f0}-\x{112f9}\x{11302}\x{11303}\x{11305}-\x{1130c}\x{1130f}\x{11310}\x{11313}-\x{11328}\x{1132a}-\x{11330}\x{11332}\x{11333}\x{11335}-\x{11339}\x{1133d}-\x{1133f}\x{11341}-\x{11344}\x{11347}\x{11348}\x{1134b}-\x{1134d}\x{11350}\x{11357}\x{1135d}-\x{11363}\x{11480}-\x{114b2}\x{114b9}\x{114bb}-\x{114be}\x{114c1}\x{114c4}-\x{114c7}\x{114d0}-\x{114d9}\x{11580}-\x{115b1}\x{115b8}-\x{115bb}\x{115be}\x{115c1}-\x{115db}\x{11600}-\x{11632}\x{1163b}\x{1163c}\x{1163e}\x{11641}-\x{11644}\x{11650}-\x{11659}\x{11680}-\x{116aa}\x{116ac}\x{116ae}\x{116af}\x{116b6}\x{116c0}-\x{116c9}\x{11700}-\x{11719}\x{11720}\x{11721}\x{11726}\x{11730}-\x{1173f}\x{118a0}-\x{118f2}\x{118ff}\x{11ac0}-\x{11af8}\x{12000}-\x{12399}\x{12400}-\x{1246e}\x{12470}-\x{12474}\x{12480}-\x{12543}\x{13000}-\x{1342e}\x{14400}-\x{14646}\x{16800}-\x{16a38}\x{16a40}-\x{16a5e}\x{16a60}-\x{16a69}\x{16a6e}\x{16a6f}\x{16ad0}-\x{16aed}\x{16af5}\x{16b00}-\x{16b2f}\x{16b37}-\x{16b45}\x{16b50}-\x{16b59}\x{16b5b}-\x{16b61}\x{16b63}-\x{16b77}\x{16b7d}-\x{16b8f}\x{16f00}-\x{16f44}\x{16f50}-\x{16f7e}\x{16f93}-\x{16f9f}\x{1b000}\x{1b001}\x{1bc00}-\x{1bc6a}\x{1bc70}-\x{1bc7c}\x{1bc80}-\x{1bc88}\x{1bc90}-\x{1bc99}\x{1bc9c}\x{1bc9f}\x{1d000}-\x{1d0f5}\x{1d100}-\x{1d126}\x{1d129}-\x{1d166}\x{1d16a}-\x{1d172}\x{1d183}\x{1d184}\x{1d18c}-\x{1d1a9}\x{1d1ae}-\x{1d1e8}\x{1d360}-\x{1d371}\x{1d400}-\x{1d454}\x{1d456}-\x{1d49c}\x{1d49e}\x{1d49f}\x{1d4a2}\x{1d4a5}\x{1d4a6}\x{1d4a9}-\x{1d4ac}\x{1d4ae}-\x{1d4b9}\x{1d4bb}\x{1d4bd}-\x{1d4c3}\x{1d4c5}-\x{1d505}\x{1d507}-\x{1d50a}\x{1d50d}-\x{1d514}\x{1d516}-\x{1d51c}\x{1d51e}-\x{1d539}\x{1d53b}-\x{1d53e}\x{1d540}-\x{1d544}\x{1d546}\x{1d54a}-\x{1d550}\x{1d552}-\x{1d6a5}\x{1d6a8}-\x{1d6da}\x{1d6dc}-\x{1d714}\x{1d716}-\x{1d74e}\x{1d750}-\x{1d788}\x{1d78a}-\x{1d7c2}\x{1d7c4}-\x{1d7cb}\x{1d800}-\x{1d9ff}\x{1da37}-\x{1da3a}\x{1da6d}-\x{1da74}\x{1da76}-\x{1da83}\x{1da85}-\x{1da8b}\x{1f110}-\x{1f12e}\x{1f130}-\x{1f169}\x{1f170}-\x{1f19a}\x{1f1e6}-\x{1f202}\x{1f210}-\x{1f23a}\x{1f240}-\x{1f248}\x{1f250}\x{1f251}\x{20000}-\x{2a6d6}\x{2a700}-\x{2b734}\x{2b740}-\x{2b81d}\x{2b820}-\x{2cea1}\x{2f800}-\x{2fa1d}\x{f0000}-\x{ffffd}\x{100000}-\x{10fffd}])|([\x{590}\x{5be}\x{5c0}\x{5c3}\x{5c6}\x{5c8}-\x{5ff}\x{7c0}-\x{7ea}\x{7f4}\x{7f5}\x{7fa}-\x{815}\x{81a}\x{824}\x{828}\x{82e}-\x{858}\x{85c}-\x{89f}\x{200f}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb4f}\x{10800}-\x{1091e}\x{10920}-\x{10a00}\x{10a04}\x{10a07}-\x{10a0b}\x{10a10}-\x{10a37}\x{10a3b}-\x{10a3e}\x{10a40}-\x{10ae4}\x{10ae7}-\x{10b38}\x{10b40}-\x{10e5f}\x{10e7f}-\x{10fff}\x{1e800}-\x{1e8cf}\x{1e8d7}-\x{1edff}\x{1ef00}-\x{1efff}\x{608}\x{60b}\x{60d}\x{61b}-\x{64a}\x{66d}-\x{66f}\x{671}-\x{6d5}\x{6e5}\x{6e6}\x{6ee}\x{6ef}\x{6fa}-\x{710}\x{712}-\x{72f}\x{74b}-\x{7a5}\x{7b1}-\x{7bf}\x{8a0}-\x{8e2}\x{fb50}-\x{fd3d}\x{fd40}-\x{fdcf}\x{fdf0}-\x{fdfc}\x{fdfe}\x{fdff}\x{fe70}-\x{fefe}\x{1ee00}-\x{1eeef}\x{1eef2}-\x{1eeff}]))/u';
331 // @codeCoverageIgnoreEnd
332
340 public static function factory( $code ) {
341 return MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $code );
342 }
343
350 public static function clearCaches() {
351 wfDeprecated( __METHOD__, '1.35' );
352
353 $services = MediaWikiServices::getInstance();
354
355 $services->resetServiceForTesting( 'LanguageFallback' );
356 $services->resetServiceForTesting( 'LanguageNameUtils' );
357 $services->resetServiceForTesting( 'LocalisationCache' );
358 $services->resetServiceForTesting( 'LanguageFactory' );
359
360 self::$mLangObjCache = [];
361 }
362
372 public static function isSupportedLanguage( $code ) {
373 return MediaWikiServices::getInstance()->getLanguageNameUtils()
374 ->isSupportedLanguage( $code );
375 }
376
392 public static function isWellFormedLanguageTag( $code, $lenient = false ) {
393 $alpha = '[a-z]';
394 $digit = '[0-9]';
395 $alphanum = '[a-z0-9]';
396 $x = 'x'; # private use singleton
397 $singleton = '[a-wy-z]'; # other singleton
398 $s = $lenient ? '[-_]' : '-';
399
400 $language = "$alpha{2,8}|$alpha{2,3}$s$alpha{3}";
401 $script = "$alpha{4}"; # ISO 15924
402 $region = "(?:$alpha{2}|$digit{3})"; # ISO 3166-1 alpha-2 or UN M.49
403 $variant = "(?:$alphanum{5,8}|$digit$alphanum{3})";
404 $extension = "$singleton(?:$s$alphanum{2,8})+";
405 $privateUse = "$x(?:$s$alphanum{1,8})+";
406
407 # Define certain grandfathered codes, since otherwise the regex is pretty useless.
408 # Since these are limited, this is safe even later changes to the registry --
409 # the only oddity is that it might change the type of the tag, and thus
410 # the results from the capturing groups.
411 # https://www.iana.org/assignments/language-subtag-registry
412
413 $grandfathered = "en{$s}GB{$s}oed"
414 . "|i{$s}(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)"
415 . "|no{$s}(?:bok|nyn)"
416 . "|sgn{$s}(?:BE{$s}(?:fr|nl)|CH{$s}de)"
417 . "|zh{$s}min{$s}nan";
418
419 $variantList = "$variant(?:$s$variant)*";
420 $extensionList = "$extension(?:$s$extension)*";
421
422 $langtag = "(?:($language)"
423 . "(?:$s$script)?"
424 . "(?:$s$region)?"
425 . "(?:$s$variantList)?"
426 . "(?:$s$extensionList)?"
427 . "(?:$s$privateUse)?)";
428
429 # The final breakdown, with capturing groups for each of these components
430 # The variants, extensions, grandfathered, and private-use may have interior '-'
431
432 $root = "^(?:$langtag|$privateUse|$grandfathered)$";
433
434 return (bool)preg_match( "/$root/", strtolower( $code ) );
435 }
436
448 public static function isValidCode( $code ) {
449 return MediaWikiServices::getInstance()->getLanguageNameUtils()->isValidCode( $code );
450 }
451
463 public static function isValidBuiltInCode( $code ) {
464 return MediaWikiServices::getInstance()->getLanguageNameUtils()
465 ->isValidBuiltInCode( $code );
466 }
467
478 public static function isKnownLanguageTag( $tag ) {
479 return MediaWikiServices::getInstance()->getLanguageNameUtils()
480 ->isKnownLanguageTag( $tag );
481 }
482
489 public static function getLocalisationCache() {
490 return MediaWikiServices::getInstance()->getLocalisationCache();
491 }
492
503 public function __construct(
504 $code = null,
505 LocalisationCache $localisationCache = null,
506 LanguageNameUtils $langNameUtils = null,
507 LanguageFallback $langFallback = null,
508 LanguageConverterFactory $converterFactory = null,
509 HookContainer $hookContainer = null
510 ) {
511 if ( !func_num_args() ) {
512 // Old calling convention, deprecated
513 if ( static::class === 'Language' ) {
514 $this->mCode = 'en';
515 } else {
516 $this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) );
517 }
518
519 $services = MediaWikiServices::getInstance();
520 $this->localisationCache = $services->getLocalisationCache();
521 $this->langNameUtils = $services->getLanguageNameUtils();
522 $this->langFallback = $services->getLanguageFallback();
523 $this->converterFactory = $services->getLanguageConverterFactory();
524 $this->hookContainer = $services->getHookContainer();
525 $this->hookRunner = new HookRunner( $this->hookContainer );
526 return;
527 }
528
529 Assert::parameter( $code !== null, '$code',
530 'Parameters cannot be null unless all are omitted' );
531 Assert::parameter( $localisationCache !== null, '$localisationCache',
532 'Parameters cannot be null unless all are omitted' );
533 Assert::parameter( $langNameUtils !== null, '$langNameUtils',
534 'Parameters cannot be null unless all are omitted' );
535 Assert::parameter( $langFallback !== null, '$langFallback',
536 'Parameters cannot be null unless all are omitted' );
537 Assert::parameter( $converterFactory !== null, '$converterFactory',
538 'Parameters cannot be null unless all are omitted' );
539 Assert::parameter( $hookContainer !== null, '$hookContainer',
540 'Parameters cannot be null unless all are omitted' );
541
542 $this->mCode = $code;
543 $this->localisationCache = $localisationCache;
544 $this->langNameUtils = $langNameUtils;
545 $this->langFallback = $langFallback;
546 $this->converterFactory = $converterFactory;
547 $this->hookContainer = $hookContainer;
548 $this->hookRunner = new HookRunner( $hookContainer );
549 }
550
555 public function __destruct() {
556 foreach ( $this as $name => $value ) {
557 unset( $this->$name );
558 }
559 }
560
565 public function getFallbackLanguages() {
566 return $this->langFallback->getAll( $this->mCode );
567 }
568
573 public function getBookstoreList() {
574 return $this->localisationCache->getItem( $this->mCode, 'bookstoreList' );
575 }
576
583 public function getNamespaces() {
584 if ( $this->namespaceNames === null ) {
586
587 $validNamespaces = MediaWikiServices::getInstance()->getNamespaceInfo()->
588 getCanonicalNamespaces();
589
590 $this->namespaceNames = $wgExtraNamespaces +
591 $this->localisationCache->getItem( $this->mCode, 'namespaceNames' );
592 $this->namespaceNames += $validNamespaces;
593
594 $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
595 if ( $wgMetaNamespaceTalk ) {
596 $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk;
597 } else {
598 $talk = $this->namespaceNames[NS_PROJECT_TALK];
599 $this->namespaceNames[NS_PROJECT_TALK] =
600 $this->fixVariableInNamespace( $talk );
601 }
602
603 # Sometimes a language will be localised but not actually exist on this wiki.
604 foreach ( $this->namespaceNames as $key => $text ) {
605 if ( !isset( $validNamespaces[$key] ) ) {
606 unset( $this->namespaceNames[$key] );
607 }
608 }
609
610 # The above mixing may leave namespaces out of canonical order.
611 # Re-order by namespace ID number...
612 ksort( $this->namespaceNames );
613
614 $this->getHookRunner()->onLanguageGetNamespaces( $this->namespaceNames );
615 }
616
618 }
619
624 public function setNamespaces( array $namespaces ) {
625 $this->namespaceNames = $namespaces;
626 $this->mNamespaceIds = null;
627 }
628
632 public function resetNamespaces() {
633 $this->namespaceNames = null;
634 $this->mNamespaceIds = null;
635 $this->namespaceAliases = null;
636 }
637
644 public function getFormattedNamespaces() {
645 $ns = $this->getNamespaces();
646 foreach ( $ns as $k => $v ) {
647 $ns[$k] = strtr( $v, '_', ' ' );
648 }
649 return $ns;
650 }
651
663 public function getNsText( $index ) {
664 $ns = $this->getNamespaces();
665 return $ns[$index] ?? false;
666 }
667
681 public function getFormattedNsText( $index ) {
682 $ns = $this->getNsText( $index );
683 return strtr( $ns, '_', ' ' );
684 }
685
694 public function getGenderNsText( $index, $gender ) {
696
698 (array)$this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' );
699
700 return $ns[$index][$gender] ?? $this->getNsText( $index );
701 }
702
709 public function needsGenderDistinction() {
711 if ( count( $wgExtraGenderNamespaces ) > 0 ) {
712 // $wgExtraGenderNamespaces overrides everything
713 return true;
714 } elseif ( isset( $wgExtraNamespaces[NS_USER] ) && isset( $wgExtraNamespaces[NS_USER_TALK] ) ) {
716 // $wgExtraNamespaces overrides any gender aliases specified in i18n files
717 return false;
718 } else {
719 // Check what is in i18n files
720 $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' );
721 return count( $aliases ) > 0;
722 }
723 }
724
733 public function getLocalNsIndex( $text ) {
734 $lctext = $this->lc( $text );
735 $ids = $this->getNamespaceIds();
736 return $ids[$lctext] ?? false;
737 }
738
743 public function getNamespaceAliases() {
744 if ( $this->namespaceAliases === null ) {
745 $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceAliases' );
746 if ( !$aliases ) {
747 $aliases = [];
748 } else {
749 foreach ( $aliases as $name => $index ) {
750 if ( $index === NS_PROJECT_TALK ) {
751 unset( $aliases[$name] );
752 $name = $this->fixVariableInNamespace( $name );
753 $aliases[$name] = $index;
754 }
755 }
756 }
757
759 $genders = $wgExtraGenderNamespaces + (array)$this->localisationCache
760 ->getItem( $this->mCode, 'namespaceGenderAliases' );
761 foreach ( $genders as $index => $forms ) {
762 foreach ( $forms as $alias ) {
763 $aliases[$alias] = $index;
764 }
765 }
766
767 # Also add converted namespace names as aliases, to avoid confusion.
768 $convertedNames = [];
769 foreach ( $this->getConverter()->getVariants() as $variant ) {
770 if ( $variant === $this->mCode ) {
771 continue;
772 }
773 foreach ( $this->getNamespaces() as $ns => $_ ) {
774 $convertedNames[$this->getConverter()->convertNamespace( $ns, $variant )] = $ns;
775 }
776 }
777
778 $this->namespaceAliases = $aliases + $convertedNames;
779
780 // In the case of conflicts between $wgNamespaceAliases and other sources
781 // of aliasing, $wgNamespaceAliases wins.
782 global $wgNamespaceAliases;
783 $this->namespaceAliases = $wgNamespaceAliases + $this->namespaceAliases;
784
785 # Filter out aliases to namespaces that don't exist, e.g. from extensions
786 # that aren't loaded here but are included in the l10n cache.
787 # (array_intersect preserves keys from its first argument)
788 $this->namespaceAliases = array_intersect(
789 $this->namespaceAliases,
790 array_keys( $this->getNamespaces() )
791 );
792 }
793
795 }
796
800 public function getNamespaceIds() {
801 if ( $this->mNamespaceIds === null ) {
802 # Put namespace names and aliases into a hashtable.
803 # If this is too slow, then we should arrange it so that it is done
804 # before caching. The catch is that at pre-cache time, the above
805 # class-specific fixup hasn't been done.
806 $this->mNamespaceIds = [];
807 foreach ( $this->getNamespaces() as $index => $name ) {
808 $this->mNamespaceIds[$this->lc( $name )] = $index;
809 }
810 foreach ( $this->getNamespaceAliases() as $name => $index ) {
811 $this->mNamespaceIds[$this->lc( $name )] = $index;
812 }
813 }
814 return $this->mNamespaceIds;
815 }
816
824 public function getNsIndex( $text ) {
825 $lctext = $this->lc( $text );
826 $ns = MediaWikiServices::getInstance()->getNamespaceInfo()->
827 getCanonicalIndex( $lctext );
828 if ( $ns !== null ) {
829 return $ns;
830 }
831 $ids = $this->getNamespaceIds();
832 return $ids[$lctext] ?? false;
833 }
834
842 public function getVariantname( $code, $usemsg = true ) {
843 $msg = "variantname-$code";
844 if ( $usemsg && wfMessage( $msg )->exists() ) {
845 return $this->getMessageFromDB( $msg );
846 }
847 $name = $this->langNameUtils->getLanguageName( $code );
848 if ( $name ) {
849 return $name; # if it's defined as a language name, show that
850 } else {
851 # otherwise, output the language code
852 return $code;
853 }
854 }
855
859 public function getDatePreferences() {
860 return $this->localisationCache->getItem( $this->mCode, 'datePreferences' );
861 }
862
866 public function getDateFormats() {
867 return $this->localisationCache->getItem( $this->mCode, 'dateFormats' );
868 }
869
873 public function getDefaultDateFormat() {
874 $df = $this->localisationCache->getItem( $this->mCode, 'defaultDateFormat' );
875 if ( $df === 'dmy or mdy' ) {
876 global $wgAmericanDates;
877 return $wgAmericanDates ? 'mdy' : 'dmy';
878 } else {
879 return $df;
880 }
881 }
882
886 public function getDatePreferenceMigrationMap() {
887 return $this->localisationCache->getItem( $this->mCode, 'datePreferenceMigrationMap' );
888 }
889
893 public function getExtraUserToggles() {
894 wfDeprecated( __METHOD__, '1.34' );
895 return [];
896 }
897
913 public static function fetchLanguageNames(
914 $inLanguage = LanguageNameUtils::AUTONYMS,
915 $include = 'mw'
916 ) {
917 return MediaWikiServices::getInstance()->getLanguageNameUtils()
918 ->getLanguageNames( $inLanguage, $include );
919 }
920
930 public static function fetchLanguageName(
931 $code,
932 $inLanguage = LanguageNameUtils::AUTONYMS,
933 $include = LanguageNameUtils::ALL
934 ) {
935 return MediaWikiServices::getInstance()->getLanguageNameUtils()
936 ->getLanguageName( $code, $inLanguage, $include );
937 }
938
945 public function getMessageFromDB( $msg ) {
946 return $this->msg( $msg )->text();
947 }
948
955 protected function msg( $msg ) {
956 return wfMessage( $msg )->inLanguage( $this );
957 }
958
963 public function getMonthName( $key ) {
964 return $this->getMessageFromDB( self::MONTH_MESSAGES[$key - 1] );
965 }
966
970 public function getMonthNamesArray() {
971 $monthNames = [ '' ];
972 for ( $i = 1; $i < 13; $i++ ) {
973 $monthNames[] = $this->getMonthName( $i );
974 }
975 return $monthNames;
976 }
977
982 public function getMonthNameGen( $key ) {
983 return $this->getMessageFromDB( self::MONTH_GENITIVE_MESSAGES[$key - 1] );
984 }
985
990 public function getMonthAbbreviation( $key ) {
991 return $this->getMessageFromDB( self::MONTH_ABBREVIATED_MESSAGES[$key - 1] );
992 }
993
997 public function getMonthAbbreviationsArray() {
998 $monthNames = [ '' ];
999 for ( $i = 1; $i < 13; $i++ ) {
1000 $monthNames[] = $this->getMonthAbbreviation( $i );
1001 }
1002 return $monthNames;
1003 }
1004
1009 public function getWeekdayName( $key ) {
1010 return $this->getMessageFromDB( self::WEEKDAY_MESSAGES[$key - 1] );
1011 }
1012
1017 public function getWeekdayAbbreviation( $key ) {
1018 return $this->getMessageFromDB( self::WEEKDAY_ABBREVIATED_MESSAGES[$key - 1] );
1019 }
1020
1025 private function getIranianCalendarMonthName( $key ) {
1026 return $this->getMessageFromDB( self::IRANIAN_CALENDAR_MONTHS_MESSAGES[$key - 1] );
1027 }
1028
1033 private function getHebrewCalendarMonthName( $key ) {
1034 return $this->getMessageFromDB( self::HEBREW_CALENDAR_MONTHS_MESSAGES[$key - 1] );
1035 }
1036
1041 private function getHebrewCalendarMonthNameGen( $key ) {
1042 return $this->getMessageFromDB( self::HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES[$key - 1] );
1043 }
1044
1049 private function getHijriCalendarMonthName( $key ) {
1050 return $this->getMessageFromDB( self::HIJRI_CALENDAR_MONTH_MESSAGES[$key - 1] );
1051 }
1052
1061 private static function dateTimeObjFormat( &$dateTimeObj, $ts, $zone, $code ) {
1062 if ( !$dateTimeObj ) {
1063 $dateTimeObj = DateTime::createFromFormat(
1064 'YmdHis', $ts, $zone ?: new DateTimeZone( 'UTC' )
1065 );
1066 }
1067 return $dateTimeObj->format( $code );
1068 }
1069
1140 public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = 'unused' ) {
1141 $s = '';
1142 $raw = false;
1143 $roman = false;
1144 $hebrewNum = false;
1145 $dateTimeObj = false;
1146 $rawToggle = false;
1147 $iranian = false;
1148 $hebrew = false;
1149 $hijri = false;
1150 $thai = false;
1151 $minguo = false;
1152 $tenno = false;
1153
1154 $usedSecond = false;
1155 $usedMinute = false;
1156 $usedHour = false;
1157 $usedAMPM = false;
1158 $usedDay = false;
1159 $usedWeek = false;
1160 $usedMonth = false;
1161 $usedYear = false;
1162 $usedISOYear = false;
1163 $usedIsLeapYear = false;
1164
1165 $usedHebrewMonth = false;
1166 $usedIranianMonth = false;
1167 $usedHijriMonth = false;
1168 $usedHebrewYear = false;
1169 $usedIranianYear = false;
1170 $usedHijriYear = false;
1171 $usedTennoYear = false;
1172
1173 if ( strlen( $ts ) !== 14 ) {
1174 throw new MWException( __METHOD__ . ": The timestamp $ts should have 14 characters" );
1175 }
1176
1177 if ( !ctype_digit( $ts ) ) {
1178 throw new MWException( __METHOD__ . ": The timestamp $ts should be a number" );
1179 }
1180
1181 $formatLength = strlen( $format );
1182 for ( $p = 0; $p < $formatLength; $p++ ) {
1183 $num = false;
1184 $code = $format[$p];
1185 if ( $code == 'x' && $p < $formatLength - 1 ) {
1186 $code .= $format[++$p];
1187 }
1188
1189 if ( ( $code === 'xi'
1190 || $code === 'xj'
1191 || $code === 'xk'
1192 || $code === 'xm'
1193 || $code === 'xo'
1194 || $code === 'xt' )
1195 && $p < $formatLength - 1 ) {
1196 $code .= $format[++$p];
1197 }
1198
1199 switch ( $code ) {
1200 case 'xx':
1201 $s .= 'x';
1202 break;
1203 case 'xn':
1204 $raw = true;
1205 break;
1206 case 'xN':
1207 $rawToggle = !$rawToggle;
1208 break;
1209 case 'xr':
1210 $roman = true;
1211 break;
1212 case 'xh':
1213 $hebrewNum = true;
1214 break;
1215 case 'xg':
1216 $usedMonth = true;
1217 $s .= $this->getMonthNameGen( substr( $ts, 4, 2 ) );
1218 break;
1219 case 'xjx':
1220 $usedHebrewMonth = true;
1221 if ( !$hebrew ) {
1222 $hebrew = self::tsToHebrew( $ts );
1223 }
1224 $s .= $this->getHebrewCalendarMonthNameGen( $hebrew[1] );
1225 break;
1226 case 'd':
1227 $usedDay = true;
1228 $num = substr( $ts, 6, 2 );
1229 break;
1230 case 'D':
1231 $usedDay = true;
1232 $s .= $this->getWeekdayAbbreviation(
1233 self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'w' ) + 1
1234 );
1235 break;
1236 case 'j':
1237 $usedDay = true;
1238 $num = intval( substr( $ts, 6, 2 ) );
1239 break;
1240 case 'xij':
1241 $usedDay = true;
1242 if ( !$iranian ) {
1243 $iranian = self::tsToIranian( $ts );
1244 }
1245 $num = $iranian[2];
1246 break;
1247 case 'xmj':
1248 $usedDay = true;
1249 if ( !$hijri ) {
1250 $hijri = self::tsToHijri( $ts );
1251 }
1252 $num = $hijri[2];
1253 break;
1254 case 'xjj':
1255 $usedDay = true;
1256 if ( !$hebrew ) {
1257 $hebrew = self::tsToHebrew( $ts );
1258 }
1259 $num = $hebrew[2];
1260 break;
1261 case 'l':
1262 $usedDay = true;
1263 $s .= $this->getWeekdayName(
1264 self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'w' ) + 1
1265 );
1266 break;
1267 case 'F':
1268 $usedMonth = true;
1269 $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
1270 break;
1271 case 'xiF':
1272 $usedIranianMonth = true;
1273 if ( !$iranian ) {
1274 $iranian = self::tsToIranian( $ts );
1275 }
1276 $s .= $this->getIranianCalendarMonthName( $iranian[1] );
1277 break;
1278 case 'xmF':
1279 $usedHijriMonth = true;
1280 if ( !$hijri ) {
1281 $hijri = self::tsToHijri( $ts );
1282 }
1283 $s .= $this->getHijriCalendarMonthName( $hijri[1] );
1284 break;
1285 case 'xjF':
1286 $usedHebrewMonth = true;
1287 if ( !$hebrew ) {
1288 $hebrew = self::tsToHebrew( $ts );
1289 }
1290 $s .= $this->getHebrewCalendarMonthName( $hebrew[1] );
1291 break;
1292 case 'm':
1293 $usedMonth = true;
1294 $num = substr( $ts, 4, 2 );
1295 break;
1296 case 'M':
1297 $usedMonth = true;
1298 $s .= $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
1299 break;
1300 case 'n':
1301 $usedMonth = true;
1302 $num = intval( substr( $ts, 4, 2 ) );
1303 break;
1304 case 'xin':
1305 $usedIranianMonth = true;
1306 if ( !$iranian ) {
1307 $iranian = self::tsToIranian( $ts );
1308 }
1309 $num = $iranian[1];
1310 break;
1311 case 'xmn':
1312 $usedHijriMonth = true;
1313 if ( !$hijri ) {
1314 $hijri = self::tsToHijri( $ts );
1315 }
1316 $num = $hijri[1];
1317 break;
1318 case 'xjn':
1319 $usedHebrewMonth = true;
1320 if ( !$hebrew ) {
1321 $hebrew = self::tsToHebrew( $ts );
1322 }
1323 $num = $hebrew[1];
1324 break;
1325 case 'xjt':
1326 $usedHebrewMonth = true;
1327 if ( !$hebrew ) {
1328 $hebrew = self::tsToHebrew( $ts );
1329 }
1330 $num = $hebrew[3];
1331 break;
1332 case 'Y':
1333 $usedYear = true;
1334 $num = substr( $ts, 0, 4 );
1335 break;
1336 case 'xiY':
1337 $usedIranianYear = true;
1338 if ( !$iranian ) {
1339 $iranian = self::tsToIranian( $ts );
1340 }
1341 $num = $iranian[0];
1342 break;
1343 case 'xmY':
1344 $usedHijriYear = true;
1345 if ( !$hijri ) {
1346 $hijri = self::tsToHijri( $ts );
1347 }
1348 $num = $hijri[0];
1349 break;
1350 case 'xjY':
1351 $usedHebrewYear = true;
1352 if ( !$hebrew ) {
1353 $hebrew = self::tsToHebrew( $ts );
1354 }
1355 $num = $hebrew[0];
1356 break;
1357 case 'xkY':
1358 $usedYear = true;
1359 if ( !$thai ) {
1360 $thai = self::tsToYear( $ts, 'thai' );
1361 }
1362 $num = $thai[0];
1363 break;
1364 case 'xoY':
1365 $usedYear = true;
1366 if ( !$minguo ) {
1367 $minguo = self::tsToYear( $ts, 'minguo' );
1368 }
1369 $num = $minguo[0];
1370 break;
1371 case 'xtY':
1372 $usedTennoYear = true;
1373 if ( !$tenno ) {
1374 $tenno = self::tsToYear( $ts, 'tenno' );
1375 }
1376 $num = $tenno[0];
1377 break;
1378 case 'y':
1379 $usedYear = true;
1380 $num = substr( $ts, 2, 2 );
1381 break;
1382 case 'xiy':
1383 $usedIranianYear = true;
1384 if ( !$iranian ) {
1385 $iranian = self::tsToIranian( $ts );
1386 }
1387 $num = substr( $iranian[0], -2 );
1388 break;
1389 case 'xit':
1390 $usedIranianYear = true;
1391 if ( !$iranian ) {
1392 $iranian = self::tsToIranian( $ts );
1393 }
1394 $num = self::$IRANIAN_DAYS[$iranian[1] - 1];
1395 break;
1396 case 'xiz':
1397 $usedIranianYear = true;
1398 if ( !$iranian ) {
1399 $iranian = self::tsToIranian( $ts );
1400 }
1401 $num = $iranian[3];
1402 break;
1403 case 'a':
1404 $usedAMPM = true;
1405 $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'am' : 'pm';
1406 break;
1407 case 'A':
1408 $usedAMPM = true;
1409 $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'AM' : 'PM';
1410 break;
1411 case 'g':
1412 $usedHour = true;
1413 $h = substr( $ts, 8, 2 );
1414 $num = $h % 12 ?: 12;
1415 break;
1416 case 'G':
1417 $usedHour = true;
1418 $num = intval( substr( $ts, 8, 2 ) );
1419 break;
1420 case 'h':
1421 $usedHour = true;
1422 $h = substr( $ts, 8, 2 );
1423 $num = sprintf( '%02d', $h % 12 ?: 12 );
1424 break;
1425 case 'H':
1426 $usedHour = true;
1427 $num = substr( $ts, 8, 2 );
1428 break;
1429 case 'i':
1430 $usedMinute = true;
1431 $num = substr( $ts, 10, 2 );
1432 break;
1433 case 's':
1434 $usedSecond = true;
1435 $num = substr( $ts, 12, 2 );
1436 break;
1437 case 'c':
1438 case 'r':
1439 $usedSecond = true;
1440 // fall through
1441 case 'e':
1442 case 'O':
1443 case 'P':
1444 case 'T':
1445 $s .= self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1446 break;
1447 case 'w':
1448 case 'N':
1449 case 'z':
1450 $usedDay = true;
1451 $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1452 break;
1453 case 'W':
1454 $usedWeek = true;
1455 $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1456 break;
1457 case 't':
1458 $usedMonth = true;
1459 $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1460 break;
1461 case 'L':
1462 $usedIsLeapYear = true;
1463 $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1464 break;
1465 case 'o':
1466 $usedISOYear = true;
1467 $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1468 break;
1469 case 'U':
1470 $usedSecond = true;
1471 // fall through
1472 case 'I':
1473 case 'Z':
1474 $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1475 break;
1476 case '\\':
1477 # Backslash escaping
1478 if ( $p < $formatLength - 1 ) {
1479 $s .= $format[++$p];
1480 } else {
1481 $s .= '\\';
1482 }
1483 break;
1484 case '"':
1485 # Quoted literal
1486 if ( $p < $formatLength - 1 ) {
1487 $endQuote = strpos( $format, '"', $p + 1 );
1488 if ( $endQuote === false ) {
1489 # No terminating quote, assume literal "
1490 $s .= '"';
1491 } else {
1492 $s .= substr( $format, $p + 1, $endQuote - $p - 1 );
1493 $p = $endQuote;
1494 }
1495 } else {
1496 # Quote at end of string, assume literal "
1497 $s .= '"';
1498 }
1499 break;
1500 default:
1501 $s .= $format[$p];
1502 }
1503 if ( $num !== false ) {
1504 if ( $rawToggle || $raw ) {
1505 $s .= $num;
1506 $raw = false;
1507 } elseif ( $roman ) {
1508 $s .= self::romanNumeral( $num );
1509 $roman = false;
1510 } elseif ( $hebrewNum ) {
1511 $s .= self::hebrewNumeral( $num );
1512 $hebrewNum = false;
1513 } else {
1514 $s .= $this->formatNum( $num, true );
1515 }
1516 }
1517 }
1518
1519 if ( $ttl === 'unused' ) {
1520 // No need to calculate the TTL, the caller wont use it anyway.
1521 } elseif ( $usedSecond ) {
1522 $ttl = 1;
1523 } elseif ( $usedMinute ) {
1524 $ttl = 60 - substr( $ts, 12, 2 );
1525 } elseif ( $usedHour ) {
1526 $ttl = 3600 - substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1527 } elseif ( $usedAMPM ) {
1528 $ttl = 43200 - ( substr( $ts, 8, 2 ) % 12 ) * 3600 -
1529 substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1530 } elseif (
1531 $usedDay ||
1532 $usedHebrewMonth ||
1533 $usedIranianMonth ||
1534 $usedHijriMonth ||
1535 $usedHebrewYear ||
1536 $usedIranianYear ||
1537 $usedHijriYear ||
1538 $usedTennoYear
1539 ) {
1540 // @todo Someone who understands the non-Gregorian calendars
1541 // should write proper logic for them so that they don't need purged every day.
1542 $ttl = 86400 - substr( $ts, 8, 2 ) * 3600 -
1543 substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1544 } else {
1545 $possibleTtls = [];
1546 $timeRemainingInDay = 86400 - substr( $ts, 8, 2 ) * 3600 -
1547 substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1548 if ( $usedWeek ) {
1549 $possibleTtls[] =
1550 ( 7 - self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'N' ) ) * 86400 +
1551 $timeRemainingInDay;
1552 } elseif ( $usedISOYear ) {
1553 // December 28th falls on the last ISO week of the year, every year.
1554 // The last ISO week of a year can be 52 or 53.
1555 $lastWeekOfISOYear = DateTime::createFromFormat(
1556 'Ymd',
1557 substr( $ts, 0, 4 ) . '1228',
1558 $zone ?: new DateTimeZone( 'UTC' )
1559 )->format( 'W' );
1560 $currentISOWeek = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'W' );
1561 $weeksRemaining = $lastWeekOfISOYear - $currentISOWeek;
1562 $timeRemainingInWeek =
1563 ( 7 - self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'N' ) ) * 86400
1564 + $timeRemainingInDay;
1565 $possibleTtls[] = $weeksRemaining * 604800 + $timeRemainingInWeek;
1566 }
1567
1568 if ( $usedMonth ) {
1569 $possibleTtls[] =
1570 ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 't' ) -
1571 substr( $ts, 6, 2 ) ) * 86400
1572 + $timeRemainingInDay;
1573 } elseif ( $usedYear ) {
1574 $possibleTtls[] =
1575 ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'L' ) + 364 -
1576 self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'z' ) ) * 86400
1577 + $timeRemainingInDay;
1578 } elseif ( $usedIsLeapYear ) {
1579 $year = substr( $ts, 0, 4 );
1580 $timeRemainingInYear =
1581 ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'L' ) + 364 -
1582 self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'z' ) ) * 86400
1583 + $timeRemainingInDay;
1584 $mod = $year % 4;
1585 if ( $mod || ( !( $year % 100 ) && $year % 400 ) ) {
1586 // this isn't a leap year. see when the next one starts
1587 $nextCandidate = $year - $mod + 4;
1588 if ( $nextCandidate % 100 || !( $nextCandidate % 400 ) ) {
1589 $possibleTtls[] = ( $nextCandidate - $year - 1 ) * 365 * 86400 +
1590 $timeRemainingInYear;
1591 } else {
1592 $possibleTtls[] = ( $nextCandidate - $year + 3 ) * 365 * 86400 +
1593 $timeRemainingInYear;
1594 }
1595 } else {
1596 // this is a leap year, so the next year isn't
1597 $possibleTtls[] = $timeRemainingInYear;
1598 }
1599 }
1600
1601 if ( $possibleTtls ) {
1602 $ttl = min( $possibleTtls );
1603 }
1604 }
1605
1606 return $s;
1607 }
1608
1609 private static $GREG_DAYS = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
1610 private static $IRANIAN_DAYS = [ 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 ];
1611
1624 private static function tsToIranian( $ts ) {
1625 $gy = substr( $ts, 0, 4 ) - 1600;
1626 $gm = substr( $ts, 4, 2 ) - 1;
1627 $gd = substr( $ts, 6, 2 ) - 1;
1628
1629 # Days passed from the beginning (including leap years)
1630 $gDayNo = 365 * $gy
1631 + floor( ( $gy + 3 ) / 4 )
1632 - floor( ( $gy + 99 ) / 100 )
1633 + floor( ( $gy + 399 ) / 400 );
1634
1635 // Add days of the past months of this year
1636 for ( $i = 0; $i < $gm; $i++ ) {
1637 $gDayNo += self::$GREG_DAYS[$i];
1638 }
1639
1640 // Leap years
1641 if ( $gm > 1 && ( ( $gy % 4 === 0 && $gy % 100 !== 0 || ( $gy % 400 == 0 ) ) ) ) {
1642 $gDayNo++;
1643 }
1644
1645 // Days passed in current month
1646 $gDayNo += (int)$gd;
1647
1648 $jDayNo = $gDayNo - 79;
1649
1650 $jNp = floor( $jDayNo / 12053 );
1651 $jDayNo %= 12053;
1652
1653 $jy = 979 + 33 * $jNp + 4 * floor( $jDayNo / 1461 );
1654 $jDayNo %= 1461;
1655
1656 if ( $jDayNo >= 366 ) {
1657 $jy += floor( ( $jDayNo - 1 ) / 365 );
1658 $jDayNo = floor( ( $jDayNo - 1 ) % 365 );
1659 }
1660
1661 $jz = $jDayNo;
1662
1663 for ( $i = 0; $i < 11 && $jDayNo >= self::$IRANIAN_DAYS[$i]; $i++ ) {
1664 $jDayNo -= self::$IRANIAN_DAYS[$i];
1665 }
1666
1667 $jm = $i + 1;
1668 $jd = $jDayNo + 1;
1669
1670 return [ $jy, $jm, $jd, $jz ];
1671 }
1672
1684 private static function tsToHijri( $ts ) {
1685 $year = substr( $ts, 0, 4 );
1686 $month = substr( $ts, 4, 2 );
1687 $day = substr( $ts, 6, 2 );
1688
1689 $zyr = $year;
1690 $zd = $day;
1691 $zm = $month;
1692 $zy = $zyr;
1693
1694 if (
1695 ( $zy > 1582 ) || ( ( $zy == 1582 ) && ( $zm > 10 ) ) ||
1696 ( ( $zy == 1582 ) && ( $zm == 10 ) && ( $zd > 14 ) )
1697 ) {
1698 $zjd = (int)( ( 1461 * ( $zy + 4800 + (int)( ( $zm - 14 ) / 12 ) ) ) / 4 ) +
1699 (int)( ( 367 * ( $zm - 2 - 12 * ( (int)( ( $zm - 14 ) / 12 ) ) ) ) / 12 ) -
1700 (int)( ( 3 * (int)( ( ( $zy + 4900 + (int)( ( $zm - 14 ) / 12 ) ) / 100 ) ) ) / 4 ) +
1701 $zd - 32075;
1702 } else {
1703 $zjd = 367 * $zy - (int)( ( 7 * ( $zy + 5001 + (int)( ( $zm - 9 ) / 7 ) ) ) / 4 ) +
1704 (int)( ( 275 * $zm ) / 9 ) + $zd + 1729777;
1705 }
1706
1707 $zl = $zjd - 1948440 + 10632;
1708 $zn = (int)( ( $zl - 1 ) / 10631 );
1709 $zl = $zl - 10631 * $zn + 354;
1710 $zj = ( (int)( ( 10985 - $zl ) / 5316 ) ) * ( (int)( ( 50 * $zl ) / 17719 ) ) +
1711 ( (int)( $zl / 5670 ) ) * ( (int)( ( 43 * $zl ) / 15238 ) );
1712 $zl = $zl - ( (int)( ( 30 - $zj ) / 15 ) ) * ( (int)( ( 17719 * $zj ) / 50 ) ) -
1713 ( (int)( $zj / 16 ) ) * ( (int)( ( 15238 * $zj ) / 43 ) ) + 29;
1714 $zm = (int)( ( 24 * $zl ) / 709 );
1715 $zd = $zl - (int)( ( 709 * $zm ) / 24 );
1716 $zy = 30 * $zn + $zj - 30;
1717
1718 return [ $zy, $zm, $zd ];
1719 }
1720
1736 private static function tsToHebrew( $ts ) {
1737 # Parse date
1738 $year = substr( $ts, 0, 4 );
1739 $month = substr( $ts, 4, 2 );
1740 $day = substr( $ts, 6, 2 );
1741
1742 # Calculate Hebrew year
1743 $hebrewYear = $year + 3760;
1744
1745 # Month number when September = 1, August = 12
1746 $month += 4;
1747 if ( $month > 12 ) {
1748 # Next year
1749 $month -= 12;
1750 $year++;
1751 $hebrewYear++;
1752 }
1753
1754 # Calculate day of year from 1 September
1755 $dayOfYear = $day;
1756 for ( $i = 1; $i < $month; $i++ ) {
1757 if ( $i == 6 ) {
1758 # February
1759 $dayOfYear += 28;
1760 # Check if the year is leap
1761 if ( $year % 400 == 0 || ( $year % 4 == 0 && $year % 100 > 0 ) ) {
1762 $dayOfYear++;
1763 }
1764 } elseif ( $i == 8 || $i == 10 || $i == 1 || $i == 3 ) {
1765 $dayOfYear += 30;
1766 } else {
1767 $dayOfYear += 31;
1768 }
1769 }
1770
1771 # Calculate the start of the Hebrew year
1772 $start = self::hebrewYearStart( $hebrewYear );
1773
1774 # Calculate next year's start
1775 if ( $dayOfYear <= $start ) {
1776 # Day is before the start of the year - it is the previous year
1777 # Next year's start
1778 $nextStart = $start;
1779 # Previous year
1780 $year--;
1781 $hebrewYear--;
1782 # Add days since previous year's 1 September
1783 $dayOfYear += 365;
1784 if ( ( $year % 400 == 0 ) || ( $year % 100 != 0 && $year % 4 == 0 ) ) {
1785 # Leap year
1786 $dayOfYear++;
1787 }
1788 # Start of the new (previous) year
1789 $start = self::hebrewYearStart( $hebrewYear );
1790 } else {
1791 # Next year's start
1792 $nextStart = self::hebrewYearStart( $hebrewYear + 1 );
1793 }
1794
1795 # Calculate Hebrew day of year
1796 $hebrewDayOfYear = $dayOfYear - $start;
1797
1798 # Difference between year's days
1799 $diff = $nextStart - $start;
1800 # Add 12 (or 13 for leap years) days to ignore the difference between
1801 # Hebrew and Gregorian year (353 at least vs. 365/6) - now the
1802 # difference is only about the year type
1803 if ( ( $year % 400 == 0 ) || ( $year % 100 != 0 && $year % 4 == 0 ) ) {
1804 $diff += 13;
1805 } else {
1806 $diff += 12;
1807 }
1808
1809 # Check the year pattern, and is leap year
1810 # 0 means an incomplete year, 1 means a regular year, 2 means a complete year
1811 # This is mod 30, to work on both leap years (which add 30 days of Adar I)
1812 # and non-leap years
1813 $yearPattern = $diff % 30;
1814 # Check if leap year
1815 $isLeap = $diff >= 30;
1816
1817 # Calculate day in the month from number of day in the Hebrew year
1818 # Don't check Adar - if the day is not in Adar, we will stop before;
1819 # if it is in Adar, we will use it to check if it is Adar I or Adar II
1820 $hebrewDay = $hebrewDayOfYear;
1821 $hebrewMonth = 1;
1822 $days = 0;
1823 while ( $hebrewMonth <= 12 ) {
1824 # Calculate days in this month
1825 if ( $isLeap && $hebrewMonth == 6 ) {
1826 # Leap year - has Adar I, with 30 days, and Adar II, with 29 days
1827 $days = 30;
1828 if ( $hebrewDay <= $days ) {
1829 # Day in Adar I
1830 $hebrewMonth = 13;
1831 } else {
1832 # Subtract the days of Adar I
1833 $hebrewDay -= $days;
1834 # Try Adar II
1835 $days = 29;
1836 if ( $hebrewDay <= $days ) {
1837 # Day in Adar II
1838 $hebrewMonth = 14;
1839 }
1840 }
1841 } elseif ( $hebrewMonth == 2 && $yearPattern == 2 ) {
1842 # Cheshvan in a complete year (otherwise as the rule below)
1843 $days = 30;
1844 } elseif ( $hebrewMonth == 3 && $yearPattern == 0 ) {
1845 # Kislev in an incomplete year (otherwise as the rule below)
1846 $days = 29;
1847 } else {
1848 # Odd months have 30 days, even have 29
1849 $days = 30 - ( $hebrewMonth - 1 ) % 2;
1850 }
1851 if ( $hebrewDay <= $days ) {
1852 # In the current month
1853 break;
1854 } else {
1855 # Subtract the days of the current month
1856 $hebrewDay -= $days;
1857 # Try in the next month
1858 $hebrewMonth++;
1859 }
1860 }
1861
1862 return [ $hebrewYear, $hebrewMonth, $hebrewDay, $days ];
1863 }
1864
1874 private static function hebrewYearStart( $year ) {
1875 $a = ( 12 * ( $year - 1 ) + 17 ) % 19;
1876 $b = ( $year - 1 ) % 4;
1877 $m = 32.044093161144 + 1.5542417966212 * $a + $b / 4.0 - 0.0031777940220923 * ( $year - 1 );
1878 if ( $m < 0 ) {
1879 $m--;
1880 }
1881 $Mar = intval( $m );
1882 if ( $m < 0 ) {
1883 $m++;
1884 }
1885 $m -= $Mar;
1886
1887 $c = ( $Mar + 3 * ( $year - 1 ) + 5 * $b + 5 ) % 7;
1888 if ( $c == 0 && $a > 11 && $m >= 0.89772376543210 ) {
1889 $Mar++;
1890 } elseif ( $c == 1 && $a > 6 && $m >= 0.63287037037037 ) {
1891 $Mar += 2;
1892 } elseif ( $c == 2 || $c == 4 || $c == 6 ) {
1893 $Mar++;
1894 }
1895
1896 $Mar += intval( ( $year - 3761 ) / 100 ) - intval( ( $year - 3761 ) / 400 ) - 24;
1897 return $Mar;
1898 }
1899
1912 private static function tsToYear( $ts, $cName ) {
1913 $gy = substr( $ts, 0, 4 );
1914 $gm = substr( $ts, 4, 2 );
1915 $gd = substr( $ts, 6, 2 );
1916
1917 if ( !strcmp( $cName, 'thai' ) ) {
1918 # Thai solar dates
1919 # Add 543 years to the Gregorian calendar
1920 # Months and days are identical
1921 $gy_offset = $gy + 543;
1922 # fix for dates between 1912 and 1941
1923 # https://en.wikipedia.org/?oldid=836596673#New_year
1924 if ( $gy >= 1912 && $gy <= 1940 ) {
1925 if ( $gm <= 3 ) {
1926 $gy_offset--;
1927 }
1928 $gm = ( $gm - 3 ) % 12;
1929 }
1930 } elseif ( ( !strcmp( $cName, 'minguo' ) ) || !strcmp( $cName, 'juche' ) ) {
1931 # Minguo dates
1932 # Deduct 1911 years from the Gregorian calendar
1933 # Months and days are identical
1934 $gy_offset = $gy - 1911;
1935 } elseif ( !strcmp( $cName, 'tenno' ) ) {
1936 # Nengō dates up to Meiji period
1937 # Deduct years from the Gregorian calendar
1938 # depending on the nengo periods
1939 # Months and days are identical
1940 if ( ( $gy < 1912 )
1941 || ( ( $gy == 1912 ) && ( $gm < 7 ) )
1942 || ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd < 31 ) )
1943 ) {
1944 # Meiji period
1945 $gy_gannen = $gy - 1868 + 1;
1946 $gy_offset = $gy_gannen;
1947 if ( $gy_gannen == 1 ) {
1948 $gy_offset = '元';
1949 }
1950 $gy_offset = '明治' . $gy_offset;
1951 } elseif (
1952 ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd == 31 ) ) ||
1953 ( ( $gy == 1912 ) && ( $gm >= 8 ) ) ||
1954 ( ( $gy > 1912 ) && ( $gy < 1926 ) ) ||
1955 ( ( $gy == 1926 ) && ( $gm < 12 ) ) ||
1956 ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd < 26 ) )
1957 ) {
1958 # Taishō period
1959 $gy_gannen = $gy - 1912 + 1;
1960 $gy_offset = $gy_gannen;
1961 if ( $gy_gannen == 1 ) {
1962 $gy_offset = '元';
1963 }
1964 $gy_offset = '大正' . $gy_offset;
1965 } elseif (
1966 ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd >= 26 ) ) ||
1967 ( ( $gy > 1926 ) && ( $gy < 1989 ) ) ||
1968 ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd < 8 ) )
1969 ) {
1970 # Shōwa period
1971 $gy_gannen = $gy - 1926 + 1;
1972 $gy_offset = $gy_gannen;
1973 if ( $gy_gannen == 1 ) {
1974 $gy_offset = '元';
1975 }
1976 $gy_offset = '昭和' . $gy_offset;
1977 } elseif (
1978 ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd >= 8 ) ) ||
1979 ( ( $gy > 1989 ) && ( $gy < 2019 ) ) ||
1980 ( ( $gy == 2019 ) && ( $gm < 5 ) )
1981 ) {
1982 # Heisei period
1983 $gy_gannen = $gy - 1989 + 1;
1984 $gy_offset = $gy_gannen;
1985 if ( $gy_gannen == 1 ) {
1986 $gy_offset = '元';
1987 }
1988 $gy_offset = '平成' . $gy_offset;
1989 } else {
1990 # Reiwa period
1991 $gy_gannen = $gy - 2019 + 1;
1992 $gy_offset = $gy_gannen;
1993 if ( $gy_gannen == 1 ) {
1994 $gy_offset = '元';
1995 }
1996 $gy_offset = '令和' . $gy_offset;
1997 }
1998 } else {
1999 $gy_offset = $gy;
2000 }
2001
2002 return [ $gy_offset, $gm, $gd ];
2003 }
2004
2018 private static function strongDirFromContent( $text = '' ) {
2019 if ( !preg_match( self::$strongDirRegex, $text, $matches ) ) {
2020 return null;
2021 }
2022 if ( $matches[1] === '' ) {
2023 return 'rtl';
2024 }
2025 return 'ltr';
2026 }
2027
2035 public static function romanNumeral( $num ) {
2036 static $table = [
2037 [ '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ],
2038 [ '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ],
2039 [ '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ],
2040 [ '', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM', 'MMMMMM', 'MMMMMMM',
2041 'MMMMMMMM', 'MMMMMMMMM', 'MMMMMMMMMM' ]
2042 ];
2043
2044 $num = intval( $num );
2045 if ( $num > 10000 || $num <= 0 ) {
2046 return $num;
2047 }
2048
2049 $s = '';
2050 for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) {
2051 if ( $num >= $pow10 ) {
2052 $s .= $table[$i][(int)floor( $num / $pow10 )];
2053 }
2054 $num %= $pow10;
2055 }
2056 return $s;
2057 }
2058
2066 public static function hebrewNumeral( $num ) {
2067 static $table = [
2068 [ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ],
2069 [ '', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ', 'ק' ],
2070 [ '',
2071 [ 'ק' ],
2072 [ 'ר' ],
2073 [ 'ש' ],
2074 [ 'ת' ],
2075 [ 'ת', 'ק' ],
2076 [ 'ת', 'ר' ],
2077 [ 'ת', 'ש' ],
2078 [ 'ת', 'ת' ],
2079 [ 'ת', 'ת', 'ק' ],
2080 [ 'ת', 'ת', 'ר' ],
2081 ],
2082 [ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ]
2083 ];
2084
2085 $num = intval( $num );
2086 if ( $num > 9999 || $num <= 0 ) {
2087 return $num;
2088 }
2089
2090 // Round thousands have special notations
2091 if ( $num === 1000 ) {
2092 return "א' אלף";
2093 } elseif ( $num % 1000 === 0 ) {
2094 return $table[0][$num / 1000] . "' אלפים";
2095 }
2096
2097 $letters = [];
2098
2099 for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) {
2100 if ( $num >= $pow10 ) {
2101 if ( $num === 15 || $num === 16 ) {
2102 $letters[] = $table[0][9];
2103 $letters[] = $table[0][$num - 9];
2104 $num = 0;
2105 } else {
2106 $letters = array_merge(
2107 $letters,
2108 (array)$table[$i][intval( $num / $pow10 )]
2109 );
2110
2111 if ( $pow10 === 1000 ) {
2112 $letters[] = "'";
2113 }
2114 }
2115 }
2116
2117 $num %= $pow10;
2118 }
2119
2120 $preTransformLength = count( $letters );
2121 if ( $preTransformLength === 1 ) {
2122 // Add geresh (single quote) to one-letter numbers
2123 $letters[] = "'";
2124 } else {
2125 $lastIndex = $preTransformLength - 1;
2126 $letters[$lastIndex] = str_replace(
2127 [ 'כ', 'מ', 'נ', 'פ', 'צ' ],
2128 [ 'ך', 'ם', 'ן', 'ף', 'ץ' ],
2129 $letters[$lastIndex]
2130 );
2131
2132 // Add gershayim (double quote) to multiple-letter numbers,
2133 // but exclude numbers with only one letter after the thousands
2134 // (1001-1009, 1020, 1030, 2001-2009, etc.)
2135 if ( $letters[1] === "'" && $preTransformLength === 3 ) {
2136 $letters[] = "'";
2137 } else {
2138 array_splice( $letters, -1, 0, '"' );
2139 }
2140 }
2141
2142 return implode( $letters );
2143 }
2144
2153 public function userAdjust( $ts, $tz = false ) {
2154 global $wgUser, $wgLocalTZoffset;
2155
2156 if ( $tz === false ) {
2157 $tz = $wgUser->getOption( 'timecorrection' );
2158 }
2159
2160 $data = explode( '|', $tz, 3 );
2161
2162 if ( $data[0] == 'ZoneInfo' ) {
2163 try {
2164 $userTZ = new DateTimeZone( $data[2] );
2165 $date = new DateTime( $ts, new DateTimeZone( 'UTC' ) );
2166 $date->setTimezone( $userTZ );
2167 return $date->format( 'YmdHis' );
2168 } catch ( Exception $e ) {
2169 // Unrecognized timezone, default to 'Offset' with the stored offset.
2170 $data[0] = 'Offset';
2171 }
2172 }
2173
2174 // @phan-suppress-next-line PhanSuspiciousValueComparison
2175 if ( $data[0] == 'System' || $tz == '' ) {
2176 # Global offset in minutes.
2177 $minDiff = $wgLocalTZoffset;
2178 } elseif ( $data[0] == 'Offset' ) {
2179 $minDiff = intval( $data[1] );
2180 } else {
2181 $data = explode( ':', $tz );
2182 if ( count( $data ) == 2 ) {
2183 $data[0] = intval( $data[0] );
2184 $data[1] = intval( $data[1] );
2185 $minDiff = abs( $data[0] ) * 60 + $data[1];
2186 if ( $data[0] < 0 ) {
2187 $minDiff = -$minDiff;
2188 }
2189 } else {
2190 $minDiff = intval( $data[0] ) * 60;
2191 }
2192 }
2193
2194 # No difference ? Return time unchanged
2195 if ( $minDiff == 0 ) {
2196 return $ts;
2197 }
2198
2199 Wikimedia\suppressWarnings(); // E_STRICT system time bitching
2200 # Generate an adjusted date; take advantage of the fact that mktime
2201 # will normalize out-of-range values so we don't have to split $minDiff
2202 # into hours and minutes.
2203 $t = mktime( (
2204 (int)substr( $ts, 8, 2 ) ), # Hours
2205 (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
2206 (int)substr( $ts, 12, 2 ), # Seconds
2207 (int)substr( $ts, 4, 2 ), # Month
2208 (int)substr( $ts, 6, 2 ), # Day
2209 (int)substr( $ts, 0, 4 ) ); # Year
2210
2211 $date = date( 'YmdHis', $t );
2212 Wikimedia\restoreWarnings();
2213
2214 return $date;
2215 }
2216
2232 public function dateFormat( $usePrefs = true ) {
2233 global $wgUser;
2234
2235 if ( is_bool( $usePrefs ) ) {
2236 if ( $usePrefs ) {
2237 $datePreference = $wgUser->getDatePreference();
2238 } else {
2239 $datePreference = (string)User::getDefaultOption( 'date' );
2240 }
2241 } else {
2242 $datePreference = (string)$usePrefs;
2243 }
2244
2245 // return int
2246 if ( $datePreference == '' ) {
2247 return 'default';
2248 }
2249
2250 return $datePreference;
2251 }
2252
2263 public function getDateFormatString( $type, $pref ) {
2264 $wasDefault = false;
2265 if ( $pref == 'default' ) {
2266 $wasDefault = true;
2267 $pref = $this->getDefaultDateFormat();
2268 }
2269
2270 if ( !isset( $this->dateFormatStrings[$type][$pref] ) ) {
2271 $df = $this->localisationCache
2272 ->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
2273
2274 if ( $type === 'pretty' && $df === null ) {
2275 $df = $this->getDateFormatString( 'date', $pref );
2276 }
2277
2278 if ( !$wasDefault && $df === null ) {
2279 $pref = $this->getDefaultDateFormat();
2280 $df = $this->localisationCache
2281 ->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
2282 }
2283
2284 $this->dateFormatStrings[$type][$pref] = $df;
2285 }
2286 return $this->dateFormatStrings[$type][$pref];
2287 }
2288
2299 public function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
2300 $ts = wfTimestamp( TS_MW, $ts );
2301 if ( $adj ) {
2302 $ts = $this->userAdjust( $ts, $timecorrection );
2303 }
2304 $df = $this->getDateFormatString( 'date', $this->dateFormat( $format ) );
2305 return $this->sprintfDate( $df, $ts );
2306 }
2307
2318 public function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
2319 $ts = wfTimestamp( TS_MW, $ts );
2320 if ( $adj ) {
2321 $ts = $this->userAdjust( $ts, $timecorrection );
2322 }
2323 $df = $this->getDateFormatString( 'time', $this->dateFormat( $format ) );
2324 return $this->sprintfDate( $df, $ts );
2325 }
2326
2338 public function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false ) {
2339 $ts = wfTimestamp( TS_MW, $ts );
2340 if ( $adj ) {
2341 $ts = $this->userAdjust( $ts, $timecorrection );
2342 }
2343 $df = $this->getDateFormatString( 'both', $this->dateFormat( $format ) );
2344 return $this->sprintfDate( $df, $ts );
2345 }
2346
2357 public function formatDuration( $seconds, array $chosenIntervals = [] ) {
2358 $intervals = $this->getDurationIntervals( $seconds, $chosenIntervals );
2359
2360 $segments = [];
2361
2362 foreach ( $intervals as $intervalName => $intervalValue ) {
2363 // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
2364 // duration-years, duration-decades, duration-centuries, duration-millennia
2365 $message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
2366 $segments[] = $message->inLanguage( $this )->escaped();
2367 }
2368
2369 return $this->listToText( $segments );
2370 }
2371
2383 public function getDurationIntervals( $seconds, array $chosenIntervals = [] ) {
2384 if ( empty( $chosenIntervals ) ) {
2385 $chosenIntervals = [
2386 'millennia',
2387 'centuries',
2388 'decades',
2389 'years',
2390 'days',
2391 'hours',
2392 'minutes',
2393 'seconds'
2394 ];
2395 }
2396
2397 $intervals = array_intersect_key( self::DURATION_INTERVALS, array_flip( $chosenIntervals ) );
2398 $sortedNames = array_keys( $intervals );
2399 $smallestInterval = array_pop( $sortedNames );
2400
2401 $segments = [];
2402
2403 foreach ( $intervals as $name => $length ) {
2404 $value = floor( $seconds / $length );
2405
2406 if ( $value > 0 || ( $name == $smallestInterval && empty( $segments ) ) ) {
2407 $seconds -= $value * $length;
2408 $segments[$name] = $value;
2409 }
2410 }
2411
2412 return $segments;
2413 }
2414
2434 private function internalUserTimeAndDate( $type, $ts, User $user, array $options ) {
2435 $ts = wfTimestamp( TS_MW, $ts );
2436 $options += [ 'timecorrection' => true, 'format' => true ];
2437 if ( $options['timecorrection'] !== false ) {
2438 if ( $options['timecorrection'] === true ) {
2439 $offset = $user->getOption( 'timecorrection' );
2440 } else {
2441 $offset = $options['timecorrection'];
2442 }
2443 $ts = $this->userAdjust( $ts, $offset );
2444 }
2445 if ( $options['format'] === true ) {
2446 $format = $user->getDatePreference();
2447 } else {
2448 $format = $options['format'];
2449 }
2450 $df = $this->getDateFormatString( $type, $this->dateFormat( $format ) );
2451 return $this->sprintfDate( $df, $ts );
2452 }
2453
2473 public function userDate( $ts, User $user, array $options = [] ) {
2474 return $this->internalUserTimeAndDate( 'date', $ts, $user, $options );
2475 }
2476
2496 public function userTime( $ts, User $user, array $options = [] ) {
2497 return $this->internalUserTimeAndDate( 'time', $ts, $user, $options );
2498 }
2499
2519 public function userTimeAndDate( $ts, User $user, array $options = [] ) {
2520 return $this->internalUserTimeAndDate( 'both', $ts, $user, $options );
2521 }
2522
2538 public function getHumanTimestamp(
2539 MWTimestamp $time, MWTimestamp $relativeTo = null, User $user = null
2540 ) {
2541 if ( $relativeTo === null ) {
2542 $relativeTo = new MWTimestamp();
2543 }
2544 if ( $user === null ) {
2545 $user = RequestContext::getMain()->getUser();
2546 }
2547
2548 // Adjust for the user's timezone.
2549 $offsetThis = $time->offsetForUser( $user );
2550 $offsetRel = $relativeTo->offsetForUser( $user );
2551
2552 $ts = '';
2553 if ( $this->getHookRunner()->onGetHumanTimestamp( $ts, $time, $relativeTo, $user, $this ) ) {
2554 $ts = $this->getHumanTimestampInternal( $time, $relativeTo, $user );
2555 }
2556
2557 // Reset the timezone on the objects.
2558 $time->timestamp->sub( $offsetThis );
2559 $relativeTo->timestamp->sub( $offsetRel );
2560
2561 return $ts;
2562 }
2563
2576 MWTimestamp $ts, MWTimestamp $relativeTo, User $user
2577 ) {
2578 $diff = $ts->diff( $relativeTo );
2579 $diffDay = (bool)( (int)$ts->timestamp->format( 'w' ) -
2580 (int)$relativeTo->timestamp->format( 'w' ) );
2581 $days = $diff->days ?: (int)$diffDay;
2582 if ( $diff->invert || $days > 5
2583 && $ts->timestamp->format( 'Y' ) !== $relativeTo->timestamp->format( 'Y' )
2584 ) {
2585 // Timestamps are in different years: use full timestamp
2586 // Also do full timestamp for future dates
2590 $format = $this->getDateFormatString( 'both', $user->getDatePreference() ?: 'default' );
2591 $ts = $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) );
2592 } elseif ( $days > 5 ) {
2593 // Timestamps are in same year, but more than 5 days ago: show day and month only.
2594 $format = $this->getDateFormatString( 'pretty', $user->getDatePreference() ?: 'default' );
2595 $ts = $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) );
2596 } elseif ( $days > 1 ) {
2597 // Timestamp within the past week: show the day of the week and time
2598 $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2599 $weekday = self::WEEKDAY_MESSAGES[$ts->timestamp->format( 'w' )];
2600 // Messages:
2601 // sunday-at, monday-at, tuesday-at, wednesday-at, thursday-at, friday-at, saturday-at
2602 $ts = wfMessage( "$weekday-at" )
2603 ->inLanguage( $this )
2604 ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2605 ->text();
2606 } elseif ( $days == 1 ) {
2607 // Timestamp was yesterday: say 'yesterday' and the time.
2608 $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2609 $ts = wfMessage( 'yesterday-at' )
2610 ->inLanguage( $this )
2611 ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2612 ->text();
2613 } elseif ( $diff->h > 1 || $diff->h == 1 && $diff->i > 30 ) {
2614 // Timestamp was today, but more than 90 minutes ago: say 'today' and the time.
2615 $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2616 $ts = wfMessage( 'today-at' )
2617 ->inLanguage( $this )
2618 ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2619 ->text();
2620
2621 // From here on in, the timestamp was soon enough ago so that we can simply say
2622 // XX units ago, e.g., "2 hours ago" or "5 minutes ago"
2623 } elseif ( $diff->h == 1 ) {
2624 // Less than 90 minutes, but more than an hour ago.
2625 $ts = wfMessage( 'hours-ago' )->inLanguage( $this )->numParams( 1 )->text();
2626 } elseif ( $diff->i >= 1 ) {
2627 // A few minutes ago.
2628 $ts = wfMessage( 'minutes-ago' )->inLanguage( $this )->numParams( $diff->i )->text();
2629 } elseif ( $diff->s >= 30 ) {
2630 // Less than a minute, but more than 30 sec ago.
2631 $ts = wfMessage( 'seconds-ago' )->inLanguage( $this )->numParams( $diff->s )->text();
2632 } else {
2633 // Less than 30 seconds ago.
2634 $ts = wfMessage( 'just-now' )->text();
2635 }
2636
2637 return $ts;
2638 }
2639
2644 public function getMessage( $key ) {
2645 return $this->localisationCache->getSubitem( $this->mCode, 'messages', $key );
2646 }
2647
2651 public function getAllMessages() {
2652 return $this->localisationCache->getItem( $this->mCode, 'messages' );
2653 }
2654
2661 public function iconv( $in, $out, $string ) {
2662 # Even with //IGNORE iconv can whine about illegal characters in
2663 # *input* string. We just ignore those too.
2664 # REF: https://bugs.php.net/bug.php?id=37166
2665 # REF: https://phabricator.wikimedia.org/T18885
2666 Wikimedia\suppressWarnings();
2667 $text = iconv( $in, $out . '//IGNORE', $string );
2668 Wikimedia\restoreWarnings();
2669 return $text;
2670 }
2671
2676 public function ucfirst( $str ) {
2677 $octetCode = ord( $str );
2678 // See https://en.wikipedia.org/wiki/ASCII#Printable_characters
2679 if ( $octetCode < 96 ) {
2680 // Assume this is an uppercase/uncased ASCII character
2681 return (string)$str;
2682 } elseif ( $octetCode < 128 ) {
2683 // Assume this is a lowercase/uncased ASCII character
2684 return ucfirst( $str );
2685 }
2686
2687 $first = mb_substr( $str, 0, 1 );
2688 return ( strlen( $first ) !== 1 )
2689 // Assume this is a multibyte character and mb_internal_encoding() is appropriate
2690 ? $this->mbUpperChar( $first ) . mb_substr( $str, 1 )
2691 // Assume this is a non-multibyte character and LC_CASE is appropriate
2692 : ucfirst( $str );
2693 }
2694
2700 public function uc( $str, $first = false ) {
2701 if ( $first ) {
2702 return $this->ucfirst( $str );
2703 } else {
2704 return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
2705 }
2706 }
2707
2721 protected function mbUpperChar( $char ) {
2723
2724 return $wgOverrideUcfirstCharacters[$char] ?? mb_strtoupper( $char );
2725 }
2726
2731 public function lcfirst( $str ) {
2732 $octetCode = ord( $str );
2733 // See https://en.wikipedia.org/wiki/ASCII#Printable_characters
2734 if ( $octetCode < 96 ) {
2735 // Assume this is an uppercase/uncased ASCII character
2736 return lcfirst( $str );
2737 } elseif ( $octetCode < 128 ) {
2738 // Assume this is a lowercase/uncased ASCII character
2739 return (string)$str;
2740 }
2741
2742 return $this->isMultibyte( $str )
2743 // Assume this is a multibyte character and mb_internal_encoding() is appropriate
2744 ? mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 )
2745 // Assume this is a non-multibyte character and LC_CASE is appropriate
2746 : lcfirst( $str );
2747 }
2748
2754 public function lc( $str, $first = false ) {
2755 if ( $first ) {
2756 return $this->lcfirst( $str );
2757 } else {
2758 return $this->isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
2759 }
2760 }
2761
2766 private function isMultibyte( $str ) {
2767 return strlen( $str ) !== mb_strlen( $str );
2768 }
2769
2774 public function ucwords( $str ) {
2775 if ( $this->isMultibyte( $str ) ) {
2776 $str = $this->lc( $str );
2777
2778 // regexp to find first letter in each word (i.e. after each space)
2779 $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
2780
2781 // function to use to capitalize a single char
2782 return preg_replace_callback(
2783 $replaceRegexp,
2784 function ( $matches ) {
2785 return mb_strtoupper( $matches[0] );
2786 },
2787 $str
2788 );
2789 } else {
2790 return ucwords( strtolower( $str ) );
2791 }
2792 }
2793
2800 public function ucwordbreaks( $str ) {
2801 if ( $this->isMultibyte( $str ) ) {
2802 $str = $this->lc( $str );
2803
2804 // since \b doesn't work for UTF-8, we explicitely define word break chars
2805 $breaks = "[ \-\‍(\‍)\}\{\.,\?!]";
2806
2807 // find first letter after word break
2808 $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|" .
2809 "$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
2810
2811 return preg_replace_callback(
2812 $replaceRegexp,
2813 function ( $matches ) {
2814 return mb_strtoupper( $matches[0] );
2815 },
2816 $str
2817 );
2818 } else {
2819 return preg_replace_callback(
2820 '/\b([\w\x80-\xff]+)\b/',
2821 function ( $matches ) {
2822 return $this->ucfirst( $matches[1] );
2823 },
2824 $str
2825 );
2826 }
2827 }
2828
2844 public function caseFold( $s ) {
2845 return $this->uc( $s );
2846 }
2847
2853 public function checkTitleEncoding( $s ) {
2854 if ( is_array( $s ) ) {
2855 throw new MWException( 'Given array to checkTitleEncoding.' );
2856 }
2857 if ( StringUtils::isUtf8( $s ) ) {
2858 return $s;
2859 }
2860
2861 return $this->iconv( $this->fallback8bitEncoding(), 'utf-8', $s );
2862 }
2863
2867 public function fallback8bitEncoding() {
2868 return $this->localisationCache->getItem( $this->mCode, 'fallback8bitEncoding' );
2869 }
2870
2879 public function hasWordBreaks() {
2880 return true;
2881 }
2882
2890 public function segmentByWord( $string ) {
2891 return $string;
2892 }
2893
2901 public function normalizeForSearch( $string ) {
2902 return self::convertDoubleWidth( $string );
2903 }
2904
2913 protected static function convertDoubleWidth( $string ) {
2914 static $full = null;
2915 static $half = null;
2916
2917 if ( $full === null ) {
2918 $fullWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2919 $halfWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2920 $full = str_split( $fullWidth, 3 );
2921 $half = str_split( $halfWidth );
2922 }
2923
2924 $string = str_replace( $full, $half, $string );
2925 return $string;
2926 }
2927
2933 protected static function insertSpace( $string, $pattern ) {
2934 $string = preg_replace( $pattern, " $1 ", $string );
2935 $string = preg_replace( '/ +/', ' ', $string );
2936 return $string;
2937 }
2938
2943 public function convertForSearchResult( $termsArray ) {
2944 # some languages, e.g. Chinese, need to do a conversion
2945 # in order for search results to be displayed correctly
2946 return $termsArray;
2947 }
2948
2955 public function firstChar( $s ) {
2956 $firstChar = mb_substr( $s, 0, 1 );
2957
2958 if ( $firstChar !== false ) {
2959 if ( strlen( $firstChar ) != 3 ) {
2960 return $firstChar;
2961 }
2962
2963 // Break down Hangul syllables to grab the first jamo
2964 $code = mb_ord( $firstChar );
2965 if ( $code < 0xac00 || $code >= 0xd7a4 ) {
2966 return $firstChar;
2967 } elseif ( $code < 0xb098 ) {
2968 return "\u{3131}";
2969 } elseif ( $code < 0xb2e4 ) {
2970 return "\u{3134}";
2971 } elseif ( $code < 0xb77c ) {
2972 return "\u{3137}";
2973 } elseif ( $code < 0xb9c8 ) {
2974 return "\u{3139}";
2975 } elseif ( $code < 0xbc14 ) {
2976 return "\u{3141}";
2977 } elseif ( $code < 0xc0ac ) {
2978 return "\u{3142}";
2979 } elseif ( $code < 0xc544 ) {
2980 return "\u{3145}";
2981 } elseif ( $code < 0xc790 ) {
2982 return "\u{3147}";
2983 } elseif ( $code < 0xcc28 ) {
2984 return "\u{3148}";
2985 } elseif ( $code < 0xce74 ) {
2986 return "\u{314A}";
2987 } elseif ( $code < 0xd0c0 ) {
2988 return "\u{314B}";
2989 } elseif ( $code < 0xd30c ) {
2990 return "\u{314C}";
2991 } elseif ( $code < 0xd558 ) {
2992 return "\u{314D}";
2993 } else {
2994 return "\u{314E}";
2995 }
2996 }
2997
2998 return '';
2999 }
3000
3012 public function normalize( $s ) {
3013 global $wgAllUnicodeFixes, $IP;
3014
3015 $s = UtfNormal\Validator::cleanUp( $s );
3016 if ( $wgAllUnicodeFixes ) {
3017 $s = $this->transformUsingPairFile( 'normalize-ar.php', $s, $IP );
3018 $s = $this->transformUsingPairFile( 'normalize-ml.php', $s, $IP );
3019 }
3020
3021 return $s;
3022 }
3023
3039 protected function transformUsingPairFile( $file, $string, $basePath = null ) {
3040 if ( isset( $this->transformData[$file] ) ) {
3042 'Modification of Language::$transformData is deprecated since MediaWiki 1.35',
3043 '1.35'
3044 );
3045 return $this->transformData[$file]->replace( $string );
3046 }
3047
3048 if ( $basePath === null ) {
3049 wfDeprecated( __METHOD__ . ' without $basePath', '1.35' );
3050 global $IP;
3051 $basePath = $IP;
3052 }
3053
3054 if (
3055 $basePath === null
3056 || $basePath === ''
3057 || !file_exists( "{$basePath}/languages/data/{$file}" )
3058 ) {
3059 return $string;
3060 }
3061
3062 if ( !isset( $this->transformData[$basePath][$file] ) ) {
3063 $data = require "{$basePath}/languages/data/{$file}";
3064 $this->transformData[$basePath][$file] = new ReplacementArray( $data );
3065 }
3066
3067 return $this->transformData[$basePath][$file]->replace( $string );
3068 }
3069
3075 public function isRTL() {
3076 return $this->localisationCache->getItem( $this->mCode, 'rtl' );
3077 }
3078
3083 public function getDir() {
3084 return $this->isRTL() ? 'rtl' : 'ltr';
3085 }
3086
3095 public function alignStart() {
3096 return $this->isRTL() ? 'right' : 'left';
3097 }
3098
3107 public function alignEnd() {
3108 return $this->isRTL() ? 'left' : 'right';
3109 }
3110
3122 public function getDirMarkEntity( $opposite = false ) {
3123 if ( $opposite ) {
3124 return $this->isRTL() ? '&lrm;' : '&rlm;';
3125 }
3126 return $this->isRTL() ? '&rlm;' : '&lrm;';
3127 }
3128
3139 public function getDirMark( $opposite = false ) {
3140 $lrm = "\u{200E}"; # LEFT-TO-RIGHT MARK, commonly abbreviated LRM
3141 $rlm = "\u{200F}"; # RIGHT-TO-LEFT MARK, commonly abbreviated RLM
3142 if ( $opposite ) {
3143 return $this->isRTL() ? $lrm : $rlm;
3144 }
3145 return $this->isRTL() ? $rlm : $lrm;
3146 }
3147
3151 public function capitalizeAllNouns() {
3152 return $this->localisationCache->getItem( $this->mCode, 'capitalizeAllNouns' );
3153 }
3154
3162 public function getArrow( $direction = 'forwards' ) {
3163 switch ( $direction ) {
3164 case 'forwards':
3165 return $this->isRTL() ? '←' : '→';
3166 case 'backwards':
3167 return $this->isRTL() ? '→' : '←';
3168 case 'left':
3169 return '←';
3170 case 'right':
3171 return '→';
3172 case 'up':
3173 return '↑';
3174 case 'down':
3175 return '↓';
3176 }
3177 }
3178
3184 public function linkPrefixExtension() {
3185 return $this->localisationCache->getItem( $this->mCode, 'linkPrefixExtension' );
3186 }
3187
3192 public function getMagicWords() {
3193 return $this->localisationCache->getItem( $this->mCode, 'magicWords' );
3194 }
3195
3201 public function getMagic( $mw ) {
3202 $rawEntry = $this->mMagicExtensions[$mw->mId] ??
3203 $this->localisationCache->getSubitem( $this->mCode, 'magicWords', $mw->mId );
3204
3205 if ( !is_array( $rawEntry ) ) {
3206 wfWarn( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" );
3207 } else {
3208 $mw->mCaseSensitive = $rawEntry[0];
3209 $mw->mSynonyms = array_slice( $rawEntry, 1 );
3210 }
3211 }
3212
3218 public function getSpecialPageAliases() {
3219 // Cache aliases because it may be slow to load them
3220 if ( $this->mExtendedSpecialPageAliases === null ) {
3221 // Initialise array
3222 $this->mExtendedSpecialPageAliases =
3223 $this->localisationCache->getItem( $this->mCode, 'specialPageAliases' );
3224 }
3225
3226 return $this->mExtendedSpecialPageAliases;
3227 }
3228
3235 public function emphasize( $text ) {
3236 return "<em>$text</em>";
3237 }
3238
3261 public function formatNum( $number, $nocommafy = false ) {
3262 global $wgTranslateNumerals;
3263
3264 $number = (string)$number;
3265 if ( !$nocommafy ) {
3266 $number = $this->commafy( $number );
3267 $s = $this->separatorTransformTable();
3268 if ( $s ) {
3269 $number = strtr( $number, $s );
3270 }
3271 }
3272
3273 if ( $wgTranslateNumerals ) {
3274 $s = $this->digitTransformTable();
3275 if ( $s ) {
3276 $number = strtr( $number, $s );
3277 }
3278 }
3279
3280 return $number;
3281 }
3282
3291 public function formatNumNoSeparators( $number ) {
3292 return $this->formatNum( $number, true );
3293 }
3294
3299 public function parseFormattedNumber( $number ) {
3300 $s = $this->digitTransformTable();
3301 if ( $s ) {
3302 // eliminate empty array values such as ''. (T66347)
3303 $s = array_filter( $s );
3304 $number = strtr( $number, array_flip( $s ) );
3305 }
3306
3307 $s = $this->separatorTransformTable();
3308 if ( $s ) {
3309 // eliminate empty array values such as ''. (T66347)
3310 $s = array_filter( $s );
3311 $number = strtr( $number, array_flip( $s ) );
3312 }
3313
3314 $number = strtr( $number, [ ',' => '' ] );
3315 return $number;
3316 }
3317
3326 public function commafy( $number ) {
3327 $digitGroupingPattern = $this->digitGroupingPattern();
3328 $minimumGroupingDigits = $this->minimumGroupingDigits();
3329 if ( $number === null ) {
3330 return '';
3331 }
3332
3333 if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
3334 // Default grouping is at thousands, use the same for ###,###,### pattern too.
3335 // In some languages it's conventional not to insert a thousands separator
3336 // in numbers that are four digits long (1000-9999).
3337 if ( $minimumGroupingDigits ) {
3338 // Number of '#' characters after last comma in the grouping pattern.
3339 // The pattern is hardcoded here, but this would vary for different patterns.
3340 $primaryGroupingSize = 3;
3341 // Maximum length of a number to suppress digit grouping for.
3342 $maximumLength = $minimumGroupingDigits + $primaryGroupingSize - 1;
3343 if ( preg_match( '/^\-?\d{1,' . $maximumLength . '}(\.\d+)?$/', $number ) ) {
3344 return $number;
3345 }
3346 }
3347 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $number ) ) );
3348 } else {
3349 // Ref: http://cldr.unicode.org/translation/number-patterns
3350 $sign = "";
3351 if ( intval( $number ) < 0 ) {
3352 // For negative numbers apply the algorithm like positive number and add sign.
3353 $sign = "-";
3354 $number = substr( $number, 1 );
3355 }
3356 $integerPart = [];
3357 $decimalPart = [];
3358 $numMatches = preg_match_all( "/(#+)/", $digitGroupingPattern, $matches );
3359 preg_match( "/\d+/", $number, $integerPart );
3360 preg_match( "/\.\d*/", $number, $decimalPart );
3361 $groupedNumber = ( count( $decimalPart ) > 0 ) ? $decimalPart[0] : "";
3362 if ( $groupedNumber === $number ) {
3363 // the string does not have any number part. Eg: .12345
3364 return $sign . $groupedNumber;
3365 }
3366 $start = $end = ( $integerPart ) ? strlen( $integerPart[0] ) : 0;
3367 while ( $start > 0 ) {
3368 $match = $matches[0][$numMatches - 1];
3369 $matchLen = strlen( $match );
3370 $start = $end - $matchLen;
3371 if ( $start < 0 ) {
3372 $start = 0;
3373 }
3374 $groupedNumber = substr( $number, $start, $end - $start ) . $groupedNumber;
3375 $end = $start;
3376 if ( $numMatches > 1 ) {
3377 // use the last pattern for the rest of the number
3378 $numMatches--;
3379 }
3380 if ( $start > 0 ) {
3381 $groupedNumber = "," . $groupedNumber;
3382 }
3383 }
3384 return $sign . $groupedNumber;
3385 }
3386 }
3387
3391 public function digitGroupingPattern() {
3392 return $this->localisationCache->getItem( $this->mCode, 'digitGroupingPattern' );
3393 }
3394
3398 public function digitTransformTable() {
3399 return $this->localisationCache->getItem( $this->mCode, 'digitTransformTable' );
3400 }
3401
3405 public function separatorTransformTable() {
3406 return $this->localisationCache->getItem( $this->mCode, 'separatorTransformTable' );
3407 }
3408
3412 public function minimumGroupingDigits() {
3413 return $this->localisationCache->getItem( $this->mCode, 'minimumGroupingDigits' );
3414 }
3415
3424 public function listToText( array $list ) {
3425 $itemCount = count( $list );
3426 if ( $itemCount < 1 ) {
3427 return '';
3428 }
3429 $text = array_pop( $list );
3430 if ( $itemCount > 1 ) {
3431 $and = $this->msg( 'and' )->escaped();
3432 $space = $this->msg( 'word-separator' )->escaped();
3433 $comma = '';
3434 if ( $itemCount > 2 ) {
3435 $comma = $this->msg( 'comma-separator' )->escaped();
3436 }
3437 $text = implode( $comma, $list ) . $and . $space . $text;
3438 }
3439 return $text;
3440 }
3441
3448 public function commaList( array $list ) {
3449 return implode(
3450 wfMessage( 'comma-separator' )->inLanguage( $this )->escaped(),
3451 $list
3452 );
3453 }
3454
3461 public function semicolonList( array $list ) {
3462 return implode(
3463 wfMessage( 'semicolon-separator' )->inLanguage( $this )->escaped(),
3464 $list
3465 );
3466 }
3467
3473 public function pipeList( array $list ) {
3474 return implode(
3475 wfMessage( 'pipe-separator' )->inLanguage( $this )->escaped(),
3476 $list
3477 );
3478 }
3479
3495 public function truncateForDatabase( $string, $length, $ellipsis = '...', $adjustLength = true ) {
3496 return $this->truncateInternal(
3497 $string, $length, $ellipsis, $adjustLength, 'strlen', 'substr'
3498 );
3499 }
3500
3519 public function truncateForVisual( $string, $length, $ellipsis = '...', $adjustLength = true ) {
3520 // Passing encoding to mb_strlen and mb_substr is optional.
3521 // Encoding defaults to mb_internal_encoding(), which is set to UTF-8 in Setup.php, so
3522 // explicit specification of encoding is skipped.
3523 // Note: Both multibyte methods are callables invoked in truncateInternal.
3524 return $this->truncateInternal(
3525 $string, $length, $ellipsis, $adjustLength, 'mb_strlen', 'mb_substr'
3526 );
3527 }
3528
3545 private function truncateInternal(
3546 $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
3547 ) {
3548 # Check if there is no need to truncate
3549 if ( $measureLength( $string ) <= abs( $length ) ) {
3550 return $string; // no need to truncate
3551 }
3552
3553 # Use the localized ellipsis character
3554 if ( $ellipsis == '...' ) {
3555 $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
3556 }
3557 if ( $length == 0 ) {
3558 return $ellipsis; // convention
3559 }
3560
3561 $stringOriginal = $string;
3562 # If ellipsis length is >= $length then we can't apply $adjustLength
3563 if ( $adjustLength && $measureLength( $ellipsis ) >= abs( $length ) ) {
3564 $string = $ellipsis; // this can be slightly unexpected
3565 # Otherwise, truncate and add ellipsis...
3566 } else {
3567 $ellipsisLength = $adjustLength ? $measureLength( $ellipsis ) : 0;
3568 if ( $length > 0 ) {
3569 $length -= $ellipsisLength;
3570 $string = $getSubstring( $string, 0, $length ); // xyz...
3571 $string = $this->removeBadCharLast( $string );
3572 $string = rtrim( $string ) . $ellipsis;
3573 } else {
3574 $length += $ellipsisLength;
3575 $string = $getSubstring( $string, $length ); // ...xyz
3576 $string = $this->removeBadCharFirst( $string );
3577 $string = $ellipsis . ltrim( $string );
3578 }
3579 }
3580
3581 # Do not truncate if the ellipsis makes the string longer/equal (T24181).
3582 # This check is *not* redundant if $adjustLength, due to the single case where
3583 # LEN($ellipsis) > ABS($limit arg); $stringOriginal could be shorter than $string.
3584 if ( $measureLength( $string ) < $measureLength( $stringOriginal ) ) {
3585 return $string;
3586 } else {
3587 return $stringOriginal;
3588 }
3589 }
3590
3598 protected function removeBadCharLast( $string ) {
3599 if ( $string != '' ) {
3600 $char = ord( $string[strlen( $string ) - 1] );
3601 $m = [];
3602 if ( $char >= 0xc0 ) {
3603 # We got the first byte only of a multibyte char; remove it.
3604 $string = substr( $string, 0, -1 );
3605 } elseif ( $char >= 0x80 &&
3606 // Use the /s modifier (PCRE_DOTALL) so (.*) also matches newlines
3607 preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
3608 '[\xf0-\xf7][\x80-\xbf]{1,2})$/s', $string, $m )
3609 ) {
3610 # We chopped in the middle of a character; remove it
3611 $string = $m[1];
3612 }
3613 }
3614 return $string;
3615 }
3616
3624 protected function removeBadCharFirst( $string ) {
3625 if ( $string != '' ) {
3626 $char = ord( $string[0] );
3627 if ( $char >= 0x80 && $char < 0xc0 ) {
3628 # We chopped in the middle of a character; remove the whole thing
3629 $string = preg_replace( '/^[\x80-\xbf]+/', '', $string );
3630 }
3631 }
3632 return $string;
3633 }
3634
3650 public function truncateHtml( $text, $length, $ellipsis = '...' ) {
3651 # Use the localized ellipsis character
3652 if ( $ellipsis == '...' ) {
3653 $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
3654 }
3655 # Check if there is clearly no need to truncate
3656 if ( $length <= 0 ) {
3657 return $ellipsis; // no text shown, nothing to format (convention)
3658 } elseif ( strlen( $text ) <= $length ) {
3659 return $text; // string short enough even *with* HTML (short-circuit)
3660 }
3661
3662 $dispLen = 0; // innerHTML legth so far
3663 $testingEllipsis = false; // checking if ellipses will make string longer/equal?
3664 $tagType = 0; // 0-open, 1-close
3665 $bracketState = 0; // 1-tag start, 2-tag name, 0-neither
3666 $entityState = 0; // 0-not entity, 1-entity
3667 $tag = $ret = ''; // accumulated tag name, accumulated result string
3668 $openTags = []; // open tag stack
3669 $maybeState = null; // possible truncation state
3670
3671 $textLen = strlen( $text );
3672 $neLength = max( 0, $length - strlen( $ellipsis ) ); // non-ellipsis len if truncated
3673 for ( $pos = 0; true; ++$pos ) {
3674 # Consider truncation once the display length has reached the maximim.
3675 # We check if $dispLen > 0 to grab tags for the $neLength = 0 case.
3676 # Check that we're not in the middle of a bracket/entity...
3677 if ( $dispLen && $dispLen >= $neLength && $bracketState == 0 && !$entityState ) {
3678 if ( !$testingEllipsis ) {
3679 $testingEllipsis = true;
3680 # Save where we are; we will truncate here unless there turn out to
3681 # be so few remaining characters that truncation is not necessary.
3682 if ( !$maybeState ) { // already saved? ($neLength = 0 case)
3683 $maybeState = [ $ret, $openTags ]; // save state
3684 }
3685 } elseif ( $dispLen > $length && $dispLen > strlen( $ellipsis ) ) {
3686 # String in fact does need truncation, the truncation point was OK.
3687 // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring
3688 list( $ret, $openTags ) = $maybeState; // reload state
3689 $ret = $this->removeBadCharLast( $ret ); // multi-byte char fix
3690 $ret .= $ellipsis; // add ellipsis
3691 break;
3692 }
3693 }
3694 if ( $pos >= $textLen ) {
3695 break; // extra iteration just for above checks
3696 }
3697
3698 # Read the next char...
3699 $ch = $text[$pos];
3700 $lastCh = $pos ? $text[$pos - 1] : '';
3701 $ret .= $ch; // add to result string
3702 if ( $ch == '<' ) {
3703 $this->truncate_endBracket( $tag, $tagType, $lastCh, $openTags ); // for bad HTML
3704 $entityState = 0; // for bad HTML
3705 $bracketState = 1; // tag started (checking for backslash)
3706 } elseif ( $ch == '>' ) {
3707 $this->truncate_endBracket( $tag, $tagType, $lastCh, $openTags );
3708 $entityState = 0; // for bad HTML
3709 $bracketState = 0; // out of brackets
3710 } elseif ( $bracketState == 1 ) {
3711 if ( $ch == '/' ) {
3712 $tagType = 1; // close tag (e.g. "</span>")
3713 } else {
3714 $tagType = 0; // open tag (e.g. "<span>")
3715 $tag .= $ch;
3716 }
3717 $bracketState = 2; // building tag name
3718 } elseif ( $bracketState == 2 ) {
3719 if ( $ch != ' ' ) {
3720 $tag .= $ch;
3721 } else {
3722 // Name found (e.g. "<a href=..."), add on tag attributes...
3723 $pos += $this->truncate_skip( $ret, $text, "<>", $pos + 1 );
3724 }
3725 } elseif ( $bracketState == 0 ) {
3726 if ( $entityState ) {
3727 if ( $ch == ';' ) {
3728 $entityState = 0;
3729 $dispLen++; // entity is one displayed char
3730 }
3731 } else {
3732 if ( $neLength == 0 && !$maybeState ) {
3733 // Save state without $ch. We want to *hit* the first
3734 // display char (to get tags) but not *use* it if truncating.
3735 $maybeState = [ substr( $ret, 0, -1 ), $openTags ];
3736 }
3737 if ( $ch == '&' ) {
3738 $entityState = 1; // entity found, (e.g. "&#160;")
3739 } else {
3740 $dispLen++; // this char is displayed
3741 // Add the next $max display text chars after this in one swoop...
3742 $max = ( $testingEllipsis ? $length : $neLength ) - $dispLen;
3743 $skipped = $this->truncate_skip( $ret, $text, "<>&", $pos + 1, $max );
3744 $dispLen += $skipped;
3745 $pos += $skipped;
3746 }
3747 }
3748 }
3749 }
3750 // Close the last tag if left unclosed by bad HTML
3751 $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags );
3752 while ( count( $openTags ) > 0 ) {
3753 $ret .= '</' . array_pop( $openTags ) . '>'; // close open tags
3754 }
3755 return $ret;
3756 }
3757
3769 private function truncate_skip( &$ret, $text, $search, $start, $len = null ) {
3770 if ( $len === null ) {
3771 $len = -1; // -1 means "no limit" for strcspn
3772 } elseif ( $len < 0 ) {
3773 $len = 0; // sanity
3774 }
3775 $skipCount = 0;
3776 if ( $start < strlen( $text ) ) {
3777 $skipCount = strcspn( $text, $search, $start, $len );
3778 $ret .= substr( $text, $start, $skipCount );
3779 }
3780 return $skipCount;
3781 }
3782
3792 private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) {
3793 $tag = ltrim( $tag );
3794 if ( $tag != '' ) {
3795 if ( $tagType == 0 && $lastCh != '/' ) {
3796 $openTags[] = $tag; // tag opened (didn't close itself)
3797 } elseif ( $tagType == 1 ) {
3798 if ( $openTags && $tag == $openTags[count( $openTags ) - 1] ) {
3799 array_pop( $openTags ); // tag closed
3800 }
3801 }
3802 $tag = '';
3803 }
3804 }
3805
3814 public function convertGrammar( $word, $case ) {
3815 global $wgGrammarForms;
3816 if ( isset( $wgGrammarForms[$this->getCode()][$case][$word] ) ) {
3817 return $wgGrammarForms[$this->getCode()][$case][$word];
3818 }
3819
3820 $grammarTransformations = $this->getGrammarTransformations();
3821
3822 if ( isset( $grammarTransformations[$case] ) ) {
3823 $forms = $grammarTransformations[$case];
3824
3825 // Some names of grammar rules are aliases for other rules.
3826 // In such cases the value is a string rather than object,
3827 // so load the actual rules.
3828 if ( is_string( $forms ) ) {
3829 $forms = $grammarTransformations[$forms];
3830 }
3831
3832 foreach ( array_values( $forms ) as $rule ) {
3833 $form = $rule[0];
3834
3835 if ( $form === '@metadata' ) {
3836 continue;
3837 }
3838
3839 $replacement = $rule[1];
3840
3841 $regex = '/' . addcslashes( $form, '/' ) . '/u';
3842 $patternMatches = preg_match( $regex, $word );
3843
3844 if ( $patternMatches === false ) {
3846 'An error occurred while processing grammar. ' .
3847 "Word: '$word'. Regex: /$form/."
3848 );
3849 } elseif ( $patternMatches === 1 ) {
3850 $word = preg_replace( $regex, $replacement, $word );
3851
3852 break;
3853 }
3854 }
3855 }
3856
3857 return $word;
3858 }
3859
3865 public function getGrammarForms() {
3866 global $wgGrammarForms;
3867 if ( isset( $wgGrammarForms[$this->getCode()] )
3868 && is_array( $wgGrammarForms[$this->getCode()] )
3869 ) {
3870 return $wgGrammarForms[$this->getCode()];
3871 }
3872
3873 return [];
3874 }
3875
3885 public function getGrammarTransformations() {
3886 if ( $this->grammarTransformCache !== null ) {
3887 return $this->grammarTransformCache;
3888 }
3889
3890 $grammarDataFile = __DIR__ . "/data/grammarTransformations/{$this->getCode()}.json";
3891
3892 $this->grammarTransformCache = is_readable( $grammarDataFile )
3893 ? FormatJson::decode( file_get_contents( $grammarDataFile ), true )
3894 : [];
3895
3896 if ( $this->grammarTransformCache === null ) {
3897 throw new MWException( "Invalid grammar data for \"{$this->getCode()}\"." );
3898 }
3899
3900 return $this->grammarTransformCache;
3901 }
3902
3922 public function gender( $gender, $forms ) {
3923 if ( !count( $forms ) ) {
3924 return '';
3925 }
3926 $forms = $this->preConvertPlural( $forms, 2 );
3927 if ( $gender === 'male' ) {
3928 return $forms[0];
3929 }
3930 if ( $gender === 'female' ) {
3931 return $forms[1];
3932 }
3933 return $forms[2] ?? $forms[0];
3934 }
3935
3951 public function convertPlural( $count, $forms ) {
3952 // Handle explicit n=pluralform cases
3953 $forms = $this->handleExplicitPluralForms( $count, $forms );
3954 if ( is_string( $forms ) ) {
3955 return $forms;
3956 }
3957 if ( !count( $forms ) ) {
3958 return '';
3959 }
3960
3961 $pluralForm = $this->getPluralRuleIndexNumber( $count );
3962 $pluralForm = min( $pluralForm, count( $forms ) - 1 );
3963 return $forms[$pluralForm];
3964 }
3965
3981 protected function handleExplicitPluralForms( $count, array $forms ) {
3982 foreach ( $forms as $index => $form ) {
3983 if ( preg_match( '/\d+=/i', $form ) ) {
3984 $pos = strpos( $form, '=' );
3985 if ( substr( $form, 0, $pos ) === (string)$count ) {
3986 return substr( $form, $pos + 1 );
3987 }
3988 unset( $forms[$index] );
3989 }
3990 }
3991 return array_values( $forms );
3992 }
3993
4002 protected function preConvertPlural( /* Array */ $forms, $count ) {
4003 return array_pad( $forms, $count, end( $forms ) );
4004 }
4005
4022 public function embedBidi( $text = '' ) {
4023 $dir = self::strongDirFromContent( $text );
4024 if ( $dir === 'ltr' ) {
4025 // Wrap in LEFT-TO-RIGHT EMBEDDING ... POP DIRECTIONAL FORMATTING
4026 return self::LRE . $text . self::PDF;
4027 }
4028 if ( $dir === 'rtl' ) {
4029 // Wrap in RIGHT-TO-LEFT EMBEDDING ... POP DIRECTIONAL FORMATTING
4030 return self::RLE . $text . self::PDF;
4031 }
4032 // No strong directionality: do not wrap
4033 return $text;
4034 }
4035
4049 public function translateBlockExpiry( $str, User $user = null, $now = 0 ) {
4050 $duration = SpecialBlock::getSuggestedDurations( $this );
4051 foreach ( $duration as $show => $value ) {
4052 if ( strcmp( $str, $value ) == 0 ) {
4053 return trim( $show );
4054 }
4055 }
4056
4057 if ( wfIsInfinity( $str ) ) {
4058 foreach ( $duration as $show => $value ) {
4059 if ( wfIsInfinity( $value ) ) {
4060 return trim( $show );
4061 }
4062 }
4063 }
4064
4065 // If all else fails, return a standard duration or timestamp description.
4066 $time = strtotime( $str, $now );
4067 if ( $time === false ) { // Unknown format. Return it as-is in case.
4068 return $str;
4069 } elseif ( $time !== strtotime( $str, $now + 1 ) ) { // It's a relative timestamp.
4070 // The result differs based on current time, so the difference
4071 // is a fixed duration length.
4072 return $this->formatDuration( $time - $now );
4073 } else { // It's an absolute timestamp.
4074 if ( $time === 0 ) {
4075 // wfTimestamp() handles 0 as current time instead of epoch.
4076 $time = '19700101000000';
4077 }
4078 if ( $user ) {
4079 return $this->userTimeAndDate( $time, $user );
4080 }
4081 return $this->timeanddate( $time );
4082 }
4083 }
4084
4092 public function segmentForDiff( $text ) {
4093 return $text;
4094 }
4095
4102 public function unsegmentForDiff( $text ) {
4103 return $text;
4104 }
4105
4115 public function getConverter() : ILanguageConverter {
4116 return $this->converterFactory->getLanguageConverter( $this );
4117 }
4118
4129 public function autoConvert( $text, $variant = false ) {
4130 return $this->getConverter()->autoConvert( $text, $variant );
4131 }
4132
4141 public function autoConvertToAllVariants( $text ) {
4142 return $this->getConverter()->autoConvertToAllVariants( $text );
4143 }
4144
4159 public function convert( $text ) {
4160 return $this->getConverter()->convert( $text );
4161 }
4162
4171 public function convertTitle( $title ) {
4172 return $this->getConverter()->convertTitle( $title );
4173 }
4174
4185 public function convertNamespace( $ns, $variant = null ) {
4186 return $this->getConverter()->convertNamespace( $ns, $variant );
4187 }
4188
4196 public function hasVariants() {
4197 return count( $this->getVariants() ) > 1;
4198 }
4199
4212 public function hasVariant( $variant ) {
4213 return $this->getConverter()->hasVariant( $variant );
4214 }
4215
4225 public function convertHtml( $text ) {
4226 return htmlspecialchars( $this->convert( $text ) );
4227 }
4228
4235 public function convertCategoryKey( $key ) {
4236 return $this->getConverter()->convertCategoryKey( $key );
4237 }
4238
4247 public function getVariants() {
4248 return $this->getConverter()->getVariants();
4249 }
4250
4255 public function getPreferredVariant() {
4256 return $this->getConverter()->getPreferredVariant();
4257 }
4258
4263 public function getDefaultVariant() {
4264 return $this->getConverter()->getDefaultVariant();
4265 }
4266
4271 public function getURLVariant() {
4272 return $this->getConverter()->getURLVariant();
4273 }
4274
4289 public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
4290 $this->getConverter()->findVariantLink( $link, $nt, $ignoreOtherCond );
4291 }
4292
4301 public function getExtraHashOptions() {
4302 return $this->getConverter()->getExtraHashOptions();
4303 }
4304
4313 public function updateConversionTable( LinkTarget $linkTarget ) {
4314 $this->getConverter()->updateConversionTable( $linkTarget );
4315 }
4316
4323 public function linkTrail() {
4324 return $this->localisationCache->getItem( $this->mCode, 'linkTrail' );
4325 }
4326
4333 public function linkPrefixCharset() {
4334 return $this->localisationCache->getItem( $this->mCode, 'linkPrefixCharset' );
4335 }
4336
4345 public function getParentLanguage() {
4346 return MediaWikiServices::getInstance()->getLanguageFactory()
4347 ->getParentLanguage( $this->getCode() );
4348 }
4349
4357 public function equals( Language $lang ) {
4358 return $lang === $this || $lang->getCode() === $this->mCode;
4359 }
4360
4369 public function getCode() {
4370 return $this->mCode;
4371 }
4372
4383 public function getHtmlCode() {
4384 if ( $this->mHtmlCode === null ) {
4385 $this->mHtmlCode = LanguageCode::bcp47( $this->getCode() );
4386 }
4387 return $this->mHtmlCode;
4388 }
4389
4397 public static function getCodeFromFileName( $filename, $prefix = 'Language', $suffix = '.php' ) {
4398 $m = null;
4399 preg_match( '/' . preg_quote( $prefix, '/' ) . '([A-Z][a-z_]+)' .
4400 preg_quote( $suffix, '/' ) . '/', $filename, $m );
4401 if ( !count( $m ) ) {
4402 return false;
4403 }
4404 return str_replace( '_', '-', strtolower( $m[1] ) );
4405 }
4406
4415 public static function classFromCode( $code, $fallback = true ) {
4416 wfDeprecated( __METHOD__, '1.35' );
4417
4418 if ( $fallback && $code == 'en' ) {
4419 return 'Language';
4420 } else {
4421 return 'Language' . str_replace( '-', '_', ucfirst( $code ) );
4422 }
4423 }
4424
4435 public static function getFileName( $prefix, $code, $suffix = '.php' ) {
4436 return MediaWikiServices::getInstance()->getLanguageNameUtils()
4437 ->getFileName( $prefix, $code, $suffix );
4438 }
4439
4445 public static function getMessagesFileName( $code ) {
4446 return MediaWikiServices::getInstance()->getLanguageNameUtils()
4447 ->getMessagesFileName( $code );
4448 }
4449
4457 public static function getJsonMessagesFileName( $code ) {
4458 return MediaWikiServices::getInstance()->getLanguageNameUtils()
4459 ->getJsonMessagesFileName( $code );
4460 }
4461
4470 public static function getFallbackFor( $code ) {
4471 return MediaWikiServices::getInstance()->getLanguageFallback()->getFirst( $code )
4472 ?? false;
4473 }
4474
4487 public static function getFallbacksFor( $code, $mode = LanguageFallback::MESSAGES ) {
4488 return MediaWikiServices::getInstance()->getLanguageFallback()->getAll( $code, $mode );
4489 }
4490
4501 public static function getFallbacksIncludingSiteLanguage( $code ) {
4502 return MediaWikiServices::getInstance()->getLanguageFallback()
4503 ->getAllIncludingSiteLanguage( $code );
4504 }
4505
4517 public static function getMessagesFor( $code ) {
4518 return self::getLocalisationCache()->getItem( $code, 'messages' );
4519 }
4520
4531 public static function getMessageFor( $key, $code ) {
4532 return self::getLocalisationCache()->getSubitem( $code, 'messages', $key );
4533 }
4534
4545 public static function getMessageKeysFor( $code ) {
4546 return self::getLocalisationCache()->getSubitemList( $code, 'messages' );
4547 }
4548
4553 private function fixVariableInNamespace( $talk ) {
4554 if ( strpos( $talk, '$1' ) === false ) {
4555 return $talk;
4556 }
4557
4558 global $wgMetaNamespace;
4559 $talk = str_replace( '$1', $wgMetaNamespace, $talk );
4560
4561 # Allow grammar transformations
4562 # Allowing full message-style parsing would make simple requests
4563 # such as action=raw much more expensive than they need to be.
4564 # This will hopefully cover most cases.
4565 $talk = preg_replace_callback(
4566 '/{{grammar:(.*?)\|(.*?)}}/i',
4567 function ( $m ) {
4568 return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
4569 },
4570 $talk
4571 );
4572 return str_replace( ' ', '_', $talk );
4573 }
4574
4585 public function formatExpiry( $expiry, $format = true, $infinity = 'infinity' ) {
4586 static $dbInfinity;
4587 if ( $dbInfinity === null ) {
4588 $dbInfinity = wfGetDB( DB_REPLICA )->getInfinity();
4589 }
4590
4591 if ( $expiry == '' || $expiry === 'infinity' || $expiry == $dbInfinity ) {
4592 return $format === true
4593 ? $this->getMessageFromDB( 'infiniteblock' )
4594 : $infinity;
4595 } else {
4596 return $format === true
4597 ? $this->timeanddate( $expiry, /* User preference timezone */ true )
4598 : wfTimestamp( $format, $expiry );
4599 }
4600 }
4601
4616 public function formatTimePeriod( $seconds, $format = [] ) {
4617 if ( !is_array( $format ) ) {
4618 $format = [ 'avoid' => $format ]; // For backwards compatibility
4619 }
4620 if ( !isset( $format['avoid'] ) ) {
4621 $format['avoid'] = false;
4622 }
4623 if ( !isset( $format['noabbrevs'] ) ) {
4624 $format['noabbrevs'] = false;
4625 }
4626 $secondsMsg = wfMessage(
4627 $format['noabbrevs'] ? 'seconds' : 'seconds-abbrev' )->inLanguage( $this );
4628 $minutesMsg = wfMessage(
4629 $format['noabbrevs'] ? 'minutes' : 'minutes-abbrev' )->inLanguage( $this );
4630 $hoursMsg = wfMessage(
4631 $format['noabbrevs'] ? 'hours' : 'hours-abbrev' )->inLanguage( $this );
4632 $daysMsg = wfMessage(
4633 $format['noabbrevs'] ? 'days' : 'days-abbrev' )->inLanguage( $this );
4634
4635 if ( round( $seconds * 10 ) < 100 ) {
4636 $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) );
4637 $s = $secondsMsg->params( $s )->text();
4638 } elseif ( round( $seconds ) < 60 ) {
4639 $s = $this->formatNum( round( $seconds ) );
4640 $s = $secondsMsg->params( $s )->text();
4641 } elseif ( round( $seconds ) < 3600 ) {
4642 $minutes = floor( $seconds / 60 );
4643 $secondsPart = round( fmod( $seconds, 60 ) );
4644 if ( $secondsPart == 60 ) {
4645 $secondsPart = 0;
4646 $minutes++;
4647 }
4648 $s = $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4649 $s .= ' ';
4650 $s .= $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
4651 } elseif ( round( $seconds ) <= 2 * 86400 ) {
4652 $hours = floor( $seconds / 3600 );
4653 $minutes = floor( ( $seconds - $hours * 3600 ) / 60 );
4654 $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 );
4655 if ( $secondsPart == 60 ) {
4656 $secondsPart = 0;
4657 $minutes++;
4658 }
4659 if ( $minutes == 60 ) {
4660 $minutes = 0;
4661 $hours++;
4662 }
4663 $s = $hoursMsg->params( $this->formatNum( $hours ) )->text();
4664 $s .= ' ';
4665 $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4666 if ( !in_array( $format['avoid'], [ 'avoidseconds', 'avoidminutes', 'avoidhours' ] ) ) {
4667 $s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
4668 }
4669 } else {
4670 $days = floor( $seconds / 86400 );
4671 if ( $format['avoid'] === 'avoidhours' ) {
4672 $hours = round( ( $seconds - $days * 86400 ) / 3600 );
4673 if ( $hours == 24 ) {
4674 $hours = 0;
4675 $days++;
4676 }
4677 $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4678 } elseif ( $format['avoid'] === 'avoidminutes' ) {
4679 $hours = round( ( $seconds - $days * 86400 ) / 3600 );
4680 if ( $hours == 24 ) {
4681 $hours = 0;
4682 $days++;
4683 }
4684 $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4685 $s .= ' ';
4686 $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
4687 } elseif ( $format['avoid'] === 'avoidseconds' ) {
4688 $hours = floor( ( $seconds - $days * 86400 ) / 3600 );
4689 $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 );
4690 if ( $minutes == 60 ) {
4691 $minutes = 0;
4692 $hours++;
4693 }
4694 if ( $hours == 24 ) {
4695 $hours = 0;
4696 $days++;
4697 }
4698 $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4699 $s .= ' ';
4700 $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
4701 $s .= ' ';
4702 $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4703 } else {
4704 $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4705 $s .= ' ';
4706 $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format );
4707 }
4708 }
4709 return $s;
4710 }
4711
4723 public function formatBitrate( $bps ) {
4724 // bitrate-petabits, bitrate-exabits, bitrate-zettabits, bitrate-yottabits, bitrate-ronnabits,
4725 // bitrate-quettabits
4726 return $this->formatComputingNumbers( $bps, 1000, "bitrate-$1bits" );
4727 }
4728
4735 public function formatComputingNumbers( $size, $boundary, $messageKey ) {
4736 if ( $size <= 0 ) {
4737 return str_replace( '$1', $this->formatNum( $size ),
4738 $this->getMessageFromDB( str_replace( '$1', '', $messageKey ) )
4739 );
4740 }
4741 $sizes = [ '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta', 'ronna', 'quetta' ];
4742 $index = 0;
4743
4744 $maxIndex = count( $sizes ) - 1;
4745 while ( $size >= $boundary && $index < $maxIndex ) {
4746 $index++;
4747 $size /= $boundary;
4748 }
4749
4750 // For small sizes no decimal places necessary
4751 $round = 0;
4752 if ( $index > 1 ) {
4753 // For MB and bigger two decimal places are smarter
4754 $round = 2;
4755 }
4756 $msg = str_replace( '$1', $sizes[$index], $messageKey );
4757
4758 $size = round( $size, $round );
4759 $text = $this->getMessageFromDB( $msg );
4760 return str_replace( '$1', $this->formatNum( $size ), $text );
4761 }
4762
4773 public function formatSize( $size ) {
4774 // size-petabytes, size-exabytes, size-zettabytes, size-yottabytes, size-ronnabytes, size-quettabytes
4775 return $this->formatComputingNumbers( $size, 1024, "size-$1bytes" );
4776 }
4777
4787 public function specialList( $page, $details, $oppositedm = true ) {
4788 if ( !$details ) {
4789 return $page;
4790 }
4791
4792 $dirmark = ( $oppositedm ? $this->getDirMark( true ) : '' ) . $this->getDirMark();
4793 return $page .
4794 $dirmark .
4795 $this->msg( 'word-separator' )->escaped() .
4796 $this->msg( 'parentheses' )->rawParams( $details )->escaped();
4797 }
4798
4811 public function viewPrevNext( Title $title, $offset, $limit,
4812 array $query = [], $atend = false
4813 ) {
4814 wfDeprecated( __METHOD__, '1.34' );
4815 // @todo FIXME: Why on earth this needs one message for the text and another one for tooltip?
4816
4817 # Make 'previous' link
4818 $prev = wfMessage( 'prevn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
4819 if ( $offset > 0 ) {
4820 $plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit,
4821 $query, $prev, 'prevn-title', 'mw-prevlink' );
4822 } else {
4823 $plink = htmlspecialchars( $prev );
4824 }
4825
4826 # Make 'next' link
4827 $next = wfMessage( 'nextn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
4828 if ( $atend ) {
4829 $nlink = htmlspecialchars( $next );
4830 } else {
4831 $nlink = $this->numLink( $title, $offset + $limit, $limit,
4832 $query, $next, 'nextn-title', 'mw-nextlink' );
4833 }
4834
4835 # Make links to set number of items per page
4836 $numLinks = [];
4837 foreach ( [ 20, 50, 100, 250, 500 ] as $num ) {
4838 $numLinks[] = $this->numLink( $title, $offset, $num,
4839 $query, $this->formatNum( $num ), 'shown-title', 'mw-numlink' );
4840 }
4841
4842 return wfMessage( 'viewprevnext' )->inLanguage( $this )->title( $title
4843 )->rawParams( $plink, $nlink, $this->pipeList( $numLinks ) )->escaped();
4844 }
4845
4860 private function numLink( Title $title, $offset, $limit, array $query, $link,
4861 $tooltipMsg, $class
4862 ) {
4863 $query = [ 'limit' => $limit, 'offset' => $offset ] + $query;
4864 $tooltip = wfMessage( $tooltipMsg )->inLanguage( $this )->title( $title )
4865 ->numParams( $limit )->text();
4866
4867 return Html::element( 'a', [ 'href' => $title->getLocalURL( $query ),
4868 'title' => $tooltip, 'class' => $class ], $link );
4869 }
4870
4878 public function getConvRuleTitle() {
4879 return $this->getConverter()->getConvRuleTitle();
4880 }
4881
4887 public function getCompiledPluralRules() {
4888 $pluralRules =
4889 $this->localisationCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' );
4890 if ( !$pluralRules ) {
4891 $fallbacks = $this->getFallbackLanguages();
4892 foreach ( $fallbacks as $fallbackCode ) {
4893 $pluralRules = $this->localisationCache
4894 ->getItem( strtolower( $fallbackCode ), 'compiledPluralRules' );
4895 if ( $pluralRules ) {
4896 break;
4897 }
4898 }
4899 }
4900 return $pluralRules;
4901 }
4902
4908 public function getPluralRules() {
4909 $pluralRules =
4910 $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRules' );
4911 if ( !$pluralRules ) {
4912 $fallbacks = $this->getFallbackLanguages();
4913 foreach ( $fallbacks as $fallbackCode ) {
4914 $pluralRules = $this->localisationCache
4915 ->getItem( strtolower( $fallbackCode ), 'pluralRules' );
4916 if ( $pluralRules ) {
4917 break;
4918 }
4919 }
4920 }
4921 return $pluralRules;
4922 }
4923
4929 public function getPluralRuleTypes() {
4930 $pluralRuleTypes =
4931 $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRuleTypes' );
4932 if ( !$pluralRuleTypes ) {
4933 $fallbacks = $this->getFallbackLanguages();
4934 foreach ( $fallbacks as $fallbackCode ) {
4935 $pluralRuleTypes = $this->localisationCache
4936 ->getItem( strtolower( $fallbackCode ), 'pluralRuleTypes' );
4937 if ( $pluralRuleTypes ) {
4938 break;
4939 }
4940 }
4941 }
4942 return $pluralRuleTypes;
4943 }
4944
4950 public function getPluralRuleIndexNumber( $number ) {
4951 $pluralRules = $this->getCompiledPluralRules();
4952 $form = Evaluator::evaluateCompiled( $number, $pluralRules );
4953 return $form;
4954 }
4955
4964 public function getPluralRuleType( $number ) {
4965 $index = $this->getPluralRuleIndexNumber( $number );
4966 $pluralRuleTypes = $this->getPluralRuleTypes();
4967 return $pluralRuleTypes[$index] ?? 'other';
4968 }
4969
4976 protected function getHookContainer() {
4977 return $this->hookContainer;
4978 }
4979
4988 protected function getHookRunner() {
4989 return $this->hookRunner;
4990 }
4991}
$wgExtraGenderNamespaces
Same as above, but for namespaces with gender distinction.
$wgTranslateNumerals
For Hindi and Arabic use local numerals instead of Western style (0-9) numerals in interface.
array $wgOverrideUcfirstCharacters
List of Unicode characters for which capitalization is overridden in Language::ucfirst.
$wgGrammarForms
Some languages need different word forms, usually for different cases.
$wgExtraNamespaces
Additional namespaces.
$wgAllUnicodeFixes
Set this to always convert certain Unicode sequences to modern ones regardless of the content languag...
$wgNamespaceAliases
Define extra namespace aliases.
$wgMetaNamespace
Name of the project namespace.
$wgMetaNamespaceTalk
Name of the project talk namespace.
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfIsInfinity( $str)
Determine input string is represents as infinity.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
$namespaceAliases
$namespaceNames
$digitGroupingPattern
$minimumGroupingDigits
$fallback
return[ 'abap'=> true, 'abl'=> true, 'abnf'=> true, 'aconf'=> true, 'actionscript'=> true, 'actionscript3'=> true, 'ada'=> true, 'ada2005'=> true, 'ada95'=> true, 'adl'=> true, 'agda'=> true, 'aheui'=> true, 'ahk'=> true, 'alloy'=> true, 'ambienttalk'=> true, 'ambienttalk/2'=> true, 'ampl'=> true, 'antlr'=> true, 'antlr-actionscript'=> true, 'antlr-as'=> true, 'antlr-c#'=> true, 'antlr-cpp'=> true, 'antlr-csharp'=> true, 'antlr-java'=> true, 'antlr-objc'=> true, 'antlr-perl'=> true, 'antlr-python'=> true, 'antlr-rb'=> true, 'antlr-ruby'=> true, 'apache'=> true, 'apacheconf'=> true, 'apl'=> true, 'applescript'=> true, 'arduino'=> true, 'arexx'=> true, 'arrow'=> true, 'as'=> true, 'as3'=> true, 'asm'=> true, 'aspectj'=> true, 'aspx-cs'=> true, 'aspx-vb'=> true, 'asy'=> true, 'asymptote'=> true, 'at'=> true, 'augeas'=> true, 'autohotkey'=> true, 'autoit'=> true, 'awk'=> true, 'b3d'=> true, 'bare'=> true, 'basemake'=> true, 'bash'=> true, 'basic'=> true, 'bat'=> true, 'batch'=> true, 'bbcbasic'=> true, 'bbcode'=> true, 'bc'=> true, 'befunge'=> true, 'bf'=> true, 'bib'=> true, 'bibtex'=> true, 'blitzbasic'=> true, 'blitzmax'=> true, 'bmax'=> true, 'bnf'=> true, 'boa'=> true, 'boo'=> true, 'boogie'=> true, 'bplus'=> true, 'brainfuck'=> true, 'bro'=> true, 'bsdmake'=> true, 'bst'=> true, 'bst-pybtex'=> true, 'bugs'=> true, 'c'=> true, 'c#'=> true, 'c++'=> true, 'c++-objdumb'=> true, 'c-objdump'=> true, 'ca65'=> true, 'cadl'=> true, 'camkes'=> true, 'capdl'=> true, 'capnp'=> true, 'cbmbas'=> true, 'ceylon'=> true, 'cf3'=> true, 'cfc'=> true, 'cfengine3'=> true, 'cfg'=> true, 'cfm'=> true, 'cfs'=> true, 'chai'=> true, 'chaiscript'=> true, 'chapel'=> true, 'charmci'=> true, 'cheetah'=> true, 'chpl'=> true, 'cirru'=> true, 'cl'=> true, 'clay'=> true, 'clean'=> true, 'clipper'=> true, 'clj'=> true, 'cljs'=> true, 'clojure'=> true, 'clojurescript'=> true, 'cmake'=> true, 'cobol'=> true, 'cobolfree'=> true, 'coffee'=> true, 'coffee-script'=> true, 'coffeescript'=> true, 'common-lisp'=> true, 'componentpascal'=> true, 'console'=> true, 'control'=> true, 'coq'=> true, 'cp'=> true, 'cpp'=> true, 'cpp-objdump'=> true, 'cpsa'=> true, 'cr'=> true, 'crmsh'=> true, 'croc'=> true, 'cry'=> true, 'cryptol'=> true, 'crystal'=> true, 'csh'=> true, 'csharp'=> true, 'csound'=> true, 'csound-csd'=> true, 'csound-document'=> true, 'csound-orc'=> true, 'csound-sco'=> true, 'csound-score'=> true, 'css'=> true, 'css+django'=> true, 'css+erb'=> true, 'css+genshi'=> true, 'css+genshitext'=> true, 'css+jinja'=> true, 'css+lasso'=> true, 'css+mako'=> true, 'css+mozpreproc'=> true, 'css+myghty'=> true, 'css+php'=> true, 'css+ruby'=> true, 'css+smarty'=> true, 'cu'=> true, 'cucumber'=> true, 'cuda'=> true, 'cxx-objdump'=> true, 'cypher'=> true, 'cython'=> true, 'd'=> true, 'd-objdump'=> true, 'dart'=> true, 'dasm16'=> true, 'debcontrol'=> true, 'debsources'=> true, 'delphi'=> true, 'devicetree'=> true, 'dg'=> true, 'diff'=> true, 'django'=> true, 'dmesg'=> true, 'do'=> true, 'docker'=> true, 'dockerfile'=> true, 'dosbatch'=> true, 'doscon'=> true, 'dosini'=> true, 'dpatch'=> true, 'dtd'=> true, 'dts'=> true, 'duby'=> true, 'duel'=> true, 'dylan'=> true, 'dylan-console'=> true, 'dylan-lid'=> true, 'dylan-repl'=> true, 'earl-grey'=> true, 'earlgrey'=> true, 'easytrieve'=> true, 'ebnf'=> true, 'ec'=> true, 'ecl'=> true, 'eg'=> true, 'eiffel'=> true, 'elisp'=> true, 'elixir'=> true, 'elm'=> true, 'emacs'=> true, 'emacs-lisp'=> true, 'email'=> true, 'eml'=> true, 'erb'=> true, 'erl'=> true, 'erlang'=> true, 'evoque'=> true, 'ex'=> true, 'execline'=> true, 'exs'=> true, 'extempore'=> true, 'ezhil'=> true, 'f#'=> true, 'factor'=> true, 'fan'=> true, 'fancy'=> true, 'felix'=> true, 'fennel'=> true, 'fish'=> true, 'fishshell'=> true, 'flatline'=> true, 'flo'=> true, 'floscript'=> true, 'flx'=> true, 'fnl'=> true, 'forth'=> true, 'fortran'=> true, 'fortranfixed'=> true, 'foxpro'=> true, 'freefem'=> true, 'fsharp'=> true, 'fstar'=> true, 'fy'=> true, 'gap'=> true, 'gas'=> true, 'gawk'=> true, 'gd'=> true, 'gdscript'=> true, 'genshi'=> true, 'genshitext'=> true, 'gherkin'=> true, 'glsl'=> true, 'gnuplot'=> true, 'go'=> true, 'golo'=> true, 'gooddata-cl'=> true, 'gosu'=> true, 'groff'=> true, 'groovy'=> true, 'gst'=> true, 'haml'=> true, 'handlebars'=> true, 'haskell'=> true, 'haxe'=> true, 'haxeml'=> true, 'hexdump'=> true, 'hlsl'=> true, 'hs'=> true, 'hsa'=> true, 'hsail'=> true, 'hspec'=> true, 'html'=> true, 'html+cheetah'=> true, 'html+django'=> true, 'html+erb'=> true, 'html+evoque'=> true, 'html+genshi'=> true, 'html+handlebars'=> true, 'html+jinja'=> true, 'html+kid'=> true, 'html+lasso'=> true, 'html+mako'=> true, 'html+myghty'=> true, 'html+ng2'=> true, 'html+php'=> true, 'html+ruby'=> true, 'html+smarty'=> true, 'html+spitfire'=> true, 'html+twig'=> true, 'html+velocity'=> true, 'htmlcheetah'=> true, 'htmldjango'=> true, 'http'=> true, 'hx'=> true, 'hxml'=> true, 'hxsl'=> true, 'hy'=> true, 'hybris'=> true, 'hylang'=> true, 'i6'=> true, 'i6t'=> true, 'i7'=> true, 'icon'=> true, 'idl'=> true, 'idl4'=> true, 'idr'=> true, 'idris'=> true, 'iex'=> true, 'igor'=> true, 'igorpro'=> true, 'ik'=> true, 'inform6'=> true, 'inform7'=> true, 'ini'=> true, 'io'=> true, 'ioke'=> true, 'irb'=> true, 'irc'=> true, 'isabelle'=> true, 'j'=> true, 'jade'=> true, 'jags'=> true, 'jasmin'=> true, 'jasminxt'=> true, 'java'=> true, 'javascript'=> true, 'javascript+cheetah'=> true, 'javascript+django'=> true, 'javascript+erb'=> true, 'javascript+genshi'=> true, 'javascript+genshitext'=> true, 'javascript+jinja'=> true, 'javascript+lasso'=> true, 'javascript+mako'=> true, 'javascript+mozpreproc'=> true, 'javascript+myghty'=> true, 'javascript+php'=> true, 'javascript+ruby'=> true, 'javascript+smarty'=> true, 'javascript+spitfire'=> true, 'jbst'=> true, 'jcl'=> true, 'jinja'=> true, 'jl'=> true, 'jlcon'=> true, 'jproperties'=> true, 'js'=> true, 'js+cheetah'=> true, 'js+django'=> true, 'js+erb'=> true, 'js+genshi'=> true, 'js+genshitext'=> true, 'js+jinja'=> true, 'js+lasso'=> true, 'js+mako'=> true, 'js+myghty'=> true, 'js+php'=> true, 'js+ruby'=> true, 'js+smarty'=> true, 'js+spitfire'=> true, 'jsgf'=> true, 'json'=> true, 'json-ld'=> true, 'json-object'=> true, 'jsonld'=> true, 'jsonml+bst'=> true, 'jsp'=> true, 'julia'=> true, 'juttle'=> true, 'kal'=> true, 'kconfig'=> true, 'kernel-config'=> true, 'kid'=> true, 'kmsg'=> true, 'koka'=> true, 'kotlin'=> true, 'ksh'=> true, 'lagda'=> true, 'lasso'=> true, 'lassoscript'=> true, 'latex'=> true, 'lcry'=> true, 'lcryptol'=> true, 'lean'=> true, 'less'=> true, 'lhaskell'=> true, 'lhs'=> true, 'lid'=> true, 'lidr'=> true, 'lidris'=> true, 'lighttpd'=> true, 'lighty'=> true, 'limbo'=> true, 'linux-config'=> true, 'liquid'=> true, 'lisp'=> true, 'literate-agda'=> true, 'literate-cryptol'=> true, 'literate-haskell'=> true, 'literate-idris'=> true, 'live-script'=> true, 'livescript'=> true, 'llvm'=> true, 'llvm-mir'=> true, 'llvm-mir-body'=> true, 'logos'=> true, 'logtalk'=> true, 'lsl'=> true, 'lua'=> true, 'm2'=> true, 'make'=> true, 'makefile'=> true, 'mako'=> true, 'man'=> true, 'maql'=> true, 'mask'=> true, 'mason'=> true, 'mathematica'=> true, 'matlab'=> true, 'matlabsession'=> true, 'mawk'=> true, 'md'=> true, 'menuconfig'=> true, 'mf'=> true, 'mime'=> true, 'minid'=> true, 'miniscript'=> true, 'mma'=> true, 'modelica'=> true, 'modula2'=> true, 'moin'=> true, 'monkey'=> true, 'monte'=> true, 'moo'=> true, 'moocode'=> true, 'moon'=> true, 'moonscript'=> true, 'mosel'=> true, 'mozhashpreproc'=> true, 'mozpercentpreproc'=> true, 'mq4'=> true, 'mq5'=> true, 'mql'=> true, 'mql4'=> true, 'mql5'=> true, 'ms'=> true, 'msc'=> true, 'mscgen'=> true, 'mupad'=> true, 'mxml'=> true, 'myghty'=> true, 'mysql'=> true, 'nasm'=> true, 'nawk'=> true, 'nb'=> true, 'ncl'=> true, 'nemerle'=> true, 'nesc'=> true, 'newlisp'=> true, 'newspeak'=> true, 'ng2'=> true, 'nginx'=> true, 'nim'=> true, 'nimrod'=> true, 'nit'=> true, 'nix'=> true, 'nixos'=> true, 'notmuch'=> true, 'nroff'=> true, 'nsh'=> true, 'nsi'=> true, 'nsis'=> true, 'numpy'=> true, 'nusmv'=> true, 'obj-c'=> true, 'obj-c++'=> true, 'obj-j'=> true, 'objc'=> true, 'objc++'=> true, 'objdump'=> true, 'objdump-nasm'=> true, 'objective-c'=> true, 'objective-c++'=> true, 'objective-j'=> true, 'objectivec'=> true, 'objectivec++'=> true, 'objectivej'=> true, 'objectpascal'=> true, 'objj'=> true, 'ocaml'=> true, 'octave'=> true, 'odin'=> true, 'ooc'=> true, 'opa'=> true, 'openbugs'=> true, 'openedge'=> true, 'pacmanconf'=> true, 'pan'=> true, 'parasail'=> true, 'pas'=> true, 'pascal'=> true, 'pawn'=> true, 'pcmk'=> true, 'peg'=> true, 'perl'=> true, 'perl6'=> true, 'php'=> true, 'php3'=> true, 'php4'=> true, 'php5'=> true, 'pig'=> true, 'pike'=> true, 'pkgconfig'=> true, 'pl'=> true, 'pl6'=> true, 'plpgsql'=> true, 'po'=> true, 'pointless'=> true, 'pony'=> true, 'posh'=> true, 'postgres'=> true, 'postgres-console'=> true, 'postgresql'=> true, 'postgresql-console'=> true, 'postscr'=> true, 'postscript'=> true, 'pot'=> true, 'pov'=> true, 'powershell'=> true, 'praat'=> true, 'progress'=> true, 'prolog'=> true, 'promql'=> true, 'properties'=> true, 'proto'=> true, 'protobuf'=> true, 'ps1'=> true, 'ps1con'=> true, 'psm1'=> true, 'psql'=> true, 'psysh'=> true, 'pug'=> true, 'puppet'=> true, 'py'=> true, 'py2'=> true, 'py2tb'=> true, 'py3'=> true, 'py3tb'=> true, 'pycon'=> true, 'pypy'=> true, 'pypylog'=> true, 'pyrex'=> true, 'pytb'=> true, 'python'=> true, 'python2'=> true, 'python3'=> true, 'pyx'=> true, 'qbasic'=> true, 'qbs'=> true, 'qml'=> true, 'qvt'=> true, 'qvto'=> true, 'r'=> true, 'racket'=> true, 'ragel'=> true, 'ragel-c'=> true, 'ragel-cpp'=> true, 'ragel-d'=> true, 'ragel-em'=> true, 'ragel-java'=> true, 'ragel-objc'=> true, 'ragel-rb'=> true, 'ragel-ruby'=> true, 'raku'=> true, 'raw'=> true, 'rb'=> true, 'rbcon'=> true, 'rconsole'=> true, 'rd'=> true, 'reason'=> true, 'reasonml'=> true, 'rebol'=> true, 'red'=> true, 'red/system'=> true, 'redcode'=> true, 'registry'=> true, 'resource'=> true, 'resourcebundle'=> true, 'rest'=> true, 'restructuredtext'=> true, 'rexx'=> true, 'rhtml'=> true, 'ride'=> true, 'rkt'=> true, 'rnc'=> true, 'rng-compact'=> true, 'roboconf-graph'=> true, 'roboconf-instances'=> true, 'robotframework'=> true, 'rout'=> true, 'rql'=> true, 'rs'=> true, 'rsl'=> true, 'rst'=> true, 'rts'=> true, 'ruby'=> true, 'rust'=> true, 's'=> true, 'sage'=> true, 'salt'=> true, 'sarl'=> true, 'sas'=> true, 'sass'=> true, 'sbatch'=> true, 'sc'=> true, 'scala'=> true, 'scaml'=> true, 'scd'=> true, 'scdoc'=> true, 'scheme'=> true, 'scilab'=> true, 'scm'=> true, 'scss'=> true, 'sgf'=> true, 'sh'=> true, 'shell'=> true, 'shell-session'=> true, 'shen'=> true, 'shex'=> true, 'shexc'=> true, 'sieve'=> true, 'silver'=> true, 'singularity'=> true, 'slash'=> true, 'slim'=> true, 'sls'=> true, 'slurm'=> true, 'smali'=> true, 'smalltalk'=> true, 'smarty'=> true, 'sml'=> true, 'snobol'=> true, 'snowball'=> true, 'solidity'=> true, 'sources.list'=> true, 'sourceslist'=> true, 'sp'=> true, 'sparql'=> true, 'spec'=> true, 'spitfire'=> true, 'splus'=> true, 'sql'=> true, 'sqlite3'=> true, 'squeak'=> true, 'squid'=> true, 'squid.conf'=> true, 'squidconf'=> true, 'ssp'=> true, 'st'=> true, 'stan'=> true, 'stata'=> true, 'supercollider'=> true, 'sv'=> true, 'swift'=> true, 'swig'=> true, 'systemverilog'=> true, 't-sql'=> true, 'tads3'=> true, 'tap'=> true, 'tasm'=> true, 'tcl'=> true, 'tcsh'=> true, 'tcshcon'=> true, 'tea'=> true, 'teraterm'=> true, 'teratermmacro'=> true, 'termcap'=> true, 'terminfo'=> true, 'terraform'=> true, 'tex'=> true, 'text'=> true, 'tf'=> true, 'thrift'=> true, 'tid'=> true, 'tnt'=> true, 'todotxt'=> true, 'toml'=> true, 'trac-wiki'=> true, 'trafficscript'=> true, 'treetop'=> true, 'ts'=> true, 'tsql'=> true, 'ttl'=> true, 'turtle'=> true, 'twig'=> true, 'typescript'=> true, 'typoscript'=> true, 'typoscriptcssdata'=> true, 'typoscripthtmldata'=> true, 'ucode'=> true, 'udiff'=> true, 'unicon'=> true, 'urbiscript'=> true, 'usd'=> true, 'usda'=> true, 'v'=> true, 'vala'=> true, 'vapi'=> true, 'vb.net'=> true, 'vbnet'=> true, 'vbscript'=> true, 'vcl'=> true, 'vclsnippet'=> true, 'vclsnippets'=> true, 'vctreestatus'=> true, 'velocity'=> true, 'verilog'=> true, 'vfp'=> true, 'vgl'=> true, 'vhdl'=> true, 'vim'=> true, 'wdiff'=> true, 'webidl'=> true, 'whiley'=> true, 'winbatch'=> true, 'winbugs'=> true, 'x10'=> true, 'xbase'=> true, 'xml'=> true, 'xml+cheetah'=> true, 'xml+django'=> true, 'xml+erb'=> true, 'xml+evoque'=> true, 'xml+genshi'=> true, 'xml+jinja'=> true, 'xml+kid'=> true, 'xml+lasso'=> true, 'xml+mako'=> true, 'xml+myghty'=> true, 'xml+php'=> true, 'xml+ruby'=> true, 'xml+smarty'=> true, 'xml+spitfire'=> true, 'xml+velocity'=> true, 'xorg.conf'=> true, 'xq'=> true, 'xql'=> true, 'xqm'=> true, 'xquery'=> true, 'xqy'=> true, 'xslt'=> true, 'xten'=> true, 'xtend'=> true, 'xul+mozpreproc'=> true, 'yaml'=> true, 'yaml+jinja'=> true, 'yang'=> true, 'zeek'=> true, 'zephir'=> true, 'zig'=> true, 'zsh'=> true,]
$basePath
Definition addSite.php:5
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition Language.php:41
const STRICT_FALLBACKS
Return a strict fallback chain in getFallbacksFor.
Definition Language.php:158
const MESSAGES_FALLBACKS
Return a fallback chain for messages in getFallbacksFor.
Definition Language.php:151
HookRunner $hookRunner
Definition Language.php:138
hasVariants()
Check if this is a language with variants.
const MONTH_ABBREVIATED_MESSAGES
Definition Language.php:216
static $mWeekdayMsgs
Definition Language.php:171
getLocalNsIndex( $text)
Get a namespace key by value, case insensitive.
Definition Language.php:733
const RLE
Definition Language.php:314
date( $ts, $adj=false, $format=true, $timecorrection=false)
linkTrail()
A regular expression to match legal word-trailing characters which should be merged onto a link of th...
static $strongDirRegex
Directionality test regex for embedBidi().
Definition Language.php:330
const WEEKDAY_ABBREVIATED_MESSAGES
Definition Language.php:176
formatExpiry( $expiry, $format=true, $infinity='infinity')
Decode an expiry (block, protection, etc) which has come from the DB.
getPluralRuleTypes()
Get the plural rule types for the language.
static tsToIranian( $ts)
Algorithm by Roozbeh Pournader and Mohammad Toossi to convert Gregorian dates to Iranian dates.
getDefaultVariant()
convertCategoryKey( $key)
array null $namespaceNames
Definition Language.php:104
static getMessageKeysFor( $code)
Get all message keys for a given language.
static isWellFormedLanguageTag( $code, $lenient=false)
Returns true if a language code string is a well-formed language tag according to RFC 5646.
Definition Language.php:392
getVariantname( $code, $usemsg=true)
short names for language variants used for language conversion links.
Definition Language.php:842
static $mHebrewCalendarMonthGenMsgs
Definition Language.php:271
LanguageConverterFactory $converterFactory
Definition Language.php:128
static isValidBuiltInCode( $code)
Returns true if a language code is of a valid form for the purposes of internal customisation of Medi...
Definition Language.php:463
static getMessageFor( $key, $code)
Get a message for a given language.
const HEBREW_CALENDAR_MONTHS_MESSAGES
Definition Language.php:244
gender( $gender, $forms)
Provides an alternative text depending on specified gender.
static tsToYear( $ts, $cName)
Algorithm to convert Gregorian dates to Thai solar dates, Minguo dates or Minguo dates.
truncateForVisual( $string, $length, $ellipsis='...', $adjustLength=true)
Truncate a string to a specified number of characters, appending an optional string (e....
ucwords( $str)
formatNum( $number, $nocommafy=false)
Normally we output all numbers in plain en_US style, that is 293,291.235 for twohundredninetythreetho...
static clearCaches()
Intended for tests that may change configuration in a way that invalidates caches.
Definition Language.php:350
digitGroupingPattern()
static array $mLangObjCache
Definition Language.php:144
getSpecialPageAliases()
Get special page names, as an associative array canonical name => array of valid names,...
LanguageNameUtils $langNameUtils
Definition Language.php:117
static isSupportedLanguage( $code)
Checks whether any localisation is available for that language tag in MediaWiki (MessagesXx....
Definition Language.php:372
hasVariant( $variant)
Strict check if the language has the specific variant.
static classFromCode( $code, $fallback=true)
formatDuration( $seconds, array $chosenIntervals=[])
Takes a number of seconds and turns it into a text using values such as hours and minutes.
getMessage( $key)
const MONTH_GENITIVE_MESSAGES
Definition Language.php:202
const ALL
Return all known languages in fetchLanguageName(s).
Definition Language.php:54
pipeList(array $list)
Same as commaList, but separate it with the pipe instead.
internalUserTimeAndDate( $type, $ts, User $user, array $options)
Internal helper function for userDate(), userTime() and userTimeAndDate()
lc( $str, $first=false)
fallback8bitEncoding()
getPluralRuleType( $number)
Find the plural rule type appropriate for the given number For example, if the language is set to Ara...
const PDF
Definition Language.php:315
normalize( $s)
Convert a UTF-8 string to normal form C.
userAdjust( $ts, $tz=false)
Used by date() and time() to adjust the time output.
LocalisationCache $localisationCache
Definition Language.php:114
getArrow( $direction='forwards')
An arrow, depending on the language direction.
mbUpperChar( $char)
Convert character to uppercase, allowing overrides of the default mb_upper behaviour,...
equals(Language $lang)
Compare with an other language object.
convert( $text)
convert text to different variants of a language.
getParentLanguage()
Get the "parent" language which has a converter to convert a "compatible" language (in another varian...
getGenderNsText( $index, $gender)
Returns gender-dependent namespace alias if available.
Definition Language.php:694
translateBlockExpiry( $str, User $user=null, $now=0)
truncateHtml( $text, $length, $ellipsis='...')
Truncate a string of valid HTML to a specified length in bytes, appending an optional string (e....
getAllMessages()
getGrammarTransformations()
Get the grammar transformations data for the language.
__destruct()
Reduce memory usage PhanTypeSuspiciousNonTraversableForeach.
Definition Language.php:555
getFormattedNsText( $index)
A convenience function that returns the same thing as getNsText() except with '_' changed to ' ',...
Definition Language.php:681
getURLVariant()
getMessageFromDB( $msg)
Get a message from the MediaWiki namespace.
Definition Language.php:945
capitalizeAllNouns()
getDirMark( $opposite=false)
A hidden direction mark (LRM or RLM), depending on the language direction.
truncate_skip(&$ret, $text, $search, $start, $len=null)
truncateHtml() helper function like strcspn() but adds the skipped chars to $ret
getFormattedNamespaces()
A convenience function that returns getNamespaces() with spaces instead of underscores in values.
Definition Language.php:644
getExtraHashOptions()
returns language specific options used by User::getPageRenderHash() for example, the preferred langua...
$transformData
ReplacementArray object memoize.
Definition Language.php:111
userTimeAndDate( $ts, User $user, array $options=[])
Get the formatted date and time for the given timestamp and formatted for the given user.
setNamespaces(array $namespaces)
Arbitrarily set all of the namespace names at once.
Definition Language.php:624
commafy( $number)
Adds commas to a given number.
truncate_endBracket(&$tag, $tagType, $lastCh, &$openTags)
truncateHtml() helper function (a) push or pop $tag from $openTags as needed (b) clear $tag value
firstChar( $s)
Get the first character of a string.
const DURATION_INTERVALS
Definition Language.php:291
getGrammarForms()
Get the grammar forms for the content language.
getNamespaces()
Returns an array of localised namespaces indexed by their numbers.
Definition Language.php:583
static convertDoubleWidth( $string)
convert double-width roman characters to single-width.
static tsToHebrew( $ts)
Converting Gregorian dates to Hebrew dates.
updateConversionTable(LinkTarget $linkTarget)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
specialList( $page, $details, $oppositedm=true)
Make a list item, used by various special pages.
getHtmlCode()
Get the code in BCP 47 format which we can use inside of html lang="" tags.
needsGenderDistinction()
Whether this language uses gender-dependent namespace aliases.
Definition Language.php:709
static array $durationIntervals
Definition Language.php:308
getNsIndex( $text)
Get a namespace key by value, case insensitive.
Definition Language.php:824
linkPrefixCharset()
A regular expression character set to match legal word-prefixing characters which should be merged on...
static getFallbacksFor( $code, $mode=LanguageFallback::MESSAGES)
Get the ordered list of fallback languages.
listToText(array $list)
Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separa...
caseFold( $s)
Return a case-folded representation of $s.
truncateInternal( $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring)
Internal method used for truncation.
array[] null $grammarTransformCache
Definition Language.php:123
getHookContainer()
Get a HookContainer, for hook metadata and running extension hooks.
static hebrewNumeral( $num)
Hebrew Gematria number formatting up to 9999.
getCode()
Get the internal language code for this language object.
static $mIranianCalendarMonthMsgs
Definition Language.php:239
uc( $str, $first=false)
HookContainer $hookContainer
Definition Language.php:133
static $mHebrewCalendarMonthMsgs
Definition Language.php:255
normalizeForSearch( $string)
Some languages have special punctuation need to be normalized.
const HIJRI_CALENDAR_MONTH_MESSAGES
Definition Language.php:276
truncateForDatabase( $string, $length, $ellipsis='...', $adjustLength=true)
Truncate a string to a specified length in bytes, appending an optional string (e....
embedBidi( $text='')
Wraps argument with unicode control characters for directionality safety.
transformUsingPairFile( $file, $string, $basePath=null)
Transform a string using serialized data stored in the given file (which must be in the serialized su...
getMagic( $mw)
Fill a MagicWord object with data from here.
viewPrevNext(Title $title, $offset, $limit, array $query=[], $atend=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
resetNamespaces()
Resets all of the namespace caches.
Definition Language.php:632
getMagicWords()
Get all magic words from cache.
minimumGroupingDigits()
emphasize( $text)
Italic is unsuitable for some languages.
timeanddate( $ts, $adj=false, $format=true, $timecorrection=false)
static getFallbacksIncludingSiteLanguage( $code)
Get the ordered list of fallback languages, ending with the fallback language chain for the site lang...
convertForSearchResult( $termsArray)
static $mMonthGenMsgs
Definition Language.php:211
getPreferredVariant()
getDirMarkEntity( $opposite=false)
A hidden direction mark (LRM or RLM), depending on the language direction.
convertGrammar( $word, $case)
Grammatical transformations, needed for inflected languages Invoked by putting {{grammar:case|word}} ...
autoConvert( $text, $variant=false)
convert text to a variant
getHumanTimestampInternal(MWTimestamp $ts, MWTimestamp $relativeTo, User $user)
Convert an MWTimestamp into a pretty human-readable timestamp using the given user preferences and re...
getHumanTimestamp(MWTimestamp $time, MWTimestamp $relativeTo=null, User $user=null)
Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
convertNamespace( $ns, $variant=null)
Convert a namespace index to a string in the preferred variant.
preConvertPlural($forms, $count)
Checks that convertPlural was given an array and pads it to requested amount of forms by copying the ...
formatTimePeriod( $seconds, $format=[])
Formats a time given in seconds into a string representation of that time.
static getFallbackFor( $code)
Get the first fallback for a given language.
isRTL()
For right-to-left language support.
separatorTransformTable()
segmentForDiff( $text)
languages like Chinese need to be segmented in order for the diff to be of any use
static $mMonthAbbrevMsgs
Definition Language.php:224
__construct( $code=null, LocalisationCache $localisationCache=null, LanguageNameUtils $langNameUtils=null, LanguageFallback $langFallback=null, LanguageConverterFactory $converterFactory=null, HookContainer $hookContainer=null)
Definition Language.php:503
getBookstoreList()
Exports $wgBookstoreListEn.
Definition Language.php:573
getDir()
Return the correct HTML 'dir' attribute value for this language.
parseFormattedNumber( $number)
static factory( $code)
Get a cached or new language object for a given language code.
Definition Language.php:340
$mMagicExtensions
Definition Language.php:86
linkPrefixExtension()
To allow "foo[[bar]]" to extend the link over the whole word "foobar".
getFallbackLanguages()
Definition Language.php:565
userDate( $ts, User $user, array $options=[])
Get the formatted date for the given timestamp and formatted for the given user.
const HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES
Definition Language.php:260
getPluralRules()
Get the plural rules for the language.
autoConvertToAllVariants( $text)
convert text to all supported variants
const AS_AUTONYMS
Return autonyms in fetchLanguageName(s).
Definition Language.php:47
iconv( $in, $out, $string)
formatSize( $size)
Format a size in bytes for output, using an appropriate unit (B, KB, MB, GB, TB, PB,...
semicolonList(array $list)
Take a list of strings and build a locale-friendly semicolon-separated list, using the local semicolo...
fixVariableInNamespace( $talk)
static insertSpace( $string, $pattern)
commaList(array $list)
Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separa...
dateFormat( $usePrefs=true)
This is meant to be used by time(), date(), and timeanddate() to get the date preference they're supp...
static getMessagesFor( $code)
Get all messages for a given language WARNING: this may take a long time.
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
If a language supports multiple variants, it is possible that non-existing link in one variant actual...
const MONTH_MESSAGES
Definition Language.php:188
const SUPPORTED
Return in fetchLanguageName(s) only the languages for which we have at least some localisation.
Definition Language.php:62
handleExplicitPluralForms( $count, array $forms)
Handles explicit plural forms for Language::convertPlural()
const LRE
Unicode directional formatting characters, for embedBidi()
Definition Language.php:313
alignEnd()
Return 'right' or 'left' as appropriate alignment for line-end for this language's text direction.
getDateFormatString( $type, $pref)
Get a format string for a given type and preference.
convertPlural( $count, $forms)
Plural form transformations, needed for some languages.
getDurationIntervals( $seconds, array $chosenIntervals=[])
Takes a number of seconds and returns an array with a set of corresponding intervals.
LanguageFallback $langFallback
Definition Language.php:120
static getLocalisationCache()
Get the LocalisationCache instance.
Definition Language.php:489
static getFileName( $prefix, $code, $suffix='.php')
Get the name of a file for a certain language code.
formatNumNoSeparators( $number)
Front-end for non-commafied formatNum.
static isKnownLanguageTag( $tag)
Returns true if a language code is an IETF tag known to MediaWiki.
Definition Language.php:478
const IRANIAN_CALENDAR_MONTHS_MESSAGES
Definition Language.php:229
removeBadCharLast( $string)
Remove bytes that represent an incomplete Unicode character at the end of string (e....
static getJsonMessagesFileName( $code)
getNamespaceAliases()
Definition Language.php:743
ucwordbreaks( $str)
capitalize words at word breaks
ucfirst( $str)
static strongDirFromContent( $text='')
Gets directionality of the first strongly directional codepoint, for embedBidi()
userTime( $ts, User $user, array $options=[])
Get the formatted time for the given timestamp and formatted for the given user.
getNsText( $index)
Get a namespace value by key.
Definition Language.php:663
hasWordBreaks()
Most writing systems use whitespace to break up words.
getConvRuleTitle()
Get the conversion rule title, if any.
formatBitrate( $bps)
Format a bitrate for output, using an appropriate unit (bps, kbps, Mbps, Gbps, Tbps,...
convertTitle( $title)
Convert a Title object to a string in the preferred variant.
__get(string $name)
Use PHP's magic __get handler to handle lazy accessing to deprecated mConverter.
Definition Language.php:71
numLink(Title $title, $offset, $limit, array $query, $link, $tooltipMsg, $class)
Helper function for viewPrevNext() that generates links.
getHookRunner()
Get a HookRunner, for running core hooks.
static getMessagesFileName( $code)
getNamespaceIds()
Definition Language.php:800
getVariants()
Get the list of variants supported by this language see sample implementation in LanguageZh....
time( $ts, $adj=false, $format=true, $timecorrection=false)
static getCodeFromFileName( $filename, $prefix='Language', $suffix='.php')
Get the language code from a file name.
removeBadCharFirst( $string)
Remove bytes that represent an incomplete Unicode character at the start of string (e....
static $mHijriCalendarMonthMsgs
Definition Language.php:286
static $mWeekdayAbbrevMsgs
Definition Language.php:183
unsegmentForDiff( $text)
and unsegment to show the result
formatComputingNumbers( $size, $boundary, $messageKey)
isMultibyte( $str)
lcfirst( $str)
getPluralRuleIndexNumber( $number)
Find the index number of the plural rule appropriate for the given number.
const WEEKDAY_MESSAGES
Definition Language.php:163
segmentByWord( $string)
Some languages such as Chinese require word segmentation, Specify such segmentation when overridden i...
checkTitleEncoding( $s)
TODO: $s is not always a string per T218883.
convertHtml( $text)
Perform output conversion on a string, and encode for safe HTML output.
getConverter()
Return the LanguageConverter used in the Language.
static tsToHijri( $ts)
Converting Gregorian dates to Hijri dates.
digitTransformTable()
static isValidCode( $code)
Returns true if a language code string is of a valid form, whether or not it exists.
Definition Language.php:448
array[] $mExtendedSpecialPageAliases
memoize
Definition Language.php:101
static $mMonthMsgs
Definition Language.php:197
$dateFormatStrings
memoize
Definition Language.php:94
static romanNumeral( $num)
Roman number formatting up to 10000.
alignStart()
Return 'left' or 'right' as appropriate alignment for line-start for this language's text direction.
static hebrewYearStart( $year)
This calculates the Hebrew year start, as days since 1 September.
getCompiledPluralRules()
Get the compiled plural rules for the language.
Class for caching the contents of localisation files, Messages*.php and *.i18n.php.
MediaWiki exception.
Library for creating and parsing MW-style timestamps.
offsetForUser(User $user)
Adjust the timestamp depending on the given user's preferences.
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
An interface for creating language converters.
A service that provides utilities to do with language names and codes.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Wrapper around strtr() that holds replacements.
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
Definition User.php:2665
getDatePreference()
Get the user's preferred date format.
Definition User.php:2866
const NS_USER
Definition Defines.php:72
const NS_PROJECT_TALK
Definition Defines.php:75
const NS_USER_TALK
Definition Defines.php:73
const NS_PROJECT
Definition Defines.php:74
The shared interface for all language converters.
const DB_REPLICA
Definition defines.php:25
$IP
Definition rebuild.php:19
return true
Definition router.php:92
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42
if(!isset( $args[0])) $lang