Template:CityLocativefromCat/doc
Jump to navigation
Jump to search
Purpose
[edit]Note that this technique does not work with all languages, because not all of them use the locative form in their "Births in" categories (pt and tr are examples of this)
Assumptions
[edit]Input
[edit]- P1 expects a city's QID or its Commons category, which is generally its English name. The "Category" namespace prefix is optional.
- Q270 → Warsaw (Q270)
- Warsaw → Category:Warsaw → Warsaw (Q270)
- Category:Warsaw → Category:Warsaw → Warsaw (Q270)
- Warszawa → Category:Warszawa
Todo
[edit]- Create template that checks whether input is "Category:XXXX", "XXXX", or "Qnnnn"
- Assume that all non-Qnnnn inputs refer to the Category?
What is more expensive? A wikidata call or mediawiki logic? if prefix * ///"Category:" or "Cat:": normalize to "Category" and continue with the complex nested calls starting with the category. * Category: * something else: ** Assume it is a Qnnn; * if QID is valid ** check "instance of" **** if category: get Category's main topic (P301) **** if page: continue with the complex nested calls starting with the PAGE. * if QID is invalid ** append "Category:" and try again. if it fails, return error: "P1 not a valid category"
Simpler redesign
[edit]- P373 = Commons category
- EXPECT a Commons category (in either of these formats: "Category:Warsaw" or "Warsaw", or q="Q270")
- Category: <<<
{{wdt|Q|Category:Istanbul}}
{{#switch: {{#iferror: {{wdt|S.q|{{wdt|Q|{{{id|Category:{{PAGENAME:{{{1|}}}}}}}}|{{{id|Category:{{PAGENAME:{{{1|}}}}}}}}}}|P373}}}} | not | correct }}
latest
[edit]{{#switch: {{wdt|Q|{{{id|Category:{{PAGENAME:{{{1|}}}}}}}}|{{{id|Category:{{PAGENAME:{{{1|}}}}}}}}|error-invalidID}}<!-- assume Category or category QID and fail otherwise.--> |error-invalidID=Invalid ID provided. |#default={{#iferror: {{wdt|S.q|{{wdt|Q|{{{id|Category:{{PAGENAME:{{{1|}}}}}}}}|{{{id|Category:{{PAGENAME:{{{1|}}}}}}}}}}|P373}} <!-- -->|{{red|error getting P373 ("{{label|P373}}")}} <!-- -->|P373 {{label|P373}} found. <!-- -->}} }}
Tests (disabled as the code do not work yet)
[edit]{{CityLocativefromCat|Q270|pl}}
{{CityLocativefromCat|Q6892020|pl}}
{{CityLocativefromCat|id=Q270|pl}}
{{CityLocativefromCat|id=Q6892020|pl}}
{{CityLocativefromCat|id=Q270||pl}}
Examples (disabled as the code do not work yet)
[edit]{{CityLocativefromCat|Q270|pl}}
{{CityLocativefromCat|Warsaw|pl}}
{{CityLocativefromCat|Category:Warsaw|pl}}
{{CityLocativefromCat|Category:Warsaw|en}}
{{CityLocativefromCat|Q5465|be}}
{{CityLocativefromCat|Q5465|bg}}
{{CityLocativefromCat|Q5465|cs}}
{{CityLocativefromCat|Q5465|en}}
{{CityLocativefromCat|Q5465|es}}
{{CityLocativefromCat|Q5465|eu}}
{{CityLocativefromCat|Category:Cape Town|eu}}
{{CityLocativefromCat|Q5465|fr}}
{{CityLocativefromCat|Q5465|it}}
{{CityLocativefromCat|Q5465|pl}}
{{CityLocativefromCat|Q5465|pt}}
//not locative{{CityLocativefromCat|Q5465|ru}}
{{CityLocativefromCat|Q5465|tr}}
//not locative{{CityLocativefromCat|Q5465|vo}}
Calls
[edit]Dependencies
[edit]- {{IfStrCategory}} – helps determine whether passed parameter is a category or not, so the appropriate Wikidata calls are made.
Used by
[edit]- {{CityLocative}}