MediaWiki  master
Language.php
Go to the documentation of this file.
1 <?php
25 use CLDRPluralRuleParser\Evaluator;
31 use Wikimedia\Assert\Assert;
32 
39 class Language {
45  const AS_AUTONYMS = LanguageNameUtils::AUTONYMS;
46 
52  const ALL = LanguageNameUtils::ALL;
53 
60  const SUPPORTED = LanguageNameUtils::SUPPORTED;
61 
69  public function __get( string $name ) {
70  if ( $name == "mConverter" ) {
71  wfDeprecated( 'Language::mConverter', '1.35' );
72  return $this->getConverter();
73  }
74  throw new RuntimeException( "Cannot get '$name' property." );
75  }
76 
77  public $mCode;
78 
82  public $mMagicExtensions = [];
83 
84  private $mHtmlCode = null;
85 
90  public $dateFormatStrings = [];
91 
98 
100  protected $namespaceNames;
102 
107  public $transformData = [];
108 
111 
113  private $langNameUtils;
114 
116  private $langFallback;
117 
120 
125 
130  public static $mLangObjCache = [];
131 
137  const MESSAGES_FALLBACKS = LanguageFallback::MESSAGES;
138 
144  const STRICT_FALLBACKS = LanguageFallback::STRICT;
145 
149  public const WEEKDAY_MESSAGES = [
150  'sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
151  'friday', 'saturday'
152  ];
153 
158 
163  'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'
164  ];
165 
170 
174  public const MONTH_MESSAGES = [
175  'january', 'february', 'march', 'april', 'may_long', 'june',
176  'july', 'august', 'september', 'october', 'november',
177  'december'
178  ];
179 
184 
188  public const MONTH_GENITIVE_MESSAGES = [
189  'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
190  'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen',
191  'december-gen'
192  ];
193 
198 
202  public const MONTH_ABBREVIATED_MESSAGES = [
203  'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
204  'sep', 'oct', 'nov', 'dec'
205  ];
206 
211 
216  'iranian-calendar-m1', 'iranian-calendar-m2', 'iranian-calendar-m3',
217  'iranian-calendar-m4', 'iranian-calendar-m5', 'iranian-calendar-m6',
218  'iranian-calendar-m7', 'iranian-calendar-m8', 'iranian-calendar-m9',
219  'iranian-calendar-m10', 'iranian-calendar-m11', 'iranian-calendar-m12'
220  ];
221 
226 
231  'hebrew-calendar-m1', 'hebrew-calendar-m2', 'hebrew-calendar-m3',
232  'hebrew-calendar-m4', 'hebrew-calendar-m5', 'hebrew-calendar-m6',
233  'hebrew-calendar-m7', 'hebrew-calendar-m8', 'hebrew-calendar-m9',
234  'hebrew-calendar-m10', 'hebrew-calendar-m11', 'hebrew-calendar-m12',
235  'hebrew-calendar-m6a', 'hebrew-calendar-m6b'
236  ];
237 
242 
247  'hebrew-calendar-m1-gen', 'hebrew-calendar-m2-gen', 'hebrew-calendar-m3-gen',
248  'hebrew-calendar-m4-gen', 'hebrew-calendar-m5-gen', 'hebrew-calendar-m6-gen',
249  'hebrew-calendar-m7-gen', 'hebrew-calendar-m8-gen', 'hebrew-calendar-m9-gen',
250  'hebrew-calendar-m10-gen', 'hebrew-calendar-m11-gen', 'hebrew-calendar-m12-gen',
251  'hebrew-calendar-m6a-gen', 'hebrew-calendar-m6b-gen'
252  ];
253 
258 
263  'hijri-calendar-m1', 'hijri-calendar-m2', 'hijri-calendar-m3',
264  'hijri-calendar-m4', 'hijri-calendar-m5', 'hijri-calendar-m6',
265  'hijri-calendar-m7', 'hijri-calendar-m8', 'hijri-calendar-m9',
266  'hijri-calendar-m10', 'hijri-calendar-m11', 'hijri-calendar-m12'
267  ];
268 
273 
277  protected const DURATION_INTERVALS = [
278  'millennia' => 31556952000,
279  'centuries' => 3155695200,
280  'decades' => 315569520,
281  'years' => 31556952, // 86400 * ( 365 + ( 24 * 3 + 25 ) / 400 )
282  'weeks' => 604800,
283  'days' => 86400,
284  'hours' => 3600,
285  'minutes' => 60,
286  'seconds' => 1,
287  ];
288 
295 
299  private const LRE = "\u{202A}"; // U+202A LEFT-TO-RIGHT EMBEDDING
300  private const RLE = "\u{202B}"; // U+202B RIGHT-TO-LEFT EMBEDDING
301  private const PDF = "\u{202C}"; // U+202C POP DIRECTIONAL FORMATTING
302 
314  // @codeCoverageIgnoreStart
315  // phpcs:ignore Generic.Files.LineLength
316  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';
317  // @codeCoverageIgnoreEnd
318 
326  public static function factory( $code ) {
327  return MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( $code );
328  }
329 
336  public static function clearCaches() {
337  wfDeprecated( __METHOD__, '1.35' );
338 
339  $services = MediaWikiServices::getInstance();
340 
341  $services->resetServiceForTesting( 'LanguageFallback' );
342  $services->resetServiceForTesting( 'LanguageNameUtils' );
343  $services->resetServiceForTesting( 'LocalisationCache' );
344  $services->resetServiceForTesting( 'LanguageFactory' );
345 
346  self::$mLangObjCache = [];
347  }
348 
358  public static function isSupportedLanguage( $code ) {
359  return MediaWikiServices::getInstance()->getLanguageNameUtils()
360  ->isSupportedLanguage( $code );
361  }
362 
378  public static function isWellFormedLanguageTag( $code, $lenient = false ) {
379  $alpha = '[a-z]';
380  $digit = '[0-9]';
381  $alphanum = '[a-z0-9]';
382  $x = 'x'; # private use singleton
383  $singleton = '[a-wy-z]'; # other singleton
384  $s = $lenient ? '[-_]' : '-';
385 
386  $language = "$alpha{2,8}|$alpha{2,3}$s$alpha{3}";
387  $script = "$alpha{4}"; # ISO 15924
388  $region = "(?:$alpha{2}|$digit{3})"; # ISO 3166-1 alpha-2 or UN M.49
389  $variant = "(?:$alphanum{5,8}|$digit$alphanum{3})";
390  $extension = "$singleton(?:$s$alphanum{2,8})+";
391  $privateUse = "$x(?:$s$alphanum{1,8})+";
392 
393  # Define certain grandfathered codes, since otherwise the regex is pretty useless.
394  # Since these are limited, this is safe even later changes to the registry --
395  # the only oddity is that it might change the type of the tag, and thus
396  # the results from the capturing groups.
397  # https://www.iana.org/assignments/language-subtag-registry
398 
399  $grandfathered = "en{$s}GB{$s}oed"
400  . "|i{$s}(?:ami|bnn|default|enochian|hak|klingon|lux|mingo|navajo|pwn|tao|tay|tsu)"
401  . "|no{$s}(?:bok|nyn)"
402  . "|sgn{$s}(?:BE{$s}(?:fr|nl)|CH{$s}de)"
403  . "|zh{$s}min{$s}nan";
404 
405  $variantList = "$variant(?:$s$variant)*";
406  $extensionList = "$extension(?:$s$extension)*";
407 
408  $langtag = "(?:($language)"
409  . "(?:$s$script)?"
410  . "(?:$s$region)?"
411  . "(?:$s$variantList)?"
412  . "(?:$s$extensionList)?"
413  . "(?:$s$privateUse)?)";
414 
415  # The final breakdown, with capturing groups for each of these components
416  # The variants, extensions, grandfathered, and private-use may have interior '-'
417 
418  $root = "^(?:$langtag|$privateUse|$grandfathered)$";
419 
420  return (bool)preg_match( "/$root/", strtolower( $code ) );
421  }
422 
434  public static function isValidCode( $code ) {
435  return MediaWikiServices::getInstance()->getLanguageNameUtils()->isValidCode( $code );
436  }
437 
449  public static function isValidBuiltInCode( $code ) {
450  return MediaWikiServices::getInstance()->getLanguageNameUtils()
451  ->isValidBuiltInCode( $code );
452  }
453 
464  public static function isKnownLanguageTag( $tag ) {
465  return MediaWikiServices::getInstance()->getLanguageNameUtils()
466  ->isKnownLanguageTag( $tag );
467  }
468 
475  public static function getLocalisationCache() {
476  return MediaWikiServices::getInstance()->getLocalisationCache();
477  }
478 
488  public function __construct(
489  $code = null,
494  ) {
495  if ( !func_num_args() ) {
496  // Old calling convention, deprecated
497  if ( static::class === 'Language' ) {
498  $this->mCode = 'en';
499  } else {
500  $this->mCode = str_replace( '_', '-', strtolower( substr( static::class, 8 ) ) );
501  }
502 
503  $services = MediaWikiServices::getInstance();
504  $this->localisationCache = $services->getLocalisationCache();
505  $this->langNameUtils = $services->getLanguageNameUtils();
506  $this->langFallback = $services->getLanguageFallback();
507  $this->converterFactory = $services->getLanguageConverterFactory();
508  return;
509  }
510 
511  Assert::parameter( $code !== null, '$code',
512  'Parameters cannot be null unless all are omitted' );
513  Assert::parameter( $localisationCache !== null, '$localisationCache',
514  'Parameters cannot be null unless all are omitted' );
515  Assert::parameter( $langNameUtils !== null, '$langNameUtils',
516  'Parameters cannot be null unless all are omitted' );
517  Assert::parameter( $langFallback !== null, '$langFallback',
518  'Parameters cannot be null unless all are omitted' );
519  Assert::parameter( $converterFactory !== null, '$converterFactory',
520  'Parameters cannot be null unless all are omitted' );
521 
522  $this->mCode = $code;
523  $this->localisationCache = $localisationCache;
524  $this->langNameUtils = $langNameUtils;
525  $this->langFallback = $langFallback;
526  $this->converterFactory = $converterFactory;
527  }
528 
533  public function __destruct() {
534  foreach ( $this as $name => $value ) {
535  unset( $this->$name );
536  }
537  }
538 
543  public function getFallbackLanguages() {
544  return $this->langFallback->getAll( $this->mCode );
545  }
546 
551  public function getBookstoreList() {
552  return $this->localisationCache->getItem( $this->mCode, 'bookstoreList' );
553  }
554 
561  public function getNamespaces() {
562  if ( $this->namespaceNames === null ) {
564 
565  $validNamespaces = MediaWikiServices::getInstance()->getNamespaceInfo()->
566  getCanonicalNamespaces();
567 
568  $this->namespaceNames = $wgExtraNamespaces +
569  $this->localisationCache->getItem( $this->mCode, 'namespaceNames' );
570  $this->namespaceNames += $validNamespaces;
571 
572  $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
573  if ( $wgMetaNamespaceTalk ) {
574  $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk;
575  } else {
576  $talk = $this->namespaceNames[NS_PROJECT_TALK];
577  $this->namespaceNames[NS_PROJECT_TALK] =
578  $this->fixVariableInNamespace( $talk );
579  }
580 
581  # Sometimes a language will be localised but not actually exist on this wiki.
582  foreach ( $this->namespaceNames as $key => $text ) {
583  if ( !isset( $validNamespaces[$key] ) ) {
584  unset( $this->namespaceNames[$key] );
585  }
586  }
587 
588  # The above mixing may leave namespaces out of canonical order.
589  # Re-order by namespace ID number...
590  ksort( $this->namespaceNames );
591 
592  Hooks::run( 'LanguageGetNamespaces', [ &$this->namespaceNames ] );
593  }
594 
595  return $this->namespaceNames;
596  }
597 
602  public function setNamespaces( array $namespaces ) {
603  $this->namespaceNames = $namespaces;
604  $this->mNamespaceIds = null;
605  }
606 
610  public function resetNamespaces() {
611  $this->namespaceNames = null;
612  $this->mNamespaceIds = null;
613  $this->namespaceAliases = null;
614  }
615 
622  public function getFormattedNamespaces() {
623  $ns = $this->getNamespaces();
624  foreach ( $ns as $k => $v ) {
625  $ns[$k] = strtr( $v, '_', ' ' );
626  }
627  return $ns;
628  }
629 
641  public function getNsText( $index ) {
642  $ns = $this->getNamespaces();
643  return $ns[$index] ?? false;
644  }
645 
659  public function getFormattedNsText( $index ) {
660  $ns = $this->getNsText( $index );
661  return strtr( $ns, '_', ' ' );
662  }
663 
672  public function getGenderNsText( $index, $gender ) {
674 
676  (array)$this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' );
677 
678  return $ns[$index][$gender] ?? $this->getNsText( $index );
679  }
680 
687  public function needsGenderDistinction() {
689  if ( count( $wgExtraGenderNamespaces ) > 0 ) {
690  // $wgExtraGenderNamespaces overrides everything
691  return true;
692  } elseif ( isset( $wgExtraNamespaces[NS_USER] ) && isset( $wgExtraNamespaces[NS_USER_TALK] ) ) {
694  // $wgExtraNamespaces overrides any gender aliases specified in i18n files
695  return false;
696  } else {
697  // Check what is in i18n files
698  $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceGenderAliases' );
699  return count( $aliases ) > 0;
700  }
701  }
702 
711  public function getLocalNsIndex( $text ) {
712  $lctext = $this->lc( $text );
713  $ids = $this->getNamespaceIds();
714  return $ids[$lctext] ?? false;
715  }
716 
721  public function getNamespaceAliases() {
722  if ( $this->namespaceAliases === null ) {
723  $aliases = $this->localisationCache->getItem( $this->mCode, 'namespaceAliases' );
724  if ( !$aliases ) {
725  $aliases = [];
726  } else {
727  foreach ( $aliases as $name => $index ) {
728  if ( $index === NS_PROJECT_TALK ) {
729  unset( $aliases[$name] );
730  $name = $this->fixVariableInNamespace( $name );
731  $aliases[$name] = $index;
732  }
733  }
734  }
735 
737  $genders = $wgExtraGenderNamespaces + (array)$this->localisationCache
738  ->getItem( $this->mCode, 'namespaceGenderAliases' );
739  foreach ( $genders as $index => $forms ) {
740  foreach ( $forms as $alias ) {
741  $aliases[$alias] = $index;
742  }
743  }
744 
745  # Also add converted namespace names as aliases, to avoid confusion.
746  $convertedNames = [];
747  foreach ( $this->getConverter()->getVariants() as $variant ) {
748  if ( $variant === $this->mCode ) {
749  continue;
750  }
751  foreach ( $this->getNamespaces() as $ns => $_ ) {
752  $convertedNames[$this->getConverter()->convertNamespace( $ns, $variant )] = $ns;
753  }
754  }
755 
756  $this->namespaceAliases = $aliases + $convertedNames;
757 
758  // In the case of conflicts between $wgNamespaceAliases and other sources
759  // of aliasing, $wgNamespaceAliases wins.
760  global $wgNamespaceAliases;
761  $this->namespaceAliases = $wgNamespaceAliases + $this->namespaceAliases;
762 
763  # Filter out aliases to namespaces that don't exist, e.g. from extensions
764  # that aren't loaded here but are included in the l10n cache.
765  # (array_intersect preserves keys from its first argument)
766  $this->namespaceAliases = array_intersect(
767  $this->namespaceAliases,
768  array_keys( $this->getNamespaces() )
769  );
770  }
771 
773  }
774 
778  public function getNamespaceIds() {
779  if ( $this->mNamespaceIds === null ) {
780  # Put namespace names and aliases into a hashtable.
781  # If this is too slow, then we should arrange it so that it is done
782  # before caching. The catch is that at pre-cache time, the above
783  # class-specific fixup hasn't been done.
784  $this->mNamespaceIds = [];
785  foreach ( $this->getNamespaces() as $index => $name ) {
786  $this->mNamespaceIds[$this->lc( $name )] = $index;
787  }
788  foreach ( $this->getNamespaceAliases() as $name => $index ) {
789  $this->mNamespaceIds[$this->lc( $name )] = $index;
790  }
791  }
792  return $this->mNamespaceIds;
793  }
794 
802  public function getNsIndex( $text ) {
803  $lctext = $this->lc( $text );
804  $ns = MediaWikiServices::getInstance()->getNamespaceInfo()->
805  getCanonicalIndex( $lctext );
806  if ( $ns !== null ) {
807  return $ns;
808  }
809  $ids = $this->getNamespaceIds();
810  return $ids[$lctext] ?? false;
811  }
812 
820  public function getVariantname( $code, $usemsg = true ) {
821  $msg = "variantname-$code";
822  if ( $usemsg && wfMessage( $msg )->exists() ) {
823  return $this->getMessageFromDB( $msg );
824  }
825  $name = $this->langNameUtils->getLanguageName( $code );
826  if ( $name ) {
827  return $name; # if it's defined as a language name, show that
828  } else {
829  # otherwise, output the language code
830  return $code;
831  }
832  }
833 
837  public function getDatePreferences() {
838  return $this->localisationCache->getItem( $this->mCode, 'datePreferences' );
839  }
840 
844  public function getDateFormats() {
845  return $this->localisationCache->getItem( $this->mCode, 'dateFormats' );
846  }
847 
851  public function getDefaultDateFormat() {
852  $df = $this->localisationCache->getItem( $this->mCode, 'defaultDateFormat' );
853  if ( $df === 'dmy or mdy' ) {
854  global $wgAmericanDates;
855  return $wgAmericanDates ? 'mdy' : 'dmy';
856  } else {
857  return $df;
858  }
859  }
860 
864  public function getDatePreferenceMigrationMap() {
865  return $this->localisationCache->getItem( $this->mCode, 'datePreferenceMigrationMap' );
866  }
867 
871  public function getExtraUserToggles() {
872  wfDeprecated( __METHOD__, '1.34' );
873  return [];
874  }
875 
889  public static function fetchLanguageNames( $inLanguage = self::AS_AUTONYMS, $include = 'mw' ) {
890  return MediaWikiServices::getInstance()->getLanguageNameUtils()
891  ->getLanguageNames( $inLanguage, $include );
892  }
893 
903  public static function fetchLanguageName(
904  $code,
905  $inLanguage = self::AS_AUTONYMS,
906  $include = self::ALL
907  ) {
908  return MediaWikiServices::getInstance()->getLanguageNameUtils()
909  ->getLanguageName( $code, $inLanguage, $include );
910  }
911 
918  public function getMessageFromDB( $msg ) {
919  return $this->msg( $msg )->text();
920  }
921 
928  protected function msg( $msg ) {
929  return wfMessage( $msg )->inLanguage( $this );
930  }
931 
936  public function getMonthName( $key ) {
937  return $this->getMessageFromDB( self::MONTH_MESSAGES[$key - 1] );
938  }
939 
943  public function getMonthNamesArray() {
944  $monthNames = [ '' ];
945  for ( $i = 1; $i < 13; $i++ ) {
946  $monthNames[] = $this->getMonthName( $i );
947  }
948  return $monthNames;
949  }
950 
955  public function getMonthNameGen( $key ) {
956  return $this->getMessageFromDB( self::MONTH_GENITIVE_MESSAGES[$key - 1] );
957  }
958 
963  public function getMonthAbbreviation( $key ) {
964  return $this->getMessageFromDB( self::MONTH_ABBREVIATED_MESSAGES[$key - 1] );
965  }
966 
970  public function getMonthAbbreviationsArray() {
971  $monthNames = [ '' ];
972  for ( $i = 1; $i < 13; $i++ ) {
973  $monthNames[] = $this->getMonthAbbreviation( $i );
974  }
975  return $monthNames;
976  }
977 
982  public function getWeekdayName( $key ) {
983  return $this->getMessageFromDB( self::WEEKDAY_MESSAGES[$key - 1] );
984  }
985 
990  public function getWeekdayAbbreviation( $key ) {
991  return $this->getMessageFromDB( self::WEEKDAY_ABBREVIATED_MESSAGES[$key - 1] );
992  }
993 
998  private function getIranianCalendarMonthName( $key ) {
999  return $this->getMessageFromDB( self::IRANIAN_CALENDAR_MONTHS_MESSAGES[$key - 1] );
1000  }
1001 
1006  private function getHebrewCalendarMonthName( $key ) {
1007  return $this->getMessageFromDB( self::HEBREW_CALENDAR_MONTHS_MESSAGES[$key - 1] );
1008  }
1009 
1014  private function getHebrewCalendarMonthNameGen( $key ) {
1015  return $this->getMessageFromDB( self::HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES[$key - 1] );
1016  }
1017 
1022  private function getHijriCalendarMonthName( $key ) {
1023  return $this->getMessageFromDB( self::HIJRI_CALENDAR_MONTH_MESSAGES[$key - 1] );
1024  }
1025 
1034  private static function dateTimeObjFormat( &$dateTimeObj, $ts, $zone, $code ) {
1035  if ( !$dateTimeObj ) {
1036  $dateTimeObj = DateTime::createFromFormat(
1037  'YmdHis', $ts, $zone ?: new DateTimeZone( 'UTC' )
1038  );
1039  }
1040  return $dateTimeObj->format( $code );
1041  }
1042 
1113  public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = 'unused' ) {
1114  $s = '';
1115  $raw = false;
1116  $roman = false;
1117  $hebrewNum = false;
1118  $dateTimeObj = false;
1119  $rawToggle = false;
1120  $iranian = false;
1121  $hebrew = false;
1122  $hijri = false;
1123  $thai = false;
1124  $minguo = false;
1125  $tenno = false;
1126 
1127  $usedSecond = false;
1128  $usedMinute = false;
1129  $usedHour = false;
1130  $usedAMPM = false;
1131  $usedDay = false;
1132  $usedWeek = false;
1133  $usedMonth = false;
1134  $usedYear = false;
1135  $usedISOYear = false;
1136  $usedIsLeapYear = false;
1137 
1138  $usedHebrewMonth = false;
1139  $usedIranianMonth = false;
1140  $usedHijriMonth = false;
1141  $usedHebrewYear = false;
1142  $usedIranianYear = false;
1143  $usedHijriYear = false;
1144  $usedTennoYear = false;
1145 
1146  if ( strlen( $ts ) !== 14 ) {
1147  throw new MWException( __METHOD__ . ": The timestamp $ts should have 14 characters" );
1148  }
1149 
1150  if ( !ctype_digit( $ts ) ) {
1151  throw new MWException( __METHOD__ . ": The timestamp $ts should be a number" );
1152  }
1153 
1154  $formatLength = strlen( $format );
1155  for ( $p = 0; $p < $formatLength; $p++ ) {
1156  $num = false;
1157  $code = $format[$p];
1158  if ( $code == 'x' && $p < $formatLength - 1 ) {
1159  $code .= $format[++$p];
1160  }
1161 
1162  if ( ( $code === 'xi'
1163  || $code === 'xj'
1164  || $code === 'xk'
1165  || $code === 'xm'
1166  || $code === 'xo'
1167  || $code === 'xt' )
1168  && $p < $formatLength - 1 ) {
1169  $code .= $format[++$p];
1170  }
1171 
1172  switch ( $code ) {
1173  case 'xx':
1174  $s .= 'x';
1175  break;
1176  case 'xn':
1177  $raw = true;
1178  break;
1179  case 'xN':
1180  $rawToggle = !$rawToggle;
1181  break;
1182  case 'xr':
1183  $roman = true;
1184  break;
1185  case 'xh':
1186  $hebrewNum = true;
1187  break;
1188  case 'xg':
1189  $usedMonth = true;
1190  $s .= $this->getMonthNameGen( substr( $ts, 4, 2 ) );
1191  break;
1192  case 'xjx':
1193  $usedHebrewMonth = true;
1194  if ( !$hebrew ) {
1195  $hebrew = self::tsToHebrew( $ts );
1196  }
1197  $s .= $this->getHebrewCalendarMonthNameGen( $hebrew[1] );
1198  break;
1199  case 'd':
1200  $usedDay = true;
1201  $num = substr( $ts, 6, 2 );
1202  break;
1203  case 'D':
1204  $usedDay = true;
1205  $s .= $this->getWeekdayAbbreviation(
1206  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'w' ) + 1
1207  );
1208  break;
1209  case 'j':
1210  $usedDay = true;
1211  $num = intval( substr( $ts, 6, 2 ) );
1212  break;
1213  case 'xij':
1214  $usedDay = true;
1215  if ( !$iranian ) {
1216  $iranian = self::tsToIranian( $ts );
1217  }
1218  $num = $iranian[2];
1219  break;
1220  case 'xmj':
1221  $usedDay = true;
1222  if ( !$hijri ) {
1223  $hijri = self::tsToHijri( $ts );
1224  }
1225  $num = $hijri[2];
1226  break;
1227  case 'xjj':
1228  $usedDay = true;
1229  if ( !$hebrew ) {
1230  $hebrew = self::tsToHebrew( $ts );
1231  }
1232  $num = $hebrew[2];
1233  break;
1234  case 'l':
1235  $usedDay = true;
1236  $s .= $this->getWeekdayName(
1237  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'w' ) + 1
1238  );
1239  break;
1240  case 'F':
1241  $usedMonth = true;
1242  $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
1243  break;
1244  case 'xiF':
1245  $usedIranianMonth = true;
1246  if ( !$iranian ) {
1247  $iranian = self::tsToIranian( $ts );
1248  }
1249  $s .= $this->getIranianCalendarMonthName( $iranian[1] );
1250  break;
1251  case 'xmF':
1252  $usedHijriMonth = true;
1253  if ( !$hijri ) {
1254  $hijri = self::tsToHijri( $ts );
1255  }
1256  $s .= $this->getHijriCalendarMonthName( $hijri[1] );
1257  break;
1258  case 'xjF':
1259  $usedHebrewMonth = true;
1260  if ( !$hebrew ) {
1261  $hebrew = self::tsToHebrew( $ts );
1262  }
1263  $s .= $this->getHebrewCalendarMonthName( $hebrew[1] );
1264  break;
1265  case 'm':
1266  $usedMonth = true;
1267  $num = substr( $ts, 4, 2 );
1268  break;
1269  case 'M':
1270  $usedMonth = true;
1271  $s .= $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
1272  break;
1273  case 'n':
1274  $usedMonth = true;
1275  $num = intval( substr( $ts, 4, 2 ) );
1276  break;
1277  case 'xin':
1278  $usedIranianMonth = true;
1279  if ( !$iranian ) {
1280  $iranian = self::tsToIranian( $ts );
1281  }
1282  $num = $iranian[1];
1283  break;
1284  case 'xmn':
1285  $usedHijriMonth = true;
1286  if ( !$hijri ) {
1287  $hijri = self::tsToHijri( $ts );
1288  }
1289  $num = $hijri[1];
1290  break;
1291  case 'xjn':
1292  $usedHebrewMonth = true;
1293  if ( !$hebrew ) {
1294  $hebrew = self::tsToHebrew( $ts );
1295  }
1296  $num = $hebrew[1];
1297  break;
1298  case 'xjt':
1299  $usedHebrewMonth = true;
1300  if ( !$hebrew ) {
1301  $hebrew = self::tsToHebrew( $ts );
1302  }
1303  $num = $hebrew[3];
1304  break;
1305  case 'Y':
1306  $usedYear = true;
1307  $num = substr( $ts, 0, 4 );
1308  break;
1309  case 'xiY':
1310  $usedIranianYear = true;
1311  if ( !$iranian ) {
1312  $iranian = self::tsToIranian( $ts );
1313  }
1314  $num = $iranian[0];
1315  break;
1316  case 'xmY':
1317  $usedHijriYear = true;
1318  if ( !$hijri ) {
1319  $hijri = self::tsToHijri( $ts );
1320  }
1321  $num = $hijri[0];
1322  break;
1323  case 'xjY':
1324  $usedHebrewYear = true;
1325  if ( !$hebrew ) {
1326  $hebrew = self::tsToHebrew( $ts );
1327  }
1328  $num = $hebrew[0];
1329  break;
1330  case 'xkY':
1331  $usedYear = true;
1332  if ( !$thai ) {
1333  $thai = self::tsToYear( $ts, 'thai' );
1334  }
1335  $num = $thai[0];
1336  break;
1337  case 'xoY':
1338  $usedYear = true;
1339  if ( !$minguo ) {
1340  $minguo = self::tsToYear( $ts, 'minguo' );
1341  }
1342  $num = $minguo[0];
1343  break;
1344  case 'xtY':
1345  $usedTennoYear = true;
1346  if ( !$tenno ) {
1347  $tenno = self::tsToYear( $ts, 'tenno' );
1348  }
1349  $num = $tenno[0];
1350  break;
1351  case 'y':
1352  $usedYear = true;
1353  $num = substr( $ts, 2, 2 );
1354  break;
1355  case 'xiy':
1356  $usedIranianYear = true;
1357  if ( !$iranian ) {
1358  $iranian = self::tsToIranian( $ts );
1359  }
1360  $num = substr( $iranian[0], -2 );
1361  break;
1362  case 'xit':
1363  $usedIranianYear = true;
1364  if ( !$iranian ) {
1365  $iranian = self::tsToIranian( $ts );
1366  }
1367  $num = self::$IRANIAN_DAYS[$iranian[1] - 1];
1368  break;
1369  case 'xiz':
1370  $usedIranianYear = true;
1371  if ( !$iranian ) {
1372  $iranian = self::tsToIranian( $ts );
1373  }
1374  $num = $iranian[3];
1375  break;
1376  case 'a':
1377  $usedAMPM = true;
1378  $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'am' : 'pm';
1379  break;
1380  case 'A':
1381  $usedAMPM = true;
1382  $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'AM' : 'PM';
1383  break;
1384  case 'g':
1385  $usedHour = true;
1386  $h = substr( $ts, 8, 2 );
1387  $num = $h % 12 ?: 12;
1388  break;
1389  case 'G':
1390  $usedHour = true;
1391  $num = intval( substr( $ts, 8, 2 ) );
1392  break;
1393  case 'h':
1394  $usedHour = true;
1395  $h = substr( $ts, 8, 2 );
1396  $num = sprintf( '%02d', $h % 12 ?: 12 );
1397  break;
1398  case 'H':
1399  $usedHour = true;
1400  $num = substr( $ts, 8, 2 );
1401  break;
1402  case 'i':
1403  $usedMinute = true;
1404  $num = substr( $ts, 10, 2 );
1405  break;
1406  case 's':
1407  $usedSecond = true;
1408  $num = substr( $ts, 12, 2 );
1409  break;
1410  case 'c':
1411  case 'r':
1412  $usedSecond = true;
1413  // fall through
1414  case 'e':
1415  case 'O':
1416  case 'P':
1417  case 'T':
1418  $s .= self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1419  break;
1420  case 'w':
1421  case 'N':
1422  case 'z':
1423  $usedDay = true;
1424  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1425  break;
1426  case 'W':
1427  $usedWeek = true;
1428  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1429  break;
1430  case 't':
1431  $usedMonth = true;
1432  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1433  break;
1434  case 'L':
1435  $usedIsLeapYear = true;
1436  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1437  break;
1438  case 'o':
1439  $usedISOYear = true;
1440  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1441  break;
1442  case 'U':
1443  $usedSecond = true;
1444  // fall through
1445  case 'I':
1446  case 'Z':
1447  $num = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, $code );
1448  break;
1449  case '\\':
1450  # Backslash escaping
1451  if ( $p < $formatLength - 1 ) {
1452  $s .= $format[++$p];
1453  } else {
1454  $s .= '\\';
1455  }
1456  break;
1457  case '"':
1458  # Quoted literal
1459  if ( $p < $formatLength - 1 ) {
1460  $endQuote = strpos( $format, '"', $p + 1 );
1461  if ( $endQuote === false ) {
1462  # No terminating quote, assume literal "
1463  $s .= '"';
1464  } else {
1465  $s .= substr( $format, $p + 1, $endQuote - $p - 1 );
1466  $p = $endQuote;
1467  }
1468  } else {
1469  # Quote at end of string, assume literal "
1470  $s .= '"';
1471  }
1472  break;
1473  default:
1474  $s .= $format[$p];
1475  }
1476  if ( $num !== false ) {
1477  if ( $rawToggle || $raw ) {
1478  $s .= $num;
1479  $raw = false;
1480  } elseif ( $roman ) {
1481  $s .= self::romanNumeral( $num );
1482  $roman = false;
1483  } elseif ( $hebrewNum ) {
1484  $s .= self::hebrewNumeral( $num );
1485  $hebrewNum = false;
1486  } else {
1487  $s .= $this->formatNum( $num, true );
1488  }
1489  }
1490  }
1491 
1492  if ( $ttl === 'unused' ) {
1493  // No need to calculate the TTL, the caller wont use it anyway.
1494  } elseif ( $usedSecond ) {
1495  $ttl = 1;
1496  } elseif ( $usedMinute ) {
1497  $ttl = 60 - substr( $ts, 12, 2 );
1498  } elseif ( $usedHour ) {
1499  $ttl = 3600 - substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1500  } elseif ( $usedAMPM ) {
1501  $ttl = 43200 - ( substr( $ts, 8, 2 ) % 12 ) * 3600 -
1502  substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1503  } elseif (
1504  $usedDay ||
1505  $usedHebrewMonth ||
1506  $usedIranianMonth ||
1507  $usedHijriMonth ||
1508  $usedHebrewYear ||
1509  $usedIranianYear ||
1510  $usedHijriYear ||
1511  $usedTennoYear
1512  ) {
1513  // @todo Someone who understands the non-Gregorian calendars
1514  // should write proper logic for them so that they don't need purged every day.
1515  $ttl = 86400 - substr( $ts, 8, 2 ) * 3600 -
1516  substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1517  } else {
1518  $possibleTtls = [];
1519  $timeRemainingInDay = 86400 - substr( $ts, 8, 2 ) * 3600 -
1520  substr( $ts, 10, 2 ) * 60 - substr( $ts, 12, 2 );
1521  if ( $usedWeek ) {
1522  $possibleTtls[] =
1523  ( 7 - self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'N' ) ) * 86400 +
1524  $timeRemainingInDay;
1525  } elseif ( $usedISOYear ) {
1526  // December 28th falls on the last ISO week of the year, every year.
1527  // The last ISO week of a year can be 52 or 53.
1528  $lastWeekOfISOYear = DateTime::createFromFormat(
1529  'Ymd',
1530  substr( $ts, 0, 4 ) . '1228',
1531  $zone ?: new DateTimeZone( 'UTC' )
1532  )->format( 'W' );
1533  $currentISOWeek = self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'W' );
1534  $weeksRemaining = $lastWeekOfISOYear - $currentISOWeek;
1535  $timeRemainingInWeek =
1536  ( 7 - self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'N' ) ) * 86400
1537  + $timeRemainingInDay;
1538  $possibleTtls[] = $weeksRemaining * 604800 + $timeRemainingInWeek;
1539  }
1540 
1541  if ( $usedMonth ) {
1542  $possibleTtls[] =
1543  ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 't' ) -
1544  substr( $ts, 6, 2 ) ) * 86400
1545  + $timeRemainingInDay;
1546  } elseif ( $usedYear ) {
1547  $possibleTtls[] =
1548  ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'L' ) + 364 -
1549  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'z' ) ) * 86400
1550  + $timeRemainingInDay;
1551  } elseif ( $usedIsLeapYear ) {
1552  $year = substr( $ts, 0, 4 );
1553  $timeRemainingInYear =
1554  ( self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'L' ) + 364 -
1555  self::dateTimeObjFormat( $dateTimeObj, $ts, $zone, 'z' ) ) * 86400
1556  + $timeRemainingInDay;
1557  $mod = $year % 4;
1558  if ( $mod || ( !( $year % 100 ) && $year % 400 ) ) {
1559  // this isn't a leap year. see when the next one starts
1560  $nextCandidate = $year - $mod + 4;
1561  if ( $nextCandidate % 100 || !( $nextCandidate % 400 ) ) {
1562  $possibleTtls[] = ( $nextCandidate - $year - 1 ) * 365 * 86400 +
1563  $timeRemainingInYear;
1564  } else {
1565  $possibleTtls[] = ( $nextCandidate - $year + 3 ) * 365 * 86400 +
1566  $timeRemainingInYear;
1567  }
1568  } else {
1569  // this is a leap year, so the next year isn't
1570  $possibleTtls[] = $timeRemainingInYear;
1571  }
1572  }
1573 
1574  if ( $possibleTtls ) {
1575  $ttl = min( $possibleTtls );
1576  }
1577  }
1578 
1579  return $s;
1580  }
1581 
1582  private static $GREG_DAYS = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
1583  private static $IRANIAN_DAYS = [ 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29 ];
1584 
1597  private static function tsToIranian( $ts ) {
1598  $gy = substr( $ts, 0, 4 ) - 1600;
1599  $gm = substr( $ts, 4, 2 ) - 1;
1600  $gd = substr( $ts, 6, 2 ) - 1;
1601 
1602  # Days passed from the beginning (including leap years)
1603  $gDayNo = 365 * $gy
1604  + floor( ( $gy + 3 ) / 4 )
1605  - floor( ( $gy + 99 ) / 100 )
1606  + floor( ( $gy + 399 ) / 400 );
1607 
1608  // Add days of the past months of this year
1609  for ( $i = 0; $i < $gm; $i++ ) {
1610  $gDayNo += self::$GREG_DAYS[$i];
1611  }
1612 
1613  // Leap years
1614  if ( $gm > 1 && ( ( $gy % 4 === 0 && $gy % 100 !== 0 || ( $gy % 400 == 0 ) ) ) ) {
1615  $gDayNo++;
1616  }
1617 
1618  // Days passed in current month
1619  $gDayNo += (int)$gd;
1620 
1621  $jDayNo = $gDayNo - 79;
1622 
1623  $jNp = floor( $jDayNo / 12053 );
1624  $jDayNo %= 12053;
1625 
1626  $jy = 979 + 33 * $jNp + 4 * floor( $jDayNo / 1461 );
1627  $jDayNo %= 1461;
1628 
1629  if ( $jDayNo >= 366 ) {
1630  $jy += floor( ( $jDayNo - 1 ) / 365 );
1631  $jDayNo = floor( ( $jDayNo - 1 ) % 365 );
1632  }
1633 
1634  $jz = $jDayNo;
1635 
1636  for ( $i = 0; $i < 11 && $jDayNo >= self::$IRANIAN_DAYS[$i]; $i++ ) {
1637  $jDayNo -= self::$IRANIAN_DAYS[$i];
1638  }
1639 
1640  $jm = $i + 1;
1641  $jd = $jDayNo + 1;
1642 
1643  return [ $jy, $jm, $jd, $jz ];
1644  }
1645 
1657  private static function tsToHijri( $ts ) {
1658  $year = substr( $ts, 0, 4 );
1659  $month = substr( $ts, 4, 2 );
1660  $day = substr( $ts, 6, 2 );
1661 
1662  $zyr = $year;
1663  $zd = $day;
1664  $zm = $month;
1665  $zy = $zyr;
1666 
1667  if (
1668  ( $zy > 1582 ) || ( ( $zy == 1582 ) && ( $zm > 10 ) ) ||
1669  ( ( $zy == 1582 ) && ( $zm == 10 ) && ( $zd > 14 ) )
1670  ) {
1671  $zjd = (int)( ( 1461 * ( $zy + 4800 + (int)( ( $zm - 14 ) / 12 ) ) ) / 4 ) +
1672  (int)( ( 367 * ( $zm - 2 - 12 * ( (int)( ( $zm - 14 ) / 12 ) ) ) ) / 12 ) -
1673  (int)( ( 3 * (int)( ( ( $zy + 4900 + (int)( ( $zm - 14 ) / 12 ) ) / 100 ) ) ) / 4 ) +
1674  $zd - 32075;
1675  } else {
1676  $zjd = 367 * $zy - (int)( ( 7 * ( $zy + 5001 + (int)( ( $zm - 9 ) / 7 ) ) ) / 4 ) +
1677  (int)( ( 275 * $zm ) / 9 ) + $zd + 1729777;
1678  }
1679 
1680  $zl = $zjd - 1948440 + 10632;
1681  $zn = (int)( ( $zl - 1 ) / 10631 );
1682  $zl = $zl - 10631 * $zn + 354;
1683  $zj = ( (int)( ( 10985 - $zl ) / 5316 ) ) * ( (int)( ( 50 * $zl ) / 17719 ) ) +
1684  ( (int)( $zl / 5670 ) ) * ( (int)( ( 43 * $zl ) / 15238 ) );
1685  $zl = $zl - ( (int)( ( 30 - $zj ) / 15 ) ) * ( (int)( ( 17719 * $zj ) / 50 ) ) -
1686  ( (int)( $zj / 16 ) ) * ( (int)( ( 15238 * $zj ) / 43 ) ) + 29;
1687  $zm = (int)( ( 24 * $zl ) / 709 );
1688  $zd = $zl - (int)( ( 709 * $zm ) / 24 );
1689  $zy = 30 * $zn + $zj - 30;
1690 
1691  return [ $zy, $zm, $zd ];
1692  }
1693 
1709  private static function tsToHebrew( $ts ) {
1710  # Parse date
1711  $year = substr( $ts, 0, 4 );
1712  $month = substr( $ts, 4, 2 );
1713  $day = substr( $ts, 6, 2 );
1714 
1715  # Calculate Hebrew year
1716  $hebrewYear = $year + 3760;
1717 
1718  # Month number when September = 1, August = 12
1719  $month += 4;
1720  if ( $month > 12 ) {
1721  # Next year
1722  $month -= 12;
1723  $year++;
1724  $hebrewYear++;
1725  }
1726 
1727  # Calculate day of year from 1 September
1728  $dayOfYear = $day;
1729  for ( $i = 1; $i < $month; $i++ ) {
1730  if ( $i == 6 ) {
1731  # February
1732  $dayOfYear += 28;
1733  # Check if the year is leap
1734  if ( $year % 400 == 0 || ( $year % 4 == 0 && $year % 100 > 0 ) ) {
1735  $dayOfYear++;
1736  }
1737  } elseif ( $i == 8 || $i == 10 || $i == 1 || $i == 3 ) {
1738  $dayOfYear += 30;
1739  } else {
1740  $dayOfYear += 31;
1741  }
1742  }
1743 
1744  # Calculate the start of the Hebrew year
1745  $start = self::hebrewYearStart( $hebrewYear );
1746 
1747  # Calculate next year's start
1748  if ( $dayOfYear <= $start ) {
1749  # Day is before the start of the year - it is the previous year
1750  # Next year's start
1751  $nextStart = $start;
1752  # Previous year
1753  $year--;
1754  $hebrewYear--;
1755  # Add days since previous year's 1 September
1756  $dayOfYear += 365;
1757  if ( ( $year % 400 == 0 ) || ( $year % 100 != 0 && $year % 4 == 0 ) ) {
1758  # Leap year
1759  $dayOfYear++;
1760  }
1761  # Start of the new (previous) year
1762  $start = self::hebrewYearStart( $hebrewYear );
1763  } else {
1764  # Next year's start
1765  $nextStart = self::hebrewYearStart( $hebrewYear + 1 );
1766  }
1767 
1768  # Calculate Hebrew day of year
1769  $hebrewDayOfYear = $dayOfYear - $start;
1770 
1771  # Difference between year's days
1772  $diff = $nextStart - $start;
1773  # Add 12 (or 13 for leap years) days to ignore the difference between
1774  # Hebrew and Gregorian year (353 at least vs. 365/6) - now the
1775  # difference is only about the year type
1776  if ( ( $year % 400 == 0 ) || ( $year % 100 != 0 && $year % 4 == 0 ) ) {
1777  $diff += 13;
1778  } else {
1779  $diff += 12;
1780  }
1781 
1782  # Check the year pattern, and is leap year
1783  # 0 means an incomplete year, 1 means a regular year, 2 means a complete year
1784  # This is mod 30, to work on both leap years (which add 30 days of Adar I)
1785  # and non-leap years
1786  $yearPattern = $diff % 30;
1787  # Check if leap year
1788  $isLeap = $diff >= 30;
1789 
1790  # Calculate day in the month from number of day in the Hebrew year
1791  # Don't check Adar - if the day is not in Adar, we will stop before;
1792  # if it is in Adar, we will use it to check if it is Adar I or Adar II
1793  $hebrewDay = $hebrewDayOfYear;
1794  $hebrewMonth = 1;
1795  $days = 0;
1796  while ( $hebrewMonth <= 12 ) {
1797  # Calculate days in this month
1798  if ( $isLeap && $hebrewMonth == 6 ) {
1799  # Leap year - has Adar I, with 30 days, and Adar II, with 29 days
1800  $days = 30;
1801  if ( $hebrewDay <= $days ) {
1802  # Day in Adar I
1803  $hebrewMonth = 13;
1804  } else {
1805  # Subtract the days of Adar I
1806  $hebrewDay -= $days;
1807  # Try Adar II
1808  $days = 29;
1809  if ( $hebrewDay <= $days ) {
1810  # Day in Adar II
1811  $hebrewMonth = 14;
1812  }
1813  }
1814  } elseif ( $hebrewMonth == 2 && $yearPattern == 2 ) {
1815  # Cheshvan in a complete year (otherwise as the rule below)
1816  $days = 30;
1817  } elseif ( $hebrewMonth == 3 && $yearPattern == 0 ) {
1818  # Kislev in an incomplete year (otherwise as the rule below)
1819  $days = 29;
1820  } else {
1821  # Odd months have 30 days, even have 29
1822  $days = 30 - ( $hebrewMonth - 1 ) % 2;
1823  }
1824  if ( $hebrewDay <= $days ) {
1825  # In the current month
1826  break;
1827  } else {
1828  # Subtract the days of the current month
1829  $hebrewDay -= $days;
1830  # Try in the next month
1831  $hebrewMonth++;
1832  }
1833  }
1834 
1835  return [ $hebrewYear, $hebrewMonth, $hebrewDay, $days ];
1836  }
1837 
1847  private static function hebrewYearStart( $year ) {
1848  $a = intval( ( 12 * ( $year - 1 ) + 17 ) % 19 );
1849  $b = intval( ( $year - 1 ) % 4 );
1850  $m = 32.044093161144 + 1.5542417966212 * $a + $b / 4.0 - 0.0031777940220923 * ( $year - 1 );
1851  if ( $m < 0 ) {
1852  $m--;
1853  }
1854  $Mar = intval( $m );
1855  if ( $m < 0 ) {
1856  $m++;
1857  }
1858  $m -= $Mar;
1859 
1860  $c = intval( ( $Mar + 3 * ( $year - 1 ) + 5 * $b + 5 ) % 7 );
1861  if ( $c == 0 && $a > 11 && $m >= 0.89772376543210 ) {
1862  $Mar++;
1863  } elseif ( $c == 1 && $a > 6 && $m >= 0.63287037037037 ) {
1864  $Mar += 2;
1865  } elseif ( $c == 2 || $c == 4 || $c == 6 ) {
1866  $Mar++;
1867  }
1868 
1869  $Mar += intval( ( $year - 3761 ) / 100 ) - intval( ( $year - 3761 ) / 400 ) - 24;
1870  return $Mar;
1871  }
1872 
1885  private static function tsToYear( $ts, $cName ) {
1886  $gy = substr( $ts, 0, 4 );
1887  $gm = substr( $ts, 4, 2 );
1888  $gd = substr( $ts, 6, 2 );
1889 
1890  if ( !strcmp( $cName, 'thai' ) ) {
1891  # Thai solar dates
1892  # Add 543 years to the Gregorian calendar
1893  # Months and days are identical
1894  $gy_offset = $gy + 543;
1895  # fix for dates between 1912 and 1941
1896  # https://en.wikipedia.org/?oldid=836596673#New_year
1897  if ( $gy >= 1912 && $gy <= 1940 ) {
1898  if ( $gm <= 3 ) {
1899  $gy_offset--;
1900  }
1901  $gm = ( $gm - 3 ) % 12;
1902  }
1903  } elseif ( ( !strcmp( $cName, 'minguo' ) ) || !strcmp( $cName, 'juche' ) ) {
1904  # Minguo dates
1905  # Deduct 1911 years from the Gregorian calendar
1906  # Months and days are identical
1907  $gy_offset = $gy - 1911;
1908  } elseif ( !strcmp( $cName, 'tenno' ) ) {
1909  # Nengō dates up to Meiji period
1910  # Deduct years from the Gregorian calendar
1911  # depending on the nengo periods
1912  # Months and days are identical
1913  if ( ( $gy < 1912 )
1914  || ( ( $gy == 1912 ) && ( $gm < 7 ) )
1915  || ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd < 31 ) )
1916  ) {
1917  # Meiji period
1918  $gy_gannen = $gy - 1868 + 1;
1919  $gy_offset = $gy_gannen;
1920  if ( $gy_gannen == 1 ) {
1921  $gy_offset = '元';
1922  }
1923  $gy_offset = '明治' . $gy_offset;
1924  } elseif (
1925  ( ( $gy == 1912 ) && ( $gm == 7 ) && ( $gd == 31 ) ) ||
1926  ( ( $gy == 1912 ) && ( $gm >= 8 ) ) ||
1927  ( ( $gy > 1912 ) && ( $gy < 1926 ) ) ||
1928  ( ( $gy == 1926 ) && ( $gm < 12 ) ) ||
1929  ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd < 26 ) )
1930  ) {
1931  # Taishō period
1932  $gy_gannen = $gy - 1912 + 1;
1933  $gy_offset = $gy_gannen;
1934  if ( $gy_gannen == 1 ) {
1935  $gy_offset = '元';
1936  }
1937  $gy_offset = '大正' . $gy_offset;
1938  } elseif (
1939  ( ( $gy == 1926 ) && ( $gm == 12 ) && ( $gd >= 26 ) ) ||
1940  ( ( $gy > 1926 ) && ( $gy < 1989 ) ) ||
1941  ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd < 8 ) )
1942  ) {
1943  # Shōwa period
1944  $gy_gannen = $gy - 1926 + 1;
1945  $gy_offset = $gy_gannen;
1946  if ( $gy_gannen == 1 ) {
1947  $gy_offset = '元';
1948  }
1949  $gy_offset = '昭和' . $gy_offset;
1950  } elseif (
1951  ( ( $gy == 1989 ) && ( $gm == 1 ) && ( $gd >= 8 ) ) ||
1952  ( ( $gy > 1989 ) && ( $gy < 2019 ) ) ||
1953  ( ( $gy == 2019 ) && ( $gm < 5 ) )
1954  ) {
1955  # Heisei period
1956  $gy_gannen = $gy - 1989 + 1;
1957  $gy_offset = $gy_gannen;
1958  if ( $gy_gannen == 1 ) {
1959  $gy_offset = '元';
1960  }
1961  $gy_offset = '平成' . $gy_offset;
1962  } else {
1963  # Reiwa period
1964  $gy_gannen = $gy - 2019 + 1;
1965  $gy_offset = $gy_gannen;
1966  if ( $gy_gannen == 1 ) {
1967  $gy_offset = '元';
1968  }
1969  $gy_offset = '令和' . $gy_offset;
1970  }
1971  } else {
1972  $gy_offset = $gy;
1973  }
1974 
1975  return [ $gy_offset, $gm, $gd ];
1976  }
1977 
1991  private static function strongDirFromContent( $text = '' ) {
1992  if ( !preg_match( self::$strongDirRegex, $text, $matches ) ) {
1993  return null;
1994  }
1995  if ( $matches[1] === '' ) {
1996  return 'rtl';
1997  }
1998  return 'ltr';
1999  }
2000 
2008  public static function romanNumeral( $num ) {
2009  static $table = [
2010  [ '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ],
2011  [ '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ],
2012  [ '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ],
2013  [ '', 'M', 'MM', 'MMM', 'MMMM', 'MMMMM', 'MMMMMM', 'MMMMMMM',
2014  'MMMMMMMM', 'MMMMMMMMM', 'MMMMMMMMMM' ]
2015  ];
2016 
2017  $num = intval( $num );
2018  if ( $num > 10000 || $num <= 0 ) {
2019  return $num;
2020  }
2021 
2022  $s = '';
2023  for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) {
2024  if ( $num >= $pow10 ) {
2025  $s .= $table[$i][(int)floor( $num / $pow10 )];
2026  }
2027  $num = $num % $pow10;
2028  }
2029  return $s;
2030  }
2031 
2039  public static function hebrewNumeral( $num ) {
2040  static $table = [
2041  [ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ],
2042  [ '', 'י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ', 'ק' ],
2043  [ '',
2044  [ 'ק' ],
2045  [ 'ר' ],
2046  [ 'ש' ],
2047  [ 'ת' ],
2048  [ 'ת', 'ק' ],
2049  [ 'ת', 'ר' ],
2050  [ 'ת', 'ש' ],
2051  [ 'ת', 'ת' ],
2052  [ 'ת', 'ת', 'ק' ],
2053  [ 'ת', 'ת', 'ר' ],
2054  ],
2055  [ '', 'א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט', 'י' ]
2056  ];
2057 
2058  $num = intval( $num );
2059  if ( $num > 9999 || $num <= 0 ) {
2060  return $num;
2061  }
2062 
2063  // Round thousands have special notations
2064  if ( $num === 1000 ) {
2065  return "א' אלף";
2066  } elseif ( $num % 1000 === 0 ) {
2067  return $table[0][$num / 1000] . "' אלפים";
2068  }
2069 
2070  $letters = [];
2071 
2072  for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) {
2073  if ( $num >= $pow10 ) {
2074  if ( $num === 15 || $num === 16 ) {
2075  $letters[] = $table[0][9];
2076  $letters[] = $table[0][$num - 9];
2077  $num = 0;
2078  } else {
2079  $letters = array_merge(
2080  $letters,
2081  (array)$table[$i][intval( $num / $pow10 )]
2082  );
2083 
2084  if ( $pow10 === 1000 ) {
2085  $letters[] = "'";
2086  }
2087  }
2088  }
2089 
2090  $num = $num % $pow10;
2091  }
2092 
2093  $preTransformLength = count( $letters );
2094  if ( $preTransformLength === 1 ) {
2095  // Add geresh (single quote) to one-letter numbers
2096  $letters[] = "'";
2097  } else {
2098  $lastIndex = $preTransformLength - 1;
2099  $letters[$lastIndex] = str_replace(
2100  [ 'כ', 'מ', 'נ', 'פ', 'צ' ],
2101  [ 'ך', 'ם', 'ן', 'ף', 'ץ' ],
2102  $letters[$lastIndex]
2103  );
2104 
2105  // Add gershayim (double quote) to multiple-letter numbers,
2106  // but exclude numbers with only one letter after the thousands
2107  // (1001-1009, 1020, 1030, 2001-2009, etc.)
2108  if ( $letters[1] === "'" && $preTransformLength === 3 ) {
2109  $letters[] = "'";
2110  } else {
2111  array_splice( $letters, -1, 0, '"' );
2112  }
2113  }
2114 
2115  return implode( $letters );
2116  }
2117 
2126  public function userAdjust( $ts, $tz = false ) {
2127  global $wgUser, $wgLocalTZoffset;
2128 
2129  if ( $tz === false ) {
2130  $tz = $wgUser->getOption( 'timecorrection' );
2131  }
2132 
2133  $data = explode( '|', $tz, 3 );
2134 
2135  if ( $data[0] == 'ZoneInfo' ) {
2136  try {
2137  $userTZ = new DateTimeZone( $data[2] );
2138  $date = new DateTime( $ts, new DateTimeZone( 'UTC' ) );
2139  $date->setTimezone( $userTZ );
2140  return $date->format( 'YmdHis' );
2141  } catch ( Exception $e ) {
2142  // Unrecognized timezone, default to 'Offset' with the stored offset.
2143  $data[0] = 'Offset';
2144  }
2145  }
2146 
2147  if ( $data[0] == 'System' || $tz == '' ) {
2148  # Global offset in minutes.
2149  $minDiff = $wgLocalTZoffset;
2150  } elseif ( $data[0] == 'Offset' ) {
2151  $minDiff = intval( $data[1] );
2152  } else {
2153  $data = explode( ':', $tz );
2154  if ( count( $data ) == 2 ) {
2155  $data[0] = intval( $data[0] );
2156  $data[1] = intval( $data[1] );
2157  $minDiff = abs( $data[0] ) * 60 + $data[1];
2158  if ( $data[0] < 0 ) {
2159  $minDiff = -$minDiff;
2160  }
2161  } else {
2162  $minDiff = intval( $data[0] ) * 60;
2163  }
2164  }
2165 
2166  # No difference ? Return time unchanged
2167  if ( $minDiff == 0 ) {
2168  return $ts;
2169  }
2170 
2171  Wikimedia\suppressWarnings(); // E_STRICT system time bitching
2172  # Generate an adjusted date; take advantage of the fact that mktime
2173  # will normalize out-of-range values so we don't have to split $minDiff
2174  # into hours and minutes.
2175  $t = mktime( (
2176  (int)substr( $ts, 8, 2 ) ), # Hours
2177  (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
2178  (int)substr( $ts, 12, 2 ), # Seconds
2179  (int)substr( $ts, 4, 2 ), # Month
2180  (int)substr( $ts, 6, 2 ), # Day
2181  (int)substr( $ts, 0, 4 ) ); # Year
2182 
2183  $date = date( 'YmdHis', $t );
2184  Wikimedia\restoreWarnings();
2185 
2186  return $date;
2187  }
2188 
2204  public function dateFormat( $usePrefs = true ) {
2205  global $wgUser;
2206 
2207  if ( is_bool( $usePrefs ) ) {
2208  if ( $usePrefs ) {
2209  $datePreference = $wgUser->getDatePreference();
2210  } else {
2211  $datePreference = (string)User::getDefaultOption( 'date' );
2212  }
2213  } else {
2214  $datePreference = (string)$usePrefs;
2215  }
2216 
2217  // return int
2218  if ( $datePreference == '' ) {
2219  return 'default';
2220  }
2221 
2222  return $datePreference;
2223  }
2224 
2235  public function getDateFormatString( $type, $pref ) {
2236  $wasDefault = false;
2237  if ( $pref == 'default' ) {
2238  $wasDefault = true;
2239  $pref = $this->getDefaultDateFormat();
2240  }
2241 
2242  if ( !isset( $this->dateFormatStrings[$type][$pref] ) ) {
2243  $df = $this->localisationCache
2244  ->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
2245 
2246  if ( $type === 'pretty' && $df === null ) {
2247  $df = $this->getDateFormatString( 'date', $pref );
2248  }
2249 
2250  if ( !$wasDefault && $df === null ) {
2251  $pref = $this->getDefaultDateFormat();
2252  $df = $this->localisationCache
2253  ->getSubitem( $this->mCode, 'dateFormats', "$pref $type" );
2254  }
2255 
2256  $this->dateFormatStrings[$type][$pref] = $df;
2257  }
2258  return $this->dateFormatStrings[$type][$pref];
2259  }
2260 
2271  public function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
2272  $ts = wfTimestamp( TS_MW, $ts );
2273  if ( $adj ) {
2274  $ts = $this->userAdjust( $ts, $timecorrection );
2275  }
2276  $df = $this->getDateFormatString( 'date', $this->dateFormat( $format ) );
2277  return $this->sprintfDate( $df, $ts );
2278  }
2279 
2290  public function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
2291  $ts = wfTimestamp( TS_MW, $ts );
2292  if ( $adj ) {
2293  $ts = $this->userAdjust( $ts, $timecorrection );
2294  }
2295  $df = $this->getDateFormatString( 'time', $this->dateFormat( $format ) );
2296  return $this->sprintfDate( $df, $ts );
2297  }
2298 
2310  public function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false ) {
2311  $ts = wfTimestamp( TS_MW, $ts );
2312  if ( $adj ) {
2313  $ts = $this->userAdjust( $ts, $timecorrection );
2314  }
2315  $df = $this->getDateFormatString( 'both', $this->dateFormat( $format ) );
2316  return $this->sprintfDate( $df, $ts );
2317  }
2318 
2329  public function formatDuration( $seconds, array $chosenIntervals = [] ) {
2330  $intervals = $this->getDurationIntervals( $seconds, $chosenIntervals );
2331 
2332  $segments = [];
2333 
2334  foreach ( $intervals as $intervalName => $intervalValue ) {
2335  // Messages: duration-seconds, duration-minutes, duration-hours, duration-days, duration-weeks,
2336  // duration-years, duration-decades, duration-centuries, duration-millennia
2337  $message = wfMessage( 'duration-' . $intervalName )->numParams( $intervalValue );
2338  $segments[] = $message->inLanguage( $this )->escaped();
2339  }
2340 
2341  return $this->listToText( $segments );
2342  }
2343 
2355  public function getDurationIntervals( $seconds, array $chosenIntervals = [] ) {
2356  if ( empty( $chosenIntervals ) ) {
2357  $chosenIntervals = [
2358  'millennia',
2359  'centuries',
2360  'decades',
2361  'years',
2362  'days',
2363  'hours',
2364  'minutes',
2365  'seconds'
2366  ];
2367  }
2368 
2369  $intervals = array_intersect_key( self::DURATION_INTERVALS, array_flip( $chosenIntervals ) );
2370  $sortedNames = array_keys( $intervals );
2371  $smallestInterval = array_pop( $sortedNames );
2372 
2373  $segments = [];
2374 
2375  foreach ( $intervals as $name => $length ) {
2376  $value = floor( $seconds / $length );
2377 
2378  if ( $value > 0 || ( $name == $smallestInterval && empty( $segments ) ) ) {
2379  $seconds -= $value * $length;
2380  $segments[$name] = $value;
2381  }
2382  }
2383 
2384  return $segments;
2385  }
2386 
2406  private function internalUserTimeAndDate( $type, $ts, User $user, array $options ) {
2407  $ts = wfTimestamp( TS_MW, $ts );
2408  $options += [ 'timecorrection' => true, 'format' => true ];
2409  if ( $options['timecorrection'] !== false ) {
2410  if ( $options['timecorrection'] === true ) {
2411  $offset = $user->getOption( 'timecorrection' );
2412  } else {
2413  $offset = $options['timecorrection'];
2414  }
2415  $ts = $this->userAdjust( $ts, $offset );
2416  }
2417  if ( $options['format'] === true ) {
2418  $format = $user->getDatePreference();
2419  } else {
2420  $format = $options['format'];
2421  }
2422  $df = $this->getDateFormatString( $type, $this->dateFormat( $format ) );
2423  return $this->sprintfDate( $df, $ts );
2424  }
2425 
2445  public function userDate( $ts, User $user, array $options = [] ) {
2446  return $this->internalUserTimeAndDate( 'date', $ts, $user, $options );
2447  }
2448 
2468  public function userTime( $ts, User $user, array $options = [] ) {
2469  return $this->internalUserTimeAndDate( 'time', $ts, $user, $options );
2470  }
2471 
2491  public function userTimeAndDate( $ts, User $user, array $options = [] ) {
2492  return $this->internalUserTimeAndDate( 'both', $ts, $user, $options );
2493  }
2494 
2510  public function getHumanTimestamp(
2511  MWTimestamp $time, MWTimestamp $relativeTo = null, User $user = null
2512  ) {
2513  if ( $relativeTo === null ) {
2514  $relativeTo = new MWTimestamp();
2515  }
2516  if ( $user === null ) {
2517  $user = RequestContext::getMain()->getUser();
2518  }
2519 
2520  // Adjust for the user's timezone.
2521  $offsetThis = $time->offsetForUser( $user );
2522  $offsetRel = $relativeTo->offsetForUser( $user );
2523 
2524  $ts = '';
2525  if ( Hooks::run( 'GetHumanTimestamp', [ &$ts, $time, $relativeTo, $user, $this ] ) ) {
2526  $ts = $this->getHumanTimestampInternal( $time, $relativeTo, $user );
2527  }
2528 
2529  // Reset the timezone on the objects.
2530  $time->timestamp->sub( $offsetThis );
2531  $relativeTo->timestamp->sub( $offsetRel );
2532 
2533  return $ts;
2534  }
2535 
2547  private function getHumanTimestampInternal(
2548  MWTimestamp $ts, MWTimestamp $relativeTo, User $user
2549  ) {
2550  $diff = $ts->diff( $relativeTo );
2551  $diffDay = (bool)( (int)$ts->timestamp->format( 'w' ) -
2552  (int)$relativeTo->timestamp->format( 'w' ) );
2553  $days = $diff->days ?: (int)$diffDay;
2554  if ( $diff->invert || $days > 5
2555  && $ts->timestamp->format( 'Y' ) !== $relativeTo->timestamp->format( 'Y' )
2556  ) {
2557  // Timestamps are in different years: use full timestamp
2558  // Also do full timestamp for future dates
2562  $format = $this->getDateFormatString( 'both', $user->getDatePreference() ?: 'default' );
2563  $ts = $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) );
2564  } elseif ( $days > 5 ) {
2565  // Timestamps are in same year, but more than 5 days ago: show day and month only.
2566  $format = $this->getDateFormatString( 'pretty', $user->getDatePreference() ?: 'default' );
2567  $ts = $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) );
2568  } elseif ( $days > 1 ) {
2569  // Timestamp within the past week: show the day of the week and time
2570  $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2571  $weekday = self::WEEKDAY_MESSAGES[$ts->timestamp->format( 'w' )];
2572  // Messages:
2573  // sunday-at, monday-at, tuesday-at, wednesday-at, thursday-at, friday-at, saturday-at
2574  $ts = wfMessage( "$weekday-at" )
2575  ->inLanguage( $this )
2576  ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2577  ->text();
2578  } elseif ( $days == 1 ) {
2579  // Timestamp was yesterday: say 'yesterday' and the time.
2580  $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2581  $ts = wfMessage( 'yesterday-at' )
2582  ->inLanguage( $this )
2583  ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2584  ->text();
2585  } elseif ( $diff->h > 1 || $diff->h == 1 && $diff->i > 30 ) {
2586  // Timestamp was today, but more than 90 minutes ago: say 'today' and the time.
2587  $format = $this->getDateFormatString( 'time', $user->getDatePreference() ?: 'default' );
2588  $ts = wfMessage( 'today-at' )
2589  ->inLanguage( $this )
2590  ->params( $this->sprintfDate( $format, $ts->getTimestamp( TS_MW ) ) )
2591  ->text();
2592 
2593  // From here on in, the timestamp was soon enough ago so that we can simply say
2594  // XX units ago, e.g., "2 hours ago" or "5 minutes ago"
2595  } elseif ( $diff->h == 1 ) {
2596  // Less than 90 minutes, but more than an hour ago.
2597  $ts = wfMessage( 'hours-ago' )->inLanguage( $this )->numParams( 1 )->text();
2598  } elseif ( $diff->i >= 1 ) {
2599  // A few minutes ago.
2600  $ts = wfMessage( 'minutes-ago' )->inLanguage( $this )->numParams( $diff->i )->text();
2601  } elseif ( $diff->s >= 30 ) {
2602  // Less than a minute, but more than 30 sec ago.
2603  $ts = wfMessage( 'seconds-ago' )->inLanguage( $this )->numParams( $diff->s )->text();
2604  } else {
2605  // Less than 30 seconds ago.
2606  $ts = wfMessage( 'just-now' )->text();
2607  }
2608 
2609  return $ts;
2610  }
2611 
2616  public function getMessage( $key ) {
2617  return $this->localisationCache->getSubitem( $this->mCode, 'messages', $key );
2618  }
2619 
2623  public function getAllMessages() {
2624  return $this->localisationCache->getItem( $this->mCode, 'messages' );
2625  }
2626 
2633  public function iconv( $in, $out, $string ) {
2634  # Even with //IGNORE iconv can whine about illegal characters in
2635  # *input* string. We just ignore those too.
2636  # REF: https://bugs.php.net/bug.php?id=37166
2637  # REF: https://phabricator.wikimedia.org/T18885
2638  Wikimedia\suppressWarnings();
2639  $text = iconv( $in, $out . '//IGNORE', $string );
2640  Wikimedia\restoreWarnings();
2641  return $text;
2642  }
2643 
2648  public function ucfirst( $str ) {
2649  $octetCode = ord( $str );
2650  // See https://en.wikipedia.org/wiki/ASCII#Printable_characters
2651  if ( $octetCode < 96 ) {
2652  // Assume this is an uppercase/uncased ASCII character
2653  return (string)$str;
2654  } elseif ( $octetCode < 128 ) {
2655  // Assume this is a lowercase/uncased ASCII character
2656  return ucfirst( $str );
2657  }
2658 
2659  return $this->isMultibyte( $str )
2660  // Assume this is a multibyte character and mb_internal_encoding() is appropriate
2661  ? $this->mbUpperChar( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 )
2662  // Assume this is a non-multibyte character and LC_CASE is appropriate
2663  : ucfirst( $str );
2664  }
2665 
2671  public function uc( $str, $first = false ) {
2672  if ( $first ) {
2673  return $this->ucfirst( $str );
2674  } else {
2675  return $this->isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
2676  }
2677  }
2678 
2692  protected function mbUpperChar( $char ) {
2694 
2695  return $wgOverrideUcfirstCharacters[$char] ?? mb_strtoupper( $char );
2696  }
2697 
2702  public function lcfirst( $str ) {
2703  $octetCode = ord( $str );
2704  // See https://en.wikipedia.org/wiki/ASCII#Printable_characters
2705  if ( $octetCode < 96 ) {
2706  // Assume this is an uppercase/uncased ASCII character
2707  return lcfirst( $str );
2708  } elseif ( $octetCode < 128 ) {
2709  // Assume this is a lowercase/uncased ASCII character
2710  return (string)$str;
2711  }
2712 
2713  return $this->isMultibyte( $str )
2714  // Assume this is a multibyte character and mb_internal_encoding() is appropriate
2715  ? mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 )
2716  // Assume this is a non-multibyte character and LC_CASE is appropriate
2717  : lcfirst( $str );
2718  }
2719 
2725  public function lc( $str, $first = false ) {
2726  if ( $first ) {
2727  return $this->lcfirst( $str );
2728  } else {
2729  return $this->isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
2730  }
2731  }
2732 
2737  private function isMultibyte( $str ) {
2738  return strlen( $str ) !== mb_strlen( $str );
2739  }
2740 
2745  public function ucwords( $str ) {
2746  if ( $this->isMultibyte( $str ) ) {
2747  $str = $this->lc( $str );
2748 
2749  // regexp to find first letter in each word (i.e. after each space)
2750  $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
2751 
2752  // function to use to capitalize a single char
2753  return preg_replace_callback(
2754  $replaceRegexp,
2755  function ( $matches ) {
2756  return mb_strtoupper( $matches[0] );
2757  },
2758  $str
2759  );
2760  } else {
2761  return ucwords( strtolower( $str ) );
2762  }
2763  }
2764 
2771  public function ucwordbreaks( $str ) {
2772  if ( $this->isMultibyte( $str ) ) {
2773  $str = $this->lc( $str );
2774 
2775  // since \b doesn't work for UTF-8, we explicitely define word break chars
2776  $breaks = "[ \-\(\)\}\{\.,\?!]";
2777 
2778  // find first letter after word break
2779  $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|" .
2780  "$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
2781 
2782  return preg_replace_callback(
2783  $replaceRegexp,
2784  function ( $matches ) {
2785  return mb_strtoupper( $matches[0] );
2786  },
2787  $str
2788  );
2789  } else {
2790  return preg_replace_callback(
2791  '/\b([\w\x80-\xff]+)\b/',
2792  function ( $matches ) {
2793  return $this->ucfirst( $matches[1] );
2794  },
2795  $str
2796  );
2797  }
2798  }
2799 
2815  public function caseFold( $s ) {
2816  return $this->uc( $s );
2817  }
2818 
2824  public function checkTitleEncoding( $s ) {
2825  if ( is_array( $s ) ) {
2826  throw new MWException( 'Given array to checkTitleEncoding.' );
2827  }
2828  if ( StringUtils::isUtf8( $s ) ) {
2829  return $s;
2830  }
2831 
2832  return $this->iconv( $this->fallback8bitEncoding(), 'utf-8', $s );
2833  }
2834 
2838  public function fallback8bitEncoding() {
2839  return $this->localisationCache->getItem( $this->mCode, 'fallback8bitEncoding' );
2840  }
2841 
2850  public function hasWordBreaks() {
2851  return true;
2852  }
2853 
2861  public function segmentByWord( $string ) {
2862  return $string;
2863  }
2864 
2872  public function normalizeForSearch( $string ) {
2873  return self::convertDoubleWidth( $string );
2874  }
2875 
2884  protected static function convertDoubleWidth( $string ) {
2885  static $full = null;
2886  static $half = null;
2887 
2888  if ( $full === null ) {
2889  $fullWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2890  $halfWidth = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2891  $full = str_split( $fullWidth, 3 );
2892  $half = str_split( $halfWidth );
2893  }
2894 
2895  $string = str_replace( $full, $half, $string );
2896  return $string;
2897  }
2898 
2904  protected static function insertSpace( $string, $pattern ) {
2905  $string = preg_replace( $pattern, " $1 ", $string );
2906  $string = preg_replace( '/ +/', ' ', $string );
2907  return $string;
2908  }
2909 
2914  public function convertForSearchResult( $termsArray ) {
2915  # some languages, e.g. Chinese, need to do a conversion
2916  # in order for search results to be displayed correctly
2917  return $termsArray;
2918  }
2919 
2926  public function firstChar( $s ) {
2927  $firstChar = mb_substr( $s, 0, 1 );
2928 
2929  if ( $firstChar !== false ) {
2930  if ( strlen( $firstChar ) != 3 ) {
2931  return $firstChar;
2932  }
2933 
2934  // Break down Hangul syllables to grab the first jamo
2935  $code = mb_ord( $firstChar );
2936  if ( $code < 0xac00 || 0xd7a4 <= $code ) {
2937  return $firstChar;
2938  } elseif ( $code < 0xb098 ) {
2939  return "\u{3131}";
2940  } elseif ( $code < 0xb2e4 ) {
2941  return "\u{3134}";
2942  } elseif ( $code < 0xb77c ) {
2943  return "\u{3137}";
2944  } elseif ( $code < 0xb9c8 ) {
2945  return "\u{3139}";
2946  } elseif ( $code < 0xbc14 ) {
2947  return "\u{3141}";
2948  } elseif ( $code < 0xc0ac ) {
2949  return "\u{3142}";
2950  } elseif ( $code < 0xc544 ) {
2951  return "\u{3145}";
2952  } elseif ( $code < 0xc790 ) {
2953  return "\u{3147}";
2954  } elseif ( $code < 0xcc28 ) {
2955  return "\u{3148}";
2956  } elseif ( $code < 0xce74 ) {
2957  return "\u{314A}";
2958  } elseif ( $code < 0xd0c0 ) {
2959  return "\u{314B}";
2960  } elseif ( $code < 0xd30c ) {
2961  return "\u{314C}";
2962  } elseif ( $code < 0xd558 ) {
2963  return "\u{314D}";
2964  } else {
2965  return "\u{314E}";
2966  }
2967  }
2968 
2969  return '';
2970  }
2971 
2983  public function normalize( $s ) {
2984  global $wgAllUnicodeFixes, $IP;
2985 
2986  $s = UtfNormal\Validator::cleanUp( $s );
2987  if ( $wgAllUnicodeFixes ) {
2988  $s = $this->transformUsingPairFile( 'normalize-ar.php', $s, $IP );
2989  $s = $this->transformUsingPairFile( 'normalize-ml.php', $s, $IP );
2990  }
2991 
2992  return $s;
2993  }
2994 
3010  protected function transformUsingPairFile( $file, $string, $basePath = null ) {
3011  if ( isset( $this->transformData[$file] ) ) {
3012  wfDeprecated(
3013  __METHOD__ . ' structure of $transformData is changed',
3014  '1.35'
3015  );
3016  return $this->transformData[$file]->replace( $string );
3017  }
3018 
3019  if ( $basePath === null ) {
3020  wfDeprecated( __METHOD__ . ' $basePath is required', '1.35' );
3021  global $IP;
3022  $basePath = $IP;
3023  }
3024 
3025  if (
3026  $basePath === null
3027  || $basePath === ''
3028  || !file_exists( "{$basePath}/languages/data/{$file}" )
3029  ) {
3030  return $string;
3031  }
3032 
3033  if ( !isset( $this->transformData[$basePath][$file] ) ) {
3034  $data = require "{$basePath}/languages/data/{$file}";
3035  $this->transformData[$basePath][$file] = new ReplacementArray( $data );
3036  }
3037 
3038  return $this->transformData[$basePath][$file]->replace( $string );
3039  }
3040 
3046  public function isRTL() {
3047  return $this->localisationCache->getItem( $this->mCode, 'rtl' );
3048  }
3049 
3054  public function getDir() {
3055  return $this->isRTL() ? 'rtl' : 'ltr';
3056  }
3057 
3066  public function alignStart() {
3067  return $this->isRTL() ? 'right' : 'left';
3068  }
3069 
3078  public function alignEnd() {
3079  return $this->isRTL() ? 'left' : 'right';
3080  }
3081 
3093  public function getDirMarkEntity( $opposite = false ) {
3094  if ( $opposite ) {
3095  return $this->isRTL() ? '&lrm;' : '&rlm;';
3096  }
3097  return $this->isRTL() ? '&rlm;' : '&lrm;';
3098  }
3099 
3110  public function getDirMark( $opposite = false ) {
3111  $lrm = "\u{200E}"; # LEFT-TO-RIGHT MARK, commonly abbreviated LRM
3112  $rlm = "\u{200F}"; # RIGHT-TO-LEFT MARK, commonly abbreviated RLM
3113  if ( $opposite ) {
3114  return $this->isRTL() ? $lrm : $rlm;
3115  }
3116  return $this->isRTL() ? $rlm : $lrm;
3117  }
3118 
3122  public function capitalizeAllNouns() {
3123  return $this->localisationCache->getItem( $this->mCode, 'capitalizeAllNouns' );
3124  }
3125 
3133  public function getArrow( $direction = 'forwards' ) {
3134  switch ( $direction ) {
3135  case 'forwards':
3136  return $this->isRTL() ? '←' : '→';
3137  case 'backwards':
3138  return $this->isRTL() ? '→' : '←';
3139  case 'left':
3140  return '←';
3141  case 'right':
3142  return '→';
3143  case 'up':
3144  return '↑';
3145  case 'down':
3146  return '↓';
3147  }
3148  }
3149 
3155  public function linkPrefixExtension() {
3156  return $this->localisationCache->getItem( $this->mCode, 'linkPrefixExtension' );
3157  }
3158 
3163  public function getMagicWords() {
3164  return $this->localisationCache->getItem( $this->mCode, 'magicWords' );
3165  }
3166 
3172  public function getMagic( $mw ) {
3173  $rawEntry = $this->mMagicExtensions[$mw->mId] ??
3174  $this->localisationCache->getSubitem( $this->mCode, 'magicWords', $mw->mId );
3175 
3176  if ( !is_array( $rawEntry ) ) {
3177  wfWarn( "\"$rawEntry\" is not a valid magic word for \"$mw->mId\"" );
3178  } else {
3179  $mw->mCaseSensitive = $rawEntry[0];
3180  $mw->mSynonyms = array_slice( $rawEntry, 1 );
3181  }
3182  }
3183 
3189  public function getSpecialPageAliases() {
3190  // Cache aliases because it may be slow to load them
3191  if ( $this->mExtendedSpecialPageAliases === null ) {
3192  // Initialise array
3193  $this->mExtendedSpecialPageAliases =
3194  $this->localisationCache->getItem( $this->mCode, 'specialPageAliases' );
3195  }
3196 
3197  return $this->mExtendedSpecialPageAliases;
3198  }
3199 
3206  public function emphasize( $text ) {
3207  return "<em>$text</em>";
3208  }
3209 
3232  public function formatNum( $number, $nocommafy = false ) {
3233  global $wgTranslateNumerals;
3234 
3235  $number = (string)$number;
3236  if ( !$nocommafy ) {
3237  $number = $this->commafy( $number );
3238  $s = $this->separatorTransformTable();
3239  if ( $s ) {
3240  $number = strtr( $number, $s );
3241  }
3242  }
3243 
3244  if ( $wgTranslateNumerals ) {
3245  $s = $this->digitTransformTable();
3246  if ( $s ) {
3247  $number = strtr( $number, $s );
3248  }
3249  }
3250 
3251  return $number;
3252  }
3253 
3262  public function formatNumNoSeparators( $number ) {
3263  return $this->formatNum( $number, true );
3264  }
3265 
3270  public function parseFormattedNumber( $number ) {
3271  $s = $this->digitTransformTable();
3272  if ( $s ) {
3273  // eliminate empty array values such as ''. (T66347)
3274  $s = array_filter( $s );
3275  $number = strtr( $number, array_flip( $s ) );
3276  }
3277 
3278  $s = $this->separatorTransformTable();
3279  if ( $s ) {
3280  // eliminate empty array values such as ''. (T66347)
3281  $s = array_filter( $s );
3282  $number = strtr( $number, array_flip( $s ) );
3283  }
3284 
3285  $number = strtr( $number, [ ',' => '' ] );
3286  return $number;
3287  }
3288 
3297  public function commafy( $number ) {
3298  $digitGroupingPattern = $this->digitGroupingPattern();
3299  $minimumGroupingDigits = $this->minimumGroupingDigits();
3300  if ( $number === null ) {
3301  return '';
3302  }
3303 
3304  if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
3305  // Default grouping is at thousands, use the same for ###,###,### pattern too.
3306  // In some languages it's conventional not to insert a thousands separator
3307  // in numbers that are four digits long (1000-9999).
3308  if ( $minimumGroupingDigits ) {
3309  // Number of '#' characters after last comma in the grouping pattern.
3310  // The pattern is hardcoded here, but this would vary for different patterns.
3311  $primaryGroupingSize = 3;
3312  // Maximum length of a number to suppress digit grouping for.
3313  $maximumLength = $minimumGroupingDigits + $primaryGroupingSize - 1;
3314  if ( preg_match( '/^\-?\d{1,' . $maximumLength . '}(\.\d+)?$/', $number ) ) {
3315  return $number;
3316  }
3317  }
3318  return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $number ) ) );
3319  } else {
3320  // Ref: http://cldr.unicode.org/translation/number-patterns
3321  $sign = "";
3322  if ( intval( $number ) < 0 ) {
3323  // For negative numbers apply the algorithm like positive number and add sign.
3324  $sign = "-";
3325  $number = substr( $number, 1 );
3326  }
3327  $integerPart = [];
3328  $decimalPart = [];
3329  $numMatches = preg_match_all( "/(#+)/", $digitGroupingPattern, $matches );
3330  preg_match( "/\d+/", $number, $integerPart );
3331  preg_match( "/\.\d*/", $number, $decimalPart );
3332  $groupedNumber = ( count( $decimalPart ) > 0 ) ? $decimalPart[0] : "";
3333  if ( $groupedNumber === $number ) {
3334  // the string does not have any number part. Eg: .12345
3335  return $sign . $groupedNumber;
3336  }
3337  $start = $end = ( $integerPart ) ? strlen( $integerPart[0] ) : 0;
3338  while ( $start > 0 ) {
3339  $match = $matches[0][$numMatches - 1];
3340  $matchLen = strlen( $match );
3341  $start = $end - $matchLen;
3342  if ( $start < 0 ) {
3343  $start = 0;
3344  }
3345  $groupedNumber = substr( $number, $start, $end - $start ) . $groupedNumber;
3346  $end = $start;
3347  if ( $numMatches > 1 ) {
3348  // use the last pattern for the rest of the number
3349  $numMatches--;
3350  }
3351  if ( $start > 0 ) {
3352  $groupedNumber = "," . $groupedNumber;
3353  }
3354  }
3355  return $sign . $groupedNumber;
3356  }
3357  }
3358 
3362  public function digitGroupingPattern() {
3363  return $this->localisationCache->getItem( $this->mCode, 'digitGroupingPattern' );
3364  }
3365 
3369  public function digitTransformTable() {
3370  return $this->localisationCache->getItem( $this->mCode, 'digitTransformTable' );
3371  }
3372 
3376  public function separatorTransformTable() {
3377  return $this->localisationCache->getItem( $this->mCode, 'separatorTransformTable' );
3378  }
3379 
3383  public function minimumGroupingDigits() {
3384  return $this->localisationCache->getItem( $this->mCode, 'minimumGroupingDigits' );
3385  }
3386 
3395  public function listToText( array $list ) {
3396  $itemCount = count( $list );
3397  if ( $itemCount < 1 ) {
3398  return '';
3399  }
3400  $text = array_pop( $list );
3401  if ( $itemCount > 1 ) {
3402  $and = $this->msg( 'and' )->escaped();
3403  $space = $this->msg( 'word-separator' )->escaped();
3404  $comma = '';
3405  if ( $itemCount > 2 ) {
3406  $comma = $this->msg( 'comma-separator' )->escaped();
3407  }
3408  $text = implode( $comma, $list ) . $and . $space . $text;
3409  }
3410  return $text;
3411  }
3412 
3419  public function commaList( array $list ) {
3420  return implode(
3421  wfMessage( 'comma-separator' )->inLanguage( $this )->escaped(),
3422  $list
3423  );
3424  }
3425 
3432  public function semicolonList( array $list ) {
3433  return implode(
3434  wfMessage( 'semicolon-separator' )->inLanguage( $this )->escaped(),
3435  $list
3436  );
3437  }
3438 
3444  public function pipeList( array $list ) {
3445  return implode(
3446  wfMessage( 'pipe-separator' )->inLanguage( $this )->escaped(),
3447  $list
3448  );
3449  }
3450 
3466  public function truncateForDatabase( $string, $length, $ellipsis = '...', $adjustLength = true ) {
3467  return $this->truncateInternal(
3468  $string, $length, $ellipsis, $adjustLength, 'strlen', 'substr'
3469  );
3470  }
3471 
3490  public function truncateForVisual( $string, $length, $ellipsis = '...', $adjustLength = true ) {
3491  // Passing encoding to mb_strlen and mb_substr is optional.
3492  // Encoding defaults to mb_internal_encoding(), which is set to UTF-8 in Setup.php, so
3493  // explicit specification of encoding is skipped.
3494  // Note: Both multibyte methods are callables invoked in truncateInternal.
3495  return $this->truncateInternal(
3496  $string, $length, $ellipsis, $adjustLength, 'mb_strlen', 'mb_substr'
3497  );
3498  }
3499 
3516  private function truncateInternal(
3517  $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring
3518  ) {
3519  # Check if there is no need to truncate
3520  if ( $measureLength( $string ) <= abs( $length ) ) {
3521  return $string; // no need to truncate
3522  }
3523 
3524  # Use the localized ellipsis character
3525  if ( $ellipsis == '...' ) {
3526  $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
3527  }
3528  if ( $length == 0 ) {
3529  return $ellipsis; // convention
3530  }
3531 
3532  $stringOriginal = $string;
3533  # If ellipsis length is >= $length then we can't apply $adjustLength
3534  if ( $adjustLength && $measureLength( $ellipsis ) >= abs( $length ) ) {
3535  $string = $ellipsis; // this can be slightly unexpected
3536  # Otherwise, truncate and add ellipsis...
3537  } else {
3538  $ellipsisLength = $adjustLength ? $measureLength( $ellipsis ) : 0;
3539  if ( $length > 0 ) {
3540  $length -= $ellipsisLength;
3541  $string = $getSubstring( $string, 0, $length ); // xyz...
3542  $string = $this->removeBadCharLast( $string );
3543  $string = rtrim( $string ) . $ellipsis;
3544  } else {
3545  $length += $ellipsisLength;
3546  $string = $getSubstring( $string, $length ); // ...xyz
3547  $string = $this->removeBadCharFirst( $string );
3548  $string = $ellipsis . ltrim( $string );
3549  }
3550  }
3551 
3552  # Do not truncate if the ellipsis makes the string longer/equal (T24181).
3553  # This check is *not* redundant if $adjustLength, due to the single case where
3554  # LEN($ellipsis) > ABS($limit arg); $stringOriginal could be shorter than $string.
3555  if ( $measureLength( $string ) < $measureLength( $stringOriginal ) ) {
3556  return $string;
3557  } else {
3558  return $stringOriginal;
3559  }
3560  }
3561 
3569  protected function removeBadCharLast( $string ) {
3570  if ( $string != '' ) {
3571  $char = ord( $string[strlen( $string ) - 1] );
3572  $m = [];
3573  if ( $char >= 0xc0 ) {
3574  # We got the first byte only of a multibyte char; remove it.
3575  $string = substr( $string, 0, -1 );
3576  } elseif ( $char >= 0x80 &&
3577  // Use the /s modifier (PCRE_DOTALL) so (.*) also matches newlines
3578  preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
3579  '[\xf0-\xf7][\x80-\xbf]{1,2})$/s', $string, $m )
3580  ) {
3581  # We chopped in the middle of a character; remove it
3582  $string = $m[1];
3583  }
3584  }
3585  return $string;
3586  }
3587 
3595  protected function removeBadCharFirst( $string ) {
3596  if ( $string != '' ) {
3597  $char = ord( $string[0] );
3598  if ( $char >= 0x80 && $char < 0xc0 ) {
3599  # We chopped in the middle of a character; remove the whole thing
3600  $string = preg_replace( '/^[\x80-\xbf]+/', '', $string );
3601  }
3602  }
3603  return $string;
3604  }
3605 
3621  public function truncateHtml( $text, $length, $ellipsis = '...' ) {
3622  # Use the localized ellipsis character
3623  if ( $ellipsis == '...' ) {
3624  $ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this )->escaped();
3625  }
3626  # Check if there is clearly no need to truncate
3627  if ( $length <= 0 ) {
3628  return $ellipsis; // no text shown, nothing to format (convention)
3629  } elseif ( strlen( $text ) <= $length ) {
3630  return $text; // string short enough even *with* HTML (short-circuit)
3631  }
3632 
3633  $dispLen = 0; // innerHTML legth so far
3634  $testingEllipsis = false; // checking if ellipses will make string longer/equal?
3635  $tagType = 0; // 0-open, 1-close
3636  $bracketState = 0; // 1-tag start, 2-tag name, 0-neither
3637  $entityState = 0; // 0-not entity, 1-entity
3638  $tag = $ret = ''; // accumulated tag name, accumulated result string
3639  $openTags = []; // open tag stack
3640  $maybeState = null; // possible truncation state
3641 
3642  $textLen = strlen( $text );
3643  $neLength = max( 0, $length - strlen( $ellipsis ) ); // non-ellipsis len if truncated
3644  for ( $pos = 0; true; ++$pos ) {
3645  # Consider truncation once the display length has reached the maximim.
3646  # We check if $dispLen > 0 to grab tags for the $neLength = 0 case.
3647  # Check that we're not in the middle of a bracket/entity...
3648  if ( $dispLen && $dispLen >= $neLength && $bracketState == 0 && !$entityState ) {
3649  if ( !$testingEllipsis ) {
3650  $testingEllipsis = true;
3651  # Save where we are; we will truncate here unless there turn out to
3652  # be so few remaining characters that truncation is not necessary.
3653  if ( !$maybeState ) { // already saved? ($neLength = 0 case)
3654  $maybeState = [ $ret, $openTags ]; // save state
3655  }
3656  } elseif ( $dispLen > $length && $dispLen > strlen( $ellipsis ) ) {
3657  # String in fact does need truncation, the truncation point was OK.
3658  // @phan-suppress-next-line PhanTypeInvalidExpressionArrayDestructuring
3659  list( $ret, $openTags ) = $maybeState; // reload state
3660  $ret = $this->removeBadCharLast( $ret ); // multi-byte char fix
3661  $ret .= $ellipsis; // add ellipsis
3662  break;
3663  }
3664  }
3665  if ( $pos >= $textLen ) {
3666  break; // extra iteration just for above checks
3667  }
3668 
3669  # Read the next char...
3670  $ch = $text[$pos];
3671  $lastCh = $pos ? $text[$pos - 1] : '';
3672  $ret .= $ch; // add to result string
3673  if ( $ch == '<' ) {
3674  $this->truncate_endBracket( $tag, $tagType, $lastCh, $openTags ); // for bad HTML
3675  $entityState = 0; // for bad HTML
3676  $bracketState = 1; // tag started (checking for backslash)
3677  } elseif ( $ch == '>' ) {
3678  $this->truncate_endBracket( $tag, $tagType, $lastCh, $openTags );
3679  $entityState = 0; // for bad HTML
3680  $bracketState = 0; // out of brackets
3681  } elseif ( $bracketState == 1 ) {
3682  if ( $ch == '/' ) {
3683  $tagType = 1; // close tag (e.g. "</span>")
3684  } else {
3685  $tagType = 0; // open tag (e.g. "<span>")
3686  $tag .= $ch;
3687  }
3688  $bracketState = 2; // building tag name
3689  } elseif ( $bracketState == 2 ) {
3690  if ( $ch != ' ' ) {
3691  $tag .= $ch;
3692  } else {
3693  // Name found (e.g. "<a href=..."), add on tag attributes...
3694  $pos += $this->truncate_skip( $ret, $text, "<>", $pos + 1 );
3695  }
3696  } elseif ( $bracketState == 0 ) {
3697  if ( $entityState ) {
3698  if ( $ch == ';' ) {
3699  $entityState = 0;
3700  $dispLen++; // entity is one displayed char
3701  }
3702  } else {
3703  if ( $neLength == 0 && !$maybeState ) {
3704  // Save state without $ch. We want to *hit* the first
3705  // display char (to get tags) but not *use* it if truncating.
3706  $maybeState = [ substr( $ret, 0, -1 ), $openTags ];
3707  }
3708  if ( $ch == '&' ) {
3709  $entityState = 1; // entity found, (e.g. "&#160;")
3710  } else {
3711  $dispLen++; // this char is displayed
3712  // Add the next $max display text chars after this in one swoop...
3713  $max = ( $testingEllipsis ? $length : $neLength ) - $dispLen;
3714  $skipped = $this->truncate_skip( $ret, $text, "<>&", $pos + 1, $max );
3715  $dispLen += $skipped;
3716  $pos += $skipped;
3717  }
3718  }
3719  }
3720  }
3721  // Close the last tag if left unclosed by bad HTML
3722  $this->truncate_endBracket( $tag, $text[$textLen - 1], $tagType, $openTags );
3723  while ( count( $openTags ) > 0 ) {
3724  $ret .= '</' . array_pop( $openTags ) . '>'; // close open tags
3725  }
3726  return $ret;
3727  }
3728 
3740  private function truncate_skip( &$ret, $text, $search, $start, $len = null ) {
3741  if ( $len === null ) {
3742  $len = -1; // -1 means "no limit" for strcspn
3743  } elseif ( $len < 0 ) {
3744  $len = 0; // sanity
3745  }
3746  $skipCount = 0;
3747  if ( $start < strlen( $text ) ) {
3748  $skipCount = strcspn( $text, $search, $start, $len );
3749  $ret .= substr( $text, $start, $skipCount );
3750  }
3751  return $skipCount;
3752  }
3753 
3763  private function truncate_endBracket( &$tag, $tagType, $lastCh, &$openTags ) {
3764  $tag = ltrim( $tag );
3765  if ( $tag != '' ) {
3766  if ( $tagType == 0 && $lastCh != '/' ) {
3767  $openTags[] = $tag; // tag opened (didn't close itself)
3768  } elseif ( $tagType == 1 ) {
3769  if ( $openTags && $tag == $openTags[count( $openTags ) - 1] ) {
3770  array_pop( $openTags ); // tag closed
3771  }
3772  }
3773  $tag = '';
3774  }
3775  }
3776 
3785  public function convertGrammar( $word, $case ) {
3786  global $wgGrammarForms;
3787  if ( isset( $wgGrammarForms[$this->getCode()][$case][$word] ) ) {
3788  return $wgGrammarForms[$this->getCode()][$case][$word];
3789  }
3790 
3791  $grammarTransformations = $this->getGrammarTransformations();
3792 
3793  if ( isset( $grammarTransformations[$case] ) ) {
3794  $forms = $grammarTransformations[$case];
3795 
3796  // Some names of grammar rules are aliases for other rules.
3797  // In such cases the value is a string rather than object,
3798  // so load the actual rules.
3799  if ( is_string( $forms ) ) {
3800  $forms = $grammarTransformations[$forms];
3801  }
3802 
3803  foreach ( array_values( $forms ) as $rule ) {
3804  $form = $rule[0];
3805 
3806  if ( $form === '@metadata' ) {
3807  continue;
3808  }
3809 
3810  $replacement = $rule[1];
3811 
3812  $regex = '/' . addcslashes( $form, '/' ) . '/u';
3813  $patternMatches = preg_match( $regex, $word );
3814 
3815  if ( $patternMatches === false ) {
3816  wfLogWarning(
3817  'An error occurred while processing grammar. ' .
3818  "Word: '$word'. Regex: /$form/."
3819  );
3820  } elseif ( $patternMatches === 1 ) {
3821  $word = preg_replace( $regex, $replacement, $word );
3822 
3823  break;
3824  }
3825  }
3826  }
3827 
3828  return $word;
3829  }
3830 
3836  public function getGrammarForms() {
3837  global $wgGrammarForms;
3838  if ( isset( $wgGrammarForms[$this->getCode()] )
3839  && is_array( $wgGrammarForms[$this->getCode()] )
3840  ) {
3841  return $wgGrammarForms[$this->getCode()];
3842  }
3843 
3844  return [];
3845  }
3846 
3856  public function getGrammarTransformations() {
3857  if ( $this->grammarTransformCache !== null ) {
3858  return $this->grammarTransformCache;
3859  }
3860 
3861  $grammarDataFile = __DIR__ . "/data/grammarTransformations/{$this->getCode()}.json";
3862 
3863  $this->grammarTransformCache = is_readable( $grammarDataFile )
3864  ? FormatJson::decode( file_get_contents( $grammarDataFile ), true )
3865  : [];
3866 
3867  if ( $this->grammarTransformCache === null ) {
3868  throw new MWException( "Invalid grammar data for \"{$this->getCode()}\"." );
3869  }
3870 
3871  return $this->grammarTransformCache;
3872  }
3873 
3893  public function gender( $gender, $forms ) {
3894  if ( !count( $forms ) ) {
3895  return '';
3896  }
3897  $forms = $this->preConvertPlural( $forms, 2 );
3898  if ( $gender === 'male' ) {
3899  return $forms[0];
3900  }
3901  if ( $gender === 'female' ) {
3902  return $forms[1];
3903  }
3904  return $forms[2] ?? $forms[0];
3905  }
3906 
3922  public function convertPlural( $count, $forms ) {
3923  // Handle explicit n=pluralform cases
3924  $forms = $this->handleExplicitPluralForms( $count, $forms );
3925  if ( is_string( $forms ) ) {
3926  return $forms;
3927  }
3928  if ( !count( $forms ) ) {
3929  return '';
3930  }
3931 
3932  $pluralForm = $this->getPluralRuleIndexNumber( $count );
3933  $pluralForm = min( $pluralForm, count( $forms ) - 1 );
3934  return $forms[$pluralForm];
3935  }
3936 
3952  protected function handleExplicitPluralForms( $count, array $forms ) {
3953  foreach ( $forms as $index => $form ) {
3954  if ( preg_match( '/\d+=/i', $form ) ) {
3955  $pos = strpos( $form, '=' );
3956  if ( substr( $form, 0, $pos ) === (string)$count ) {
3957  return substr( $form, $pos + 1 );
3958  }
3959  unset( $forms[$index] );
3960  }
3961  }
3962  return array_values( $forms );
3963  }
3964 
3973  protected function preConvertPlural( /* Array */ $forms, $count ) {
3974  return array_pad( $forms, $count, end( $forms ) );
3975  }
3976 
3993  public function embedBidi( $text = '' ) {
3994  $dir = self::strongDirFromContent( $text );
3995  if ( $dir === 'ltr' ) {
3996  // Wrap in LEFT-TO-RIGHT EMBEDDING ... POP DIRECTIONAL FORMATTING
3997  return self::LRE . $text . self::PDF;
3998  }
3999  if ( $dir === 'rtl' ) {
4000  // Wrap in RIGHT-TO-LEFT EMBEDDING ... POP DIRECTIONAL FORMATTING
4001  return self::RLE . $text . self::PDF;
4002  }
4003  // No strong directionality: do not wrap
4004  return $text;
4005  }
4006 
4020  public function translateBlockExpiry( $str, User $user = null, $now = 0 ) {
4021  $duration = SpecialBlock::getSuggestedDurations( $this );
4022  foreach ( $duration as $show => $value ) {
4023  if ( strcmp( $str, $value ) == 0 ) {
4024  return htmlspecialchars( trim( $show ) );
4025  }
4026  }
4027 
4028  if ( wfIsInfinity( $str ) ) {
4029  foreach ( $duration as $show => $value ) {
4030  if ( wfIsInfinity( $value ) ) {
4031  return htmlspecialchars( trim( $show ) );
4032  }
4033  }
4034  }
4035 
4036  // If all else fails, return a standard duration or timestamp description.
4037  $time = strtotime( $str, $now );
4038  if ( $time === false ) { // Unknown format. Return it as-is in case.
4039  return $str;
4040  } elseif ( $time !== strtotime( $str, $now + 1 ) ) { // It's a relative timestamp.
4041  // The result differs based on current time, so the difference
4042  // is a fixed duration length.
4043  return $this->formatDuration( $time - $now );
4044  } else { // It's an absolute timestamp.
4045  if ( $time === 0 ) {
4046  // wfTimestamp() handles 0 as current time instead of epoch.
4047  $time = '19700101000000';
4048  }
4049  if ( $user ) {
4050  return $this->userTimeAndDate( $time, $user );
4051  }
4052  return $this->timeanddate( $time );
4053  }
4054  }
4055 
4063  public function segmentForDiff( $text ) {
4064  return $text;
4065  }
4066 
4073  public function unsegmentForDiff( $text ) {
4074  return $text;
4075  }
4076 
4086  public function getConverter() : ILanguageConverter {
4087  return $this->converterFactory->getLanguageConverter( $this );
4088  }
4089 
4100  public function autoConvert( $text, $variant = false ) {
4101  return $this->getConverter()->autoConvert( $text, $variant );
4102  }
4103 
4112  public function autoConvertToAllVariants( $text ) {
4113  return $this->getConverter()->autoConvertToAllVariants( $text );
4114  }
4115 
4130  public function convert( $text ) {
4131  return $this->getConverter()->convert( $text );
4132  }
4133 
4142  public function convertTitle( $title ) {
4143  return $this->getConverter()->convertTitle( $title );
4144  }
4145 
4156  public function convertNamespace( $ns, $variant = null ) {
4157  return $this->getConverter()->convertNamespace( $ns, $variant );
4158  }
4159 
4167  public function hasVariants() {
4168  return count( $this->getVariants() ) > 1;
4169  }
4170 
4183  public function hasVariant( $variant ) {
4184  return $this->getConverter()->hasVariant( $variant );
4185  }
4186 
4196  public function convertHtml( $text ) {
4197  return htmlspecialchars( $this->convert( $text ) );
4198  }
4199 
4206  public function convertCategoryKey( $key ) {
4207  return $this->getConverter()->convertCategoryKey( $key );
4208  }
4209 
4218  public function getVariants() {
4219  return $this->getConverter()->getVariants();
4220  }
4221 
4226  public function getPreferredVariant() {
4227  return $this->getConverter()->getPreferredVariant();
4228  }
4229 
4234  public function getDefaultVariant() {
4235  return $this->getConverter()->getDefaultVariant();
4236  }
4237 
4242  public function getURLVariant() {
4243  return $this->getConverter()->getURLVariant();
4244  }
4245 
4260  public function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
4261  $this->getConverter()->findVariantLink( $link, $nt, $ignoreOtherCond );
4262  }
4263 
4272  public function getExtraHashOptions() {
4273  return $this->getConverter()->getExtraHashOptions();
4274  }
4275 
4284  public function updateConversionTable( LinkTarget $linkTarget ) {
4285  $this->getConverter()->updateConversionTable( $linkTarget );
4286  }
4287 
4294  public function linkTrail() {
4295  return $this->localisationCache->getItem( $this->mCode, 'linkTrail' );
4296  }
4297 
4304  public function linkPrefixCharset() {
4305  return $this->localisationCache->getItem( $this->mCode, 'linkPrefixCharset' );
4306  }
4307 
4316  public function getParentLanguage() {
4317  return MediaWikiServices::getInstance()->getLanguageFactory()
4318  ->getParentLanguage( $this->getCode() );
4319  }
4320 
4328  public function equals( Language $lang ) {
4329  return $lang === $this || $lang->getCode() === $this->mCode;
4330  }
4331 
4340  public function getCode() {
4341  return $this->mCode;
4342  }
4343 
4354  public function getHtmlCode() {
4355  if ( $this->mHtmlCode === null ) {
4356  $this->mHtmlCode = LanguageCode::bcp47( $this->getCode() );
4357  }
4358  return $this->mHtmlCode;
4359  }
4360 
4368  public static function getCodeFromFileName( $filename, $prefix = 'Language', $suffix = '.php' ) {
4369  $m = null;
4370  preg_match( '/' . preg_quote( $prefix, '/' ) . '([A-Z][a-z_]+)' .
4371  preg_quote( $suffix, '/' ) . '/', $filename, $m );
4372  if ( !count( $m ) ) {
4373  return false;
4374  }
4375  return str_replace( '_', '-', strtolower( $m[1] ) );
4376  }
4377 
4386  public static function classFromCode( $code, $fallback = true ) {
4387  wfDeprecated( __METHOD__, '1.35' );
4388 
4389  if ( $fallback && $code == 'en' ) {
4390  return 'Language';
4391  } else {
4392  return 'Language' . str_replace( '-', '_', ucfirst( $code ) );
4393  }
4394  }
4395 
4406  public static function getFileName( $prefix, $code, $suffix = '.php' ) {
4407  return MediaWikiServices::getInstance()->getLanguageNameUtils()
4408  ->getFileName( $prefix, $code, $suffix );
4409  }
4410 
4416  public static function getMessagesFileName( $code ) {
4417  return MediaWikiServices::getInstance()->getLanguageNameUtils()
4418  ->getMessagesFileName( $code );
4419  }
4420 
4428  public static function getJsonMessagesFileName( $code ) {
4429  return MediaWikiServices::getInstance()->getLanguageNameUtils()
4430  ->getJsonMessagesFileName( $code );
4431  }
4432 
4441  public static function getFallbackFor( $code ) {
4442  return MediaWikiServices::getInstance()->getLanguageFallback()->getFirst( $code )
4443  ?? false;
4444  }
4445 
4458  public static function getFallbacksFor( $code, $mode = self::MESSAGES_FALLBACKS ) {
4459  return MediaWikiServices::getInstance()->getLanguageFallback()->getAll( $code, $mode );
4460  }
4461 
4472  public static function getFallbacksIncludingSiteLanguage( $code ) {
4473  return MediaWikiServices::getInstance()->getLanguageFallback()
4474  ->getAllIncludingSiteLanguage( $code );
4475  }
4476 
4488  public static function getMessagesFor( $code ) {
4489  return self::getLocalisationCache()->getItem( $code, 'messages' );
4490  }
4491 
4502  public static function getMessageFor( $key, $code ) {
4503  return self::getLocalisationCache()->getSubitem( $code, 'messages', $key );
4504  }
4505 
4516  public static function getMessageKeysFor( $code ) {
4517  return self::getLocalisationCache()->getSubitemList( $code, 'messages' );
4518  }
4519 
4524  private function fixVariableInNamespace( $talk ) {
4525  if ( strpos( $talk, '$1' ) === false ) {
4526  return $talk;
4527  }
4528 
4529  global $wgMetaNamespace;
4530  $talk = str_replace( '$1', $wgMetaNamespace, $talk );
4531 
4532  # Allow grammar transformations
4533  # Allowing full message-style parsing would make simple requests
4534  # such as action=raw much more expensive than they need to be.
4535  # This will hopefully cover most cases.
4536  $talk = preg_replace_callback(
4537  '/{{grammar:(.*?)\|(.*?)}}/i',
4538  function ( $m ) {
4539  return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
4540  },
4541  $talk
4542  );
4543  return str_replace( ' ', '_', $talk );
4544  }
4545 
4556  public function formatExpiry( $expiry, $format = true, $infinity = 'infinity' ) {
4557  static $dbInfinity;
4558  if ( $dbInfinity === null ) {
4559  $dbInfinity = wfGetDB( DB_REPLICA )->getInfinity();
4560  }
4561 
4562  if ( $expiry == '' || $expiry === 'infinity' || $expiry == $dbInfinity ) {
4563  return $format === true
4564  ? $this->getMessageFromDB( 'infiniteblock' )
4565  : $infinity;
4566  } else {
4567  return $format === true
4568  ? $this->timeanddate( $expiry, /* User preference timezone */ true )
4569  : wfTimestamp( $format, $expiry );
4570  }
4571  }
4572 
4587  public function formatTimePeriod( $seconds, $format = [] ) {
4588  if ( !is_array( $format ) ) {
4589  $format = [ 'avoid' => $format ]; // For backwards compatibility
4590  }
4591  if ( !isset( $format['avoid'] ) ) {
4592  $format['avoid'] = false;
4593  }
4594  if ( !isset( $format['noabbrevs'] ) ) {
4595  $format['noabbrevs'] = false;
4596  }
4597  $secondsMsg = wfMessage(
4598  $format['noabbrevs'] ? 'seconds' : 'seconds-abbrev' )->inLanguage( $this );
4599  $minutesMsg = wfMessage(
4600  $format['noabbrevs'] ? 'minutes' : 'minutes-abbrev' )->inLanguage( $this );
4601  $hoursMsg = wfMessage(
4602  $format['noabbrevs'] ? 'hours' : 'hours-abbrev' )->inLanguage( $this );
4603  $daysMsg = wfMessage(
4604  $format['noabbrevs'] ? 'days' : 'days-abbrev' )->inLanguage( $this );
4605 
4606  if ( round( $seconds * 10 ) < 100 ) {
4607  $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) );
4608  $s = $secondsMsg->params( $s )->text();
4609  } elseif ( round( $seconds ) < 60 ) {
4610  $s = $this->formatNum( round( $seconds ) );
4611  $s = $secondsMsg->params( $s )->text();
4612  } elseif ( round( $seconds ) < 3600 ) {
4613  $minutes = floor( $seconds / 60 );
4614  $secondsPart = round( fmod( $seconds, 60 ) );
4615  if ( $secondsPart == 60 ) {
4616  $secondsPart = 0;
4617  $minutes++;
4618  }
4619  $s = $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4620  $s .= ' ';
4621  $s .= $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
4622  } elseif ( round( $seconds ) <= 2 * 86400 ) {
4623  $hours = floor( $seconds / 3600 );
4624  $minutes = floor( ( $seconds - $hours * 3600 ) / 60 );
4625  $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 );
4626  if ( $secondsPart == 60 ) {
4627  $secondsPart = 0;
4628  $minutes++;
4629  }
4630  if ( $minutes == 60 ) {
4631  $minutes = 0;
4632  $hours++;
4633  }
4634  $s = $hoursMsg->params( $this->formatNum( $hours ) )->text();
4635  $s .= ' ';
4636  $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4637  if ( !in_array( $format['avoid'], [ 'avoidseconds', 'avoidminutes', 'avoidhours' ] ) ) {
4638  $s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
4639  }
4640  } else {
4641  $days = floor( $seconds / 86400 );
4642  if ( $format['avoid'] === 'avoidhours' ) {
4643  $hours = round( ( $seconds - $days * 86400 ) / 3600 );
4644  if ( $hours == 24 ) {
4645  $hours = 0;
4646  $days++;
4647  }
4648  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4649  } elseif ( $format['avoid'] === 'avoidminutes' ) {
4650  $hours = round( ( $seconds - $days * 86400 ) / 3600 );
4651  if ( $hours == 24 ) {
4652  $hours = 0;
4653  $days++;
4654  }
4655  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4656  $s .= ' ';
4657  $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
4658  } elseif ( $format['avoid'] === 'avoidseconds' ) {
4659  $hours = floor( ( $seconds - $days * 86400 ) / 3600 );
4660  $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 );
4661  if ( $minutes == 60 ) {
4662  $minutes = 0;
4663  $hours++;
4664  }
4665  if ( $hours == 24 ) {
4666  $hours = 0;
4667  $days++;
4668  }
4669  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4670  $s .= ' ';
4671  $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
4672  $s .= ' ';
4673  $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
4674  } else {
4675  $s = $daysMsg->params( $this->formatNum( $days ) )->text();
4676  $s .= ' ';
4677  $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format );
4678  }
4679  }
4680  return $s;
4681  }
4682 
4694  public function formatBitrate( $bps ) {
4695  return $this->formatComputingNumbers( $bps, 1000, "bitrate-$1bits" );
4696  }
4697 
4704  public function formatComputingNumbers( $size, $boundary, $messageKey ) {
4705  if ( $size <= 0 ) {
4706  return str_replace( '$1', $this->formatNum( $size ),
4707  $this->getMessageFromDB( str_replace( '$1', '', $messageKey ) )
4708  );
4709  }
4710  $sizes = [ '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' ];
4711  $index = 0;
4712 
4713  $maxIndex = count( $sizes ) - 1;
4714  while ( $size >= $boundary && $index < $maxIndex ) {
4715  $index++;
4716  $size /= $boundary;
4717  }
4718 
4719  // For small sizes no decimal places necessary
4720  $round = 0;
4721  if ( $index > 1 ) {
4722  // For MB and bigger two decimal places are smarter
4723  $round = 2;
4724  }
4725  $msg = str_replace( '$1', $sizes[$index], $messageKey );
4726 
4727  $size = round( $size, $round );
4728  $text = $this->getMessageFromDB( $msg );
4729  return str_replace( '$1', $this->formatNum( $size ), $text );
4730  }
4731 
4742  public function formatSize( $size ) {
4743  return $this->formatComputingNumbers( $size, 1024, "size-$1bytes" );
4744  }
4745 
4755  public function specialList( $page, $details, $oppositedm = true ) {
4756  if ( !$details ) {
4757  return $page;
4758  }
4759 
4760  $dirmark = ( $oppositedm ? $this->getDirMark( true ) : '' ) . $this->getDirMark();
4761  return $page .
4762  $dirmark .
4763  $this->msg( 'word-separator' )->escaped() .
4764  $this->msg( 'parentheses' )->rawParams( $details )->escaped();
4765  }
4766 
4779  public function viewPrevNext( Title $title, $offset, $limit,
4780  array $query = [], $atend = false
4781  ) {
4782  wfDeprecated( __METHOD__, '1.34' );
4783  // @todo FIXME: Why on earth this needs one message for the text and another one for tooltip?
4784 
4785  # Make 'previous' link
4786  $prev = wfMessage( 'prevn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
4787  if ( $offset > 0 ) {
4788  $plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit,
4789  $query, $prev, 'prevn-title', 'mw-prevlink' );
4790  } else {
4791  $plink = htmlspecialchars( $prev );
4792  }
4793 
4794  # Make 'next' link
4795  $next = wfMessage( 'nextn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
4796  if ( $atend ) {
4797  $nlink = htmlspecialchars( $next );
4798  } else {
4799  $nlink = $this->numLink( $title, $offset + $limit, $limit,
4800  $query, $next, 'nextn-title', 'mw-nextlink' );
4801  }
4802 
4803  # Make links to set number of items per page
4804  $numLinks = [];
4805  foreach ( [ 20, 50, 100, 250, 500 ] as $num ) {
4806  $numLinks[] = $this->numLink( $title, $offset, $num,
4807  $query, $this->formatNum( $num ), 'shown-title', 'mw-numlink' );
4808  }
4809 
4810  return wfMessage( 'viewprevnext' )->inLanguage( $this )->title( $title
4811  )->rawParams( $plink, $nlink, $this->pipeList( $numLinks ) )->escaped();
4812  }
4813 
4828  private function numLink( Title $title, $offset, $limit, array $query, $link,
4829  $tooltipMsg, $class
4830  ) {
4831  $query = [ 'limit' => $limit, 'offset' => $offset ] + $query;
4832  $tooltip = wfMessage( $tooltipMsg )->inLanguage( $this )->title( $title )
4833  ->numParams( $limit )->text();
4834 
4835  return Html::element( 'a', [ 'href' => $title->getLocalURL( $query ),
4836  'title' => $tooltip, 'class' => $class ], $link );
4837  }
4838 
4846  public function getConvRuleTitle() {
4847  return $this->getConverter()->getConvRuleTitle();
4848  }
4849 
4855  public function getCompiledPluralRules() {
4856  $pluralRules =
4857  $this->localisationCache->getItem( strtolower( $this->mCode ), 'compiledPluralRules' );
4858  if ( !$pluralRules ) {
4859  $fallbacks = $this->getFallbackLanguages();
4860  foreach ( $fallbacks as $fallbackCode ) {
4861  $pluralRules = $this->localisationCache
4862  ->getItem( strtolower( $fallbackCode ), 'compiledPluralRules' );
4863  if ( $pluralRules ) {
4864  break;
4865  }
4866  }
4867  }
4868  return $pluralRules;
4869  }
4870 
4876  public function getPluralRules() {
4877  $pluralRules =
4878  $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRules' );
4879  if ( !$pluralRules ) {
4880  $fallbacks = $this->getFallbackLanguages();
4881  foreach ( $fallbacks as $fallbackCode ) {
4882  $pluralRules = $this->localisationCache
4883  ->getItem( strtolower( $fallbackCode ), 'pluralRules' );
4884  if ( $pluralRules ) {
4885  break;
4886  }
4887  }
4888  }
4889  return $pluralRules;
4890  }
4891 
4897  public function getPluralRuleTypes() {
4898  $pluralRuleTypes =
4899  $this->localisationCache->getItem( strtolower( $this->mCode ), 'pluralRuleTypes' );
4900  if ( !$pluralRuleTypes ) {
4901  $fallbacks = $this->getFallbackLanguages();
4902  foreach ( $fallbacks as $fallbackCode ) {
4903  $pluralRuleTypes = $this->localisationCache
4904  ->getItem( strtolower( $fallbackCode ), 'pluralRuleTypes' );
4905  if ( $pluralRuleTypes ) {
4906  break;
4907  }
4908  }
4909  }
4910  return $pluralRuleTypes;
4911  }
4912 
4918  public function getPluralRuleIndexNumber( $number ) {
4919  $pluralRules = $this->getCompiledPluralRules();
4920  $form = Evaluator::evaluateCompiled( $number, $pluralRules );
4921  return $form;
4922  }
4923 
4932  public function getPluralRuleType( $number ) {
4933  $index = $this->getPluralRuleIndexNumber( $number );
4934  $pluralRuleTypes = $this->getPluralRuleTypes();
4935  return $pluralRuleTypes[$index] ?? 'other';
4936  }
4937 }
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1656
Language\$mCode
$mCode
Definition: Language.php:77
Language\internalUserTimeAndDate
internalUserTimeAndDate( $type, $ts, User $user, array $options)
Internal helper function for userDate(), userTime() and userTimeAndDate()
Definition: Language.php:2406
Language\$langFallback
LanguageFallback $langFallback
Definition: Language.php:116
Language\getCodeFromFileName
static getCodeFromFileName( $filename, $prefix='Language', $suffix='.php')
Get the language code from a file name.
Definition: Language.php:4368
Language\getExtraHashOptions
getExtraHashOptions()
returns language specific options used by User::getPageRenderHash() for example, the preferred langua...
Definition: Language.php:4272
Language\lc
lc( $str, $first=false)
Definition: Language.php:2725
MWTimestamp
Library for creating and parsing MW-style timestamps.
Definition: MWTimestamp.php:32
Language\parseFormattedNumber
parseFormattedNumber( $number)
Definition: Language.php:3270
Language\getURLVariant
getURLVariant()
Definition: Language.php:4242
Language\getVariantname
getVariantname( $code, $usemsg=true)
short names for language variants used for language conversion links.
Definition: Language.php:820
Language\linkPrefixExtension
linkPrefixExtension()
To allow "foo[[bar]]" to extend the link over the whole word "foobar".
Definition: Language.php:3155
Language\$langNameUtils
LanguageNameUtils $langNameUtils
Definition: Language.php:113
StringUtils\isUtf8
static isUtf8( $value)
Test whether a string is valid UTF-8.
Definition: StringUtils.php:44
Language\clearCaches
static clearCaches()
Intended for tests that may change configuration in a way that invalidates caches.
Definition: Language.php:336
Language\truncate_endBracket
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:3763
Language\commaList
commaList(array $list)
Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separa...
Definition: Language.php:3419
Language\semicolonList
semicolonList(array $list)
Take a list of strings and build a locale-friendly semicolon-separated list, using the local semicolo...
Definition: Language.php:3432
Language\$mIranianCalendarMonthMsgs
static $mIranianCalendarMonthMsgs
Definition: Language.php:225
Language\$mMonthAbbrevMsgs
static $mMonthAbbrevMsgs
Definition: Language.php:210
Language\formatSize
formatSize( $size)
Format a size in bytes for output, using an appropriate unit (B, KB, MB, GB, TB, PB,...
Definition: Language.php:4742
Language\separatorTransformTable
separatorTransformTable()
Definition: Language.php:3376
Language\WEEKDAY_ABBREVIATED_MESSAGES
const WEEKDAY_ABBREVIATED_MESSAGES
Definition: Language.php:162
Language\resetNamespaces
resetNamespaces()
Resets all of the namespace caches.
Definition: Language.php:610
Language\getConverter
getConverter()
Return the LanguageConverter used in the Language.
Definition: Language.php:4086
Language\hasVariants
hasVariants()
Check if this is a language with variants.
Definition: Language.php:4167
Language\$mWeekdayAbbrevMsgs
static $mWeekdayAbbrevMsgs
Definition: Language.php:169
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:137
Language\preConvertPlural
preConvertPlural($forms, $count)
Checks that convertPlural was given an array and pads it to requested amount of forms by copying the ...
Definition: Language.php:3973
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
Language\convertHtml
convertHtml( $text)
Perform output conversion on a string, and encode for safe HTML output.
Definition: Language.php:4196
Language\minimumGroupingDigits
minimumGroupingDigits()
Definition: Language.php:3383
Language\segmentByWord
segmentByWord( $string)
Some languages such as Chinese require word segmentation, Specify such segmentation when overridden i...
Definition: Language.php:2861
Language\iconv
iconv( $in, $out, $string)
Definition: Language.php:2633
n
while(( $__line=Maintenance::readconsole()) !==false) print n
Definition: eval.php:64
Language\getMessageFromDB
getMessageFromDB( $msg)
Get a message from the MediaWiki namespace.
Definition: Language.php:918
Language\convert
convert( $text)
convert text to different variants of a language.
Definition: Language.php:4130
Language\ALL
const ALL
Return all known languages in fetchLanguageName(s).
Definition: Language.php:52
true
return true
Definition: router.php:92
Language\convertGrammar
convertGrammar( $word, $case)
Grammatical transformations, needed for inflected languages Invoked by putting {{grammar:case|word}} ...
Definition: Language.php:3785
$fallback
$fallback
Definition: MessagesAb.php:11
Language\mbUpperChar
mbUpperChar( $char)
Convert character to uppercase, allowing overrides of the default mb_upper behaviour,...
Definition: Language.php:2692
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1809
Language\truncateForVisual
truncateForVisual( $string, $length, $ellipsis='...', $adjustLength=true)
Truncate a string to a specified number of characters, appending an optional string (e....
Definition: Language.php:3490
Language\$mMonthGenMsgs
static $mMonthGenMsgs
Definition: Language.php:197
Language\timeanddate
timeanddate( $ts, $adj=false, $format=true, $timecorrection=false)
Definition: Language.php:2310
Language\$grammarTransformCache
array[] null $grammarTransformCache
Definition: Language.php:119
MediaWiki\Languages\LanguageFallback
Definition: LanguageFallback.php:31
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1201
Language\MESSAGES_FALLBACKS
const MESSAGES_FALLBACKS
Return a fallback chain for messages in getFallbacksFor.
Definition: Language.php:137
$s
$s
Definition: mergeMessageFileList.php:185
Language\$mHijriCalendarMonthMsgs
static $mHijriCalendarMonthMsgs
Definition: Language.php:272
Language\$namespaceNames
array null $namespaceNames
Definition: Language.php:100
Language\getPreferredVariant
getPreferredVariant()
Definition: Language.php:4226
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1067
$digitGroupingPattern
$digitGroupingPattern
Definition: MessagesAs.php:167
User\getDatePreference
getDatePreference()
Get the user's preferred date format.
Definition: User.php:3210
Language\getDefaultVariant
getDefaultVariant()
Definition: Language.php:4234
Language\fallback8bitEncoding
fallback8bitEncoding()
Definition: Language.php:2838
Language\embedBidi
embedBidi( $text='')
Wraps argument with unicode control characters for directionality safety.
Definition: Language.php:3993
Language\truncateInternal
truncateInternal( $string, $length, $ellipsis, $adjustLength, callable $measureLength, callable $getSubstring)
Internal method used for truncation.
Definition: Language.php:3516
Language\formatTimePeriod
formatTimePeriod( $seconds, $format=[])
Formats a time given in seconds into a string representation of that time.
Definition: Language.php:4587
Language\formatBitrate
formatBitrate( $bps)
Format a bitrate for output, using an appropriate unit (bps, kbps, Mbps, Gbps, Tbps,...
Definition: Language.php:4694
Language\equals
equals(Language $lang)
Compare with an other language object.
Definition: Language.php:4328
Language\SUPPORTED
const SUPPORTED
Return in fetchLanguageName(s) only the languages for which we have at least some localisation.
Definition: Language.php:60
Language\getSpecialPageAliases
getSpecialPageAliases()
Get special page names, as an associative array canonical name => array of valid names,...
Definition: Language.php:3189
Language\getMessagesFileName
static getMessagesFileName( $code)
Definition: Language.php:4416
Language\getPluralRuleTypes
getPluralRuleTypes()
Get the plural rule types for the language.
Definition: Language.php:4897
Language\capitalizeAllNouns
capitalizeAllNouns()
Definition: Language.php:3122
Language\AS_AUTONYMS
const AS_AUTONYMS
Return autonyms in fetchLanguageName(s).
Definition: Language.php:45
Language\specialList
specialList( $page, $details, $oppositedm=true)
Make a list item, used by various special pages.
Definition: Language.php:4755
MediaWiki\Languages\LanguageConverterFactory
An interface for creating language converters.
Definition: LanguageConverterFactory.php:44
Language\$mHebrewCalendarMonthGenMsgs
static $mHebrewCalendarMonthGenMsgs
Definition: Language.php:257
$wgMetaNamespace
$wgMetaNamespace
Name of the project namespace.
Definition: DefaultSettings.php:4142
Language\checkTitleEncoding
checkTitleEncoding( $s)
TODO: $s is not always a string per T218883.
Definition: Language.php:2824
Language\isWellFormedLanguageTag
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:378
Language\getFormattedNamespaces
getFormattedNamespaces()
A convenience function that returns getNamespaces() with spaces instead of underscores in values.
Definition: Language.php:622
Language\lcfirst
lcfirst( $str)
Definition: Language.php:2702
MediaWiki\Languages\LanguageNameUtils
A service that provides utilities to do with language names and codes.
Definition: LanguageNameUtils.php:41
Language\formatExpiry
formatExpiry( $expiry, $format=true, $infinity='infinity')
Decode an expiry (block, protection, etc) which has come from the DB.
Definition: Language.php:4556
Language\isKnownLanguageTag
static isKnownLanguageTag( $tag)
Returns true if a language code is an IETF tag known to MediaWiki.
Definition: Language.php:464
Language\emphasize
emphasize( $text)
Italic is unsuitable for some languages.
Definition: Language.php:3206
Language\getFallbackLanguages
getFallbackLanguages()
Definition: Language.php:543
Language\getDurationIntervals
getDurationIntervals( $seconds, array $chosenIntervals=[])
Takes a number of seconds and returns an array with a set of corresponding intervals.
Definition: Language.php:2355
Language\caseFold
caseFold( $s)
Return a case-folded representation of $s.
Definition: Language.php:2815
Language\userTimeAndDate
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:2491
Language\segmentForDiff
segmentForDiff( $text)
languages like Chinese need to be segmented in order for the diff to be of any use
Definition: Language.php:4063
Language\classFromCode
static classFromCode( $code, $fallback=true)
Definition: Language.php:4386
Language\needsGenderDistinction
needsGenderDistinction()
Whether this language uses gender-dependent namespace aliases.
Definition: Language.php:687
FormatJson\decode
static decode( $value, $assoc=false)
Decodes a JSON string.
Definition: FormatJson.php:174
Language\getLocalisationCache
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:475
MWException
MediaWiki exception.
Definition: MWException.php:26
MWTimestamp\offsetForUser
offsetForUser(User $user)
Adjust the timestamp depending on the given user's preferences.
Definition: MWTimestamp.php:79
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:73
Language\viewPrevNext
viewPrevNext(Title $title, $offset, $limit, array $query=[], $atend=false)
Generate (prev x| next x) (20|50|100...) type links for paging.
Definition: Language.php:4779
Language\$transformData
$transformData
ReplacementArray object memoize.
Definition: Language.php:107
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1033
Language\updateConversionTable
updateConversionTable(LinkTarget $linkTarget)
Refresh the cache of conversion tables when MediaWiki:Conversiontable* is updated.
Definition: Language.php:4284
Language\tsToIranian
static tsToIranian( $ts)
Algorithm by Roozbeh Pournader and Mohammad Toossi to convert Gregorian dates to Iranian dates.
Definition: Language.php:1597
Language\unsegmentForDiff
unsegmentForDiff( $text)
and unsegment to show the result
Definition: Language.php:4073
Language\autoConvert
autoConvert( $text, $variant=false)
convert text to a variant
Definition: Language.php:4100
Language\truncateHtml
truncateHtml( $text, $length, $ellipsis='...')
Truncate a string of valid HTML to a specified length in bytes, appending an optional string (e....
Definition: Language.php:3621
Language\normalize
normalize( $s)
Convert a UTF-8 string to normal form C.
Definition: Language.php:2983
Language\getBookstoreList
getBookstoreList()
Exports $wgBookstoreListEn.
Definition: Language.php:551
Language\$mHebrewCalendarMonthMsgs
static $mHebrewCalendarMonthMsgs
Definition: Language.php:241
Language\DURATION_INTERVALS
const DURATION_INTERVALS
Definition: Language.php:277
Language\pipeList
pipeList(array $list)
Same as commaList, but separate it with the pipe instead.
Definition: Language.php:3444
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2500
Language\convertForSearchResult
convertForSearchResult( $termsArray)
Definition: Language.php:2914
Language\getMessageFor
static getMessageFor( $key, $code)
Get a message for a given language.
Definition: Language.php:4502
$matches
$matches
Definition: NoLocalSettings.php:24
Language\getGenderNsText
getGenderNsText( $index, $gender)
Returns gender-dependent namespace alias if available.
Definition: Language.php:672
Language\listToText
listToText(array $list)
Take a list of strings and build a locale-friendly comma-separated list, using the local comma-separa...
Definition: Language.php:3395
Language\getHtmlCode
getHtmlCode()
Get the code in BCP 47 format which we can use inside of html lang="" tags.
Definition: Language.php:4354
Language\getNamespaceAliases
getNamespaceAliases()
Definition: Language.php:721
Language\$mExtendedSpecialPageAliases
array[] $mExtendedSpecialPageAliases
memoize
Definition: Language.php:97
Language\getLocalNsIndex
getLocalNsIndex( $text)
Get a namespace key by value, case insensitive.
Definition: Language.php:711
Language\userDate
userDate( $ts, User $user, array $options=[])
Get the formatted date for the given timestamp and formatted for the given user.
Definition: Language.php:2445
Language\$mMonthMsgs
static $mMonthMsgs
Definition: Language.php:183
Language\truncateForDatabase
truncateForDatabase( $string, $length, $ellipsis='...', $adjustLength=true)
Truncate a string to a specified length in bytes, appending an optional string (e....
Definition: Language.php:3466
Language\getAllMessages
getAllMessages()
Definition: Language.php:2623
Language\getMagic
getMagic( $mw)
Fill a MagicWord object with data from here.
Definition: Language.php:3172
$wgOverrideUcfirstCharacters
array $wgOverrideUcfirstCharacters
List of Unicode characters for which capitalization is overridden in Language::ucfirst.
Definition: DefaultSettings.php:3270
Language\isRTL
isRTL()
For right-to-left language support.
Definition: Language.php:3046
Language\userTime
userTime( $ts, User $user, array $options=[])
Get the formatted time for the given timestamp and formatted for the given user.
Definition: Language.php:2468
$title
$title
Definition: testCompression.php:38
Language\getNsIndex
getNsIndex( $text)
Get a namespace key by value, case insensitive.
Definition: Language.php:802
Language\MONTH_GENITIVE_MESSAGES
const MONTH_GENITIVE_MESSAGES
Definition: Language.php:188
Language\getNamespaceIds
getNamespaceIds()
Definition: Language.php:778
Language\getPluralRuleIndexNumber
getPluralRuleIndexNumber( $number)
Find the index number of the plural rule appropriate for the given number.
Definition: Language.php:4918
Language\HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES
const HEBREW_CALENDAR_MONTH_GENITIVE_MESSAGES
Definition: Language.php:246
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Language\convertDoubleWidth
static convertDoubleWidth( $string)
convert double-width roman characters to single-width.
Definition: Language.php:2884
Language\getCompiledPluralRules
getCompiledPluralRules()
Get the compiled plural rules for the language.
Definition: Language.php:4855
Language\getHumanTimestampInternal
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:2547
Language\convertCategoryKey
convertCategoryKey( $key)
Definition: Language.php:4206
Language\digitGroupingPattern
digitGroupingPattern()
Definition: Language.php:3362
Language\ucwords
ucwords( $str)
Definition: Language.php:2745
Language\getPluralRules
getPluralRules()
Get the plural rules for the language.
Definition: Language.php:4876
Language\getArrow
getArrow( $direction='forwards')
An arrow, depending on the language direction.
Definition: Language.php:3133
Language\uc
uc( $str, $first=false)
Definition: Language.php:2671
Language\translateBlockExpiry
translateBlockExpiry( $str, User $user=null, $now=0)
Definition: Language.php:4020
Language\formatNumNoSeparators
formatNumNoSeparators( $number)
Front-end for non-commafied formatNum.
Definition: Language.php:3262
$wgTranslateNumerals
$wgTranslateNumerals
For Hindi and Arabic use local numerals instead of Western style (0-9) numerals in interface.
Definition: DefaultSettings.php:3131
Language\$mHtmlCode
$mHtmlCode
Definition: Language.php:84
Language\MONTH_ABBREVIATED_MESSAGES
const MONTH_ABBREVIATED_MESSAGES
Definition: Language.php:202
$wgNamespaceAliases
$wgNamespaceAliases
Define extra namespace aliases.
Definition: DefaultSettings.php:4210
Language\isValidBuiltInCode
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:449
Language\$converterFactory
LanguageConverterFactory $converterFactory
Definition: Language.php:124
Language\formatDuration
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:2329
Language\setNamespaces
setNamespaces(array $namespaces)
Arbitrarily set all of the namespace names at once.
Definition: Language.php:602
Language\linkPrefixCharset
linkPrefixCharset()
A regular expression character set to match legal word-prefixing characters which should be merged on...
Definition: Language.php:4304
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:72
ReplacementArray
Wrapper around strtr() that holds replacements.
Definition: ReplacementArray.php:24
Language\findVariantLink
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:4260
Language\fixVariableInNamespace
fixVariableInNamespace( $talk)
Definition: Language.php:4524
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:28
Language\ucwordbreaks
ucwordbreaks( $str)
capitalize words at word breaks
Definition: Language.php:2771
Language\getNsText
getNsText( $index)
Get a namespace value by key.
Definition: Language.php:641
$wgLocalTZoffset
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
Definition: DefaultSettings.php:3257
Language\getCode
getCode()
Get the internal language code for this language object.
Definition: Language.php:4340
Language\LRE
const LRE
Unicode directional formatting characters, for embedBidi()
Definition: Language.php:299
Language\getPluralRuleType
getPluralRuleType( $number)
Find the plural rule type appropriate for the given number For example, if the language is set to Ara...
Definition: Language.php:4932
User\getOption
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
Definition: User.php:2887
Language\dateFormat
dateFormat( $usePrefs=true)
This is meant to be used by time(), date(), and timeanddate() to get the date preference they're supp...
Definition: Language.php:2204
$wgMetaNamespaceTalk
$wgMetaNamespaceTalk
Name of the project talk namespace.
Definition: DefaultSettings.php:4151
Language\hebrewNumeral
static hebrewNumeral( $num)
Hebrew Gematria number formatting up to 9999.
Definition: Language.php:2039
wfIsInfinity
wfIsInfinity( $str)
Determine input string is represents as infinity.
Definition: GlobalFunctions.php:2876
Language\getFormattedNsText
getFormattedNsText( $index)
A convenience function that returns the same thing as getNsText() except with '_' changed to ' ',...
Definition: Language.php:659
Language\getMessagesFor
static getMessagesFor( $code)
Get all messages for a given language WARNING: this may take a long time.
Definition: Language.php:4488
NS_PROJECT_TALK
const NS_PROJECT_TALK
Definition: Defines.php:74
Language\handleExplicitPluralForms
handleExplicitPluralForms( $count, array $forms)
Handles explicit plural forms for Language::convertPlural()
Definition: Language.php:3952
Language\RLE
const RLE
Definition: Language.php:300
Language\getFileName
static getFileName( $prefix, $code, $suffix='.php')
Get the name of a file for a certain language code.
Definition: Language.php:4406
LocalisationCache
Class for caching the contents of localisation files, Messages*.php and *.i18n.php.
Definition: LocalisationCache.php:41
Language\MONTH_MESSAGES
const MONTH_MESSAGES
Definition: Language.php:174
Language\HEBREW_CALENDAR_MONTHS_MESSAGES
const HEBREW_CALENDAR_MONTHS_MESSAGES
Definition: Language.php:230
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:451
Language\getDirMark
getDirMark( $opposite=false)
A hidden direction mark (LRM or RLM), depending on the language direction.
Definition: Language.php:3110
Language\normalizeForSearch
normalizeForSearch( $string)
Some languages have special punctuation need to be normalized.
Definition: Language.php:2872
Language\isValidCode
static isValidCode( $code)
Returns true if a language code string is of a valid form, whether or not it exists.
Definition: Language.php:434
Language\__get
__get(string $name)
Use PHP's magic __get handler to handle lazy accessing to deprecated mConverter.
Definition: Language.php:69
Language\userAdjust
userAdjust( $ts, $tz=false)
Used by date() and time() to adjust the time output.
Definition: Language.php:2126
Language\formatComputingNumbers
formatComputingNumbers( $size, $boundary, $messageKey)
Definition: Language.php:4704
Language\$mLangObjCache
static array $mLangObjCache
Definition: Language.php:130
Language\getFallbackFor
static getFallbackFor( $code)
Get the first fallback for a given language.
Definition: Language.php:4441
Language\getParentLanguage
getParentLanguage()
Get the "parent" language which has a converter to convert a "compatible" language (in another varian...
Definition: Language.php:4316
Language\$dateFormatStrings
$dateFormatStrings
memoize
Definition: Language.php:90
Language\hasWordBreaks
hasWordBreaks()
Most writing systems use whitespace to break up words.
Definition: Language.php:2850
Language\getDir
getDir()
Return the correct HTML 'dir' attribute value for this language.
Definition: Language.php:3054
Language\date
date( $ts, $adj=false, $format=true, $timecorrection=false)
Definition: Language.php:2271
Language\alignEnd
alignEnd()
Return 'right' or 'left' as appropriate alignment for line-end for this language's text direction.
Definition: Language.php:3078
Title
Represents a title within MediaWiki.
Definition: Title.php:42
Language\truncate_skip
truncate_skip(&$ret, $text, $search, $start, $len=null)
truncateHtml() helper function like strcspn() but adds the skipped chars to $ret
Definition: Language.php:3740
Language\getVariants
getVariants()
Get the list of variants supported by this language see sample implementation in LanguageZh....
Definition: Language.php:4218
Language\convertPlural
convertPlural( $count, $forms)
Plural form transformations, needed for some languages.
Definition: Language.php:3922
$minimumGroupingDigits
$minimumGroupingDigits
Definition: MessagesBe_tarask.php:239
Language\getFallbacksIncludingSiteLanguage
static getFallbacksIncludingSiteLanguage( $code)
Get the ordered list of fallback languages, ending with the fallback language chain for the site lang...
Definition: Language.php:4472
$wgGrammarForms
$wgGrammarForms
Some languages need different word forms, usually for different cases.
Definition: DefaultSettings.php:3015
Language\transformUsingPairFile
transformUsingPairFile( $file, $string, $basePath=null)
Transform a string using serialized data stored in the given file (which must be in the serialized su...
Definition: Language.php:3010
Language\getGrammarForms
getGrammarForms()
Get the grammar forms for the content language.
Definition: Language.php:3836
Language\removeBadCharFirst
removeBadCharFirst( $string)
Remove bytes that represent an incomplete Unicode character at the start of string (e....
Definition: Language.php:3595
Language\$strongDirRegex
static $strongDirRegex
Directionality test regex for embedBidi().
Definition: Language.php:316
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:175
$wgExtraGenderNamespaces
$wgExtraGenderNamespaces
Same as above, but for namespaces with gender distinction.
Definition: DefaultSettings.php:4187
Language\getMessage
getMessage( $key)
Definition: Language.php:2616
Language\getGrammarTransformations
getGrammarTransformations()
Get the grammar transformations data for the language.
Definition: Language.php:3856
Language\getMessageKeysFor
static getMessageKeysFor( $code)
Get all message keys for a given language.
Definition: Language.php:4516
Language\getJsonMessagesFileName
static getJsonMessagesFileName( $code)
Definition: Language.php:4428
Language\IRANIAN_CALENDAR_MONTHS_MESSAGES
const IRANIAN_CALENDAR_MONTHS_MESSAGES
Definition: Language.php:215
Language\firstChar
firstChar( $s)
Get the first character of a string.
Definition: Language.php:2926
$basePath
$basePath
Definition: addSite.php:5
NS_USER
const NS_USER
Definition: Defines.php:71
Language\getNamespaces
getNamespaces()
Returns an array of localised namespaces indexed by their numbers.
Definition: Language.php:561
Language\$localisationCache
LocalisationCache $localisationCache
Definition: Language.php:110
SpecialBlock\getSuggestedDurations
static getSuggestedDurations(Language $lang=null, $includeOther=true)
Get an array of suggested block durations from MediaWiki:Ipboptions.
Definition: SpecialBlock.php:1078
Language\removeBadCharLast
removeBadCharLast( $string)
Remove bytes that represent an incomplete Unicode character at the end of string (e....
Definition: Language.php:3569
Language\romanNumeral
static romanNumeral( $num)
Roman number formatting up to 10000.
Definition: Language.php:2008
Language\getConvRuleTitle
getConvRuleTitle()
Get the conversion rule title, if any.
Definition: Language.php:4846
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:326
Language\PDF
const PDF
Definition: Language.php:301
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1054
Language\$namespaceAliases
$namespaceAliases
Definition: Language.php:101
Language\tsToHijri
static tsToHijri( $ts)
Converting Gregorian dates to Hijri dates.
Definition: Language.php:1657
Language\getHumanTimestamp
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:2510
$t
$t
Definition: testCompression.php:74
Language\time
time( $ts, $adj=false, $format=true, $timecorrection=false)
Definition: Language.php:2290
Language\insertSpace
static insertSpace( $string, $pattern)
Definition: Language.php:2904
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
Language\isMultibyte
isMultibyte( $str)
Definition: Language.php:2737
Language\alignStart
alignStart()
Return 'left' or 'right' as appropriate alignment for line-start for this language's text direction.
Definition: Language.php:3066
Language\isSupportedLanguage
static isSupportedLanguage( $code)
Checks whether any localisation is available for that language tag in MediaWiki (MessagesXx....
Definition: Language.php:358
Language\$mWeekdayMsgs
static $mWeekdayMsgs
Definition: Language.php:157
Language\digitTransformTable
digitTransformTable()
Definition: Language.php:3369
Language\tsToYear
static tsToYear( $ts, $cName)
Algorithm to convert Gregorian dates to Thai solar dates, Minguo dates or Minguo dates.
Definition: Language.php:1885
Language\getDirMarkEntity
getDirMarkEntity( $opposite=false)
A hidden direction mark (LRM or RLM), depending on the language direction.
Definition: Language.php:3093
Language\strongDirFromContent
static strongDirFromContent( $text='')
Gets directionality of the first strongly directional codepoint, for embedBidi()
Definition: Language.php:1991
Language\hebrewYearStart
static hebrewYearStart( $year)
This calculates the Hebrew year start, as days since 1 September.
Definition: Language.php:1847
Language\$mNamespaceIds
$mNamespaceIds
Definition: Language.php:101
$IP
$IP
Definition: WebStart.php:49
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:53
Language\getDateFormatString
getDateFormatString( $type, $pref)
Get a format string for a given type and preference.
Definition: Language.php:2235
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
Language\getMagicWords
getMagicWords()
Get all magic words from cache.
Definition: Language.php:3163
Language\hasVariant
hasVariant( $variant)
Strict check if the language has the specific variant.
Definition: Language.php:4183
Language\numLink
numLink(Title $title, $offset, $limit, array $query, $link, $tooltipMsg, $class)
Helper function for viewPrevNext() that generates links.
Definition: Language.php:4828
Language\__destruct
__destruct()
Reduce memory usage PhanTypeSuspiciousNonTraversableForeach.
Definition: Language.php:533
Language\commafy
commafy( $number)
Adds commas to a given number.
Definition: Language.php:3297
Language\HIJRI_CALENDAR_MONTH_MESSAGES
const HIJRI_CALENDAR_MONTH_MESSAGES
Definition: Language.php:262
Language\__construct
__construct( $code=null, LocalisationCache $localisationCache=null, LanguageNameUtils $langNameUtils=null, LanguageFallback $langFallback=null, LanguageConverterFactory $converterFactory=null)
Definition: Language.php:488
Language\STRICT_FALLBACKS
const STRICT_FALLBACKS
Return a strict fallback chain in getFallbacksFor.
Definition: Language.php:144
$wgExtraNamespaces
$wgExtraNamespaces
Additional namespaces.
Definition: DefaultSettings.php:4179
Language
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
Definition: Language.php:39
Language\getFallbacksFor
static getFallbacksFor( $code, $mode=self::MESSAGES_FALLBACKS)
Get the ordered list of fallback languages.
Definition: Language.php:4458
Language\$durationIntervals
static array $durationIntervals
Definition: Language.php:294
Language\tsToHebrew
static tsToHebrew( $ts)
Converting Gregorian dates to Hebrew dates.
Definition: Language.php:1709
Language\autoConvertToAllVariants
autoConvertToAllVariants( $text)
convert text to all supported variants
Definition: Language.php:4112
Language\linkTrail
linkTrail()
A regular expression to match legal word-trailing characters which should be merged onto a link of th...
Definition: Language.php:4294
$wgAllUnicodeFixes
$wgAllUnicodeFixes
Set this to always convert certain Unicode sequences to modern ones regardless of the content languag...
Definition: DefaultSettings.php:3093
Language\ucfirst
ucfirst( $str)
Definition: Language.php:2648
Language\$mMagicExtensions
$mMagicExtensions
Definition: Language.php:82
Language\gender
gender( $gender, $forms)
Provides an alternative text depending on specified gender.
Definition: Language.php:3893
Language\WEEKDAY_MESSAGES
const WEEKDAY_MESSAGES
Definition: Language.php:149
Language\formatNum
formatNum( $number, $nocommafy=false)
Normally we output all numbers in plain en_US style, that is 293,291.235 for twohundredninetythreetho...
Definition: Language.php:3232
$type
$type
Definition: testCompression.php:52
Language\convertNamespace
convertNamespace( $ns, $variant=null)
Convert a namespace index to a string in the preferred variant.
Definition: Language.php:4156
Language\convertTitle
convertTitle( $title)
Convert a Title object to a string in the preferred variant.
Definition: Language.php:4142