source: josm/trunk/data/validator/wikipedia.mapcss @ 15473

Last change on this file since 15473 was 15473, checked in by Klumbumbus, 5 months ago
  • fix #18251 - warn about wikipedia:lang tags with URL encoded values, no autofix as the syntax is not yet supported; reword an other validator warning
  • ignore traffic_calming=dynamic_bump, approved proposal but very few uses so far
  • Property svn:eol-style set to native
File size: 9.2 KB
Line 
1/* validation for the wikipedia=* tag - see tickets #8383, #14425, #18251 */
2
3/* If there is no language at all, this is broken. Also catches 'wikipedia' used as 'email', 'website', 'ele' [sic!] ... */
4*[wikipedia][wikipedia !~ /(?i)^[-a-z]{2,12}:/] {
5  throwError: tr("wikipedia tag has no language given, use ''wikipedia''=''language:page title''");
6  assertMatch: "node wikipedia=Foobar";
7  assertNoMatch: "node wikipedia=en:Foobar";
8  assertNoMatch: "node wikipedia=en-GB:Foobar";
9}
10
11/* Valid languages are extracted from <https://www.wikidata.org/w/api.php?action=help&modules=wbgetentities> (languages field), which may change, so this is a warning only.
12   Also includes "cz" and "be-x-old" because they can be auto-fixed */
13*[wikipedia =~ /(?i)^[-a-z]{2,12}:/][wikipedia !~ /^https?:\/\//][wikipedia !~ /^(aa|ab|ace|ady|ady-cyrl|aeb|aeb-arab|aeb-latn|af|ak|aln|als|am|an|ang|anp|ar|arc|arn|arq|ary|arz|as|ase|ast|av|avk|awa|ay|az|azb|ba|ban|bar|bat-smg|bbc|bbc-latn|bcc|bcl|be|be-tarask|be-x-old|bg|bgn|bh|bho|bi|bjn|bm|bn|bo|bpy|bqi|br|brh|bs|bto|bug|bxr|ca|cbk-zam|cdo|ce|ceb|ch|cho|chr|chy|ckb|co|cps|cr|crh|crh-cyrl|crh-latn|cs|csb|cu|cv|cy|cz|da|de|de-at|de-ch|de-formal|din|diq|dsb|dtp|dty|dv|dz|ee|egl|el|eml|en|en-ca|en-gb|eo|es|et|eu|ext|fa|ff|fi|fit|fiu-vro|fj|fo|fr|frc|frp|frr|fur|fy|ga|gag|gan|gan-hans|gan-hant|gd|gl|glk|gn|gom|gom-deva|gom-latn|gor|got|grc|gsw|gu|gv|ha|hak|haw|he|hi|hif|hif-latn|hil|ho|hr|hrx|hsb|ht|hu|hy|hz|ia|id|ie|ig|ii|ik|ike-cans|ike-latn|ilo|inh|io|is|it|iu|ja|jam|jbo|jut|jv|ka|kaa|kab|kbd|kbd-cyrl|kea|kg|khw|ki|kiu|kj|kk|kk-arab|kk-cn|kk-cyrl|kk-kz|kk-latn|kk-tr|kl|km|kn|ko|ko-kp|koi|kr|krc|kri|krj|krl|ks|ks-arab|ks-deva|ksh|ku|ku-arab|ku-latn|kv|kw|ky|la|lad|lb|lbe|lez|lfn|lg|li|lij|liv|lki|lmo|ln|lo|loz|lrc|lt|ltg|lus|luz|lv|lzh|lzz|mai|map-bms|mdf|mg|mh|mhr|mi|min|mk|ml|mn|mo|mr|mrj|ms|mt|mus|mwl|my|myv|mzn|na|nah|nan|nap|nb|nds|nds-nl|ne|new|ng|niu|nl|nl-informal|nn|no|nod|nov|nrm|nso|nv|ny|nys|oc|olo|om|or|os|ota|pa|pag|pam|pap|pcd|pdc|pdt|pfl|pi|pih|pl|pms|pnb|pnt|prg|ps|pt|pt-br|qu|qug|rgn|rif|rm|rmy|rn|ro|roa-rup|roa-tara|ru|rue|rup|ruq|ruq-cyrl|ruq-latn|rw|rwr|sa|sah|sat|sc|scn|sco|sd|sdc|sdh|se|sei|ses|sg|sgs|sh|shi|shi-latn|shi-tfng|shn|si|simple|sje|sk|sl|sli|sm|sma|smj|sn|so|sq|sr|sr-ec|sr-el|srn|srq|ss|st|stq|su|sv|sw|szl|ta|tcy|te|tet|tg|tg-cyrl|tg-latn|th|ti|tk|tl|tly|tn|to|tokipona|tpi|tr|tru|ts|tt|tt-cyrl|tt-latn|tum|tw|ty|tyv|tzm|udm|ug|ug-arab|ug-latn|uk|ur|uz|uz-cyrl|uz-latn|ve|vec|vep|vi|vls|vmf|vo|vot|vro|wa|war|wo|wuu|xal|xh|xmf|yi|yo|yue|za|zea|zh|zh-classical|zh-cn|zh-hans|zh-hant|zh-hk|zh-min-nan|zh-mo|zh-my|zh-sg|zh-tw|zh-yue|zu):/] {
14  throwWarning: tr("wikipedia tag has an unknown language prefix");
15  assertMatch: "node wikipedia=X-Y-Z:Foobar";
16  assertNoMatch: "node wikipedia=en:Foobar";
17}
18
19*[wikipedia =~ /^https?:\/\//],
20*[wikipedia =~ /(?i)^[-a-z]{2,12}:https?:\/\//] {
21  throwWarning: tr("wikipedia tag format is deprecated");
22  suggestAlternative: tr("''wikipedia''=''language:page title''");
23  group: tr("deprecated tagging");
24  assertMatch: "node wikipedia=http://en.wikipedia.org/wiki/OpenStreetMap";
25  assertNoMatch: "node wikipedia=en:OpenStreetMap";
26}
27
28*[wikipedia =~ /^be-x-old:/] {
29  throwWarning: tr("wikipedia ''{0}'' language is obsolete, use ''{1}'' instead", "be-x-old", "be-tarask");
30  fixAdd: concat("wikipedia=be-tarask:", get(regexp_match("^be-x-old:(.+)$", tag("wikipedia")),1));
31  assertMatch: "node wikipedia=be-x-old:foo";
32  assertNoMatch: "node wikipedia=abe-x-old:foo";
33}
34
35*[wikipedia =~ /^cz:/] {
36  throwWarning: tr("wikipedia ''{0}'' language is invalid, use ''{1}'' instead", "cz", "cs");
37  fixAdd: concat("wikipedia=cs:", get(regexp_match("^cz:(.+)$", tag("wikipedia")),1));
38  assertMatch: "node wikipedia=cz:foo";
39  assertNoMatch: "node wikipedia=en:cz:foo";
40}
41
42*[wikimedia_commons =~ /%[0-9A-F][0-9A-F]/] {
43  throwError: tr("{0} tag should not have URL-encoded values like ''%27''", "{0.key}");
44  fixAdd: concat("wikimedia_commons=", trim(replace(URL_decode(tag("wikimedia_commons")), "_", " ")));
45  assertMatch: "node wikimedia_commons=File:Foo%27s";
46  assertNoMatch: "node wikimedia_commons=File:Foo";
47}
48
49*[wikipedia =~ /(?i)^[-a-z]{2,12}:.*%[0-9A-F][0-9A-F]/] {
50  throwError: tr("{0} tag should not have URL-encoded values like ''%27''", "{0.key}");
51  fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)(.*)$", tag("wikipedia")),1), trim(replace(URL_decode(get(regexp_match("(?i)^([-a-z]+:)(.+)$", tag("wikipedia")),2)), "_", " ")));
52  assertMatch: "node wikipedia=en:Foo%27s";
53  assertNoMatch: "node wikipedia=en:Foo";
54}
55
56*[/^wikipedia:[-a-z]{2,12}$/][/^wikipedia:[-a-z]{2,12}$/ =~ /(?i).*%[0-9A-F][0-9A-F]/] {
57  throwError: tr("{0} tag should not have URL-encoded values like ''%27''", "{0.key}");
58  /* fixAdd: concat("{0.key}", "=", get(regexp_match("(?i)^([-a-z]+:)(.*)$", tag("{0.key}")),1), trim(replace(URL_decode(get(regexp_match("(?i)^([-a-z]+:)(.+)$", tag("{0.key}")),2)), "_", " "))); */
59    /* tag("{0.key}") is not yet supported */
60  assertMatch: "node wikipedia:de=Foo%27s";
61  assertNoMatch: "node wikipedia:de=Foo";
62}
63
64*[wikipedia =~ /(?i)^[-a-z]{2,12}: /] {
65  throwWarning: tr("wikipedia title should not start with a space after language code");
66  fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)(.*)$", tag("wikipedia")),1), trim(get(regexp_match("(?i)^([-a-z]+:)(.*)$", tag("wikipedia")),2)));
67  assertMatch: "node wikipedia=en: foo";
68  assertNoMatch: "node wikipedia=en:foo";
69}
70
71*[wikipedia =~ /(?i)^[-a-z]{2,12}:wiki\//] { 
72  throwWarning: tr("wikipedia title should not have ''{0}'' prefix", "wiki/");
73  fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)wiki/(.*)$", tag("wikipedia")),1), trim(get(regexp_match("(?i)^([-a-z]+:)wiki/(.*)$", tag("wikipedia")),2)));
74  assertMatch: "node wikipedia=en:wiki/foo";
75  assertNoMatch: "node wikipedia=en:foo";
76}
77
78/* All wikipedias except "jbo" automatically capitalize first letter of the page title.
79   To see the latest list, see <https://noc.wikimedia.org/conf/highlight.php?file=InitialiseSettings.php>
80   and look for 'wgCapitalLinks' setting. */
81*[wikipedia =~ /^[-a-zA-Z]{2,12}:\p{Ll}/][wikipedia !~ /^jbo:/][wikipedia !~ /(?i)^[-a-z]{2,12}:https?:/] {
82  throwWarning: tr("wikipedia page title should have first letter capitalized");
83  fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)(.)(.*)$", tag("wikipedia")),1), upper(get(regexp_match("(?i)^([-a-z]+:)(.)(.*)$", tag("wikipedia")),2)), get(regexp_match("(?i)^([-a-z]+:)(.)(.*)$", tag("wikipedia")),3));
84  assertMatch: "node wikipedia=en:foo";
85  assertNoMatch: "node wikipedia=en:Foo";
86  assertMatch: "node wikipedia=ru:абв";
87  assertNoMatch: "node wikipedia=ru:Абв";
88}
89
90*[wikipedia =~ /(?i)^[-a-z]{2,12}:.*_/][wikipedia !~ /(?i)^[-a-z]{2,12}:https?:/] {
91  throwWarning: tr("wikipedia page title should have spaces instead of underscores (''_''→'' '')");
92  fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)(.+)$", tag("wikipedia")),1), trim(replace(get(regexp_match("(?i)^([-a-z]+:)(.+)$", tag("wikipedia")),2), "_", " ")));
93  assertMatch: "node wikipedia=en:foo_bar";
94  assertNoMatch: "node wikipedia=en:foo bar";
95}
96
97*[wikipedia ^= "da:da:"],
98*[wikipedia ^= "da:dk:"],
99*[wikipedia ^= "de:de:"],
100*[wikipedia ^= "dk:dk:"],
101*[wikipedia ^= "en:de:"],
102*[wikipedia ^= "en:en:"],
103*[wikipedia ^= "en:es:"],
104*[wikipedia ^= "en:eu:"],
105*[wikipedia ^= "en:fr:"],
106*[wikipedia ^= "en:ja:"],
107*[wikipedia ^= "en:pl:"],
108*[wikipedia ^= "en:pt:"],
109*[wikipedia ^= "en:zh:"],
110*[wikipedia ^= "es:es:"],
111*[wikipedia ^= "eu:eu:"],
112*[wikipedia ^= "fr:fr:"],
113*[wikipedia ^= "ja:ja:"],
114*[wikipedia ^= "pl:en:"],
115*[wikipedia ^= "pl:pl:"],
116*[wikipedia ^= "pt:pt:"],
117*[wikipedia ^= "ru:fr:"],
118*[wikipedia ^= "ru:ru:"],
119*[wikipedia ^= "zh:zh:"] {
120  throwWarning: tr("wikipedia language seems to be duplicated, e.g. en:en:Foo");
121  fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)([-a-z]+:)(.*)$", tag("wikipedia")),2), trim(get(regexp_match("(?i)^([-a-z]+:)([-a-z]+:)(.*)$", tag("wikipedia")),3)));
122  assertMatch: "node wikipedia=en:en:Foo";
123  assertMatch: "node wikipedia=en:fr:Foo";
124  assertNoMatch: "node wikipedia=en:Bar";
125}
126
127/* Detect invalid wikidata tags */
128*[wikidata][wikidata !~ /^Q[1-9][0-9]{0,8}$/] {
129  throwError: tr("wikidata tag must be in Qnnnn format, where n is a digit");
130  assertMatch: "node wikidata=a";
131  assertMatch: "node wikidata=Q";
132  assertMatch: "node wikidata=Q0";
133  assertMatch: "node wikidata=Q0123";
134  assertNoMatch: "node wikidata=Q123";
135  assertNoMatch: "node wikidata=Q1";
136}
137
138/* Wikipedia without wikidata */
139*[wikipedia][!wikidata] {
140  throwOther: tr("wikipedia tag is set, but there is no wikidata tag. Wikipedia plugin might help with wikidata id lookups");
141  group: tr("missing tag");
142  assertMatch: "node wikipedia=a";
143  assertNoMatch: "node wikipedia=a wikidata=Q123";
144  assertNoMatch: "node wikidata=Q1";
145  assertNoMatch: "node foo=bar";
146}
147
148/* Wikipedia:lang without wikipedia */
149*[!wikipedia][/^wikipedia:/] {
150  throwWarning: tr("''{0}'' tag is set, but no ''{1}'' tag. Make sure to set ''wikipedia=language:value'' for the main article and optional ''wikipedia:language=value'' only for additional articles that are not just other language variants of the main article.", "{1.key}", "{0.key}");
151  assertMatch: "node wikipedia:en=a";
152  assertNoMatch: "node wikipedia=a wikipedia:en=b";
153  assertNoMatch: "node wikipedia=Foo";
154}
Note: See TracBrowser for help on using the repository browser.