Line 483: |
Line 483: |
| end | | end |
| return ret, backward | | return ret, backward |
| + | end |
| + | |
| + | --[[ |
| + | Generate Wikidata tracking categories. |
| + | ]] |
| + | local function makeWikidataCategories(qid) |
| + | local ret |
| + | local qid = qid or mw.wikibase.getEntityIdForCurrentPage() |
| + | if mw.wikibase and current_page.namespace == 0 then |
| + | if qid and mw.wikibase.entityExists(qid) and mw.wikibase.getBestStatements(qid, "P625") and mw.wikibase.getBestStatements(qid, "P625")[1] then |
| + | local snaktype = mw.wikibase.getBestStatements(qid, "P625")[1].mainsnak.snaktype |
| + | if snaktype == 'value' then |
| + | -- coordinates exist both here and on Wikidata, and can be compared. |
| + | ret = 'Coordinates on Wikidata' |
| + | elseif snaktype == 'somevalue' then |
| + | ret = 'Coordinates on Wikidata set to unknown value' |
| + | elseif snaktype == 'novalue' then |
| + | ret = 'Coordinates on Wikidata set to no value' |
| + | end |
| + | else |
| + | -- We have to either import the coordinates to Wikidata or remove them here. |
| + | ret = 'Coordinates not on Wikidata' |
| + | end |
| + | end |
| + | if ret then |
| + | return string.format('[[Category:%s]]', ret) |
| + | else |
| + | return '' |
| + | end |
| end | | end |
| | | |
Line 583: |
Line 612: |
| if not tonumber(args[1]) and not args[2] then | | if not tonumber(args[1]) and not args[2] then |
| args[3] = args[1]; args[1] = nil | | args[3] = args[1]; args[1] = nil |
− | | + | local entity = mw.wikibase.getEntityObject(args.qid) |
− | local precision = entity.claims.P625[1].mainsnak.datavalue.value.precision | + | if entity |
− | args[1] = entity.claims.P625[1].mainsnak.datavalue.value.latitude
| + | and entity.claims |
− | args[2] = entity.claims.P625[1].mainsnak.datavalue.value.longitude
| + | and entity.claims.P625 |
− | if precision then
| + | and entity.claims.P625[1].mainsnak.snaktype == 'value' |
− | precision = -math_mod._round(math.log(precision)/math.log(10),0)
| + | then |
− | args[1] = math_mod._round(args[1],precision)
| + | local precision = entity.claims.P625[1].mainsnak.datavalue.value.precision |
− | args[2] = math_mod._round(args[2],precision)
| + | args[1] = entity.claims.P625[1].mainsnak.datavalue.value.latitude |
| + | args[2] = entity.claims.P625[1].mainsnak.datavalue.value.longitude |
| + | if precision then |
| + | precision = -math_mod._round(math.log(precision)/math.log(10),0) |
| + | args[1] = math_mod._round(args[1],precision) |
| + | args[2] = math_mod._round(args[2],precision) |
| + | end |
| end | | end |
| end | | end |
Line 619: |
Line 654: |
| text = text | | text = text |
| .. displaytitle(contents, Notes) | | .. displaytitle(contents, Notes) |
| + | .. makeWikidataCategories(args.qid) |
| end | | end |
| if not args.nosave then | | if not args.nosave then |