MediaWiki  master
Language.php
Go to the documentation of this file.
1 <?php
33 
38 class Language {
44  const AS_AUTONYMS = LanguageNameUtils::AUTONYMS;
45 
51  const ALL = LanguageNameUtils::ALL;
52 
59  const SUPPORTED = LanguageNameUtils::SUPPORTED;
60 
64  public $mConverter;
65 
66  public $mVariants, $mCode, $mLoaded = false;
67  public $mMagicExtensions = [];
68  private $mHtmlCode = null;
70  private $mParentLanguage = false;
71 
72  public $dateFormatStrings = [];
74 
76  protected $namespaceNames;
78 
82  public $transformData = [];
83 
86 
88  private $langNameUtils;
89 
91  private $langFallback;
92 
95 
96  public static $mLangObjCache = [];
97 
103  const MESSAGES_FALLBACKS = LanguageFallback::MESSAGES;
104 
110  const STRICT_FALLBACKS = LanguageFallback::STRICT;
111 
112  // TODO Make these const once we drop HHVM support (T192166)
113  public static $mWeekdayMsgs = [
114  'sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
115  'friday', 'saturday'
116  ];
117 
118  public static $mWeekdayAbbrevMsgs = [
119  'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'
120  ];
121 
122  public static $mMonthMsgs = [
123  'january', 'february', 'march', 'april', 'may_long', 'june',
124  'july', 'august', 'september', 'october', 'november',
125  'december'
126  ];
127  public static $mMonthGenMsgs = [
128  'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
129  'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen',
130  'december-gen'
131  ];
132  public static $mMonthAbbrevMsgs = [
133  'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
134  'sep', 'oct', 'nov', 'dec'
135  ];
136 
137  public static $mIranianCalendarMonthMsgs = [
138  'iranian-calendar-m1', 'iranian-calendar-m2', 'iranian-calendar-m3',
139  'iranian-calendar-m4', 'iranian-calendar-m5', 'iranian-calendar-m6',
140  'iranian-calendar-m7', 'iranian-calendar-m8', 'iranian-calendar-m9',
141  'iranian-calendar-m10', 'iranian-calendar-m11', 'iranian-calendar-m12'
142  ];
143 
144  public static $mHebrewCalendarMonthMsgs = [
145  'hebrew-calendar-m1', 'hebrew-calendar-m2', 'hebrew-calendar-m3',
146  'hebrew-calendar-m4', 'hebrew-calendar-m5', 'hebrew-calendar-m6',
147  'hebrew-calendar-m7', 'hebrew-calendar-m8', 'hebrew-calendar-m9',
148  'hebrew-calendar-m10', 'hebrew-calendar-m11', 'hebrew-calendar-m12',
149  'hebrew-calendar-m6a', 'hebrew-calendar-m6b'
150  ];
151 
153  'hebrew-calendar-m1-gen', 'hebrew-calendar-m2-gen', 'hebrew-calendar-m3-gen',
154  'hebrew-calendar-m4-gen', 'hebrew-calendar-m5-gen', 'hebrew-calendar-m6-gen',
155  'hebrew-calendar-m7-gen', 'hebrew-calendar-m8-gen', 'hebrew-calendar-m9-gen',
156  'hebrew-calendar-m10-gen', 'hebrew-calendar-m11-gen', 'hebrew-calendar-m12-gen',
157  'hebrew-calendar-m6a-gen', 'hebrew-calendar-m6b-gen'
158  ];
159 
160  public static $mHijriCalendarMonthMsgs = [
161  'hijri-calendar-m1', 'hijri-calendar-m2', 'hijri-calendar-m3',
162  'hijri-calendar-m4', 'hijri-calendar-m5', 'hijri-calendar-m6',
163  'hijri-calendar-m7', 'hijri-calendar-m8', 'hijri-calendar-m9',
164  'hijri-calendar-m10', 'hijri-calendar-m11', 'hijri-calendar-m12'
165  ];
166 
171  public static $durationIntervals = [
172  'millennia' => 31556952000,
173  'centuries' => 3155695200,
174  'decades' => 315569520,
175  'years' => 31556952, // 86400 * ( 365 + ( 24 * 3 + 25 ) / 400 )
176  'weeks' => 604800,
177  'days' => 86400,
178  'hours' => 3600,
179  'minutes' => 60,
180  'seconds' => 1,
181  ];
182 
186  private static $lre = "\u{202A}"; // U+202A LEFT-TO-RIGHT EMBEDDING
187  private static $rle = "\u{202B}"; // U+202B RIGHT-TO-LEFT EMBEDDING
188  private static $pdf = "\u{202C}"; // U+202C POP DIRECTIONAL FORMATTING
189 
201  // @codeCoverageIgnoreStart
202  // phpcs:ignore Generic.Files.LineLength
203  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';
204  // @codeCoverageIgnoreEnd
205 
212  static function factory( $code ) {
214 
215  if ( isset( $wgDummyLanguageCodes[$code] ) ) {
216  $code = $wgDummyLanguageCodes[$code];
217  }
218 
219  // get the language object to process
220  $langObj = self::$mLangObjCache[$code] ?? self::newFromCode( $code );
221 
222  // merge the language object in to get it up front in the cache
223  self::$mLangObjCache = array_merge( [ $code => $langObj ], self::$mLangObjCache );
224  // get rid of the oldest ones in case we have an overflow
225  self::$mLangObjCache = array_slice( self::$mLangObjCache, 0, $wgLangObjCacheSize, true );
226 
227  return $langObj;
228  }
229 
237  protected static function newFromCode( $code, $fallback = false ) {
238  $langNameUtils = MediaWikiServices::getInstance()->getLanguageNameUtils();
239  if ( !$langNameUtils->isValidCode( $code ) ) {
240  throw new MWException( "Invalid language code \"$code\"" );
241  }
242 
243  if ( !$langNameUtils->isValidBuiltInCode( $code ) ) {
244  // It's not possible to customise this code with class files, so
245  // just return a Language object. This is to support uselang= hacks.
246  $lang = new Language;
247  $lang->mCode = $code;
248  return $lang;
249  }
250 
251  // Check if there is a language class for the code
252  $class = self::classFromCode( $code, $fallback );
253  // LanguageCode does not inherit Language
254  if ( class_exists( $class ) && is_a( $class, 'Language', true ) ) {
255  $lang = new $class;
256  return $lang;
257  }
258 
259  // Keep trying the fallback list until we find an existing class
260  $fallbacks = MediaWikiServices::getInstance()->getLanguageFallback()->getAll( $code );
261  foreach ( $fallbacks as $fallbackCode ) {
262  if ( !$langNameUtils->isValidBuiltInCode( $fallbackCode ) ) {
263  throw new MWException( "Invalid fallback '$fallbackCode' in fallback sequence for '$code'" );
264  }
265 
266  $class = self::classFromCode( $fallbackCode );
267  if ( class_exists( $class ) ) {
268  $lang = new $class;
269  $lang->mCode = $code;
270  return $lang;
271  }
272  }
273 
274  throw new MWException( "Invalid fallback sequence for language '$code'" );
275  }
276 
282  public static function clearCaches() {
283  if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MEDIAWIKI_INSTALL' ) ) {
284  throw new MWException( __METHOD__ . ' must not be used outside tests/installer' );
285  }
286  if ( defined( 'MW_PHPUNIT_TEST' ) ) {
287  MediaWikiServices::getInstance()->resetServiceForTesting( 'LanguageFallback' );
288  MediaWikiServices::getInstance()->resetServiceForTesting( 'LanguageNameUtils' );
289  MediaWikiServices::getInstance()->resetServiceForTesting( 'LocalisationCache' );
290  }
291  self::$mLangObjCache = [];
292  }
293 
303  public static function isSupportedLanguage( $code ) {
304  return MediaWikiServices::getInstance()->getLanguageNameUtils()
305  ->isSupportedLanguage( $code );
306  }
307 
323  public static function isWellFormedLanguageTag( $code, $lenient = false ) {
324  $alpha = '[a-z]';
325  $digit = '[0-9]';
326  $alphanum = '[a-z0-9]';
327  $x = 'x'; # private use singleton
328  $singleton = '[a-wy-z]'; # other singleton
329  $s = $lenient ? '[-_]' : '-';
330 
331  $language = "$alpha{2,8}|$alpha{2,3}$s$alpha{3}";
332  $script = "$alpha{4}"; # ISO 15924
333  $region = "(?:$alpha{2}|$digit{3})"; # ISO 3166-1 alpha-2 or UN M.49
334  $variant = "(?:$alphanum{5,8}|$digit$alphanum{3})";
335  $extension = "$singleton(?:$s$alphanum{2,8})+";
336  $privateUse = "$x(?:$s$alphanum{1,8})+";
337 
338  # Define certain grandfathered codes, since otherwise the regex is pretty useless.
339  # Since these are limited, this is safe even later changes to the registry --
340  # the only oddity is that it might change the type of the tag, and thus
341  # the results from the capturing groups.
342  # https://www.iana.org/assignments/language-subtag-registry
343 
344  $grandfathered = "en{$s}GB{$s}oed"
345  . "|i{$s}(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)"
346  . "|no{$s}(?:bok|nyn)"
347  . "|sgn{$s}(?:BE{$s}(?:fr|nl)|CH{$s}de)"
348  . "|zh{$s}min{$s}nan";
349 
350  $variantList = "$variant(?:$s$variant)*";
351  $extensionList = "$extension(?:$s$extension)*";
352 
353  $langtag = "(?:($language)"
354  . "(?:$s$script)?"
355  . "(?:$s$region)?"
356  . "(?:$s$variantList)?"
357  . "(?:$s$extensionList)?"
358  . "(?:$s$privateUse)?)";
359 
360  # The final breakdown, with capturing groups for each of these components
361  # The variants, extensions, grandfathered, and private-use may have interior '-'
362 
363  $root = "^(?:$langtag|$privateUse|$grandfathered)$";
364 
365  return (bool)preg_match( "/$root/", strtolower( $code ) );
366  }
367 
379  public static function isValidCode( $code ) {
380  return MediaWikiServices::getInstance()->getLanguageNameUtils()->isValidCode( $code );
381  }
382 
394  public static function isValidBuiltInCode( $code ) {
395  return MediaWikiServices::getInstance()->getLanguageNameUtils()
396  ->isValidBuiltInCode( $code );
397  }
398 
409  public static function isKnownLanguageTag( $tag ) {
410  return MediaWikiServices::getInstance()->getLanguageNameUtils()
411  ->isKnownLanguageTag( $tag );
412  }
413 
420  public static function getLocalisationCache() {
421  return MediaWikiServices::getInstance()->getLocalisationCache();
422  }
423 
424  function __construct() {
425  $this->mConverter = new FakeConverter( $this );
426  // Set the code to the name of the descendant
427  if ( static::class === 'Language' ) {
428  $this->mCode = 'en';
429  } else {
430  $this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) );
431  }
432  // These will be ported to injection at some point.
433  $services = MediaWikiServices::getInstance();
434  $this->localisationCache = $services->getLocalisationCache();
435  $this->langNameUtils = $services->getLanguageNameUtils();
436  $this->langFallback = $services->getLanguageFallback();
437  }
438 
443  function __destruct() {
444  foreach ( $this as $name => $value ) {
445  unset( $this->$name );
446  }
447  }
448 
453  function initContLang() {
454  }
455 
460  public function getFallbackLanguages() {
461  return $this->langFallback->getAll( $this->mCode );
462  }
463 
468  public function getBookstoreList() {
469  return $this->localisationCache->getItem( $this->mCode, 'bookstoreList' );
470  }
471 
478  public function getNamespaces() {
479  if ( is_null( $this->namespaceNames ) ) {
481 
482  $validNamespaces = MediaWikiServices::getInstance()->getNamespaceInfo()->
483  getCanonicalNamespaces();
484 
485  $this->namespaceNames = $wgExtraNamespaces +
486  $this->localisationCache->getItem( $this->mCode, 'namespaceNames' );
487  $this->namespaceNames += $validNamespaces;
488 
489  $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
490  if ( $wgMetaNamespaceTalk ) {
491  $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk;
492  } else {
493  $talk = $this->namespaceNames[NS_PROJECT_TALK];
494  $this->namespaceNames[NS_PROJECT_TALK] =
495  $this->fixVariableInNamespace( $talk );
496  }
497 
498  # Sometimes a language will be localised but not actually exist on this wiki.
499  foreach ( $this->namespaceNames as $key => $text ) {
500  if ( !isset( $validNamespaces[$key] ) ) {
501  unset( $this->namespaceNames[$key] );
502  }
503  }
504 
505  # The above mixing may leave namespaces out of canonical order.
506  # Re-order by namespace ID number...
507  ksort( $this->namespaceNames );
508 
509  Hooks::run( 'LanguageGetNamespaces', [ &$this->namespaceNames ] );
510  }
511 
512  return $this->namespaceNames;
513  }
514 
519  public function setNamespaces( array $namespaces ) {
520  $this->namespaceNames = $namespaces;
521  $this->mNamespaceIds = null;
522  }
523 
527  public function resetNamespaces() {
528  $this->namespaceNames = null;
529  $this->mNamespaceIds = null;
530  $this->namespaceAliases = null;
531  }
532 
539  public function getFormattedNamespaces() {
540  $ns = $this->getNamespaces();
541  foreach ( $ns as $k => $v ) {
542  $ns[$k] = strtr( $v, '_', ' ' );
543  }
544  return $ns;
545  }
546 
558  public function getNsText( $index ) {
559  $ns = $this->getNamespaces();
560  return $ns[$index] ?? false;
561  }
562 
576  public function getFormattedNsText( $index ) {
577  $ns = $this->getNsText( $index );
578  return strtr( $ns, '_', ' ' );
579  }
580 
589  public function getGenderNsText( $index, $gender ) {
591 
592  $ns = $wgExtraGenderNamespaces +
593  (array)$this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' );
594 
595  return $ns[$index][$gender] ?? $this->getNsText( $index );
596  }
597 
604  public function needsGenderDistinction() {
606  if ( count( $wgExtraGenderNamespaces ) > 0 ) {
607  // $wgExtraGenderNamespaces overrides everything
608  return true;
609  } elseif ( isset( $wgExtraNamespaces[NS_USER] ) && isset( $wgExtraNamespaces[NS_USER_TALK] ) ) {
611  // $wgExtraNamespaces overrides any gender aliases specified in i18n files
612  return false;
613  } else {
614  // Check what is in i18n files
615  $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' );
616  return count( $aliases ) > 0;
617  }
618  }
619 
628  function getLocalNsIndex( $text ) {
629  $lctext = $this->lc( $text );
630  $ids = $this->getNamespaceIds();
631  return $ids[$lctext] ?? false;
632  }
633 
637  public function getNamespaceAliases() {
638  if ( is_null( $this->namespaceAliases ) ) {
639  $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceAliases' );
640  if ( !$aliases ) {
641  $aliases = [];
642  } else {
643  foreach ( $aliases as $name => $index ) {
644  if ( $index === NS_PROJECT_TALK ) {
645  unset( $aliases[$name] );
646  $name = $this->fixVariableInNamespace( $name );
647  $aliases[$name] = $index;
648  }
649  }
650  }
651 
653  $genders = $wgExtraGenderNamespaces + (array)$this->localisationCache
654  ->getItem( $this->mCode, 'namespaceGenderAliases' );
655  foreach ( $genders as $index => $forms ) {
656  foreach ( $forms as $alias ) {
657  $aliases[$alias] = $index;
658  }
659  }
660 
661  # Also add converted namespace names as aliases, to avoid confusion.
662  $convertedNames = [];
663  foreach ( $this->getVariants() as $variant ) {
664  if ( $variant === $this->mCode ) {
665  continue;
666  }
667  foreach ( $this->getNamespaces() as $ns => $_ ) {
668  $convertedNames[$this->getConverter()->convertNamespace( $ns, $variant )] = $ns;
669  }
670  }
671 
672  $this->namespaceAliases = $aliases + $convertedNames;
673 
674  # Filter out aliases to namespaces that don't exist, e.g. from extensions
675  # that aren't loaded here but are included in the l10n cache.
676  # (array_intersect preserves keys from its first argument)
677  $this->namespaceAliases = array_intersect(
678  $this->namespaceAliases,
679  array_keys( $this->getNamespaces() )
680  );
681  }
682 
684  }
685 
689  public function getNamespaceIds() {
690  if ( is_null( $this->mNamespaceIds ) ) {
691  global $wgNamespaceAliases;
692  # Put namespace names and aliases into a hashtable.
693  # If this is too slow, then we should arrange it so that it is done
694  # before caching. The catch is that at pre-cache time, the above
695  # class-specific fixup hasn't been done.
696  $this->mNamespaceIds = [];
697  foreach ( $this->getNamespaces() as $index => $name ) {
698  $this->mNamespaceIds[$this->lc( $name )] = $index;
699  }
700  foreach ( $this->getNamespaceAliases() as $name => $index ) {
701  $this->mNamespaceIds[$this->lc( $name )] = $index;
702  }
703  if ( $wgNamespaceAliases ) {
704  foreach ( $wgNamespaceAliases as $name => $index ) {
705  $this->mNamespaceIds[$this->lc( $name )] = $index;
706  }
707  }
708  }
709  return $this->mNamespaceIds;
710  }
711 
719  public function getNsIndex( $text ) {
720  $lctext = $this->lc( $text );
721  $ns = MediaWikiServices::getInstance()->getNamespaceInfo()->
722  getCanonicalIndex( $lctext );
723  if ( $ns !== null ) {
724  return $ns;
725  }
726  $ids = $this->getNamespaceIds();
727  return $ids[$lctext] ?? false;
728  }
729 
737  public function getVariantname( $code, $usemsg = true ) {
738  $msg = "variantname-$code";
739  if ( $usemsg && wfMessage( $msg )->exists() ) {
740  return $this->getMessageFromDB( $msg );
741  }
742  $name = $this->langNameUtils->getLanguageName( $code );
743  if ( $name ) {
744  return $name; # if it's defined as a language name, show that
745  } else {
746  # otherwise, output the language code
747  return $code;
748  }
749  }
750 
754  public function getDatePreferences() {
755  return $this->localisationCache->getItem( $this->mCode, 'datePreferences' );
756  }
757 
761  function getDateFormats() {
762  return $this->localisationCache->getItem( $this->mCode, 'dateFormats' );
763  }
764 
768  public function getDefaultDateFormat() {
769  $df = $this->localisationCache->getItem( $this->mCode, 'defaultDateFormat' );
770  if ( $df === 'dmy or mdy' ) {
771  global $wgAmericanDates;
772  return $wgAmericanDates ? 'mdy' : 'dmy';
773  } else {
774  return $df;
775  }
776  }
777 
781  public function getDatePreferenceMigrationMap() {
782  return $this->localisationCache->getItem( $this->mCode, 'datePreferenceMigrationMap' );
783  }
784 
788  public function getExtraUserToggles() {
789  wfDeprecated( __METHOD__, '1.34' );
790  return [];
791  }
792 
797  function getUserToggle( $tog ) {
798  return $this->getMessageFromDB( "tog-$tog" );
799  }
800 
814  public static function fetchLanguageNames( $inLanguage = self::AS_AUTONYMS, $include = 'mw' ) {
815  return MediaWikiServices::getInstance()->getLanguageNameUtils()
816  ->getLanguageNames( $inLanguage, $include );
817  }
818 
828  public static function fetchLanguageName(
829  $code,
830  $inLanguage = self::AS_AUTONYMS,
831  $include = self::ALL
832  ) {
833  return MediaWikiServices::getInstance()->getLanguageNameUtils()
834  ->getLanguageName( $code, $inLanguage, $include );
835  }
836 
843  public function getMessageFromDB( $msg ) {
844  return $this->msg( $msg )->text();
845  }
846 
853  protected function msg( $msg ) {
854  return wfMessage( $msg )->inLanguage( $this );
855  }
856 
861  public function getMonthName( $key ) {
862  return $this->getMessageFromDB( self::$mMonthMsgs[$key - 1] );
863  }
864 
868  public function getMonthNamesArray() {
869  $monthNames = [ '' ];
870  for ( $i = 1; $i < 13; $i++ ) {
871  $monthNames[] = $this->getMonthName( $i );
872  }
873  return $monthNames;
874  }
875 
880  public function getMonthNameGen( $key ) {
881  return $this->getMessageFromDB( self::$mMonthGenMsgs[$key - 1] );
882  }
883 
888  public function getMonthAbbreviation( $key ) {
889  return $this->getMessageFromDB( self::$mMonthAbbrevMsgs[$key - 1] );
890  }
891 
895  public function getMonthAbbreviationsArray() {
896  $monthNames = [ '' ];
897  for ( $i = 1; $i < 13; $i++ ) {
898  $monthNames[] = $this->getMonthAbbreviation( $i );
899  }
900  return $monthNames;
901  }
902 
907  public function getWeekdayName( $key ) {
908  return $this->getMessageFromDB( self::$mWeekdayMsgs[$key - 1] );
909  }
910 
915  function getWeekdayAbbreviation( $key ) {
916  return $this->getMessageFromDB( self::$mWeekdayAbbrevMsgs[$key - 1] );
917  }
918 
923  function getIranianCalendarMonthName( $key ) {
924  return $this->getMessageFromDB( self::$mIranianCalendarMonthMsgs[$key - 1] );
925  }
926 
931  function getHebrewCalendarMonthName( $key ) {
932  return $this->getMessageFromDB( self::$mHebrewCalendarMonthMsgs[$key - 1] );
933  }
934 
939  function getHebrewCalendarMonthNameGen( $key ) {
940  return $this->getMessageFromDB( self::$mHebrewCalendarMonthGenMsgs[$key - 1] );
941  }
942 
947  function getHijriCalendarMonthName( $key ) {
948  return $this->getMessageFromDB( self::$mHijriCalendarMonthMsgs[$key - 1] );
949  }
950 
959  private static function dateTimeObjFormat( &$dateTimeObj, $ts, $zone, $code ) {
960  if ( !$dateTimeObj ) {
961  $dateTimeObj = DateTime::createFromFormat(
962  'YmdHis', $ts, $zone ?: new DateTimeZone( 'UTC' )
963  );
964  }
965  return $dateTimeObj->format( $code );
966  }
967 
1037  public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = 'unused' ) {
1038  $s = '';
1039  $raw = false;
1040  $roman = false;
1041  $hebrewNum = false;
1042  $dateTimeObj = false;
1043  $rawToggle = false;
1044  $iranian = false;
1045  $hebrew = false;
1046  $hijri = false;
1047  $thai = false;
1048  $minguo = false;
1049  $tenno = false;
1050 
1051  $usedSecond = false;
1052  $usedMinute = false;
1053  $usedHour = false;
1054  $usedAMPM = false;
1055  $usedDay = false;
1056  $usedWeek = false;
1057  $usedMonth = false;
1058  $usedYear = false;
1059  $usedISOYear = false;
1060  $usedIsLeapYear = false;
1061 
1062  $usedHebrewMonth = false;
1063  $usedIranianMonth = false;
1064  $usedHijriMonth = false;
1065  $usedHebrewYear = false;
1066  $usedIranianYear = false;
1067  $usedHijriYear = false;
1068  $usedTennoYear = false;
1069 
1070  if ( strlen( $ts ) !== 14 ) {
1071  throw new MWException( __METHOD__ . ": The timestamp $ts should have 14 characters" );
1072  }
1073 
1074  if ( !ctype_digit( $ts ) ) {
1075  throw new MWException( __METHOD__ . ": The timestamp $ts should be a number" );
1076  }
1077 
1078  $formatLength = strlen( $format );
1079  for ( $p = 0; $p < $formatLength; $p++ ) {
1080  $num = false;
1081  $code = $format[$p];
1082  if ( $code == 'x' && $p < $formatLength - 1 ) {
1083  $code .= $format[++$p];
1084  }
1085 
1086  if ( ( $code === 'xi'
1087  || $code === 'xj'
1088  || $code === 'xk'
1089  || $code === 'xm'
1090  || $code === 'xo'
1091  || $code === 'xt' )
1092  && $p < $formatLength - 1 ) {
1093  $code .= $format[++$p];
1094  }
1095 
1096  switch ( $code ) {
1097  case 'xx':
1098  $s .= 'x';
1099  break;
1100  case 'xn':
1101  $raw = true;
1102  break;
1103  case 'xN':
1104  $rawToggle = !$rawToggle;
1105  break;
1106  case 'xr':
1107  $roman = true;
1108  break;
1109  case 'xh':
1110  $hebrewNum = true;
1111  break;
1112  case 'xg':
1113  $usedMonth = true;
1114  $s .= $this->getMonthNameGen( substr( $ts, 4, 2 ) );
1115  break;
1116  case 'xjx':
1117  $usedHebrewMonth = true;
1118  if ( !$hebrew ) {
1119  $hebrew = self::tsToHebrew( $ts );
1120  }
1121  $s .= $this->getHebrewCalendarMonthNameGen( $hebrew[1] );
1122  break;
1123  case 'd':
1124  $usedDay = true;
1125  $num = substr( $ts, 6, 2 );
1126  break;
1127  case 'D':
1128  $usedDay = true;
1129  $s .= $this->getWeekdayAbbreviation(
1130  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'w' ) + 1
1131  );
1132  break;
1133  case 'j':
1134  $usedDay = true;
1135  $num = intval( substr( $ts, 6, 2 ) );
1136  break;
1137  case 'xij':
1138  $usedDay = true;
1139  if ( !$iranian ) {
1140  $iranian = self::tsToIranian( $ts );
1141  }
1142  $num = $iranian[2];
1143  break;
1144  case 'xmj':
1145  $usedDay = true;
1146  if ( !$hijri ) {
1147  $hijri = self::tsToHijri( $ts );
1148  }
1149  $num = $hijri[2];
1150  break;
1151  case 'xjj':
1152  $usedDay = true;
1153  if ( !$hebrew ) {
1154  $hebrew = self::tsToHebrew( $ts );
1155  }
1156  $num = $hebrew[2];
1157  break;
1158  case 'l':
1159  $usedDay = true;
1160  $s .= $this->getWeekdayName(
1161  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'w' ) + 1
1162  );
1163  break;
1164  case 'F':
1165  $usedMonth = true;
1166  $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
1167  break;
1168  case 'xiF':
1169  $usedIranianMonth = true;
1170  if ( !$iranian ) {
1171  $iranian = self::tsToIranian( $ts );
1172  }
1173  $s .= $this->getIranianCalendarMonthName( $iranian[1] );
1174  break;
1175  case 'xmF':
1176  $usedHijriMonth = true;
1177  if ( !$hijri ) {
1178  $hijri = self::tsToHijri( $ts );
1179  }
1180  $s .= $this->getHijriCalendarMonthName( $hijri[1] );
1181  break;
1182  case 'xjF':
1183  $usedHebrewMonth = true;
1184  if ( !$hebrew ) {
1185  $hebrew = self::tsToHebrew( $ts );
1186  }
1187  $s .= $this->getHebrewCalendarMonthName( $hebrew[1] );
1188  break;
1189  case 'm':
1190  $usedMonth = true;
1191  $num = substr( $ts, 4, 2 );
1192  break;
1193  case 'M':
1194  $usedMonth = true;
1195  $s .= $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
1196  break;
1197  case 'n':
1198  $usedMonth = true;
1199  $num = intval( substr( $ts, 4, 2 ) );
1200  break;
1201  case 'xin':
1202  $usedIranianMonth = true;
1203  if ( !$iranian ) {
1204  $iranian = self::tsToIranian( $ts );
1205  }
1206  $num = $iranian[1];
1207  break;
1208  case 'xmn':
1209  $usedHijriMonth = true;
1210  if ( !$hijri ) {
1211  $hijri = self::tsToHijri( $ts );
1212  }
1213  $num = $hijri[1];
1214  break;
1215  case 'xjn':
1216  $usedHebrewMonth = true;
1217  if ( !$hebrew ) {
1218  $hebrew = self::tsToHebrew( $ts );
1219  }
1220  $num = $hebrew[1];
1221  break;
1222  case 'xjt':
1223  $usedHebrewMonth = true;
1224  if ( !$hebrew ) {
1225  $hebrew = self::tsToHebrew( $ts );
1226  }
1227  $num = $hebrew[3];
1228  break;
1229  case 'Y':
1230  $usedYear = true;
1231  $num = substr( $ts, 0, 4 );
1232  break;
1233  case 'xiY':
1234  $usedIranianYear = true;
1235  if ( !$iranian ) {
1236  $iranian = self::tsToIranian( $ts );
1237  }
1238  $num = $iranian[0];
1239  break;
1240  case 'xmY':
1241  $usedHijriYear = true;
1242  if ( !$hijri ) {
1243  $hijri = self::tsToHijri( $ts );
1244  }
1245  $num = $hijri[0];
1246  break;
1247  case 'xjY':
1248  $usedHebrewYear = true;
1249  if ( !$hebrew ) {
1250  $hebrew = self::tsToHebrew( $ts );
1251  }
1252  $num = $hebrew[0];
1253  break;
1254  case 'xkY':
1255  $usedYear = true;
1256  if ( !$thai ) {
1257  $thai = self::tsToYear( $ts, 'thai' );
1258  }
1259  $num = $thai[0];
1260  break;
1261  case 'xoY':
1262  $usedYear = true;
1263  if ( !$minguo ) {
1264  $minguo = self::tsToYear( $ts, 'minguo' );
1265  }
1266  $num = $minguo[0];
1267  break;
1268  case 'xtY':
1269  $usedTennoYear = true;
1270  if ( !$tenno ) {
1271  $tenno = self::tsToYear( $ts, 'tenno' );
1272  }
1273  $num = $tenno[0];
1274  break;
1275  case 'y':
1276  $usedYear = true;
1277  $num = substr( $ts, 2, 2 );
1278  break;
1279  case 'xiy':
1280  $usedIranianYear = true;
1281  if ( !$iranian ) {
1282  $iranian = self::tsToIranian( $ts );
1283  }
1284  $num = substr( $iranian[0], -2 );
1285  break;
1286  case 'xit':
1287  $usedIranianYear = true;
1288  if ( !$iranian ) {
1289  $iranian = self::tsToIranian( $ts );
1290  }
1291  $num = self::$IRANIAN_DAYS[$iranian[1] - 1];
1292  break;
1293  case 'xiz':
1294  $usedIranianYear = true;
1295  if ( !$iranian ) {
1296  $iranian = self::tsToIranian( $ts );
1297  }
1298  $num = $iranian[3];
1299  break;
1300  case 'a':
1301  $usedAMPM = true;
1302  $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'am' : 'pm';
1303  break;
1304  case 'A':
1305  $usedAMPM = true;
1306  $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'AM' : 'PM';
1307  break;
1308  case 'g':
1309  $usedHour = true;
1310  $h = substr( $ts, 8, 2 );
1311  $num = $h % 12 ?: 12;
1312  break;
1313  case 'G':
1314  $usedHour = true;
1315  $num = intval( substr( $ts, 8, 2 ) );
1316  break;
1317  case 'h':
1318  $usedHour = true;
1319  $h = substr( $ts, 8, 2 );
1320  $num = sprintf( '%02d', $h % 12 ?: 12 );
1321  break;
1322  case 'H':
1323  $usedHour = true;
1324  $num = substr( $ts, 8, 2 );
1325  break;
1326  case 'i':
1327  $usedMinute = true;
1328  $num = substr( $ts, 10, 2 );
1329  break;
1330  case 's':
1331  $usedSecond = true;
1332  $num = substr( $ts, 12, 2 );
1333  break;
1334  case 'c':
1335  case 'r':
1336  $usedSecond = true;
1337  // fall through
1338  case 'e':
1339  case 'O':
1340  case 'P':
1341  case 'T':
1342  $s .= self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1343  break;
1344  case 'w':
1345  case 'N':
1346  case 'z':
1347  $usedDay = true;
1348  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1349  break;
1350  case 'W':
1351  $usedWeek = true;
1352  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1353  break;
1354  case 't':
1355  $usedMonth = true;
1356  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1357  break;
1358  case 'L':
1359  $usedIsLeapYear = true;
1360  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1361  break;
1362  case 'o':
1363  $usedISOYear = true;
1364  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1365  break;
1366  case 'U':
1367  $usedSecond = true;
1368  // fall through
1369  case 'I':
1370  case 'Z':
1371  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1372  break;
1373  case '\\':
1374  # Backslash escaping
1375  if ( $p < $formatLength - 1 ) {
1376  $s .= $format[++$p];
1377  } else {
1378  $s .= '\\';
1379  }
1380  break;
1381  case '"':
1382  # Quoted literal
1383  if ( $p < $formatLength - 1 ) {
1384  $endQuote = strpos( $format, '"', $p + 1 );
1385  if ( $endQuote === false ) {
1386  # No terminating quote, assume literal "
1387  $s .= '"';
1388  } else {
1389  $s .= substr( $format, $p + 1, $endQuote - $p - 1 );
1390  $p = $endQuote;
1391  }
1392  } else {
1393  # Quote at end of string, assume literal "
1394  $s .= '"';
1395  }
1396  break;
1397  default:
1398  $s .= $format[$p];
1399  }
1400  if ( $num !== false ) {
1401  if ( $rawToggle || $raw ) {
1402  $s .= $num;
1403  $raw = false;
1404  } elseif ( $roman ) {
1405  $s .= self::romanNumeral( $num );
1406  $roman = false;
1407  } elseif ( $hebrewNum ) {
1408  $s .= self::hebrewNumeral( $num );
1409  $hebrewNum = false;
1410  } else {
1411  $s .= $this->formatNum( $num, true );
1412  }
1413  }
1414  }
1415 
1416  if ( $ttl === 'unused' ) {
1417  // No need to calculate the TTL, the caller wont use it anyway.
1418  } elseif ( $usedSecond ) {
1419  $ttl = 1;
1420  } elseif ( $usedMinute ) {
1421  $ttl = 60 - substr( $ts, 12, 2 );
1422  } elseif ( $usedHour ) {
1423  $ttl = 3600 - substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1424  } elseif ( $usedAMPM ) {
1425  $ttl = 43200 - ( substr( $ts, 8, 2 ) % 12 ) * 3600 -
1426  substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1427  } elseif (
1428  $usedDay ||
1429  $usedHebrewMonth ||
1430  $usedIranianMonth ||
1431  $usedHijriMonth ||
1432  $usedHebrewYear ||
1433  $usedIranianYear ||
1434  $usedHijriYear ||
1435  $usedTennoYear
1436  ) {
1437  // @todo Someone who understands the non-Gregorian calendars
1438  // should write proper logic for them so that they don't need purged every day.
1439  $ttl = 86400 - substr( $ts, 8, 2 ) * 3600 -
1440  substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1441  } else {
1442  $possibleTtls = [];
1443  $timeRemainingInDay = 86400 - substr( $ts, 8, 2 ) * 3600 -
1444  substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1445  if ( $usedWeek ) {
1446  $possibleTtls[] =
1447  ( 7 - self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'N' ) ) * 86400 +
1448  $timeRemainingInDay;
1449  } elseif ( $usedISOYear ) {
1450  // December 28th falls on the last ISO week of the year, every year.
1451  // The last ISO week of a year can be 52 or 53.
1452  $lastWeekOfISOYear = DateTime::createFromFormat(
1453  'Ymd',
1454  substr( $ts, 0, 4 ) . '1228',
1455  $zone ?: new DateTimeZone( 'UTC' )
1456  )->format( 'W' );
1457  $currentISOWeek = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'W' );
1458  $weeksRemaining = $lastWeekOfISOYear - $currentISOWeek;
1459  $timeRemainingInWeek =
1460  ( 7 - self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'N' ) ) * 86400
1461  + $timeRemainingInDay;
1462  $possibleTtls[] = $weeksRemaining * 604800 + $timeRemainingInWeek;
1463  }
1464 
1465  if ( $usedMonth ) {
1466  $possibleTtls[] =
1467  ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 't' ) -
1468  substr( $ts, 6, 2 ) ) * 86400
1469  + $timeRemainingInDay;
1470  } elseif ( $usedYear ) {
1471  $possibleTtls[] =
1472  ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'L' ) + 364 -
1473  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'z' ) ) * 86400
1474  + $timeRemainingInDay;
1475  } elseif ( $usedIsLeapYear ) {
1476  $year = substr( $ts, 0, 4 );
1477  $timeRemainingInYear =
1478  ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'L' ) + 364 -
1479  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'z' ) ) * 86400
1480  + $timeRemainingInDay;
1481  $mod = $year % 4;
1482  if ( $mod || ( !( $year % 100 ) && $year % 400 ) ) {
1483  // this isn't a leap year. see when the next one starts
1484  $nextCandidate = $year - $mod + 4;
1485  if ( $nextCandidate % 100 || !( $nextCandidate % 400 ) ) {
1486  $possibleTtls[] = ( $nextCandidate - $year - 1 ) * 365 * 86400 +
1487  $timeRemainingInYear;
1488  } else {
1489  $possibleTtls[] = ( $nextCandidate - $year + 3 ) * 365 * 86400 +
1490  $timeRemainingInYear;
1491  }
1492  } else {
1493  // this is a leap year, so the next year isn't
1494  $possibleTtls[] = $timeRemainingInYear;
1495  }
1496  }
1497 
1498  if ( $possibleTtls ) {
1499  $ttl = min( $possibleTtls );
1500  }
1501  }
1502 
1503  return $s;
1504  }
1505 
1506  private static $GREG_DAYS = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
1507  private static $IRANIAN_DAYS = [ 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 ];
1508 
1521  private static function tsToIranian( $ts ) {
1522  $gy = substr( $ts, 0, 4 ) - 1600;
1523  $gm = substr( $ts, 4, 2 ) - 1;
1524  $gd = substr( $ts, 6, 2 ) - 1;
1525 
1526  # Days passed from the beginning (including leap years)
1527  $gDayNo = 365 * $gy
1528  + floor( ( $gy + 3 ) / 4 )
1529  - floor( ( $gy + 99 ) / 100 )
1530  + floor( ( $gy + 399 ) / 400 );
1531 
1532  // Add days of the past months of this year
1533  for ( $i = 0; $i < $gm; $i++ ) {
1534  $gDayNo += self::$GREG_DAYS[$i];
1535  }
1536 
1537  // Leap years
1538  if ( $gm > 1 && ( ( $gy % 4 === 0 && $gy % 100 !== 0 || ( $gy % 400 == 0 ) ) ) ) {
1539  $gDayNo++;
1540  }
1541 
1542  // Days passed in current month
1543  $gDayNo += (int)$gd;
1544 
1545  $jDayNo = $gDayNo - 79;
1546 
1547  $jNp = floor( $jDayNo / 12053 );
1548  $jDayNo %= 12053;
1549 
1550  $jy = 979 + 33 * $jNp + 4 * floor( $jDayNo / 1461 );
1551  $jDayNo %= 1461;
1552 
1553  if ( $jDayNo >= 366 ) {
1554  $jy += floor( ( $jDayNo - 1 ) / 365 );
1555  $jDayNo = floor( ( $jDayNo - 1 ) % 365 );
1556  }
1557 
1558  $jz = $jDayNo;
1559 
1560  for ( $i = 0; $i < 11 && $jDayNo >= self::$IRANIAN_DAYS[$i]; $i++ ) {
1561  $jDayNo -= self::$IRANIAN_DAYS[$i];
1562  }
1563 
1564  $jm = $i + 1;
1565  $jd = $jDayNo + 1;
1566 
1567  return [ $jy, $jm, $jd, $jz ];
1568  }
1569 
1581  private static function tsToHijri( $ts ) {
1582  $year = substr( $ts, 0, 4 );
1583  $month = substr( $ts, 4, 2 );
1584  $day = substr( $ts, 6, 2 );
1585 
1586  $zyr = $year;
1587  $zd = $day;
1588  $zm = $month;
1589  $zy = $zyr;
1590 
1591  if (
1592  ( $zy > 1582 ) || ( ( $zy == 1582 ) && ( $zm > 10 ) ) ||
1593  ( ( $zy == 1582 ) && ( $zm == 10 ) && ( $zd > 14 ) )
1594  ) {
1595  $zjd = (int)( ( 1461 * ( $zy + 4800 + (int)( ( $zm - 14 ) / 12 ) ) ) / 4 ) +
1596  (int)( ( 367 * ( $zm - 2 - 12 * ( (int)( ( $zm - 14 ) / 12 ) ) ) ) / 12 ) -
1597  (int)( ( 3 * (int)( ( ( $zy + 4900 + (int)( ( $zm - 14 ) / 12 ) ) / 100 ) ) ) / 4 ) +
1598  $zd - 32075;
1599  } else {
1600  $zjd = 367 * $zy - (int)( ( 7 * ( $zy + 5001 + (int)( ( $zm - 9 ) / 7 ) ) ) / 4 ) +
1601  (int)( ( 275 * $zm ) / 9 ) + $zd + 1729777;
1602  }
1603 
1604  $zl = $zjd - 1948440 + 10632;
1605  $zn = (int)( ( $zl - 1 ) / 10631 );
1606  $zl = $zl - 10631 * $zn + 354;
1607  $zj = ( (int)( ( 10985 - $zl ) / 5316 ) ) * ( (int)( ( 50 * $zl ) / 17719 ) ) +
1608  ( (int)( $zl / 5670 ) ) * ( (int)( ( 43 * $zl ) / 15238 ) );
1609  $zl = $zl - ( (int)( ( 30 - $zj ) / 15 ) ) * ( (int)( ( 17719 * $zj ) / 50 ) ) -
1610  ( (int)( $zj / 16 ) ) * ( (int)( ( 15238 * $zj ) / 43 ) ) + 29;
1611  $zm = (int)( ( 24 * $zl ) / 709 );
1612  $zd = $zl - (int)( ( 709 * $zm ) / 24 );
1613  $zy = 30 * $zn + $zj - 30;
1614 
1615  return [ $zy, $zm, $zd ];
1616  }
1617 
1633  private static function tsToHebrew( $ts ) {
1634  # Parse date
1635  $year = substr( $ts, 0, 4 );
1636  $month = substr( $ts, 4, 2 );
1637  $day = substr( $ts, 6, 2 );
1638 
1639  # Calculate Hebrew year
1640  $hebrewYear = $year + 3760;
1641 
1642  # Month number when September = 1, August = 12
1643  $month += 4;
1644  if ( $month > 12 ) {
1645  # Next year
1646  $month -= 12;
1647  $year++;
1648  $hebrewYear++;
1649  }
1650 
1651  # Calculate day of year from 1 September
1652  $dayOfYear = $day;
1653  for ( $i = 1; $i < $month; $i++ ) {
1654  if ( $i == 6 ) {
1655  # February
1656  $dayOfYear += 28;
1657  # Check if the year is leap
1658  if ( $year % 400 == 0 || ( $year % 4 == 0 && $year % 100 > 0 ) ) {
1659  $dayOfYear++;
1660  }
1661  } elseif ( $i == 8 || $i == 10 || $i == 1 || $i == 3 ) {
1662  $dayOfYear += 30;
1663  } else {
1664  $dayOfYear += 31;
1665  }
1666  }
1667 
1668  # Calculate the start of the Hebrew year
1669  $start = self::hebrewYearStart( $hebrewYear );
1670 
1671  # Calculate next year's start
1672  if ( $dayOfYear <= $start ) {
1673  # Day is before the start of the year - it is the previous year
1674  # Next year's start
1675  $nextStart = $start;
1676  # Previous year
1677  $year--;
1678  $hebrewYear--;
1679  # Add days since previous year's 1 September
1680  $dayOfYear += 365;
1681  if ( ( $year % 400 == 0 ) || ( $year % 100 != 0 && $year % 4 == 0 ) ) {
1682  # Leap year
1683  $dayOfYear++;
1684  }
1685  # Start of the new (previous) year
1686  $start = self::hebrewYearStart( $hebrewYear );
1687  } else {
1688  # Next year's start
1689  $nextStart = self::hebrewYearStart( $hebrewYear + 1 );
1690  }
1691 
1692  # Calculate Hebrew day of year
1693  $hebrewDayOfYear = $dayOfYear - $start;
1694 
1695  # Difference between year's days
1696  $diff = $nextStart - $start;
1697  # Add 12 (or 13 for leap years) days to ignore the difference between
1698  # Hebrew and Gregorian year (353 at least vs. 365/6) - now the
1699  # difference is only about the year type
1700  if ( ( $year % 400 == 0 ) || ( $year % 100 != 0 && $year % 4 == 0 ) ) {
1701  $diff += 13;
1702  } else {
1703  $diff += 12;
1704  }
1705 
1706  # Check the year pattern, and is leap year
1707  # 0 means an incomplete year, 1 means a regular year, 2 means a complete year
1708  # This is mod 30, to work on both leap years (which add 30 days of Adar I)
1709  # and non-leap years
1710  $yearPattern = $diff % 30;
1711  # Check if leap year
1712  $isLeap = $diff >= 30;
1713 
1714  # Calculate day in the month from number of day in the Hebrew year
1715  # Don't check Adar - if the day is not in Adar, we will stop before;
1716  # if it is in Adar, we will use it to check if it is Adar I or Adar II
1717  $hebrewDay = $hebrewDayOfYear;
1718  $hebrewMonth = 1;
1719  $days = 0;
1720  while ( $hebrewMonth <= 12 ) {
1721  # Calculate days in this month
1722  if ( $isLeap && $hebrewMonth == 6 ) {
1723  # Leap year - has Adar I, with 30 days, and Adar II, with 29 days
1724  $days = 30;
1725  if ( $hebrewDay <= $days ) {
1726  # Day in Adar I
1727  $hebrewMonth = 13;
1728  } else {
1729  # Subtract the days of Adar I
1730  $hebrewDay -= $days;
1731  # Try Adar II
1732  $days = 29;
1733  if ( $hebrewDay <= $days ) {
1734  # Day in Adar II
1735  $hebrewMonth = 14;
1736  }
1737  }
1738  } elseif ( $hebrewMonth == 2 && $yearPattern == 2 ) {
1739  # Cheshvan in a complete year (otherwise as the rule below)
1740  $days = 30;
1741  } elseif ( $hebrewMonth == 3 && $yearPattern == 0 ) {
1742  # Kislev in an incomplete year (otherwise as the rule below)
1743  $days = 29;
1744  } else {
1745  # Odd months have 30 days, even have 29
1746  $days = 30 - ( $hebrewMonth - 1 ) % 2;
1747  }
1748  if ( $hebrewDay <= $days ) {
1749  # In the current month
1750  break;
1751  } else {
1752  # Subtract the days of the current month
1753  $hebrewDay -= $days;
1754  # Try in the next month
1755  $hebrewMonth++;
1756  }
1757  }
1758 
1759  return [ $hebrewYear, $hebrewMonth, $hebrewDay, $days ];
1760  }
1761 
1771  private static function hebrewYearStart( $year ) {
1772  $a = intval( ( 12 * ( $year - 1 ) + 17 ) % 19 );
1773  $b = intval( ( $year - 1 ) % 4 );
1774  $m = 32.044093161144 + 1.5542417966212 * $a + $b / 4.0 - 0.0031777940220923 * ( $year - 1 );
1775  if ( $m < 0 ) {
1776  $m--;
1777  }
1778  $Mar = intval( $m );
1779  if ( $m < 0 ) {
1780  $m++;
1781  }
1782  $m -= $Mar;
1783 
1784  $c = intval( ( $Mar + 3 * ( $year - 1 ) + 5 * $b + 5 ) % 7 );
1785  if ( $c == 0 && $a > 11 && $m >= 0.89772376543210 ) {
1786  $Mar++;
1787  } elseif ( $c == 1 && $a > 6 && $m >= 0.63287037037037 ) {
1788  $Mar += 2;
1789  } elseif ( $c == 2 || $c == 4 || $c == 6 ) {
1790  $Mar++;
1791  }
1792 
1793  $Mar += intval( ( $year - 3761 ) / 100 ) - intval( ( $year - 3761 ) / 400 ) - 24;
1794  return $Mar;
1795  }
1796 
1809  private static function tsToYear( $ts, $cName ) {
1810  $gy = substr( $ts, 0, 4 );
1811  $gm = substr( $ts, 4, 2 );
1812  $gd = substr( $ts, 6, 2 );
1813 
1814  if ( !strcmp( $cName, 'thai' ) ) {
1815  # Thai solar dates
1816  # Add 543 years to the Gregorian calendar
1817  # Months and days are identical
1818  $gy_offset = $gy + 543;
1819  # fix for dates between 1912 and 1941
1820  # https://en.wikipedia.org/?oldid=836596673#New_year
1821  if ( $gy >= 1912 && $gy <= 1940 ) {
1822  if ( $gm <= 3 ) {
1823  $gy_offset--;
1824  }
1825  $gm = ( $gm - 3 ) % 12;
1826  }
1827  } elseif ( ( !strcmp( $cName, 'minguo' ) ) || !strcmp( $cName, 'juche' ) ) {
1828  # Minguo dates
1829  # Deduct 1911 years from the Gregorian calendar
1830  # Months and days are identical
1831  $gy_offset = $gy - 1911;
1832  } elseif ( !strcmp( $cName, 'tenno' ) ) {
1833  # Nengō dates up to Meiji period
1834  # Deduct years from the Gregorian calendar
1835  # depending on the nengo periods
1836  # Months and days are identical
1837  if ( ( $gy < 1912 )
1838  || ( ( $gy == 1912 ) && ( $gm < 7 ) )
1839  || ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd < 31 ) )
1840  ) {
1841  # Meiji period
1842  $gy_gannen = $gy - 1868 + 1;
1843  $gy_offset = $gy_gannen;
1844  if ( $gy_gannen == 1 ) {
1845  $gy_offset = '元';
1846  }
1847  $gy_offset = '明治' . $gy_offset;
1848  } elseif (
1849  ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd == 31 ) ) ||
1850  ( ( $gy == 1912 ) && ( $gm >= 8 ) ) ||
1851  ( ( $gy > 1912 ) && ( $gy < 1926 ) ) ||
1852  ( ( $gy == 1926 ) && ( $gm < 12 ) ) ||
1853  ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd < 26 ) )
1854  ) {
1855  # Taishō period
1856  $gy_gannen = $gy - 1912 + 1;
1857  $gy_offset = $gy_gannen;
1858  if ( $gy_gannen == 1 ) {
1859  $gy_offset = '元';
1860  }
1861  $gy_offset = '大正' . $gy_offset;
1862  } elseif (
1863  ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd >= 26 ) ) ||
1864  ( ( $gy > 1926 ) && ( $gy < 1989 ) ) ||
1865  ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd < 8 ) )
1866  ) {
1867  # Shōwa period
1868  $gy_gannen = $gy - 1926 + 1;
1869  $gy_offset = $gy_gannen;
1870  if ( $gy_gannen == 1 ) {
1871  $gy_offset = '元';
1872  }
1873  $gy_offset = '昭和' . $gy_offset;
1874  } elseif (
1875  ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd >= 8 ) ) ||
1876  ( ( $gy > 1989 ) && ( $gy < 2019 ) ) ||
1877  ( ( $gy == 2019 ) && ( $gm < 5 ) )
1878  ) {
1879  # Heisei period
1880  $gy_gannen = $gy - 1989 + 1;
1881  $gy_offset = $gy_gannen;
1882  if ( $gy_gannen == 1 ) {
1883  $gy_offset = '元';
1884  }
1885  $gy_offset = '平成' . $gy_offset;
1886  } else {
1887  # Reiwa period
1888  $gy_gannen = $gy - 2019 + 1;
1889  $gy_offset = $gy_gannen;
1890  if ( $gy_gannen == 1 ) {
1891  $gy_offset = '元';
1892  }
1893  $gy_offset = '令和' . $gy_offset;
1894  }
1895  } else {
1896  $gy_offset = $gy;
1897  }
1898 
1899  return [ $gy_offset, $gm, $gd ];
1900  }
1901 
1915  private static function strongDirFromContent( $text = '' ) {
1916  if ( !preg_match( self::$strongDirRegex, $text, $matches ) ) {
1917  return null;
1918  }
1919  if ( $matches[1] === '' ) {
1920  return 'rtl';
1921  }
1922  return 'ltr';
1923  }
1924 
1932  static function romanNumeral( $num ) {
1933  static $table = [
1934  [ '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ],
1935  [ '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ],
1936  [ '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ],
1937  [ '', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM', 'MMMMMM', 'MMMMMMM',
1938  'MMMMMMMM', 'MMMMMMMMM', 'MMMMMMMMMM' ]
1939  ];
1940 
1941  $num = intval( $num );
1942  if ( $num > 10000 || $num <= 0 ) {
1943  return $num;
1944  }
1945 
1946  $s = '';
1947  for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) {
1948  if ( $num >= $pow10 ) {
1949  $s .= $table[$i][(int)floor( $num / $pow10 )];
1950  }
1951  $num = $num % $pow10;
1952  }
1953  return $s;
1954  }
1955 
1963  static function hebrewNumeral( $num ) {
1964  static $table = [
1965  [ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ],
1966  [ '', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ', 'ק' ],
1967  [ '',
1968  [ 'ק' ],
1969  [ 'ר' ],
1970  [ 'ש' ],
1971  [ 'ת' ],
1972  [ 'ת', 'ק' ],
1973  [ 'ת', 'ר' ],
1974  [ 'ת', 'ש' ],
1975  [ 'ת', 'ת' ],
1976  [ 'ת', 'ת', 'ק' ],
1977  [ 'ת', 'ת', 'ר' ],
1978  ],
1979  [ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ]
1980  ];
1981 
1982  $num = intval( $num );
1983  if ( $num > 9999 || $num <= 0 ) {
1984  return $num;
1985  }
1986 
1987  // Round thousands have special notations
1988  if ( $num === 1000 ) {
1989  return "א' אלף";
1990  } elseif ( $num % 1000 === 0 ) {
1991  return $table[0][$num / 1000] . "' אלפים";
1992  }
1993 
1994  $letters = [];
1995 
1996  for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) {
1997  if ( $num >= $pow10 ) {
1998  if ( $num === 15 || $num === 16 ) {
1999  $letters[] = $table[0][9];
2000  $letters[] = $table[0][$num - 9];
2001  $num = 0;
2002  } else {
2003  $letters = array_merge(
2004  $letters,
2005  (array)$table[$i][intval( $num / $pow10 )]
2006  );
2007 
2008  if ( $pow10 === 1000 ) {
2009  $letters[] = "'";
2010  }
2011  }
2012  }
2013 
2014  $num = $num % $pow10;
2015  }
2016 
2017  $preTransformLength = count( $letters );
2018  if ( $preTransformLength === 1 ) {
2019  // Add geresh (single quote) to one-letter numbers
2020  $letters[] = "'";
2021  } else {
2022  $lastIndex = $preTransformLength - 1;
2023  $letters[$lastIndex] = str_replace(
2024  [ 'כ', 'מ', 'נ', 'פ', 'צ' ],
2025  [ 'ך', 'ם', 'ן', 'ף', 'ץ' ],
2026  $letters[$lastIndex]
2027  );
2028 
2029  // Add gershayim (double quote) to multiple-letter numbers,
2030  // but exclude numbers with only one letter after the thousands
2031  // (1001-1009, 1020, 1030, 2001-2009, etc.)
2032  if ( $letters[1] === "'" && $preTransformLength === 3 ) {
2033  $letters[] = "'";
2034  } else {
2035  array_splice( $letters, -1, 0, '"' );
2036  }
2037  }
2038 
2039  return implode( $letters );
2040  }
2041 
2050  public function userAdjust( $ts, $tz = false ) {
2051  global $wgUser, $wgLocalTZoffset;
2052 
2053  if ( $tz === false ) {
2054  $tz = $wgUser->getOption( 'timecorrection' );
2055  }
2056 
2057  $data = explode( '|', $tz, 3 );
2058 
2059  if ( $data[0] == 'ZoneInfo' ) {
2060  try {
2061  $userTZ = new DateTimeZone( $data[2] );
2062  $date = new DateTime( $ts, new DateTimeZone( 'UTC' ) );
2063  $date->setTimezone( $userTZ );
2064  return $date->format( 'YmdHis' );
2065  } catch ( Exception $e ) {
2066  // Unrecognized timezone, default to 'Offset' with the stored offset.
2067  $data[0] = 'Offset';
2068  }
2069  }
2070 
2071  if ( $data[0] == 'System' || $tz == '' ) {
2072  # Global offset in minutes.
2073  $minDiff = $wgLocalTZoffset;
2074  } elseif ( $data[0] == 'Offset' ) {
2075  $minDiff = intval( $data[1] );
2076  } else {
2077  $data = explode( ':', $tz );
2078  if ( count( $data ) == 2 ) {
2079  $data[0] = intval( $data[0] );
2080  $data[1] = intval( $data[1] );
2081  $minDiff = abs( $data[0] ) * 60 + $data[1];
2082  if ( $data[0] < 0 ) {
2083  $minDiff = -$minDiff;
2084  }
2085  } else {
2086  $minDiff = intval( $data[0] ) * 60;
2087  }
2088  }
2089 
2090  # No difference ? Return time unchanged
2091  if ( $minDiff == 0 ) {
2092  return $ts;
2093  }
2094 
2095  Wikimedia\suppressWarnings(); // E_STRICT system time bitching
2096  # Generate an adjusted date; take advantage of the fact that mktime
2097  # will normalize out-of-range values so we don't have to split $minDiff
2098  # into hours and minutes.
2099  $t = mktime( (
2100  (int)substr( $ts, 8, 2 ) ), # Hours
2101  (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
2102  (int)substr( $ts, 12, 2 ), # Seconds
2103  (int)substr( $ts, 4, 2 ), # Month
2104  (int)substr( $ts, 6, 2 ), # Day
2105  (int)substr( $ts, 0, 4 ) ); # Year
2106 
2107  $date = date( 'YmdHis', $t );
2108  Wikimedia\restoreWarnings();
2109 
2110  return $date;
2111  }
2112 
2128  function dateFormat( $usePrefs = true ) {
2129  global $wgUser;
2130 
2131  if ( is_bool( $usePrefs ) ) {
2132  if ( $usePrefs ) {
2133  $datePreference = $wgUser->getDatePreference();
2134  } else {
2135  $datePreference = (string)User::getDefaultOption( 'date' );
2136  }
2137  } else {
2138  $datePreference = (string)$usePrefs;
2139  }
2140 
2141  // return int
2142  if ( $datePreference == '' ) {
2143  return 'default';
2144  }
2145 
2146  return $datePreference;
2147  }
2148 
2159  function getDateFormatString( $type, $pref ) {
2160  $wasDefault = false;
2161  if ( $pref == 'default' ) {
2162  $wasDefault = true;
2163  $pref = $this->getDefaultDateFormat();
2164  }
2165 
2166  if ( !isset( $this->dateFormatStrings[$type][$pref] ) ) {
2167  $df =
2168  $this->localisationCache->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
2169 
2170  if ( $type === 'pretty' && $df === null ) {
2171  $df = $this->getDateFormatString( 'date', $pref );
2172  }
2173 
2174  if ( !$wasDefault && $df === null ) {
2175  $pref = $this->getDefaultDateFormat();
2176  $df = $this->getLocalisationCache()
2177  ->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
2178  }
2179 
2180  $this->dateFormatStrings[$type][$pref] = $df;
2181  }
2182  return $this->dateFormatStrings[$type][$pref];
2183  }
2184 
2195  public function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
2196  $ts = wfTimestamp( TS_MW, $ts );
2197  if ( $adj ) {
2198  $ts = $this->userAdjust( $ts, $timecorrection );
2199  }
2200  $df = $this->getDateFormatString( 'date', $this->dateFormat( $format ) );
2201  return $this->sprintfDate( $df, $ts );
2202  }
2203 
2214  public function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
2215  $ts = wfTimestamp( TS_MW, $ts );
2216  if ( $adj ) {
2217  $ts = $this->userAdjust( $ts, $timecorrection );
2218  }
2219  $df = $this->getDateFormatString( 'time', $this->dateFormat( $format ) );
2220  return $this->sprintfDate( $df, $ts );
2221  }
2222 
2234  public function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false ) {
2235  $ts = wfTimestamp( TS_MW, $ts );
2236  if ( $adj ) {
2237  $ts = $this->userAdjust( $ts, $timecorrection );
2238  }
2239  $df = $this->getDateFormatString( 'both', $this->dateFormat( $format ) );
2240  return $this->sprintfDate( $df, $ts );
2241  }
2242 
2253  public function formatDuration( $seconds, array $chosenIntervals = [] ) {
2254  $intervals = $this->getDurationIntervals( $seconds, $chosenIntervals );
2255 
2256  $segments = [];
2257 
2258  foreach ( $intervals as $intervalName => $intervalValue ) {
2259  // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
2260  // duration-years, duration-decades, duration-centuries, duration-millennia
2261  $message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
2262  $segments[] = $message->inLanguage( $this )->escaped();
2263  }
2264 
2265  return $this->listToText( $segments );
2266  }
2267 
2279  public function getDurationIntervals( $seconds, array $chosenIntervals = [] ) {
2280  if ( empty( $chosenIntervals ) ) {
2281  $chosenIntervals = [
2282  'millennia',
2283  'centuries',
2284  'decades',
2285  'years',
2286  'days',
2287  'hours',
2288  'minutes',
2289  'seconds'
2290  ];
2291  }
2292 
2293  $intervals = array_intersect_key( self::$durationIntervals, array_flip( $chosenIntervals ) );
2294  $sortedNames = array_keys( $intervals );
2295  $smallestInterval = array_pop( $sortedNames );
2296 
2297  $segments = [];
2298 
2299  foreach ( $intervals as $name => $length ) {
2300  $value = floor( $seconds / $length );
2301 
2302  if ( $value > 0 || ( $name == $smallestInterval && empty( $segments ) ) ) {
2303  $seconds -= $value * $length;
2304  $segments[$name] = $value;
2305  }
2306  }
2307 
2308  return $segments;
2309  }
2310 
2330  private function internalUserTimeAndDate( $type, $ts, User $user, array $options ) {
2331  $ts = wfTimestamp( TS_MW, $ts );
2332  $options += [ 'timecorrection' => true, 'format' => true ];
2333  if ( $options['timecorrection'] !== false ) {
2334  if ( $options['timecorrection'] === true ) {
2335  $offset = $user->getOption( 'timecorrection' );
2336  } else {
2337  $offset = $options['timecorrection'];
2338  }
2339  $ts = $this->userAdjust( $ts, $offset );
2340  }
2341  if ( $options['format'] === true ) {
2342  $format = $user->getDatePreference();
2343  } else {
2344  $format = $options['format'];
2345  }
2346  $df = $this->getDateFormatString( $type, $this->dateFormat( $format ) );
2347  return $this->sprintfDate( $df, $ts );
2348  }
2349 
2369  public function userDate( $ts, User $user, array $options = [] ) {
2370  return $this->internalUserTimeAndDate( 'date', $ts, $user, $options );
2371  }
2372 
2392  public function userTime( $ts, User $user, array $options = [] ) {
2393  return $this->internalUserTimeAndDate( 'time', $ts, $user, $options );
2394  }
2395 
2415  public function userTimeAndDate( $ts, User $user, array $options = [] ) {
2416  return $this->internalUserTimeAndDate( 'both', $ts, $user, $options );
2417  }
2418 
2434  public function getHumanTimestamp(
2435  MWTimestamp $time, MWTimestamp $relativeTo = null, User $user = null
2436  ) {
2437  if ( $relativeTo === null ) {
2438  $relativeTo = new MWTimestamp();
2439  }
2440  if ( $user === null ) {
2441  $user = RequestContext::getMain()->getUser();
2442  }
2443 
2444  // Adjust for the user's timezone.
2445  $offsetThis = $time->offsetForUser( $user );
2446  $offsetRel = $relativeTo->offsetForUser( $user );
2447 
2448  $ts = '';
2449  if ( Hooks::run( 'GetHumanTimestamp', [ &$ts, $time, $relativeTo, $user, $this ] ) ) {
2450  $ts = $this->getHumanTimestampInternal( $time, $relativeTo, $user );
2451  }
2452 
2453  // Reset the timezone on the objects.
2454  $time->timestamp->sub( $offsetThis );
2455  $relativeTo->timestamp->sub( $offsetRel );
2456 
2457  return $ts;
2458  }
2459 
2471  private function getHumanTimestampInternal(
2472  MWTimestamp $ts, MWTimestamp $relativeTo, User $user
2473  ) {
2474  $diff = $ts->diff( $relativeTo );
2475  $diffDay = (bool)( (int)$ts->timestamp->format( 'w' ) -
2476  (int)$relativeTo->timestamp->format( 'w' ) );
2477  $days = $diff->days ?: (int)$diffDay;
2478  if ( $diff->invert || $days > 5
2479  && $ts->timestamp->format( 'Y' ) !== $relativeTo->timestamp->format( 'Y' )
2480  ) {
2481  // Timestamps are in different years: use full timestamp
2482  // Also do full timestamp for future dates
2486  $format = $this->getDateFormatString( 'both', $user->getDatePreference() ?: 'default' );
2487  $ts = $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) );
2488  } elseif ( $days > 5 ) {
2489  // Timestamps are in same year, but more than 5 days ago: show day and month only.
2490  $format = $this->getDateFormatString( 'pretty', $user->getDatePreference() ?: 'default' );
2491  $ts = $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) );
2492  } elseif ( $days > 1 ) {
2493  // Timestamp within the past week: show the day of the week and time
2494  $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2495  $weekday = self::$mWeekdayMsgs[$ts->timestamp->format( 'w' )];
2496  // Messages:
2497  // sunday-at, monday-at, tuesday-at, wednesday-at, thursday-at, friday-at, saturday-at
2498  $ts = wfMessage( "$weekday-at" )
2499  ->inLanguage( $this )
2500  ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2501  ->text();
2502  } elseif ( $days == 1 ) {
2503  // Timestamp was yesterday: say 'yesterday' and the time.
2504  $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2505  $ts = wfMessage( 'yesterday-at' )
2506  ->inLanguage( $this )
2507  ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2508  ->text();
2509  } elseif ( $diff->h > 1 || $diff->h == 1 && $diff->i > 30 ) {
2510  // Timestamp was today, but more than 90 minutes ago: say 'today' and the time.
2511  $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2512  $ts = wfMessage( 'today-at' )
2513  ->inLanguage( $this )
2514  ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2515  ->text();
2516 
2517  // From here on in, the timestamp was soon enough ago so that we can simply say
2518  // XX units ago, e.g., "2 hours ago" or "5 minutes ago"
2519  } elseif ( $diff->h == 1 ) {
2520  // Less than 90 minutes, but more than an hour ago.
2521  $ts = wfMessage( 'hours-ago' )->inLanguage( $this )->numParams( 1 )->text();
2522  } elseif ( $diff->i >= 1 ) {
2523  // A few minutes ago.
2524  $ts = wfMessage( 'minutes-ago' )->inLanguage( $this )->numParams( $diff->i )->text();
2525  } elseif ( $diff->s >= 30 ) {
2526  // Less than a minute, but more than 30 sec ago.
2527  $ts = wfMessage( 'seconds-ago' )->inLanguage( $this )->numParams( $diff->s )->text();
2528  } else {
2529  // Less than 30 seconds ago.
2530  $ts = wfMessage( 'just-now' )->text();
2531  }
2532 
2533  return $ts;
2534  }
2535 
2540  public function getMessage( $key ) {
2541  return $this->localisationCache->getSubitem( $this->mCode, 'messages', $key );
2542  }
2543 
2547  function getAllMessages() {
2548  return $this->localisationCache->getItem( $this->mCode, 'messages' );
2549  }
2550 
2557  public function iconv( $in, $out, $string ) {
2558  # Even with //IGNORE iconv can whine about illegal characters in
2559  # *input* string. We just ignore those too.
2560  # REF: https://bugs.php.net/bug.php?id=37166
2561  # REF: https://phabricator.wikimedia.org/T18885
2562  Wikimedia\suppressWarnings();
2563  $text = iconv( $in, $out . '//IGNORE', $string );
2564  Wikimedia\restoreWarnings();
2565  return $text;
2566  }
2567 
2568  // callback functions for ucwords(), ucwordbreaks()
2569 
2575  return $this->ucfirst( $matches[1] );
2576  }
2577 
2583  return mb_strtoupper( $matches[0] );
2584  }
2585 
2591  return mb_strtoupper( $matches[0] );
2592  }
2593 
2598  public function ucfirst( $str ) {
2599  $octetCode = ord( $str );
2600  // See https://en.wikipedia.org/wiki/ASCII#Printable_characters
2601  if ( $octetCode < 96 ) {
2602  // Assume this is an uppercase/uncased ASCII character
2603  return (string)$str;
2604  } elseif ( $octetCode < 128 ) {
2605  // Assume this is a lowercase/uncased ASCII character
2606  return ucfirst( $str );
2607  }
2608 
2609  return $this->isMultibyte( $str )
2610  // Assume this is a multibyte character and mb_internal_encoding() is appropriate
2611  ? $this->mbUpperChar( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 )
2612  // Assume this is a non-multibyte character and LC_CASE is appropriate
2613  : ucfirst( $str );
2614  }
2615 
2621  public function uc( $str, $first = false ) {
2622  if ( $first ) {
2623  return $this->ucfirst( $str );
2624  } else {
2625  return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
2626  }
2627  }
2628 
2642  protected function mbUpperChar( $char ) {
2644 
2645  return $wgOverrideUcfirstCharacters[$char] ?? mb_strtoupper( $char );
2646  }
2647 
2652  public function lcfirst( $str ) {
2653  $octetCode = ord( $str );
2654  // See https://en.wikipedia.org/wiki/ASCII#Printable_characters
2655  if ( $octetCode < 96 ) {
2656  // Assume this is an uppercase/uncased ASCII character
2657  return lcfirst( $str );
2658  } elseif ( $octetCode < 128 ) {
2659  // Assume this is a lowercase/uncased ASCII character
2660  return (string)$str;
2661  }
2662 
2663  return $this->isMultibyte( $str )
2664  // Assume this is a multibyte character and mb_internal_encoding() is appropriate
2665  ? mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 )
2666  // Assume this is a non-multibyte character and LC_CASE is appropriate
2667  : lcfirst( $str );
2668  }
2669 
2675  public function lc( $str, $first = false ) {
2676  if ( $first ) {
2677  return $this->lcfirst( $str );
2678  } else {
2679  return $this->isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
2680  }
2681  }
2682 
2687  function isMultibyte( $str ) {
2688  return strlen( $str ) !== mb_strlen( $str );
2689  }
2690 
2695  function ucwords( $str ) {
2696  if ( $this->isMultibyte( $str ) ) {
2697  $str = $this->lc( $str );
2698 
2699  // regexp to find first letter in each word (i.e. after each space)
2700  $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
2701 
2702  // function to use to capitalize a single char
2703  return preg_replace_callback(
2704  $replaceRegexp,
2705  [ $this, 'ucwordsCallbackMB' ],
2706  $str
2707  );
2708  } else {
2709  return ucwords( strtolower( $str ) );
2710  }
2711  }
2712 
2719  function ucwordbreaks( $str ) {
2720  if ( $this->isMultibyte( $str ) ) {
2721  $str = $this->lc( $str );
2722 
2723  // since \b doesn't work for UTF-8, we explicitely define word break chars
2724  $breaks = "[ \-\(\)\}\{\.,\?!]";
2725 
2726  // find first letter after word break
2727  $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|" .
2728  "$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
2729 
2730  return preg_replace_callback(
2731  $replaceRegexp,
2732  [ $this, 'ucwordbreaksCallbackMB' ],
2733  $str
2734  );
2735  } else {
2736  return preg_replace_callback(
2737  '/\b([\w\x80-\xff]+)\b/',
2738  [ $this, 'ucwordbreaksCallbackAscii' ],
2739  $str
2740  );
2741  }
2742  }
2743 
2759  function caseFold( $s ) {
2760  return $this->uc( $s );
2761  }
2762 
2768  function checkTitleEncoding( $s ) {
2769  if ( is_array( $s ) ) {
2770  throw new MWException( 'Given array to checkTitleEncoding.' );
2771  }
2772  if ( StringUtils::isUtf8( $s ) ) {
2773  return $s;
2774  }
2775 
2776  return $this->iconv( $this->fallback8bitEncoding(), 'utf-8', $s );
2777  }
2778 
2783  return $this->localisationCache->getItem( $this->mCode, 'fallback8bitEncoding' );
2784  }
2785 
2794  function hasWordBreaks() {
2795  return true;
2796  }
2797 
2805  function segmentByWord( $string ) {
2806  return $string;
2807  }
2808 
2816  function normalizeForSearch( $string ) {
2817  return self::convertDoubleWidth( $string );
2818  }
2819 
2828  protected static function convertDoubleWidth( $string ) {
2829  static $full = null;
2830  static $half = null;
2831 
2832  if ( $full === null ) {
2833  $fullWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2834  $halfWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2835  $full = str_split( $fullWidth, 3 );
2836  $half = str_split( $halfWidth );
2837  }
2838 
2839  $string = str_replace( $full, $half, $string );
2840  return $string;
2841  }
2842 
2848  protected static function insertSpace( $string, $pattern ) {
2849  $string = preg_replace( $pattern, " $1 ", $string );
2850  $string = preg_replace( '/ +/', ' ', $string );
2851  return $string;
2852  }
2853 
2858  function convertForSearchResult( $termsArray ) {
2859  # some languages, e.g. Chinese, need to do a conversion
2860  # in order for search results to be displayed correctly
2861  return $termsArray;
2862  }
2863 
2870  function firstChar( $s ) {
2871  $matches = [];
2872  preg_match(
2873  '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
2874  '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/',
2875  $s,
2876  $matches
2877  );
2878 
2879  if ( isset( $matches[1] ) ) {
2880  if ( strlen( $matches[1] ) != 3 ) {
2881  return $matches[1];
2882  }
2883 
2884  // Break down Hangul syllables to grab the first jamo
2885  $code = UtfNormal\Utils::utf8ToCodepoint( $matches[1] );
2886  if ( $code < 0xac00 || 0xd7a4 <= $code ) {
2887  return $matches[1];
2888  } elseif ( $code < 0xb098 ) {
2889  return "\u{3131}";
2890  } elseif ( $code < 0xb2e4 ) {
2891  return "\u{3134}";
2892  } elseif ( $code < 0xb77c ) {
2893  return "\u{3137}";
2894  } elseif ( $code < 0xb9c8 ) {
2895  return "\u{3139}";
2896  } elseif ( $code < 0xbc14 ) {
2897  return "\u{3141}";
2898  } elseif ( $code < 0xc0ac ) {
2899  return "\u{3142}";
2900  } elseif ( $code < 0xc544 ) {
2901  return "\u{3145}";
2902  } elseif ( $code < 0xc790 ) {
2903  return "\u{3147}";
2904  } elseif ( $code < 0xcc28 ) {
2905  return "\u{3148}";
2906  } elseif ( $code < 0xce74 ) {
2907  return "\u{314A}";
2908  } elseif ( $code < 0xd0c0 ) {
2909  return "\u{314B}";
2910  } elseif ( $code < 0xd30c ) {
2911  return "\u{314C}";
2912  } elseif ( $code < 0xd558 ) {
2913  return "\u{314D}";
2914  } else {
2915  return "\u{314E}";
2916  }
2917  } else {
2918  return '';
2919  }
2920  }
2921 
2933  public function normalize( $s ) {
2934  global $wgAllUnicodeFixes;
2935  $s = UtfNormal\Validator::cleanUp( $s );
2936  if ( $wgAllUnicodeFixes ) {
2937  $s = $this->transformUsingPairFile( 'normalize-ar.php', $s );
2938  $s = $this->transformUsingPairFile( 'normalize-ml.php', $s );
2939  }
2940 
2941  return $s;
2942  }
2943 
2958  protected function transformUsingPairFile( $file, $string ) {
2959  if ( !isset( $this->transformData[$file] ) ) {
2960  global $IP;
2961  $data = require "$IP/languages/data/{$file}";
2962  $this->transformData[$file] = new ReplacementArray( $data );
2963  }
2964  return $this->transformData[$file]->replace( $string );
2965  }
2966 
2972  function isRTL() {
2973  return $this->localisationCache->getItem( $this->mCode, 'rtl' );
2974  }
2975 
2980  function getDir() {
2981  return $this->isRTL() ? 'rtl' : 'ltr';
2982  }
2983 
2992  function alignStart() {
2993  return $this->isRTL() ? 'right' : 'left';
2994  }
2995 
3004  function alignEnd() {
3005  return $this->isRTL() ? 'left' : 'right';
3006  }
3007 
3019  function getDirMarkEntity( $opposite = false ) {
3020  if ( $opposite ) {
3021  return $this->isRTL() ? '&lrm;' : '&rlm;';
3022  }
3023  return $this->isRTL() ? '&rlm;' : '&lrm;';
3024  }
3025 
3036  function getDirMark( $opposite = false ) {
3037  $lrm = "\u{200E}"; # LEFT-TO-RIGHT MARK, commonly abbreviated LRM
3038  $rlm = "\u{200F}"; # RIGHT-TO-LEFT MARK, commonly abbreviated RLM
3039  if ( $opposite ) {
3040  return $this->isRTL() ? $lrm : $rlm;
3041  }
3042  return $this->isRTL() ? $rlm : $lrm;
3043  }
3044 
3048  function capitalizeAllNouns() {
3049  return $this->localisationCache->getItem( $this->mCode, 'capitalizeAllNouns' );
3050  }
3051 
3059  function getArrow( $direction = 'forwards' ) {
3060  switch ( $direction ) {
3061  case 'forwards':
3062  return $this->isRTL() ? '←' : '→';
3063  case 'backwards':
3064  return $this->isRTL() ? '→' : '←';
3065  case 'left':
3066  return '←';
3067  case 'right':
3068  return '→';
3069  case 'up':
3070  return '↑';
3071  case 'down':
3072  return '↓';
3073  }
3074  }
3075 
3081  function linkPrefixExtension() {
3082  return $this->localisationCache->getItem( $this->mCode, 'linkPrefixExtension' );
3083  }
3084 
3089  function getMagicWords() {
3090  return $this->localisationCache->getItem( $this->mCode, 'magicWords' );
3091  }
3092 
3098  function getMagic( $mw ) {
3099  $rawEntry = $this->mMagicExtensions[$mw->mId] ??
3100  $this->localisationCache->getSubitem( $this->mCode, 'magicWords', $mw->mId );
3101 
3102  if ( !is_array( $rawEntry ) ) {
3103  wfWarn( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" );
3104  } else {
3105  $mw->mCaseSensitive = $rawEntry[0];
3106  $mw->mSynonyms = array_slice( $rawEntry, 1 );
3107  }
3108  }
3109 
3115  function addMagicWordsByLang( $newWords ) {
3116  $fallbackChain = $this->getFallbackLanguages();
3117  $fallbackChain = array_reverse( $fallbackChain );
3118  foreach ( $fallbackChain as $code ) {
3119  if ( isset( $newWords[$code] ) ) {
3120  $this->mMagicExtensions = $newWords[$code] + $this->mMagicExtensions;
3121  }
3122  }
3123  }
3124 
3131  // Cache aliases because it may be slow to load them
3132  if ( is_null( $this->mExtendedSpecialPageAliases ) ) {
3133  // Initialise array
3134  $this->mExtendedSpecialPageAliases =
3135  $this->localisationCache->getItem( $this->mCode, 'specialPageAliases' );
3136  }
3137 
3139  }
3140 
3147  function emphasize( $text ) {
3148  return "<em>$text</em>";
3149  }
3150 
3173  public function formatNum( $number, $nocommafy = false ) {
3174  global $wgTranslateNumerals;
3175  if ( !$nocommafy ) {
3176  $number = $this->commafy( $number );
3177  $s = $this->separatorTransformTable();
3178  if ( $s ) {
3179  $number = strtr( $number, $s );
3180  }
3181  }
3182 
3183  if ( $wgTranslateNumerals ) {
3184  $s = $this->digitTransformTable();
3185  if ( $s ) {
3186  $number = strtr( $number, $s );
3187  }
3188  }
3189 
3190  return (string)$number;
3191  }
3192 
3201  public function formatNumNoSeparators( $number ) {
3202  return $this->formatNum( $number, true );
3203  }
3204 
3209  public function parseFormattedNumber( $number ) {
3210  $s = $this->digitTransformTable();
3211  if ( $s ) {
3212  // eliminate empty array values such as ''. (T66347)
3213  $s = array_filter( $s );
3214  $number = strtr( $number, array_flip( $s ) );
3215  }
3216 
3217  $s = $this->separatorTransformTable();
3218  if ( $s ) {
3219  // eliminate empty array values such as ''. (T66347)
3220  $s = array_filter( $s );
3221  $number = strtr( $number, array_flip( $s ) );
3222  }
3223 
3224  $number = strtr( $number, [ ',' => '' ] );
3225  return $number;
3226  }
3227 
3234  function commafy( $number ) {
3237  if ( $number === null ) {
3238  return '';
3239  }
3240 
3241  if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
3242  // Default grouping is at thousands, use the same for ###,###,### pattern too.
3243  // In some languages it's conventional not to insert a thousands separator
3244  // in numbers that are four digits long (1000-9999).
3245  if ( $minimumGroupingDigits ) {
3246  // Number of '#' characters after last comma in the grouping pattern.
3247  // The pattern is hardcoded here, but this would vary for different patterns.
3248  $primaryGroupingSize = 3;
3249  // Maximum length of a number to suppress digit grouping for.
3250  $maximumLength = $minimumGroupingDigits + $primaryGroupingSize - 1;
3251  if ( preg_match( '/^\-?\d{1,' . $maximumLength . '}(\.\d+)?$/', $number ) ) {
3252  return $number;
3253  }
3254  }
3255  return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $number ) ) );
3256  } else {
3257  // Ref: http://cldr.unicode.org/translation/number-patterns
3258  $sign = "";
3259  if ( intval( $number ) < 0 ) {
3260  // For negative numbers apply the algorithm like positive number and add sign.
3261  $sign = "-";
3262  $number = substr( $number, 1 );
3263  }
3264  $integerPart = [];
3265  $decimalPart = [];
3266  $numMatches = preg_match_all( "/(#+)/", $digitGroupingPattern, $matches );
3267  preg_match( "/\d+/", $number, $integerPart );
3268  preg_match( "/\.\d*/", $number, $decimalPart );
3269  $groupedNumber = ( count( $decimalPart ) > 0 ) ? $decimalPart[0] : "";
3270  if ( $groupedNumber === $number ) {
3271  // the string does not have any number part. Eg: .12345
3272  return $sign . $groupedNumber;
3273  }
3274  $start = $end = ( $integerPart ) ? strlen( $integerPart[0] ) : 0;
3275  while ( $start > 0 ) {
3276  $match = $matches[0][$numMatches - 1];
3277  $matchLen = strlen( $match );
3278  $start = $end - $matchLen;
3279  if ( $start < 0 ) {
3280  $start = 0;
3281  }
3282  $groupedNumber = substr( $number, $start, $end - $start ) . $groupedNumber;
3283  $end = $start;
3284  if ( $numMatches > 1 ) {
3285  // use the last pattern for the rest of the number
3286  $numMatches--;
3287  }
3288  if ( $start > 0 ) {
3289  $groupedNumber = "," . $groupedNumber;
3290  }
3291  }
3292  return $sign . $groupedNumber;
3293  }
3294  }
3295 
3300  return $this->localisationCache->getItem( $this->mCode, 'digitGroupingPattern' );
3301  }
3302 
3306  function digitTransformTable() {
3307  return $this->localisationCache->getItem( $this->mCode, 'digitTransformTable' );
3308  }
3309 
3314  return $this->localisationCache->getItem( $this->mCode, 'separatorTransformTable' );
3315  }
3316 
3321  return $this->localisationCache->getItem( $this->mCode, 'minimumGroupingDigits' );
3322  }
3323 
3332  public function listToText( array $list ) {
3333  $itemCount = count( $list );
3334  if ( $itemCount < 1 ) {
3335  return '';
3336  }
3337  $text = array_pop( $list );
3338  if ( $itemCount > 1 ) {
3339  $and = $this->msg( 'and' )->escaped();
3340  $space = $this->msg( 'word-separator' )->escaped();
3341  $comma = '';
3342  if ( $itemCount > 2 ) {
3343  $comma = $this->msg( 'comma-separator' )->escaped();
3344  }
3345  $text = implode( $comma, $list ) . $and . $space . $text;
3346  }
3347  return $text;
3348  }
3349 
3356  function commaList( array $list ) {
3357  return implode(
3358  wfMessage( 'comma-separator' )->inLanguage( $this )->escaped(),
3359  $list
3360  );
3361  }
3362 
3369  function semicolonList( array $list ) {
3370  return implode(
3371  wfMessage( 'semicolon-separator' )->inLanguage( $this )->escaped(),
3372  $list
3373  );
3374  }
3375 
3381  function pipeList( array $list ) {
3382  return implode(
3383  wfMessage( 'pipe-separator' )->inLanguage( $this )->escaped(),
3384  $list
3385  );
3386  }
3387 
3403  function truncateForDatabase( $string, $length, $ellipsis = '...', $adjustLength = true ) {
3404  return $this->truncateInternal(
3405  $string, $length, $ellipsis, $adjustLength, 'strlen', 'substr'
3406  );
3407  }
3408 
3427  function truncateForVisual( $string, $length, $ellipsis = '...', $adjustLength = true ) {
3428  // Passing encoding to mb_strlen and mb_substr is optional.
3429  // Encoding defaults to mb_internal_encoding(), which is set to UTF-8 in Setup.php, so
3430  // explicit specification of encoding is skipped.
3431  // Note: Both multibyte methods are callables invoked in truncateInternal.
3432  return $this->truncateInternal(
3433  $string, $length, $ellipsis, $adjustLength, 'mb_strlen', 'mb_substr'
3434  );
3435  }
3436 
3453  private function truncateInternal(
3454  $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
3455  ) {
3456  # Check if there is no need to truncate
3457  if ( $measureLength( $string ) <= abs( $length ) ) {
3458  return $string; // no need to truncate
3459  }
3460 
3461  # Use the localized ellipsis character
3462  if ( $ellipsis == '...' ) {
3463  $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
3464  }
3465  if ( $length == 0 ) {
3466  return $ellipsis; // convention
3467  }
3468 
3469  $stringOriginal = $string;
3470  # If ellipsis length is >= $length then we can't apply $adjustLength
3471  if ( $adjustLength && $measureLength( $ellipsis ) >= abs( $length ) ) {
3472  $string = $ellipsis; // this can be slightly unexpected
3473  # Otherwise, truncate and add ellipsis...
3474  } else {
3475  $ellipsisLength = $adjustLength ? $measureLength( $ellipsis ) : 0;
3476  if ( $length > 0 ) {
3477  $length -= $ellipsisLength;
3478  $string = $getSubstring( $string, 0, $length ); // xyz...
3479  $string = $this->removeBadCharLast( $string );
3480  $string = rtrim( $string ) . $ellipsis;
3481  } else {
3482  $length += $ellipsisLength;
3483  $string = $getSubstring( $string, $length ); // ...xyz
3484  $string = $this->removeBadCharFirst( $string );
3485  $string = $ellipsis . ltrim( $string );
3486  }
3487  }
3488 
3489  # Do not truncate if the ellipsis makes the string longer/equal (T24181).
3490  # This check is *not* redundant if $adjustLength, due to the single case where
3491  # LEN($ellipsis) > ABS($limit arg); $stringOriginal could be shorter than $string.
3492  if ( $measureLength( $string ) < $measureLength( $stringOriginal ) ) {
3493  return $string;
3494  } else {
3495  return $stringOriginal;
3496  }
3497  }
3498 
3506  protected function removeBadCharLast( $string ) {
3507  if ( $string != '' ) {
3508  $char = ord( $string[strlen( $string ) - 1] );
3509  $m = [];
3510  if ( $char >= 0xc0 ) {
3511  # We got the first byte only of a multibyte char; remove it.
3512  $string = substr( $string, 0, -1 );
3513  } elseif ( $char >= 0x80 &&
3514  // Use the /s modifier (PCRE_DOTALL) so (.*) also matches newlines
3515  preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
3516  '[\xf0-\xf7][\x80-\xbf]{1,2})$/s', $string, $m )
3517  ) {
3518  # We chopped in the middle of a character; remove it
3519  $string = $m[1];
3520  }
3521  }
3522  return $string;
3523  }
3524 
3532  protected function removeBadCharFirst( $string ) {
3533  if ( $string != '' ) {
3534  $char = ord( $string[0] );
3535  if ( $char >= 0x80 && $char < 0xc0 ) {
3536  # We chopped in the middle of a character; remove the whole thing
3537  $string = preg_replace( '/^[\x80-\xbf]+/', '', $string );
3538  }
3539  }
3540  return $string;
3541  }
3542 
3558  function truncateHtml( $text, $length, $ellipsis = '...' ) {
3559  # Use the localized ellipsis character
3560  if ( $ellipsis == '...' ) {
3561  $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
3562  }
3563  # Check if there is clearly no need to truncate
3564  if ( $length <= 0 ) {
3565  return $ellipsis; // no text shown, nothing to format (convention)
3566  } elseif ( strlen( $text ) <= $length ) {
3567  return $text; // string short enough even *with* HTML (short-circuit)
3568  }
3569 
3570  $dispLen = 0; // innerHTML legth so far
3571  $testingEllipsis = false; // checking if ellipses will make string longer/equal?
3572  $tagType = 0; // 0-open, 1-close
3573  $bracketState = 0; // 1-tag start, 2-tag name, 0-neither
3574  $entityState = 0; // 0-not entity, 1-entity
3575  $tag = $ret = ''; // accumulated tag name, accumulated result string
3576  $openTags = []; // open tag stack
3577  $maybeState = null; // possible truncation state
3578 
3579  $textLen = strlen( $text );
3580  $neLength = max( 0, $length - strlen( $ellipsis ) ); // non-ellipsis len if truncated
3581  for ( $pos = 0; true; ++$pos ) {
3582  # Consider truncation once the display length has reached the maximim.
3583  # We check if $dispLen > 0 to grab tags for the $neLength = 0 case.
3584  # Check that we're not in the middle of a bracket/entity...
3585  if ( $dispLen && $dispLen >= $neLength && $bracketState == 0 && !$entityState ) {
3586  if ( !$testingEllipsis ) {
3587  $testingEllipsis = true;
3588  # Save where we are; we will truncate here unless there turn out to
3589  # be so few remaining characters that truncation is not necessary.
3590  if ( !$maybeState ) { // already saved? ($neLength = 0 case)
3591  $maybeState = [ $ret, $openTags ]; // save state
3592  }
3593  } elseif ( $dispLen > $length && $dispLen > strlen( $ellipsis ) ) {
3594  # String in fact does need truncation, the truncation point was OK.
3595  // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring
3596  list( $ret, $openTags ) = $maybeState; // reload state
3597  $ret = $this->removeBadCharLast( $ret ); // multi-byte char fix
3598  $ret .= $ellipsis; // add ellipsis
3599  break;
3600  }
3601  }
3602  if ( $pos >= $textLen ) {
3603  break; // extra iteration just for above checks
3604  }
3605 
3606  # Read the next char...
3607  $ch = $text[$pos];
3608  $lastCh = $pos ? $text[$pos - 1] : '';
3609  $ret .= $ch; // add to result string
3610  if ( $ch == '<' ) {
3611  $this->truncate_endBracket( $tag, $tagType, $lastCh, $openTags ); // for bad HTML
3612  $entityState = 0; // for bad HTML
3613  $bracketState = 1; // tag started (checking for backslash)
3614  } elseif ( $ch == '>' ) {
3615  $this->truncate_endBracket( $tag, $tagType, $lastCh, $openTags );
3616  $entityState = 0; // for bad HTML
3617  $bracketState = 0; // out of brackets
3618  } elseif ( $bracketState == 1 ) {
3619  if ( $ch == '/' ) {
3620  $tagType = 1; // close tag (e.g. "</span>")
3621  } else {
3622  $tagType = 0; // open tag (e.g. "<span>")
3623  $tag .= $ch;
3624  }
3625  $bracketState = 2; // building tag name
3626  } elseif ( $bracketState == 2 ) {
3627  if ( $ch != ' ' ) {
3628  $tag .= $ch;
3629  } else {
3630  // Name found (e.g. "<a href=..."), add on tag attributes...
3631  $pos += $this->truncate_skip( $ret, $text, "<>", $pos + 1 );
3632  }
3633  } elseif ( $bracketState == 0 ) {
3634  if ( $entityState ) {
3635  if ( $ch == ';' ) {
3636  $entityState = 0;
3637  $dispLen++; // entity is one displayed char
3638  }
3639  } else {
3640  if ( $neLength == 0 && !$maybeState ) {
3641  // Save state without $ch. We want to *hit* the first
3642  // display char (to get tags) but not *use* it if truncating.
3643  $maybeState = [ substr( $ret, 0, -1 ), $openTags ];
3644  }
3645  if ( $ch == '&' ) {
3646  $entityState = 1; // entity found, (e.g. "&#160;")
3647  } else {
3648  $dispLen++; // this char is displayed
3649  // Add the next $max display text chars after this in one swoop...
3650  $max = ( $testingEllipsis ? $length : $neLength ) - $dispLen;
3651  $skipped = $this->truncate_skip( $ret, $text, "<>&", $pos + 1, $max );
3652  $dispLen += $skipped;
3653  $pos += $skipped;
3654  }
3655  }
3656  }
3657  }
3658  // Close the last tag if left unclosed by bad HTML
3659  $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags );
3660  while ( count( $openTags ) > 0 ) {
3661  $ret .= '</' . array_pop( $openTags ) . '>'; // close open tags
3662  }
3663  return $ret;
3664  }
3665 
3677  private function truncate_skip( &$ret, $text, $search, $start, $len = null ) {
3678  if ( $len === null ) {
3679  $len = -1; // -1 means "no limit" for strcspn
3680  } elseif ( $len < 0 ) {
3681  $len = 0; // sanity
3682  }
3683  $skipCount = 0;
3684  if ( $start < strlen( $text ) ) {
3685  $skipCount = strcspn( $text, $search, $start, $len );
3686  $ret .= substr( $text, $start, $skipCount );
3687  }
3688  return $skipCount;
3689  }
3690 
3700  private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) {
3701  $tag = ltrim( $tag );
3702  if ( $tag != '' ) {
3703  if ( $tagType == 0 && $lastCh != '/' ) {
3704  $openTags[] = $tag; // tag opened (didn't close itself)
3705  } elseif ( $tagType == 1 ) {
3706  if ( $openTags && $tag == $openTags[count( $openTags ) - 1] ) {
3707  array_pop( $openTags ); // tag closed
3708  }
3709  }
3710  $tag = '';
3711  }
3712  }
3713 
3722  function convertGrammar( $word, $case ) {
3723  global $wgGrammarForms;
3724  if ( isset( $wgGrammarForms[$this->getCode()][$case][$word] ) ) {
3725  return $wgGrammarForms[$this->getCode()][$case][$word];
3726  }
3727 
3728  $grammarTransformations = $this->getGrammarTransformations();
3729 
3730  if ( isset( $grammarTransformations[$case] ) ) {
3731  $forms = $grammarTransformations[$case];
3732 
3733  // Some names of grammar rules are aliases for other rules.
3734  // In such cases the value is a string rather than object,
3735  // so load the actual rules.
3736  if ( is_string( $forms ) ) {
3737  $forms = $grammarTransformations[$forms];
3738  }
3739 
3740  foreach ( array_values( $forms ) as $rule ) {
3741  $form = $rule[0];
3742 
3743  if ( $form === '@metadata' ) {
3744  continue;
3745  }
3746 
3747  $replacement = $rule[1];
3748 
3749  $regex = '/' . addcslashes( $form, '/' ) . '/u';
3750  $patternMatches = preg_match( $regex, $word );
3751 
3752  if ( $patternMatches === false ) {
3753  wfLogWarning(
3754  'An error occurred while processing grammar. ' .
3755  "Word: '$word'. Regex: /$form/."
3756  );
3757  } elseif ( $patternMatches === 1 ) {
3758  $word = preg_replace( $regex, $replacement, $word );
3759 
3760  break;
3761  }
3762  }
3763  }
3764 
3765  return $word;
3766  }
3767 
3773  function getGrammarForms() {
3774  global $wgGrammarForms;
3775  if ( isset( $wgGrammarForms[$this->getCode()] )
3776  && is_array( $wgGrammarForms[$this->getCode()] )
3777  ) {
3778  return $wgGrammarForms[$this->getCode()];
3779  }
3780 
3781  return [];
3782  }
3783 
3793  public function getGrammarTransformations() {
3794  if ( $this->grammarTransformCache !== null ) {
3796  }
3797 
3798  $grammarDataFile = __DIR__ . "/data/grammarTransformations/{$this->getCode()}.json";
3799 
3800  if ( !is_readable( $grammarDataFile ) ) {
3801  return [];
3802  }
3803 
3804  $this->grammarTransformCache = FormatJson::decode(
3805  file_get_contents( $grammarDataFile ),
3806  true
3807  );
3808 
3809  if ( $this->grammarTransformCache === null ) {
3810  throw new MWException( "Invalid grammar data for \"{$this->getCode()}\"." );
3811  }
3812 
3814  }
3815 
3835  function gender( $gender, $forms ) {
3836  if ( !count( $forms ) ) {
3837  return '';
3838  }
3839  $forms = $this->preConvertPlural( $forms, 2 );
3840  if ( $gender === 'male' ) {
3841  return $forms[0];
3842  }
3843  if ( $gender === 'female' ) {
3844  return $forms[1];
3845  }
3846  return $forms[2] ?? $forms[0];
3847  }
3848 
3864  function convertPlural( $count, $forms ) {
3865  // Handle explicit n=pluralform cases
3866  $forms = $this->handleExplicitPluralForms( $count, $forms );
3867  if ( is_string( $forms ) ) {
3868  return $forms;
3869  }
3870  if ( !count( $forms ) ) {
3871  return '';
3872  }
3873 
3874  $pluralForm = $this->getPluralRuleIndexNumber( $count );
3875  $pluralForm = min( $pluralForm, count( $forms ) - 1 );
3876  return $forms[$pluralForm];
3877  }
3878 
3894  protected function handleExplicitPluralForms( $count, array $forms ) {
3895  foreach ( $forms as $index => $form ) {
3896  if ( preg_match( '/\d+=/i', $form ) ) {
3897  $pos = strpos( $form, '=' );
3898  if ( substr( $form, 0, $pos ) === (string)$count ) {
3899  return substr( $form, $pos + 1 );
3900  }
3901  unset( $forms[$index] );
3902  }
3903  }
3904  return array_values( $forms );
3905  }
3906 
3915  protected function preConvertPlural( /* Array */ $forms, $count ) {
3916  return array_pad( $forms, $count, end( $forms ) );
3917  }
3918 
3935  public function embedBidi( $text = '' ) {
3936  $dir = self::strongDirFromContent( $text );
3937  if ( $dir === 'ltr' ) {
3938  // Wrap in LEFT-TO-RIGHT EMBEDDING ... POP DIRECTIONAL FORMATTING
3939  return self::$lre . $text . self::$pdf;
3940  }
3941  if ( $dir === 'rtl' ) {
3942  // Wrap in RIGHT-TO-LEFT EMBEDDING ... POP DIRECTIONAL FORMATTING
3943  return self::$rle . $text . self::$pdf;
3944  }
3945  // No strong directionality: do not wrap
3946  return $text;
3947  }
3948 
3962  function translateBlockExpiry( $str, User $user = null, $now = 0 ) {
3963  $duration = SpecialBlock::getSuggestedDurations( $this );
3964  foreach ( $duration as $show => $value ) {
3965  if ( strcmp( $str, $value ) == 0 ) {
3966  return htmlspecialchars( trim( $show ) );
3967  }
3968  }
3969 
3970  if ( wfIsInfinity( $str ) ) {
3971  foreach ( $duration as $show => $value ) {
3972  if ( wfIsInfinity( $value ) ) {
3973  return htmlspecialchars( trim( $show ) );
3974  }
3975  }
3976  }
3977 
3978  // If all else fails, return a standard duration or timestamp description.
3979  $time = strtotime( $str, $now );
3980  if ( $time === false ) { // Unknown format. Return it as-is in case.
3981  return $str;
3982  } elseif ( $time !== strtotime( $str, $now + 1 ) ) { // It's a relative timestamp.
3983  // The result differs based on current time, so the difference
3984  // is a fixed duration length.
3985  return $this->formatDuration( $time - $now );
3986  } else { // It's an absolute timestamp.
3987  if ( $time === 0 ) {
3988  // wfTimestamp() handles 0 as current time instead of epoch.
3989  $time = '19700101000000';
3990  }
3991  if ( $user ) {
3992  return $this->userTimeAndDate( $time, $user );
3993  }
3994  return $this->timeanddate( $time );
3995  }
3996  }
3997 
4005  public function segmentForDiff( $text ) {
4006  return $text;
4007  }
4008 
4015  public function unsegmentForDiff( $text ) {
4016  return $text;
4017  }
4018 
4025  public function getConverter() {
4026  return $this->mConverter;
4027  }
4028 
4037  public function autoConvert( $text, $variant = false ) {
4038  return $this->mConverter->autoConvert( $text, $variant );
4039  }
4040 
4047  public function autoConvertToAllVariants( $text ) {
4048  return $this->mConverter->autoConvertToAllVariants( $text );
4049  }
4050 
4062  public function convert( $text ) {
4063  return $this->mConverter->convert( $text );
4064  }
4065 
4072  public function convertTitle( $title ) {
4073  return $this->mConverter->convertTitle( $title );
4074  }
4075 
4084  public function convertNamespace( $ns, $variant = null ) {
4085  return $this->mConverter->convertNamespace( $ns, $variant );
4086  }
4087 
4093  public function hasVariants() {
4094  return count( $this->getVariants() ) > 1;
4095  }
4096 
4107  public function hasVariant( $variant ) {
4108  return $variant && ( $variant === $this->mConverter->validateVariant( $variant ) );
4109  }
4110 
4117  public function convertHtml( $text ) {
4118  return htmlspecialchars( $this->convert( $text ) );
4119  }
4120 
4125  public function convertCategoryKey( $key ) {
4126  return $this->mConverter->convertCategoryKey( $key );
4127  }
4128 
4135  public function getVariants() {
4136  return $this->mConverter->getVariants();
4137  }
4138 
4142  public function getPreferredVariant() {
4143  return $this->mConverter->getPreferredVariant();
4144  }
4145 
4149  public function getDefaultVariant() {
4150  return $this->mConverter->getDefaultVariant();
4151  }
4152 
4156  public function getURLVariant() {
4157  return $this->mConverter->getURLVariant();
4158  }
4159 
4172  public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
4173  $this->mConverter->findVariantLink( $link, $nt, $ignoreOtherCond );
4174  }
4175 
4182  function getExtraHashOptions() {
4183  return $this->mConverter->getExtraHashOptions();
4184  }
4185 
4193  public function getParsedTitle() {
4194  return $this->mConverter->getParsedTitle();
4195  }
4196 
4203  public function updateConversionTable( Title $title ) {
4204  $this->mConverter->updateConversionTable( $title );
4205  }
4206 
4213  public function linkTrail() {
4214  return $this->localisationCache->getItem( $this->mCode, 'linkTrail' );
4215  }
4216 
4223  public function linkPrefixCharset() {
4224  return $this->localisationCache->getItem( $this->mCode, 'linkPrefixCharset' );
4225  }
4226 
4234  public function getParentLanguage() {
4235  if ( $this->mParentLanguage !== false ) {
4236  return $this->mParentLanguage;
4237  }
4238 
4239  $code = explode( '-', $this->getCode() )[0];
4240  if ( !in_array( $code, LanguageConverter::$languagesWithVariants ) ) {
4241  $this->mParentLanguage = null;
4242  return null;
4243  }
4244  $lang = self::factory( $code );
4245  if ( !$lang->hasVariant( $this->getCode() ) ) {
4246  $this->mParentLanguage = null;
4247  return null;
4248  }
4249 
4250  $this->mParentLanguage = $lang;
4251  return $lang;
4252  }
4253 
4261  public function equals( Language $lang ) {
4262  return $lang === $this || $lang->getCode() === $this->mCode;
4263  }
4264 
4273  public function getCode() {
4274  return $this->mCode;
4275  }
4276 
4287  public function getHtmlCode() {
4288  if ( is_null( $this->mHtmlCode ) ) {
4289  $this->mHtmlCode = LanguageCode::bcp47( $this->getCode() );
4290  }
4291  return $this->mHtmlCode;
4292  }
4293 
4301  public static function getCodeFromFileName( $filename, $prefix = 'Language', $suffix = '.php' ) {
4302  $m = null;
4303  preg_match( '/' . preg_quote( $prefix, '/' ) . '([A-Z][a-z_]+)' .
4304  preg_quote( $suffix, '/' ) . '/', $filename, $m );
4305  if ( !count( $m ) ) {
4306  return false;
4307  }
4308  return str_replace( '_', '-', strtolower( $m[1] ) );
4309  }
4310 
4316  public static function classFromCode( $code, $fallback = true ) {
4317  if ( $fallback && $code == 'en' ) {
4318  return 'Language';
4319  } else {
4320  return 'Language' . str_replace( '-', '_', ucfirst( $code ) );
4321  }
4322  }
4323 
4334  public static function getFileName( $prefix, $code, $suffix = '.php' ) {
4335  return MediaWikiServices::getInstance()->getLanguageNameUtils()
4336  ->getFileName( $prefix, $code, $suffix );
4337  }
4338 
4344  public static function getMessagesFileName( $code ) {
4345  return MediaWikiServices::getInstance()->getLanguageNameUtils()
4346  ->getMessagesFileName( $code );
4347  }
4348 
4356  public static function getJsonMessagesFileName( $code ) {
4357  return MediaWikiServices::getInstance()->getLanguageNameUtils()
4358  ->getJsonMessagesFileName( $code );
4359  }
4360 
4369  public static function getFallbackFor( $code ) {
4370  return MediaWikiServices::getInstance()->getLanguageFallback()->getFirst( $code )
4371  ?? false;
4372  }
4373 
4386  public static function getFallbacksFor( $code, $mode = self::MESSAGES_FALLBACKS ) {
4387  return MediaWikiServices::getInstance()->getLanguageFallback()->getAll( $code, $mode );
4388  }
4389 
4400  public static function getFallbacksIncludingSiteLanguage( $code ) {
4401  return MediaWikiServices::getInstance()->getLanguageFallback()
4402  ->getAllIncludingSiteLanguage( $code );
4403  }
4404 
4414  public static function getMessagesFor( $code ) {
4415  return self::getLocalisationCache()->getItem( $code, 'messages' );
4416  }
4417 
4426  public static function getMessageFor( $key, $code ) {
4427  return self::getLocalisationCache()->getSubitem( $code, 'messages', $key );
4428  }
4429 
4438  public static function getMessageKeysFor( $code ) {
4439  return self::getLocalisationCache()->getSubitemList( $code, 'messages' );
4440  }
4441 
4446  function fixVariableInNamespace( $talk ) {
4447  if ( strpos( $talk, '$1' ) === false ) {
4448  return $talk;
4449  }
4450 
4451  global $wgMetaNamespace;
4452  $talk = str_replace( '$1', $wgMetaNamespace, $talk );
4453 
4454  # Allow grammar transformations
4455  # Allowing full message-style parsing would make simple requests
4456  # such as action=raw much more expensive than they need to be.
4457  # This will hopefully cover most cases.
4458  $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/i',
4459  [ $this, 'replaceGrammarInNamespace' ], $talk );
4460  return str_replace( ' ', '_', $talk );
4461  }
4462 
4467  function replaceGrammarInNamespace( $m ) {
4468  return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
4469  }
4470 
4481  public function formatExpiry( $expiry, $format = true, $infinity = 'infinity' ) {
4482  static $dbInfinity;
4483  if ( $dbInfinity === null ) {
4484  $dbInfinity = wfGetDB( DB_REPLICA )->getInfinity();
4485  }
4486 
4487  if ( $expiry == '' || $expiry === 'infinity' || $expiry == $dbInfinity ) {
4488  return $format === true
4489  ? $this->getMessageFromDB( 'infiniteblock' )
4490  : $infinity;
4491  } else {
4492  return $format === true
4493  ? $this->timeanddate( $expiry, /* User preference timezone */ true )
4494  : wfTimestamp( $format, $expiry );
4495  }
4496  }
4497 
4512  function formatTimePeriod( $seconds, $format = [] ) {
4513  if ( !is_array( $format ) ) {
4514  $format = [ 'avoid' => $format ]; // For backwards compatibility
4515  }
4516  if ( !isset( $format['avoid'] ) ) {
4517  $format['avoid'] = false;
4518  }
4519  if ( !isset( $format['noabbrevs'] ) ) {
4520  $format['noabbrevs'] = false;
4521  }
4522  $secondsMsg = wfMessage(
4523  $format['noabbrevs'] ? 'seconds' : 'seconds-abbrev' )->inLanguage( $this );
4524  $minutesMsg = wfMessage(
4525  $format['noabbrevs'] ? 'minutes' : 'minutes-abbrev' )->inLanguage( $this );
4526  $hoursMsg = wfMessage(
4527  $format['noabbrevs'] ? 'hours' : 'hours-abbrev' )->inLanguage( $this );
4528  $daysMsg = wfMessage(
4529  $format['noabbrevs'] ? 'days' : 'days-abbrev' )->inLanguage( $this );
4530 
4531  if ( round( $seconds * 10 ) < 100 ) {
4532  $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) );
4533  $s = $secondsMsg->params( $s )->text();
4534  } elseif ( round( $seconds ) < 60 ) {
4535  $s = $this->formatNum( round( $seconds ) );
4536  $s = $secondsMsg->params( $s )->text();
4537  } elseif ( round( $seconds ) < 3600 ) {
4538  $minutes = floor( $seconds / 60 );
4539  $secondsPart = round( fmod( $seconds, 60 ) );
4540  if ( $secondsPart == 60 ) {
4541  $secondsPart = 0;
4542  $minutes++;
4543  }
4544  $s = $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4545  $s .= ' ';
4546  $s .= $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
4547  } elseif ( round( $seconds ) <= 2 * 86400 ) {
4548  $hours = floor( $seconds / 3600 );
4549  $minutes = floor( ( $seconds - $hours * 3600 ) / 60 );
4550  $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 );
4551  if ( $secondsPart == 60 ) {
4552  $secondsPart = 0;
4553  $minutes++;
4554  }
4555  if ( $minutes == 60 ) {
4556  $minutes = 0;
4557  $hours++;
4558  }
4559  $s = $hoursMsg->params( $this->formatNum( $hours ) )->text();
4560  $s .= ' ';
4561  $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4562  if ( !in_array( $format['avoid'], [ 'avoidseconds', 'avoidminutes', 'avoidhours' ] ) ) {
4563  $s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
4564  }
4565  } else {
4566  $days = floor( $seconds / 86400 );
4567  if ( $format['avoid'] === 'avoidhours' ) {
4568  $hours = round( ( $seconds - $days * 86400 ) / 3600 );
4569  if ( $hours == 24 ) {
4570  $hours = 0;
4571  $days++;
4572  }
4573  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4574  } elseif ( $format['avoid'] === 'avoidminutes' ) {
4575  $hours = round( ( $seconds - $days * 86400 ) / 3600 );
4576  if ( $hours == 24 ) {
4577  $hours = 0;
4578  $days++;
4579  }
4580  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4581  $s .= ' ';
4582  $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
4583  } elseif ( $format['avoid'] === 'avoidseconds' ) {
4584  $hours = floor( ( $seconds - $days * 86400 ) / 3600 );
4585  $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 );
4586  if ( $minutes == 60 ) {
4587  $minutes = 0;
4588  $hours++;
4589  }
4590  if ( $hours == 24 ) {
4591  $hours = 0;
4592  $days++;
4593  }
4594  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4595  $s .= ' ';
4596  $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
4597  $s .= ' ';
4598  $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4599  } else {
4600  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4601  $s .= ' ';
4602  $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format );
4603  }
4604  }
4605  return $s;
4606  }
4607 
4619  function formatBitrate( $bps ) {
4620  return $this->formatComputingNumbers( $bps, 1000, "bitrate-$1bits" );
4621  }
4622 
4629  function formatComputingNumbers( $size, $boundary, $messageKey ) {
4630  if ( $size <= 0 ) {
4631  return str_replace( '$1', $this->formatNum( $size ),
4632  $this->getMessageFromDB( str_replace( '$1', '', $messageKey ) )
4633  );
4634  }
4635  $sizes = [ '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ];
4636  $index = 0;
4637 
4638  $maxIndex = count( $sizes ) - 1;
4639  while ( $size >= $boundary && $index < $maxIndex ) {
4640  $index++;
4641  $size /= $boundary;
4642  }
4643 
4644  // For small sizes no decimal places necessary
4645  $round = 0;
4646  if ( $index > 1 ) {
4647  // For MB and bigger two decimal places are smarter
4648  $round = 2;
4649  }
4650  $msg = str_replace( '$1', $sizes[$index], $messageKey );
4651 
4652  $size = round( $size, $round );
4653  $text = $this->getMessageFromDB( $msg );
4654  return str_replace( '$1', $this->formatNum( $size ), $text );
4655  }
4656 
4667  function formatSize( $size ) {
4668  return $this->formatComputingNumbers( $size, 1024, "size-$1bytes" );
4669  }
4670 
4680  function specialList( $page, $details, $oppositedm = true ) {
4681  if ( !$details ) {
4682  return $page;
4683  }
4684 
4685  $dirmark = ( $oppositedm ? $this->getDirMark( true ) : '' ) . $this->getDirMark();
4686  return $page .
4687  $dirmark .
4688  $this->msg( 'word-separator' )->escaped() .
4689  $this->msg( 'parentheses' )->rawParams( $details )->escaped();
4690  }
4691 
4704  public function viewPrevNext( Title $title, $offset, $limit,
4705  array $query = [], $atend = false
4706  ) {
4707  wfDeprecated( __METHOD__, '1.34' );
4708  // @todo FIXME: Why on earth this needs one message for the text and another one for tooltip?
4709 
4710  # Make 'previous' link
4711  $prev = wfMessage( 'prevn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
4712  if ( $offset > 0 ) {
4713  $plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit,
4714  $query, $prev, 'prevn-title', 'mw-prevlink' );
4715  } else {
4716  $plink = htmlspecialchars( $prev );
4717  }
4718 
4719  # Make 'next' link
4720  $next = wfMessage( 'nextn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
4721  if ( $atend ) {
4722  $nlink = htmlspecialchars( $next );
4723  } else {
4724  $nlink = $this->numLink( $title, $offset + $limit, $limit,
4725  $query, $next, 'nextn-title', 'mw-nextlink' );
4726  }
4727 
4728  # Make links to set number of items per page
4729  $numLinks = [];
4730  foreach ( [ 20, 50, 100, 250, 500 ] as $num ) {
4731  $numLinks[] = $this->numLink( $title, $offset, $num,
4732  $query, $this->formatNum( $num ), 'shown-title', 'mw-numlink' );
4733  }
4734 
4735  return wfMessage( 'viewprevnext' )->inLanguage( $this )->title( $title
4736  )->rawParams( $plink, $nlink, $this->pipeList( $numLinks ) )->escaped();
4737  }
4738 
4751  private function numLink( Title $title, $offset, $limit, array $query, $link,
4752  $tooltipMsg, $class
4753  ) {
4754  $query = [ 'limit' => $limit, 'offset' => $offset ] + $query;
4755  $tooltip = wfMessage( $tooltipMsg )->inLanguage( $this )->title( $title )
4756  ->numParams( $limit )->text();
4757 
4758  return Html::element( 'a', [ 'href' => $title->getLocalURL( $query ),
4759  'title' => $tooltip, 'class' => $class ], $link );
4760  }
4761 
4767  public function getConvRuleTitle() {
4768  return $this->mConverter->getConvRuleTitle();
4769  }
4770 
4776  public function getCompiledPluralRules() {
4777  $pluralRules =
4778  $this->localisationCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' );
4779  $fallbacks = $this->langFallback->getAll( $this->mCode );
4780  if ( !$pluralRules ) {
4781  foreach ( $fallbacks as $fallbackCode ) {
4782  $pluralRules = $this->localisationCache
4783  ->getItem( strtolower( $fallbackCode ), 'compiledPluralRules' );
4784  if ( $pluralRules ) {
4785  break;
4786  }
4787  }
4788  }
4789  return $pluralRules;
4790  }
4791 
4797  public function getPluralRules() {
4798  $pluralRules =
4799  $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRules' );
4800  $fallbacks = $this->langFallback->getAll( $this->mCode );
4801  if ( !$pluralRules ) {
4802  foreach ( $fallbacks as $fallbackCode ) {
4803  $pluralRules = $this->localisationCache
4804  ->getItem( strtolower( $fallbackCode ), 'pluralRules' );
4805  if ( $pluralRules ) {
4806  break;
4807  }
4808  }
4809  }
4810  return $pluralRules;
4811  }
4812 
4818  public function getPluralRuleTypes() {
4819  $pluralRuleTypes =
4820  $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRuleTypes' );
4821  $fallbacks = $this->langFallback->getAll( $this->mCode );
4822  if ( !$pluralRuleTypes ) {
4823  foreach ( $fallbacks as $fallbackCode ) {
4824  $pluralRuleTypes = $this->localisationCache
4825  ->getItem( strtolower( $fallbackCode ), 'pluralRuleTypes' );
4826  if ( $pluralRuleTypes ) {
4827  break;
4828  }
4829  }
4830  }
4831  return $pluralRuleTypes;
4832  }
4833 
4839  public function getPluralRuleIndexNumber( $number ) {
4840  $pluralRules = $this->getCompiledPluralRules();
4841  $form = Evaluator::evaluateCompiled( $number, $pluralRules );
4842  return $form;
4843  }
4844 
4853  public function getPluralRuleType( $number ) {
4854  $index = $this->getPluralRuleIndexNumber( $number );
4855  $pluralRuleTypes = $this->getPluralRuleTypes();
4856  return $pluralRuleTypes[$index] ?? 'other';
4857  }
4858 }
static getSuggestedDurations(Language $lang=null, $includeOther=true)
Get an array of suggested block durations from MediaWiki:Ipboptions.
static newFromCode( $code, $fallback=false)
Create a language object for a given language code.
Definition: Language.php:237
getMessage( $key)
Definition: Language.php:2540
getPluralRuleType( $number)
Find the plural rule type appropriate for the given number For example, if the language is set to Ara...
Definition: Language.php:4853
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
static $mMonthAbbrevMsgs
Definition: Language.php:132
getSpecialPageAliases()
Get special page names, as an associative array canonical name => array of valid names, including aliases.
Definition: Language.php:3130
getPluralRuleTypes()
Get the plural rule types for the language.
Definition: Language.php:4818
firstChar( $s)
Get the first character of a string.
Definition: Language.php:2870
getHumanTimestamp(MWTimestamp $time, MWTimestamp $relativeTo=null, User $user=null)
Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
Definition: Language.php:2434
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:420
Wrapper around strtr() that holds replacements.
ucwords( $str)
Definition: Language.php:2695
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
static hebrewNumeral( $num)
Hebrew Gematria number formatting up to 9999.
Definition: Language.php:1963
translateBlockExpiry( $str, User $user=null, $now=0)
Definition: Language.php:3962
ucwordbreaksCallbackAscii( $matches)
Definition: Language.php:2574
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
segmentByWord( $string)
Some languages such as Chinese require word segmentation, Specify such segmentation when overridden i...
Definition: Language.php:2805
normalize( $s)
Convert a UTF-8 string to normal form C.
Definition: Language.php:2933
handleExplicitPluralForms( $count, array $forms)
Handles explicit plural forms for Language::convertPlural()
Definition: Language.php:3894
getDurationIntervals( $seconds, array $chosenIntervals=[])
Takes a number of seconds and returns an array with a set of corresponding intervals.
Definition: Language.php:2279
getVariantname( $code, $usemsg=true)
short names for language variants used for language conversion links.
Definition: Language.php:737
setNamespaces(array $namespaces)
Arbitrarily set all of the namespace names at once.
Definition: Language.php:519
removeBadCharLast( $string)
Remove bytes that represent an incomplete Unicode character at the end of string (e.g.
Definition: Language.php:3506
static romanNumeral( $num)
Roman number formatting up to 10000.
Definition: Language.php:1932
getDirMark( $opposite=false)
A hidden direction mark (LRM or RLM), depending on the language direction.
Definition: Language.php:3036
getHtmlCode()
Get the code in BCP 47 format which we can use inside of html lang="" tags.
Definition: Language.php:4287
static isUtf8( $value)
Test whether a string is valid UTF-8.
Definition: StringUtils.php:44
truncate_skip(&$ret, $text, $search, $start, $len=null)
truncateHtml() helper function like strcspn() but adds the skipped chars to $ret
Definition: Language.php:3677
$IP
Definition: WebStart.php:41
equals(Language $lang)
Compare with an other language object.
Definition: Language.php:4261
lcfirst( $str)
Definition: Language.php:2652
static $IRANIAN_DAYS
Definition: Language.php:1507
offsetForUser(User $user)
Adjust the timestamp depending on the given user&#39;s preferences.
Definition: MWTimestamp.php:79
alignEnd()
Return &#39;right&#39; or &#39;left&#39; as appropriate alignment for line-end for this language&#39;s text direction...
Definition: Language.php:3004
static insertSpace( $string, $pattern)
Definition: Language.php:2848
getFallbackLanguages()
Definition: Language.php:460
userTimeAndDate( $ts, User $user, array $options=[])
Get the formatted date and time for the given timestamp and formatted for the given user...
Definition: Language.php:2415
$wgLangObjCacheSize
Language cache size, or really how many languages can we handle simultaneously without degrading to c...
if(!isset( $args[0])) $lang
$namespaceAliases
Definition: Language.php:77
hasVariants()
Check if this is a language with variants.
Definition: Language.php:4093
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user&#39;s current setting for a given option.
Definition: User.php:2915
getCompiledPluralRules()
Get the compiled plural rules for the language.
Definition: Language.php:4776
getLocalNsIndex( $text)
Get a namespace key by value, case insensitive.
Definition: Language.php:628
convertCategoryKey( $key)
Definition: Language.php:4125
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
getLocalURL( $query='', $query2=false)
Get a URL with no fragment or server name (relative URL) from a Title object.
Definition: Title.php:2177
truncateForDatabase( $string, $length, $ellipsis='...', $adjustLength=true)
Truncate a string to a specified length in bytes, appending an optional string (e.g.
Definition: Language.php:3403
static array static $lre
Unicode directional formatting characters, for embedBidi()
Definition: Language.php:186
const ALL
Return all known languages in fetchLanguageName(s).
Definition: Language.php:51
$wgMetaNamespace
Name of the project namespace.
fallback8bitEncoding()
Definition: Language.php:2782
wfIsInfinity( $str)
Determine input string is represents as infinity.
unsegmentForDiff( $text)
and unsegment to show the result
Definition: Language.php:4015
static array $durationIntervals
Definition: Language.php:171
truncate_endBracket(&$tag, $tagType, $lastCh, &$openTags)
truncateHtml() helper function (a) push or pop $tag from $openTags as needed (b) clear $tag value ...
Definition: Language.php:3700
A fake language variant converter.
linkTrail()
A regular expression to match legal word-trailing characters which should be merged onto a link of th...
Definition: Language.php:4213
getAllMessages()
Definition: Language.php:2547
$wgNamespaceAliases
Namespace aliases.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
getPluralRuleIndexNumber( $number)
Find the index number of the plural rule appropriate for the given number.
Definition: Language.php:4839
getVariants()
Get the list of variants supported by this language see sample implementation in LanguageZh.php.
Definition: Language.php:4135
$dateFormatStrings
Definition: Language.php:72
static hebrewYearStart( $year)
This calculates the Hebrew year start, as days since 1 September.
Definition: Language.php:1771
getNamespaceAliases()
Definition: Language.php:637
LanguageConverter FakeConverter $mConverter
Definition: Language.php:64
minimumGroupingDigits()
Definition: Language.php:3320
static $mMonthMsgs
Definition: Language.php:122
convertForSearchResult( $termsArray)
Definition: Language.php:2858
$wgExtraGenderNamespaces
Same as above, but for namespaces with gender distinction.
static getFileName( $prefix, $code, $suffix='.php')
Get the name of a file for a certain language code.
Definition: Language.php:4334
convertTitle( $title)
Convert a Title object to a string in the preferred variant.
Definition: Language.php:4072
static $mLangObjCache
Definition: Language.php:96
static classFromCode( $code, $fallback=true)
Definition: Language.php:4316
internalUserTimeAndDate( $type, $ts, User $user, array $options)
Internal helper function for userDate(), userTime() and userTimeAndDate()
Definition: Language.php:2330
array $wgOverrideUcfirstCharacters
List of Unicode characters for which capitalization is overridden in Language::ucfirst.
$wgTranslateNumerals
For Hindi and Arabic use local numerals instead of Western style (0-9) numerals in interface...
static $mWeekdayAbbrevMsgs
Definition: Language.php:118
lc( $str, $first=false)
Definition: Language.php:2675
ucwordbreaksCallbackMB( $matches)
Definition: Language.php:2582
$mMagicExtensions
Definition: Language.php:67
LocalisationCache $localisationCache
Definition: Language.php:85
static $pdf
Definition: Language.php:188
isValidBuiltInCode( $code)
Returns true if a language code is of a valid form for the purposes of internal customisation of Medi...
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:394
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:51
__construct()
Definition: Language.php:424
truncateHtml( $text, $length, $ellipsis='...')
Truncate a string of valid HTML to a specified length in bytes, appending an optional string (e...
Definition: Language.php:3558
ucfirst( $str)
Definition: Language.php:2598
semicolonList(array $list)
Take a list of strings and build a locale-friendly semicolon-separated list, using the local semicolo...
Definition: Language.php:3369
userAdjust( $ts, $tz=false)
Used by date() and time() to adjust the time output.
Definition: Language.php:2050
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static getMessageFor( $key, $code)
Get a message for a given language.
Definition: Language.php:4426
formatNum( $number, $nocommafy=false)
Normally we output all numbers in plain en_US style, that is 293,291.235 for twohundredninetythreetho...
Definition: Language.php:3173
Language false $mParentLanguage
Definition: Language.php:70
static getFallbackFor( $code)
Get the first fallback for a given language.
Definition: Language.php:4369
timeanddate( $ts, $adj=false, $format=true, $timecorrection=false)
Definition: Language.php:2234
formatExpiry( $expiry, $format=true, $infinity='infinity')
Decode an expiry (block, protection, etc) which has come from the DB.
Definition: Language.php:4481
listToText(array $list)
Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separa...
Definition: Language.php:3332
static tsToYear( $ts, $cName)
Algorithm to convert Gregorian dates to Thai solar dates, Minguo dates or Minguo dates.
Definition: Language.php:1809
const NS_PROJECT
Definition: Defines.php:64
static $mHijriCalendarMonthMsgs
Definition: Language.php:160
linkPrefixCharset()
A regular expression character set to match legal word-prefixing characters which should be merged on...
Definition: Language.php:4223
static getMain()
Get the RequestContext object associated with the main request.
getPreferredVariant()
Definition: Language.php:4142
static getMessagesFor( $code)
Get all messages for a given language WARNING: this may take a long time.
Definition: Language.php:4414
$minimumGroupingDigits
removeBadCharFirst( $string)
Remove bytes that represent an incomplete Unicode character at the start of string (e...
Definition: Language.php:3532
getDirMarkEntity( $opposite=false)
A hidden direction mark (LRM or RLM), depending on the language direction.
Definition: Language.php:3019
__destruct()
Reduce memory usage PhanTypeSuspiciousNonTraversableForeach.
Definition: Language.php:443
static strongDirFromContent( $text='')
Gets directionality of the first strongly directional codepoint, for embedBidi()
Definition: Language.php:1915
getMagic( $mw)
Fill a MagicWord object with data from here.
Definition: Language.php:3098
static getMessageKeysFor( $code)
Get all message keys for a given language.
Definition: Language.php:4438
static getFallbacksIncludingSiteLanguage( $code)
Get the ordered list of fallback languages, ending with the fallback language chain for the site lang...
Definition: Language.php:4400
getDefaultVariant()
Definition: Language.php:4149
getNsText( $index)
Get a namespace value by key.
Definition: Language.php:558
const STRICT_FALLBACKS
Return a strict fallback chain in getFallbacksFor.
Definition: Language.php:110
viewPrevNext(Title $title, $offset, $limit, array $query=[], $atend=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
Definition: Language.php:4704
getConverter()
Return the LanguageConverter used in the Language.
Definition: Language.php:4025
static $mIranianCalendarMonthMsgs
Definition: Language.php:137
const NS_PROJECT_TALK
Definition: Defines.php:65
array [] null $grammarTransformCache
Definition: Language.php:94
autoConvertToAllVariants( $text)
convert text to all supported variants
Definition: Language.php:4047
getBookstoreList()
Exports $wgBookstoreListEn.
Definition: Language.php:468
capitalizeAllNouns()
Definition: Language.php:3048
static decode( $value, $assoc=false)
Decodes a JSON string.
Definition: FormatJson.php:174
$wgDummyLanguageCodes
Functionally the same as $wgExtraLanguageCodes, but deprecated.
emphasize( $text)
Italic is unsuitable for some languages.
Definition: Language.php:3147
date( $ts, $adj=false, $format=true, $timecorrection=false)
Definition: Language.php:2195
isMultibyte( $str)
Definition: Language.php:2687
segmentForDiff( $text)
languages like Chinese need to be segmented in order for the diff to be of any use ...
Definition: Language.php:4005
$wgAllUnicodeFixes
Set this to always convert certain Unicode sequences to modern ones regardless of the content languag...
normalizeForSearch( $string)
Some languages have special punctuation need to be normalized.
Definition: Language.php:2816
static $strongDirRegex
Directionality test regex for embedBidi().
Definition: Language.php:203
static tsToHijri( $ts)
Converting Gregorian dates to Hijri dates.
Definition: Language.php:1581
needsGenderDistinction()
Whether this language uses gender-dependent namespace aliases.
Definition: Language.php:604
getURLVariant()
Definition: Language.php:4156
LanguageNameUtils $langNameUtils
Definition: Language.php:88
caseFold( $s)
Return a case-folded representation of $s.
Definition: Language.php:2759
updateConversionTable(Title $title)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
Definition: Language.php:4203
mbUpperChar( $char)
Convert character to uppercase, allowing overrides of the default mb_upper behaviour, which is buggy in many ways.
Definition: Language.php:2642
static $rle
Definition: Language.php:187
$wgMetaNamespaceTalk
Name of the project talk namespace.
static tsToIranian( $ts)
Algorithm by Roozbeh Pournader and Mohammad Toossi to convert Gregorian dates to Iranian dates...
Definition: Language.php:1521
getNamespaceIds()
Definition: Language.php:689
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:212
dateFormat( $usePrefs=true)
This is meant to be used by time(), date(), and timeanddate() to get the date preference they&#39;re supp...
Definition: Language.php:2128
static $mHebrewCalendarMonthMsgs
Definition: Language.php:144
pipeList(array $list)
Same as commaList, but separate it with the pipe instead.
Definition: Language.php:3381
getGenderNsText( $index, $gender)
Returns gender-dependent namespace alias if available.
Definition: Language.php:589
getFormattedNsText( $index)
A convenience function that returns the same thing as getNsText() except with &#39;_&#39; changed to &#39; &#39;...
Definition: Language.php:576
$mExtendedSpecialPageAliases
Definition: Language.php:73
getPluralRules()
Get the plural rules for the language.
Definition: Language.php:4797
getDefaultDateFormat()
Definition: Language.php:768
embedBidi( $text='')
Wraps argument with unicode control characters for directionality safety.
Definition: Language.php:3935
resetNamespaces()
Resets all of the namespace caches.
Definition: Language.php:527
getDateFormatString( $type, $pref)
Get a format string for a given type and preference.
Definition: Language.php:2159
time( $ts, $adj=false, $format=true, $timecorrection=false)
Definition: Language.php:2214
getMagicWords()
Get all magic words from cache.
Definition: Language.php:3089
getGrammarTransformations()
Get the grammar transformations data for the language.
Definition: Language.php:3793
numLink(Title $title, $offset, $limit, array $query, $link, $tooltipMsg, $class)
Helper function for viewPrevNext() that generates links.
Definition: Language.php:4751
static getMessagesFileName( $code)
Definition: Language.php:4344
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1690
convertGrammar( $word, $case)
Grammatical transformations, needed for inflected languages Invoked by putting {{grammar:case|word}} ...
Definition: Language.php:3722
digitTransformTable()
Definition: Language.php:3306
getConvRuleTitle()
Get the conversion rule title, if any.
Definition: Language.php:4767
formatTimePeriod( $seconds, $format=[])
Formats a time given in seconds into a string representation of that time.
Definition: Language.php:4512
userDate( $ts, User $user, array $options=[])
Get the formatted date for the given timestamp and formatted for the given user.
Definition: Language.php:2369
getNsIndex( $text)
Get a namespace key by value, case insensitive.
Definition: Language.php:719
addMagicWordsByLang( $newWords)
Add magic words to the extension array.
Definition: Language.php:3115
autoConvert( $text, $variant=false)
convert text to a variant
Definition: Language.php:4037
static getJsonMessagesFileName( $code)
Definition: Language.php:4356
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:323
ucwordbreaks( $str)
capitalize words at word breaks
Definition: Language.php:2719
$wgExtraNamespaces
Additional namespaces.
static convertDoubleWidth( $string)
convert double-width roman characters to single-width.
Definition: Language.php:2828
getHumanTimestampInternal(MWTimestamp $ts, MWTimestamp $relativeTo, User $user)
Convert an MWTimestamp into a pretty human-readable timestamp using the given user preferences and re...
Definition: Language.php:2471
getCode()
Get the internal language code for this language object.
Definition: Language.php:4273
digitGroupingPattern()
Definition: Language.php:3299
specialList( $page, $details, $oppositedm=true)
Make a list item, used by various special pages.
Definition: Language.php:4680
static isKnownLanguageTag( $tag)
Returns true if a language code is an IETF tag known to MediaWiki.
Definition: Language.php:409
$fallback
Definition: MessagesAb.php:11
$digitGroupingPattern
Definition: MessagesAs.php:167
static isSupportedLanguage( $code)
Checks whether any localisation is available for that language tag in MediaWiki (MessagesXx.php exists).
Definition: Language.php:303
convertNamespace( $ns, $variant=null)
Convert a namespace index to a string in the preferred variant.
Definition: Language.php:4084
getArrow( $direction='forwards')
An arrow, depending on the language direction.
Definition: Language.php:3059
LanguageFallback $langFallback
Definition: Language.php:91
formatSize( $size)
Format a size in bytes for output, using an appropriate unit (B, KB, MB, GB, TB, PB, EB, ZB or YB) according to the magnitude in question.
Definition: Language.php:4667
convertHtml( $text)
Perform output conversion on a string, and encode for safe HTML output.
Definition: Language.php:4117
array null $namespaceNames
Definition: Language.php:76
commafy( $number)
Adds commas to a given number.
Definition: Language.php:3234
$transformData
ReplacementArray object caches.
Definition: Language.php:82
static getCodeFromFileName( $filename, $prefix='Language', $suffix='.php')
Get the language code from a file name.
Definition: Language.php:4301
getExtraHashOptions()
returns language specific options used by User::getPageRenderHash() for example, the preferred langua...
Definition: Language.php:4182
static getFallbacksFor( $code, $mode=self::MESSAGES_FALLBACKS)
Get the ordered list of fallback languages.
Definition: Language.php:4386
getParsedTitle()
For languages that support multiple variants, the title of an article may be displayed differently in...
Definition: Language.php:4193
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
static tsToHebrew( $ts)
Converting Gregorian dates to Hebrew dates.
Definition: Language.php:1633
preConvertPlural($forms, $count)
Checks that convertPlural was given an array and pads it to requested amount of forms by copying the ...
Definition: Language.php:3915
findVariantLink(&$link, &$nt, $ignoreOtherCond=false)
If a language supports multiple variants, it is possible that non-existing link in one variant actual...
Definition: Language.php:4172
$wgGrammarForms
Some languages need different word forms, usually for different cases.
const SUPPORTED
Return in fetchLanguageName(s) only the languages for which we have at least some localisation...
Definition: Language.php:59
hasVariant( $variant)
Strict check if the language has the specific variant.
Definition: Language.php:4107
formatBitrate( $bps)
Format a bitrate for output, using an appropriate unit (bps, kbps, Mbps, Gbps, Tbps, Pbps, Ebps, Zbps or Ybps) according to the magnitude in question.
Definition: Language.php:4619
const AS_AUTONYMS
Return autonyms in fetchLanguageName(s).
Definition: Language.php:44
transformUsingPairFile( $file, $string)
Transform a string using serialized data stored in the given file (which must be in the serialized su...
Definition: Language.php:2958
separatorTransformTable()
Definition: Language.php:3313
isRTL()
For right-to-left language support.
Definition: Language.php:2972
getDatePreference()
Get the user&#39;s preferred date format.
Definition: User.php:3238
sprintfDate( $format, $ts, DateTimeZone $zone=null, &$ttl='unused')
This is a workalike of PHP&#39;s date() function, but with better internationalisation, a reduced set of format characters, and a better escaping format.
Definition: Language.php:1037
getParentLanguage()
Get the "parent" language which has a converter to convert a "compatible" language (in another varian...
Definition: Language.php:4234
static clearCaches()
Intended for tests that may change configuration in a way that invalidates caches.
Definition: Language.php:282
getDir()
Return the correct HTML &#39;dir&#39; attribute value for this language.
Definition: Language.php:2980
getFormattedNamespaces()
A convenience function that returns getNamespaces() with spaces instead of underscores in values...
Definition: Language.php:539
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
iconv( $in, $out, $string)
Definition: Language.php:2557
static $mMonthGenMsgs
Definition: Language.php:127
static $mWeekdayMsgs
Definition: Language.php:113
linkPrefixExtension()
To allow "foo[[bar]]" to extend the link over the whole word "foobar".
Definition: Language.php:3081
msg( $msg)
Get message object in this language.
Definition: Language.php:853
const MESSAGES_FALLBACKS
Return a fallback chain for messages in getFallbacksFor.
Definition: Language.php:103
const DB_REPLICA
Definition: defines.php:25
$mNamespaceIds
Definition: Language.php:77
uc( $str, $first=false)
Definition: Language.php:2621
getGrammarForms()
Get the grammar forms for the content language.
Definition: Language.php:3773
fixVariableInNamespace( $talk)
Definition: Language.php:4446
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
formatComputingNumbers( $size, $boundary, $messageKey)
Definition: Language.php:4629
initContLang()
Hook which will be called if this is the content language.
Definition: Language.php:453
userTime( $ts, User $user, array $options=[])
Get the formatted time for the given timestamp and formatted for the given user.
Definition: Language.php:2392
ucwordsCallbackMB( $matches)
Definition: Language.php:2590
getNamespaces()
Returns an array of localised namespaces indexed by their numbers.
Definition: Language.php:478
static isValidCode( $code)
Returns true if a language code string is of a valid form, whether or not it exists.
Definition: Language.php:379
commaList(array $list)
Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separa...
Definition: Language.php:3356
static $mHebrewCalendarMonthGenMsgs
Definition: Language.php:152
const NS_USER_TALK
Definition: Defines.php:63
static array $languagesWithVariants
languages supporting variants
truncateForVisual( $string, $length, $ellipsis='...', $adjustLength=true)
Truncate a string to a specified number of characters, appending an optional string (e...
Definition: Language.php:3427
gender( $gender, $forms)
Provides an alternative text depending on specified gender.
Definition: Language.php:3835
getMessageFromDB( $msg)
Get a message from the MediaWiki namespace.
Definition: Language.php:843
hasWordBreaks()
Most writing systems use whitespace to break up words.
Definition: Language.php:2794
convert( $text)
convert text to different variants of a language.
Definition: Language.php:4062
alignStart()
Return &#39;left&#39; or &#39;right&#39; as appropriate alignment for line-start for this language&#39;s text direction...
Definition: Language.php:2992
return true
Definition: router.php:92
checkTitleEncoding( $s)
TODO: $s is not always a string per T218883.
Definition: Language.php:2768
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
convertPlural( $count, $forms)
Plural form transformations, needed for some languages.
Definition: Language.php:3864
isValidCode( $code)
Returns true if a language code string is of a valid form, whether or not it exists.
formatNumNoSeparators( $number)
Front-end for non-commafied formatNum.
Definition: Language.php:3201
parseFormattedNumber( $number)
Definition: Language.php:3209
truncateInternal( $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring)
Internal method used for truncation.
Definition: Language.php:3453
while(( $__line=Maintenance::readconsole()) !==false) print n
Definition: eval.php:64
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
replaceGrammarInNamespace( $m)
Definition: Language.php:4467
static $GREG_DAYS
Definition: Language.php:1506
formatDuration( $seconds, array $chosenIntervals=[])
Takes a number of seconds and turns it into a text using values such as hours and minutes...
Definition: Language.php:2253
$matches