!! Version 2 # LanguageConverter and language variants parser tests # This is the standard article assumed to exist. !! article Main Page !! text blah blah !! endarticle !! article A !! text Dummy article to suppress redlinks in tests !! end !! article Template:1x !! text {{{1}}} !! endarticle # For Serbian; localize Template namespace !! article Шаблон:1x !! text {{{1}}} !! endarticle !! article Тест !! text sr-el article variant !! endarticle ## sr-ec ## !! test sr-ec: Simple conversion of Latin to Cyrillic !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext abvg !! html/php
абвг
!! html/parsoidabvg
!! html/parsoid+langconvабвг
!! end !! test sr-ec: Same as above, but assert that -{}-s must be removed and not converted (1) !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext -{lj}-аб-{nj}-вг-{dž}- !! html/phpljабnjвгdž
!! html/parsoidабвг
!! html/parsoid+langconvljабnjвгdž
!! end !! test sr-ec: This text has some Cyrillic, but is recognized as Latin, so it should be converted !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext абвгšđžčć !! html/phpабвгшђжчћ
!! html/parsoidабвгšđžčć
!! html/parsoid+langconvабвгшђжчћ
!! end !! test sr-ec: Same as above, but assert that -{}-s must be removed and not converted (2) !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext -{lj}-абвг-{nj}-šđžčć-{dž}- !! html/phpljабвгnjшђжчћdž
!! html/parsoidабвгšđžčć
!! html/parsoid+langconvljабвгnjшђжчћdž
!! end !! test sr-ec: Roman numerals are not converted !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext a I b II v III g IV šđžčć !! html/phpа I б II в III г IV шђжчћ
!! html/parsoida I b II v III g IV šđžčć
!! html/parsoid+langconvа I б II в III г IV шђжчћ
!! end ## sr-el ## !! test sr-el: A simple conversion of Latin to Latin !! options language=sr htmlVariantLanguage=sr-Latn !! wikitext abcd !! html/phpabcd
!! html/parsoidabcd
!! html/parsoid+langconvabcd
!! end !! test sr-el: A simple conversion of Cyrillic to Latin !! options language=sr htmlVariantLanguage=sr-Latn !! wikitext абцд !! html/phpabcd
!! html/parsoidабцд
!! html/parsoid+langconvabcd
!! end !! test sr-el: This text has some Latin, but is recognized as Cyrillic, so it should be converted !! options language=sr htmlVariantLanguage=sr-Latn !! wikitext abcdшђжчћ !! html/phpabcdšđžčć
!! html/parsoidabcdшђжчћ
!! html/parsoid+langconvabcdšđžčć
!! end !! test External links should be converted, unless they "look like a URL". !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext [http://example.com abcd] [http://example.com http://foo.com] http://example.com [http://example.com -{abcd}-] !! html/php !! html/parsoid !! html/parsoid+langconv !! end !! test Language converter: output gets cut off unexpectedly (T7757) !! options language=zh !! wikitext this bit is safe: }- but if we add a conversion instance: -{zh-cn:xxx;zh-tw:yyy}- then we get cut off here: }- all additional text is vanished !! html/phpthis bit is safe: }-
but if we add a conversion instance: xxx
then we get cut off here: }-
all additional text is vanished
!! html/parsoidthis bit is safe: }-
but if we add a conversion instance:
then we get cut off here: }-
all additional text is vanished
!! end !! test Language converter glossary rules inside attributes (T119158) !! options language=sr htmlVariantLanguage=sr-Latn !! config wgParserEnableLegacyMediaDOM=false !! wikitext -{H|foAjrjvi=>sr-el:" onload="alert(1)" data-foo="}- [[File:Foobar.jpg|alt=-{}-foAjrjvi-{}-]] !! html/php!! html/parsoid !! end ### ### Language variants related tests ### !! test Self-link in language variants !! options title=[[Dunav]] language=sr !! wikitext Both [[Dunav]] and [[Дунав]] are names for this river. !! html/php
Both Dunav and Дунав are names for this river.
!! html/parsoidBoth Dunav and Дунав are names for this river.
!! end !! article Дуна !! text content !! endarticle !! test Link to another existing title shouldn't be parsed as self-link even if it's a variant of this title !! options title=[[Duna]] language=sr !! wikitext [[Дуна]] is not a self-link while [[Duna]] and [[Dуна]] are still self-links. !! html/phpДуна is not a self-link while Duna and Dуна are still self-links.
!! html/parsoidДуна is not a self-link while Duna and Dуна are still self-links.
!! end !! test Link to a section of a variant of this title should be parsed as mw-selflink-fragment !! options title=[[Duna]] language=sr !! wikitext [[Dуна]] is a self-link while [[Duna#Foo]] and [[Dуна#Foo]] are mw-selflink-fragments. !! html/phpDуна is a self-link while Duna#Foo and Dуна#Foo are mw-selflink-fragments.
!! html/parsoidDуна is a self-link while Duna#Foo and Dуна#Foo are mw-selflink-fragments.
!! end !! test Link to pages in language variants !! options language=sr !! wikitext Main Page can be written as [[Маин Паге]] !! html/phpMain Page can be written as Маин Паге
!! html/parsoidMain Page can be written as Маин Паге
!! end !! test Multiple links to pages in language variants !! options language=sr !! wikitext [[Main Page]] can be written as [[Маин Паге]] same as [[Маин Паге]]. !! html/phpMain Page can be written as Маин Паге same as Маин Паге.
!! html/parsoidMain Page can be written as Маин Паге same as Маин Паге.
!! end !! article Template:test !! text This is a test template !! endarticle !! test Simple template in language variants !! options language=sr !! wikitext {{тест}} !! html/phpThis is a test template
!! end !! test Template with explicit namespace in language variants !! options language=sr !! wikitext {{Template:тест}} !! html/phpThis is a test template
!! end !! article Template:paramtest !! text This is a test template with parameter {{{param}}} !! endarticle !! test Basic test for template parameter in language variants !! options language=sr !! wikitext {{парамтест|param=foo}} !! html/phpThis is a test template with parameter foo
!! end !! test Simple category in language variants !! options language=sr cat !! metadata cat=МедиаWики_Усер'с_Гуиде sort= !! wikitext [[Category:МедиаWики Усер'с Гуиде]] !! html/php !! html/parsoid !! end !! article Category:分类 !! text blah !! endarticle !! article Category:分類 !! text blah !! endarticle ## We used to, but no longer wt2wt this test since the default serializer ## will normalize all categories to serialize on their own line. ## This wikitext usage is going to be fairly uncommon in production and ## selser will take care of preserving formatting in those scenarios. !! test Don't convert blue categorylinks to another variant (T35210) !! options cat language=zh parsoid=wt2html !! metadata cat=分类 sort= !! wikitext [[A]][[Category:分类]] !! html/php !! html/parsoid !! end !! test Stripping -{}- tags (language variants) !! options language=sr !! wikitext Latin proverb: -{Ne nuntium necare}- !! html/phpLatin proverb: Ne nuntium necare
!! html/parsoidLatin proverb:
!! end !! test Prevent conversion with -{}- tags (language variants) !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext Latinski: -{Ne nuntium necare}- !! html/phpЛатински: Ne nuntium necare
!! html/parsoidLatinski:
!! end !! test Prevent conversion of text with -{}- tags (language variants) !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext Latinski: -{Ne nuntium necare}- !! html/phpЛатински: Ne nuntium necare
!! html/parsoidLatinski:
!! end !! test Prevent conversion of links with -{}- tags (language variants) !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext -{[[Main Page]]}- !! html/php !! html/parsoid!! end !! test -{}- tags within headlines (within html for parserConvert()) !! config wgFragmentMode=[ "html5", "legacy" ] !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext ==-{Naslov}-== Note that even an unprotected headline ID is not affected by language conversion: ==Latinski== !! html/php
Ноте тхат евен ан унпротецтед хеадлине ИД ис нот аффецтед бy лангуаге цонверсион:
Note that even an unprotected headline ID is not affected by language conversion:
Taiwan, not China
!! html/parsoid, not China
!! end !! test Explicit definition of language variant alternatives (BCP 47 codes) !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext -{zh:China;zh-Hant-TW:Taiwan}-, not China !! html/phpTaiwan, not China
!! html/parsoid, not China
!! end !! test Filter syntax for language variants !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext foo-{zh;zh-hans;zh-hant|blog, WEBJOURNAL, WEBLOG}-quux !! html/phpfooblog, WEBJOURNAL, WEBLOGquux
!! html/parsoidfooquux
!! end # Note that Parsoid post-processing for language variants needs to # update the `title` attribute here, based on the mw:ExpandedAttrs property !! test Conversion around HTML tags !! options language=sr htmlVariantLanguage=sr-Cyrl !! wikitext -{H|span=>sr-ec:script;title=>sr-ec:src}- ski !! html/phpски
!! html/parsoidski
!! end !! test Explicit session-wise two-way language variant mapping (A flag and - flag) !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext This is -{zh:China; zh-tw:Taiwan}-, but we'll forget that now. Taiwan is not China. But -{A|zh:China; zh-tw:Taiwan}- is China, (This-{-|zh:China; zh-tw:Taiwan}- should be stripped!) and -{China}- is China. !! html/phpThis is Taiwan, but we'll forget that now.
Taiwan is not China.
But Taiwan is Taiwan,
(This should be stripped!)
and China is China.
!! html/parsoidThis is , but we'll forget that now.
Taiwan is not China.
But is China,
(This should be stripped!)
and is China.
!! end !! test Explicit session-wise one-way language variant mapping (A flag and - flag) !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext This is -{COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}-, but we'll forget that now. COUNTRY is China or Taiwan. But -{A|COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}- is COUNTRY, (This-{-|COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}- should be stripped!) and -{COUNTRY}- is COUNTRY. !! html/phpThis is Taiwan, but we'll forget that now.
COUNTRY is China or Taiwan.
But Taiwan is Taiwan,
(This should be stripped!)
and COUNTRY is COUNTRY.
!! html/parsoidThis is , but we'll forget that now.
COUNTRY is China or Taiwan.
But is COUNTRY,
(This should be stripped!)
and is COUNTRY.
!! end !! test Explicit session-wise two-way language variant mapping (H flag for hide) !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext (This-{H|zh:China;zh-tw:Taiwan}- should be stripped!) Taiwan is China. !! html/php(This should be stripped!)
Taiwan is Taiwan.
!! html/parsoid(This should be stripped!)
Taiwan is China.
!! end !! test Explicit session-wise one-way language variant mapping (H flag for hide) !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext (This-{H|COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}- should be stripped!) COUNTRY is Taiwan or China. !! html/php(This should be stripped!)
Taiwan is Taiwan or China.
!! html/parsoid(This should be stripped!)
COUNTRY is Taiwan or China.
!! end ## Note that parsoid test runner does not support 'showtitle' option. !! test Adding explicit conversion rule for title (T flag) !! options language=zh htmlVariantLanguage=zh-Hant-TW showtitle !! wikitext Should be stripped-{T|zh:China;zh-tw:Taiwan}-! Taiwan is China. !! html/php TaiwanShould be stripped!
Taiwan is China.
!! html/parsoidShould be stripped!
Taiwan is China.
!! end !! test Code coverage: T combined with H flag !! options language=zh htmlVariantLanguage=zh-Hant-TW showtitle !! wikitext Should be stripped-{T;H|zh:China; zh-tw:Taiwan}-! Taiwan is China. !! html/php TaiwanShould be stripped!
Taiwan is Taiwan.
!! html/parsoidShould be stripped!
Taiwan is China.
!! end !! test Code coverage: T with no variants !! options language=zh htmlVariantLanguage=zh-Hant-TW showtitle !! wikitext -{H|zh:China; zh-tw:Taiwan}- Taiwan is China.-{T|Taiwan is China}- !! html/php Taiwan is ChinaTaiwan is Taiwan.
!! html/parsoidTaiwan is China.
!! end !! test Code coverage: rules with no variants !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext -{H|zh:China; zh-tw:Taiwan}- Taiwan is China. -{H|China}- Taiwan is China. !! html/phpTaiwan is Taiwan. Taiwan is China.
!! html/parsoidTaiwan is China. Taiwan is China.
!! end !! test Code coverage: D flag for conversion rule !! options language=zh htmlVariantLanguage=zh-Hant-TW !! wikitext -{D|zh-cn:XA; zh-tw:YA}- -{A;D|zh-cn:XB; zh-tw:YB}- -{D;H|zh-cn:XC; zh-tw:YC}- -{D;H|FOO=>zh-tw:BAR;FOO=>zh-cn:BAT}- -{D|0=>zh-tw:1}- -{A;D|2=>zh-tw:3}- -{D;H|4=>zh-tw:5}- XA XB XC YA YB YC FOO BAR BAT 012345 !! html/php大陆:XA;臺灣:YA; 大陆:XC;臺灣:YC;
FOO⇒臺灣:BAR;FOO⇒大陆:BAT;
0⇒臺灣:1; 4⇒臺灣:5;
XA YB YC YA YB YC BAR BAR BAT 013355
!! html/parsoid
XA XB XC YA YB YC FOO BAR BAT 012345
!! end !! test Code coverage: N flag for conversion rule !! options language=zh htmlVariantLanguage=zh-Hans-CN !! wikitext -{N|zh-cn}- -{N|zh-tw}- -{N|sr-ec}- !! html/php大陆
臺灣
српски (ћирилица)
!! html/parsoid
!! end # html2wt suppresses the bogus 'D' flag, so this is wt2html only !! test Code coverage: N flag for conversion rule (wt2html only) !! options language=zh htmlVariantLanguage=zh-Hans-CN parsoid=wt2html,html2html !! wikitext -{D;N|en}- !! html/php
English
!! html/parsoid!! end !! test Testing that changing the language variant here in the tests actually works !! options language=zh htmlVariantLanguage=zh showtitle !! wikitext Should be stripped-{T|zh:China; zh-tw:Taiwan}-! !! html/php China
Should be stripped!
!! html/parsoidShould be stripped!
!! end !! test Title with HTML !! options language=zh htmlVariantLanguage=zh showtitle !! wikitext -{T|zh:Title with HTML&Entities}- Should be stripped! !! html/php Title with HTML&EntitiesShould be stripped!
!! end !! test Title with Wiki syntax !! options language=zh htmlVariantLanguage=zh showtitle !! wikitext -{T|zh:Title ''with'' Wiki's süntax©}- Should be stripped! !! html/php Title with Wiki's süntax©Should be stripped!
!! end !! test Title with JavaScript injection !! options language=zh htmlVariantLanguage=zh showtitle !! wikitext -{T|zh:Title click me }- Should be stripped! !! html/php Title click me <script>alert(43)</script>Should be stripped!
!! end !! test Test 1 from T298401/T67747 !! options language=zh htmlVariantLanguage=zh showtitle !! wikitext -{T|zh:Title &b}- Should be stripped! !! html/php Title <script>a</script>&bShould be stripped!
!! end !! test Test 2 from T298401/T67747 !! options language=zh htmlVariantLanguage=zh showtitle !! wikitext -{T|zh:Title