/* validation for the wikipedia=* tag - see tickets #8383, #14425 */ /* If there is no language at all, this is broken. Also catches 'wikipedia' used as 'email', 'website', 'ele' [sic!] ... */ *[wikipedia][wikipedia !~ /(?i)^[-a-z]{2,12}:/] { throwError: tr("wikipedia tag has no language given, use ''wikipedia''=''language:page title''"); assertMatch: "node wikipedia=Foobar"; assertNoMatch: "node wikipedia=en:Foobar"; assertNoMatch: "node wikipedia=en-GB:Foobar"; } /* Valid languages are extracted from (languages field), which may change, so this is a warning only. Also includes "cz" and "be-x-old" because they can be auto-fixed */ *[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):/] { throwWarning: tr("wikipedia tag has an unknown language prefix"); assertMatch: "node wikipedia=X-Y-Z:Foobar"; assertNoMatch: "node wikipedia=en:Foobar"; } *[wikipedia =~ /^https?:\/\//], *[wikipedia =~ /(?i)^[-a-z]{2,12}:https?:\/\//] { throwWarning: tr("wikipedia tag format is deprecated"); suggestAlternative: tr("''wikipedia''=''language:page title''"); group: tr("deprecated tagging"); assertMatch: "node wikipedia=http://en.wikipedia.org/wiki/OpenStreetMap"; assertNoMatch: "node wikipedia=en:OpenStreetMap"; } *[wikipedia =~ /^be-x-old:/] { throwWarning: tr("wikipedia ''{0}'' language is obsolete, use ''{1}'' instead", "be-x-old", "be-tarask"); fixAdd: concat("wikipedia=be-tarask:", get(regexp_match("^be-x-old:(.+)$", tag("wikipedia")),1)); assertMatch: "node wikipedia=be-x-old:foo"; assertNoMatch: "node wikipedia=abe-x-old:foo"; } *[wikipedia =~ /^cz:/] { throwWarning: tr("wikipedia ''{0}'' language is invalid, use ''{1}'' instead", "cz", "cs"); fixAdd: concat("wikipedia=cs:", get(regexp_match("^cz:(.+)$", tag("wikipedia")),1)); assertMatch: "node wikipedia=cz:foo"; assertNoMatch: "node wikipedia=en:cz:foo"; } *[wikimedia_commons =~ /%[0-9A-F][0-9A-F]/] { throwError: tr("{0} tag should not have URL-encoded values like ''%27''", "{0.key}"); fixAdd: concat("wikimedia_commons=", trim(replace(URL_decode(tag("wikimedia_commons")), "_", " "))); assertMatch: "node wikimedia_commons=File:Foo%27s"; assertNoMatch: "node wikimedia_commons=File:Foo"; } *[wikipedia =~ /(?i)^[-a-z]{2,12}:.*%[0-9A-F][0-9A-F]/] { throwError: tr("{0} tag should not have URL-encoded values like ''%27''", "{0.key}"); 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)), "_", " "))); assertMatch: "node wikipedia=en:Foo%27s"; assertNoMatch: "node wikipedia=en:Foo"; } *[wikipedia =~ /(?i)^[-a-z]{2,12}: /] { throwWarning: tr("wikipedia title should not start with a space after language code"); fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)(.*)$", tag("wikipedia")),1), trim(get(regexp_match("(?i)^([-a-z]+:)(.*)$", tag("wikipedia")),2))); assertMatch: "node wikipedia=en: foo"; assertNoMatch: "node wikipedia=en:foo"; } *[wikipedia =~ /(?i)^[-a-z]{2,12}:wiki\//] { throwWarning: tr("wikipedia title should not have ''{0}'' prefix", "wiki/"); fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)wiki/(.*)$", tag("wikipedia")),1), trim(get(regexp_match("(?i)^([-a-z]+:)wiki/(.*)$", tag("wikipedia")),2))); assertMatch: "node wikipedia=en:wiki/foo"; assertNoMatch: "node wikipedia=en:foo"; } /* All wikipedias except "jbo" automatically capitalize first letter of the page title. To see the latest list, see and look for 'wgCapitalLinks' setting. */ *[wikipedia =~ /^[-a-zA-Z]{2,12}:\p{Ll}/][wikipedia !~ /^jbo:/][wikipedia !~ /(?i)^[-a-z]{2,12}:https?:/] { throwWarning: tr("wikipedia page title should have first letter capitalized"); 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)); assertMatch: "node wikipedia=en:foo"; assertNoMatch: "node wikipedia=en:Foo"; assertMatch: "node wikipedia=ru:абв"; assertNoMatch: "node wikipedia=ru:Абв"; } *[wikipedia =~ /(?i)^[-a-z]{2,12}:.*_/][wikipedia !~ /(?i)^[-a-z]{2,12}:https?:/] { throwWarning: tr("wikipedia page title should have spaces instead of underscores (''_''→'' '')"); fixAdd: concat("wikipedia=", get(regexp_match("(?i)^([-a-z]+:)(.+)$", tag("wikipedia")),1), trim(replace(get(regexp_match("(?i)^([-a-z]+:)(.+)$", tag("wikipedia")),2), "_", " "))); assertMatch: "node wikipedia=en:foo_bar"; assertNoMatch: "node wikipedia=en:foo bar"; } *[wikipedia ^= "da:da:"], *[wikipedia ^= "da:dk:"], *[wikipedia ^= "de:de:"], *[wikipedia ^= "dk:dk:"], *[wikipedia ^= "en:de:"], *[wikipedia ^= "en:en:"], *[wikipedia ^= "en:es:"], *[wikipedia ^= "en:eu:"], *[wikipedia ^= "en:fr:"], *[wikipedia ^= "en:ja:"], *[wikipedia ^= "en:pl:"], *[wikipedia ^= "en:pt:"], *[wikipedia ^= "en:zh:"], *[wikipedia ^= "es:es:"], *[wikipedia ^= "eu:eu:"], *[wikipedia ^= "fr:fr:"], *[wikipedia ^= "ja:ja:"], *[wikipedia ^= "pl:en:"], *[wikipedia ^= "pl:pl:"], *[wikipedia ^= "pt:pt:"], *[wikipedia ^= "ru:fr:"], *[wikipedia ^= "ru:ru:"], *[wikipedia ^= "zh:zh:"] { throwWarning: tr("wikipedia language seems to be duplicated, e.g. en:en:Foo"); 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))); assertMatch: "node wikipedia=en:en:Foo"; assertMatch: "node wikipedia=en:fr:Foo"; assertNoMatch: "node wikipedia=en:Bar"; } /* Detect invalid wikidata tags */ *[wikidata][wikidata !~ /^Q[1-9][0-9]{0,8}$/] { throwError: tr("wikidata tag must be in Qnnnn format, where n is a digit"); assertMatch: "node wikidata=a"; assertMatch: "node wikidata=Q"; assertMatch: "node wikidata=Q0"; assertMatch: "node wikidata=Q0123"; assertNoMatch: "node wikidata=Q123"; assertNoMatch: "node wikidata=Q1"; } /* Wikipedia without wikidata */ *[wikipedia][!wikidata] { throwOther: tr("wikipedia tag is set, but there is no wikidata tag. Wikipedia plugin might help with wikidata id lookups"); group: tr("missing tag"); assertMatch: "node wikipedia=a"; assertNoMatch: "node wikipedia=a wikidata=Q123"; assertNoMatch: "node wikidata=Q1"; assertNoMatch: "node foo=bar"; } /* Wikipedia without wikidata */ *[!wikipedia][/^wikipedia:/] { throwWarning: tr("wikipedia tag is not set, but a ''{0}'' tag is. Make sure to use wikipedia=language:value together with wikidata tag.", "{1.key}"); assertMatch: "node wikipedia:en=a"; assertNoMatch: "node wikipedia=a wikipedia:en=b"; assertNoMatch: "node wikipedia=Foo"; }