Module:DescriptionFromDataItem and Module:DescriptionFromDataItem/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
Content deleted Content added
Minh Nguyen (talk | contribs)
No edit summary
 
m Change sorting order in Category:Mismatched description
 
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local titleParser = require('Module:OsmPageTitleParser')
local titleParser = require('Module:OsmPageTitleParser/sandbox')
local data = mw.loadData('Module:DescriptionFromDataItem/data')
local data = mw.loadData('Module:DescriptionFromDataItem/data')
local i18n = data.translations
local i18n = data.translations
Line 36: Line 36:
p.Q_LIMIT = { id = 'P26' }
p.Q_LIMIT = { id = 'P26' }
p.KEY_ID = { id = 'P16', fallback = true }
p.KEY_ID = { id = 'P16', fallback = true }
p.KEY_PREFIX_ID = { id = 'P52', fallback = true }
p.PREFIX_ID = { id = 'P52' }
p.KEY_SUFFIX_ID = { id = 'P53', fallback = true }
p.SUFFIX_ID = { id = 'P53' }
p.TAG_ID = { id = 'P19' }
p.TAG_ID = { id = 'P19' }
p.TAG_KEY = { id = 'P10' }
p.TAG_KEY = { id = 'P10' }
Line 72: Line 72:
p.USE_ON_AREAS = { id = 'P35', map = use_on_values }
p.USE_ON_AREAS = { id = 'P35', map = use_on_values }
p.USE_ON_RELATIONS = { id = 'P36', map = use_on_values }
p.USE_ON_RELATIONS = { id = 'P36', map = use_on_values }
p.USE_ON_CHANGESETS = { id = 'P37', map = use_on_values }


-- Makes it possible to override by unit tests
-- Makes it possible to override by unit tests
Line 203: Line 202:
return { eKey }
return { eKey }
end
end
eKey = p.getClaimValue(p.KEY_PREFIX_ID, 'en', entity)
if eKey then
return { eKey .. ':' }
end
eKey = p.getClaimValue(p.KEY_SUFFIX_ID, 'en', entity)
if eKey then
return { ':' .. eKey }
end
else
else
return { eKey, eValue }
return { eKey, eValue }
Line 260: Line 251:
return entity:getBestStatements(prop.id)
return entity:getBestStatements(prop.id)
elseif prop.id == 'P28' and langCode == 'en' then
elseif prop.id == 'P28' and langCode == 'en' then
return entity:getBestStatements(prop.id)
-- For multiple images, get the best (the image with the highest rank, e.g. "preferred") in case of English description page.
return entity:getBestStatements(prop.id)
else
else
return entity:getAllStatements(prop.id)
return entity:getAllStatements(prop.id)
Line 342: Line 332:


local function validateKeyValue(self)
local function validateKeyValue(self)
if self.args.type == 'key-prefix' or self.args.type == 'key-suffix' or self.args.type == 'relation' then
if self.args.type == 'relation' then
-- Ignore for key-prefixes, key-suffixes and relations
-- Ignore for relations
return
return
end
end
Line 368: Line 358:
local function getCategories(self)
local function getCategories(self)
if next(self.categories) ~= nil then
if next(self.categories) ~= nil then
local sortkey = formatKeyVal(self.key, self.value)
local sortkey = formatKeyVal(self.key, self.value)
local prefix = '[[Category:'
local prefix = '[[Category:'
local suffix = sortkey and '|' .. sortkey .. ']]' or ']]'
local suffix = sortkey and '|' .. sortkey .. ']]' or ']]'
Line 433: Line 423:
args[argname] = formatValue(self, pageVal, qid)
args[argname] = formatValue(self, pageVal, qid)
elseif argname == 'image' and pageVal:gsub(" ", "_") == 'Image:' .. getItemValue(self, p.IMAGE):gsub(" ", "_") then
elseif argname == 'image' and pageVal:gsub(" ", "_") == 'Image:' .. getItemValue(self, p.IMAGE):gsub(" ", "_") then
do return end
do return end -- Doesn't add "Category:Mismatched image" if "|image=" on wiki page is set with "Image:" instead of "File:"
elseif argname == 'image' and pageVal:gsub(" ", "_") == 'image:' .. getItemValue(self, p.IMAGE):gsub(" ", "_") then
elseif argname == 'image' and pageVal:gsub(" ", "_") == 'image:' .. getItemValue(self, p.IMAGE):gsub(" ", "_") then
do return end
do return end -- Doesn't add "Category:Mismatched image" if "|image=" on wiki page is set with "image:" instead of "File:"
elseif argname == 'image' and pageVal:gsub(" ", "_") == 'File:' .. getItemValue(self, p.IMAGE):gsub(" ", "_") then
elseif argname == 'image' and pageVal:gsub(" ", "_") == 'File:' .. getItemValue(self, p.IMAGE):gsub(" ", "_") then
args[argname] = formatValue(self, pageVal, qid)
args[argname] = formatValue(self, pageVal, qid)
Line 451: Line 441:
if ns == 0 or ns > 15 then
if ns == 0 or ns > 15 then
if self.langCode == 'en' then
if self.langCode == 'en' then
table.insert(self.categories, 'Mismatched ' .. argname .. ' in default namespace')
table.insert(self.categories, 'Mismatched ' .. argname .. ' in default namespace')
end
end
if argname == 'description' then
if argname == 'description' then
Line 485: Line 475:


