「モジュール:Wikidata label」の版間の差分

use require('strict') instead of require('Module:No globals')
(1版 をインポートしました)
bsd>WOSlinker
(use require('strict') instead of require('Module:No globals'))
17行目: 17行目:
]]
]]


require('Module:No globals') -- used for debugging purposes as it detects cases of unintended global variables
require('strict') -- used for debugging purposes as it detects cases of unintended global variables


--=============================================
--=============================================
125行目: 125行目:
-- INPUTS:
-- INPUTS:
--  * label - label string
--  * label - label string
--  * capitalization - capitalization to be applied: allowed values are "lc",
--  * capitalization - capitalization to be applied: allowed values are "tc", "lc",
--      "uc", "lcfirst", and "ucfirst". Any other value will return original string
--      "uc", "lcfirst", and "ucfirst". Any other value will return original string
--  * lang - language of the label
--  * lang - language of the label
135行目: 135行目:
return label
return label
elseif capitalization == 'uc' then
elseif capitalization == 'uc' then
return mw.ustring.upper(label)
return mw.language.new(lang):uc(label)
elseif capitalization == 'lc' then
return mw.language.new(lang):lc(label)
elseif capitalization == 'tc' then -- title case
local new_label = {}
for _, word in ipairs(mw.text.split(label, ' ')) do
table.insert(new_label, mw.language.new(lang):ucfirst(word))
end
return table.concat(new_label, ' ')
elseif capitalization == 'ucfirst' then
elseif capitalization == 'ucfirst' then
return mw.language.new(lang):ucfirst(label)
return mw.language.new(lang):ucfirst(label)
elseif capitalization == 'lc' then
return mw.ustring.lower(label)
elseif capitalization == 'lcfirst' then
elseif capitalization == 'lcfirst' then
return mw.language.new(lang):lcfirst(label)
return mw.language.new(lang):lcfirst(label)
251行目: 257行目:
]]
]]
function p._getLabel(item, lang, link_type, capitalization, show_id)
function p._getLabel(item, lang, link_type, capitalization, show_id)
local entity, s, link, label, language
local entity, s, link, label, language, desc


-- clean up the input parameters
-- clean up the input parameters
285行目: 291行目:
if label then break end                    -- label found and we are done
if label then break end                    -- label found and we are done
end
end
end
if label then  -- wikitext-escape the label if we have one
label = mw.text.nowiki(label)
end
end
if not label then                              -- no labels found, so just show the q-id
if not label then                              -- no labels found, so just show the q-id
298行目: 307行目:
end
end
label = apply_capitalization(label, capitalization, lang)
label = apply_capitalization(label, capitalization, lang)
-- look for description
if  entity and entity.descriptions and lang then
for _, language in ipairs(langList) do
if entity.descriptions[language] then
desc = entity.descriptions[language].value
break
end
end
else
desc = mw.wikibase.getDescription(item)
end
if desc and link_type ~= '-' then  -- wikitext-escape the description if we have one
desc = mw.text.nowiki(desc) -- add description as hover text
label = '<span title="' .. desc .. '">' .. label .. '</span>'
end


-- return the results
-- return the results
424行目: 449行目:
2: language (optional; default {{int:lang}})
2: language (optional; default {{int:lang}})
3: link_style: "wikipedia" (default), "Wikidata", "Commons", or "-" (no link)
3: link_style: "wikipedia" (default), "Wikidata", "Commons", or "-" (no link)
4: capitalization - can be "uc", "lc", "ucfirst", "lcfirst"
4: capitalization - can be "uc", "lc", "tc", "ucfirst", "lcfirst"


Error Handling:
Error Handling:
匿名利用者