validateKeyValue(self)
validateKeyValue(self)

processValue(self, 'project')


-- Compare all known parameters against the data item entity
-- Compare all known parameters against the data item entity
Line 507: Line 495:
processValue(self, 'osmcarto-rendering', render and 'File:' .. render or nil)
processValue(self, 'osmcarto-rendering', render and 'File:' .. render or nil)


-- Handle onRelation, onArea, onWay, onNode, and onChangeset
-- Handle onRelation, onArray, onWay, and onNode
if args.type ~= 'relation' then
if args.type ~= 'relation' then
processValue(self, 'onNode', getItemValue(self, p.USE_ON_NODES), normalizeBoolean(args.onNode))
processValue(self, 'onNode', getItemValue(self, p.USE_ON_NODES), normalizeBoolean(args.onNode))
Line 513: Line 501:
processValue(self, 'onArea', getItemValue(self, p.USE_ON_AREAS), normalizeBoolean(args.onArea))
processValue(self, 'onArea', getItemValue(self, p.USE_ON_AREAS), normalizeBoolean(args.onArea))
processValue(self, 'onRelation', getItemValue(self, p.USE_ON_RELATIONS), normalizeBoolean(args.onRelation))
processValue(self, 'onRelation', getItemValue(self, p.USE_ON_RELATIONS), normalizeBoolean(args.onRelation))
processValue(self, 'onChangeset', getItemValue(self, p.USE_ON_CHANGESETS), normalizeBoolean(args.onChangeset))
end
end
Line 605: Line 592:
end
end
else
else
if ns == 0 and self.langCode == 'en' and not args.debug then
if ns == 0 and self.langCode == 'en' then
if args.status == 'approved' or args.status == 'Approved' then
if args.status == 'approved' or args.status == 'Approved' then
table.insert(self.categories, 'Missing data item for approved tag')
table.insert(self.categories, 'Missing data item for approved tag')
Line 612: Line 599:
elseif args.status == 'in use' or args.status == 'In use' then
elseif args.status == 'in use' or args.status == 'In use' then
table.insert(self.categories, 'Missing data item for tag in use')
table.insert(self.categories, 'Missing data item for tag in use')
elseif args.status ~= 'deprecated' then
else
table.insert(self.categories, 'Missing data item for unestablished tag')
table.insert(self.categories, 'Missing data item for unestablished tag')
end
end
Line 652: Line 639:
elseif args.templatename and string.find(args.templatename, 'ValueDescription', 1, true) then
elseif args.templatename and string.find(args.templatename, 'ValueDescription', 1, true) then
args.type = 'value'
args.type = 'value'
elseif args.templatename and string.find(args.templatename, 'KeyPrefixDescription', 1, true) then
args.type = 'key-prefix'
elseif args.templatename and string.find(args.templatename, 'KeySuffixDescription', 1, true) then
args.type = 'key-suffix'
elseif args.templatename and string.find(args.templatename, 'RelationDescription', 1, true) then
elseif args.templatename and string.find(args.templatename, 'RelationDescription', 1, true) then
args.type = 'relation'
args.type = 'relation'
Line 731: Line 722:
local result = ''
local result = ''
for _, val in pairs(args[arg]) do
for _, val in pairs(args[arg]) do
local title = 'Tag'
result = result .. '* ' .. frame:expandTemplate { title = 'Tag', args = val } .. '\n'
if val[1]:sub(-1) == ':' then
title = 'Prefix'
val[1] = val[1]:sub(1, #val[1] - 1)
elseif val[1]:sub(1, 1) == ':' then
title = 'Suffix'
val[1] = val[1]:sub(2)
end
result = result .. '* ' .. frame:expandTemplate { title = title, args = val } .. '\n'
end
end
if result ~= '' then
if result ~= '' then
Line 802: Line 785:
processValue(self, 'osmcarto-rendering', render and 'File:' .. render or nil)
processValue(self, 'osmcarto-rendering', render and 'File:' .. render or nil)


-- Handle onRelation, onArea, onWay, onNode, and onChangeset
-- Handle onRelation, onArray, onWay, and onNode
processValue(self, 'onNode', getItemValue(self, p.USE_ON_NODES), normalizeBoolean(args.onNode))
processValue(self, 'onNode', getItemValue(self, p.USE_ON_NODES), normalizeBoolean(args.onNode))
processValue(self, 'onWay', getItemValue(self, p.USE_ON_WAYS), normalizeBoolean(args.onWay))
processValue(self, 'onWay', getItemValue(self, p.USE_ON_WAYS), normalizeBoolean(args.onWay))
processValue(self, 'onArea', getItemValue(self, p.USE_ON_AREAS), normalizeBoolean(args.onArea))
processValue(self, 'onArea', getItemValue(self, p.USE_ON_AREAS), normalizeBoolean(args.onArea))
processValue(self, 'onRelation', getItemValue(self, p.USE_ON_RELATIONS), normalizeBoolean(args.onRelation))
processValue(self, 'onRelation', getItemValue(self, p.USE_ON_RELATIONS), normalizeBoolean(args.onRelation))
processValue(self, 'onChangeset', getItemValue(self, p.USE_ON_CHANGESETS), normalizeBoolean(args.onChangeset))
end
end