Modul:Taxonbar: Versiyalar orasidagi farq
Programmer (munozara | hissa) Oʻzbekcha Vikipediyadan import qilindi. |
zs-wikidata-inert: Wikibase klienti yoʻqligida Wikidata xatolarini bostirish |
||
| (3 oraliq tahrir tomonidan 2 foydalanuvchi koʻrsatilmagan) | |||
| Qator 1: | Qator 1: | ||
-- [zs-wikidata-inert] With no Wikibase client every from=Q… lookup returns | |||
-- nil, so this module can only emit "not a valid Wikidata entity ID" errors | |||
-- and Wikidata tracking categories. Both are suppressed below while the | |||
-- mw.wikibase stub is in force. Auto-added on import. | |||
local zs_no_wikibase = mw.wikibase == nil or mw.wikibase.zsProbeNoSuchKey ~= nil | |||
-- [zs-wikibase-guard] Ziyosfera has no Wikibase client; stub mw.wikibase so | |||
-- modules reading Wikidata degrade to nil instead of erroring. Auto-added on import. | |||
if not mw.wikibase then mw.wikibase = setmetatable({}, { __index = function() return function() return nil end end }) end | |||
require('strict') | require('strict') | ||
local conf = require( 'Module:Taxonbar/conf' ) --configuration module | local conf = require( 'Module:Taxonbar/conf' ) --configuration module | ||
local TaxonItalics = require( 'Module:TaxonItalics' ) --use a function to conditionally italicize taxon names | local TaxonItalics = require( 'Module:TaxonItalics' ) --use a function to conditionally italicize taxon names | ||
-- Ziyosfera compatibility: run safely even when Wikibase is not installed. | |||
local hasWikibase = type(mw.wikibase) == 'table' | |||
local function wikibaseGetEntity(id) | |||
if not hasWikibase or type(mw.wikibase.getEntity) ~= 'function' then | |||
return nil | |||
end | |||
if id == nil or id == '' then | |||
return nil | |||
end | |||
local ok, entity = pcall(function() | |||
return mw.wikibase.getEntity(id) | |||
end) | |||
if ok then | |||
return entity | |||
end | |||
return nil | |||
end | |||
local function wikibaseGetEntityIdForCurrentPage() | |||
if not hasWikibase or type(mw.wikibase.getEntityIdForCurrentPage) ~= 'function' then | |||
return nil | |||
end | |||
local ok, id = pcall(function() | |||
return mw.wikibase.getEntityIdForCurrentPage() | |||
end) | |||
if ok then | |||
return id | |||
end | |||
return nil | |||
end | |||
local function getBestStatements(entity, property) | |||
if not entity or type(entity.getBestStatements) ~= 'function' then | |||
return {} | |||
end | |||
local ok, statements = pcall(function() | |||
return entity:getBestStatements(property) | |||
end) | |||
if ok and type(statements) == 'table' then | |||
return statements | |||
end | |||
return {} | |||
end | |||
local function getBestStatement(entity, property, index) | |||
return getBestStatements(entity, property)[index or 1] | |||
end | |||
local function getEntityLabel(entity) | |||
if not entity or type(entity.getLabel) ~= 'function' then | |||
return nil | |||
end | |||
local ok, label = pcall(function() | |||
return entity:getLabel() | |||
end) | |||
if ok then | |||
return label | |||
end | |||
return nil | |||
end | |||
--[[==========================================================================]] | --[[==========================================================================]] | ||
| Qator 37: | Qator 107: | ||
end | end | ||
]] | ]] | ||
local statements = item | local statements = getBestStatement(item, property) | ||
if statements and | if statements and | ||
statements.mainsnak and | statements.mainsnak and | ||
| Qator 58: | Qator 128: | ||
else | else | ||
if type(property) == 'number' and property > 0 then | if type(property) == 'number' and property > 0 then | ||
local entityObject = | local entityObject = wikibaseGetEntity('P'..property) | ||
local dataType | local dataType | ||
| Qator 70: | Qator 140: | ||
property == 5397 --Tierstimmenarchiv | property == 5397 --Tierstimmenarchiv | ||
then | then | ||
formatterURL = entityObject | formatterURL = getBestStatement(entityObject, 'P1630', 2) --use 2nd formatterURL for English version | ||
end | end | ||
if formatterURL == nil then formatterURL = entityObject | if formatterURL == nil then formatterURL = getBestStatement(entityObject, 'P1630') end --default to [1] | ||
if formatterURL then | if formatterURL then | ||
if formatterURL.mainsnak.datavalue and formatterURL.mainsnak.datavalue.value then --nil check for ABA | if formatterURL.mainsnak.datavalue and formatterURL.mainsnak.datavalue.value then --nil check for ABA | ||
| Qator 82: | Qator 152: | ||
end | end | ||
elseif dataType == 'url' then | elseif dataType == 'url' then | ||
local subjectItem = entityObject | local subjectItem = getBestStatement(entityObject, 'P1629') | ||
if subjectItem then | if subjectItem then | ||
local | local subjectId = subjectItem.mainsnak.datavalue.value.id | ||
if officialWebsite then link = officialWebsite.mainsnak.datavalue.value end | local subjectEntity = wikibaseGetEntity(subjectId) | ||
local officialWebsite = getBestStatement(subjectEntity, 'P856') | |||
if officialWebsite and officialWebsite.mainsnak and officialWebsite.mainsnak.datavalue then | |||
link = officialWebsite.mainsnak.datavalue.value | |||
end | |||
end | end | ||
elseif dataType == 'string' then | elseif dataType == 'string' then | ||
local formatterURL = entityObject | local formatterURL = getBestStatement(entityObject, 'P1630') | ||
if formatterURL then | if formatterURL then | ||
link = formatterURL.mainsnak.datavalue.value | link = formatterURL.mainsnak.datavalue.value | ||
else | else | ||
local subjectItem = entityObject | local subjectItem = getBestStatement(entityObject, 'P1629') | ||
if subjectItem then | if subjectItem then | ||
local | local subjectId = subjectItem.mainsnak.datavalue.value.id | ||
if officialWebsite then link = officialWebsite.mainsnak.datavalue.value end | local subjectEntity = wikibaseGetEntity(subjectId) | ||
local officialWebsite = getBestStatement(subjectEntity, 'P856') | |||
if officialWebsite and officialWebsite.mainsnak and officialWebsite.mainsnak.datavalue then | |||
link = officialWebsite.mainsnak.datavalue.value | |||
end | |||
end | end | ||
end | end | ||
| Qator 155: | Qator 233: | ||
function p.authorityControlTaxon( frame ) | function p.authorityControlTaxon( frame ) | ||
local resolveEntity = require | local resolveEntity = nil | ||
do | |||
local ok, mod = pcall(require, 'Module:ResolveEntityId') | |||
if ok and type(mod) == 'table' then | |||
resolveEntity = mod | |||
end | |||
end | |||
local function resolveEntityId(value) | |||
if not resolveEntity or type(resolveEntity._id) ~= 'function' then | |||
return nil | |||
end | |||
local ok, id = pcall(resolveEntity._id, value) | |||
if ok then | |||
return id | |||
end | |||
return nil | |||
end | |||
local parentArgs = copyTable(frame:getParent().args) | local parentArgs = copyTable(frame:getParent().args) | ||
local currentTitle = mw.title.getCurrentTitle() | local currentTitle = mw.title.getCurrentTitle() | ||
local currentEntityId = | local currentEntityId = wikibaseGetEntityIdForCurrentPage() | ||
local stringArgs = false | local stringArgs = false | ||
| Qator 224: | Qator 318: | ||
local currentItem = nil | local currentItem = nil | ||
if currentTitle.namespace == 10 then --i.e. Module:Taxonbar/sandbox, Template:Taxonbar/doc, etc. | if currentTitle.namespace == 10 then --i.e. Module:Taxonbar/sandbox, Template:Taxonbar/doc, etc. | ||
if | if resolveEntityId(parentArgs['from']) then | ||
currentItem = | currentItem = wikibaseGetEntity(parentArgs['from']) | ||
end | end | ||
if currentItem == nil then | if currentItem == nil then | ||
if | if resolveEntityId(parentArgs['from1']) then | ||
currentItem = | currentItem = wikibaseGetEntity(parentArgs['from1']) | ||
end | end | ||
end | end | ||
elseif | elseif resolveEntityId(currentEntityId) then | ||
currentItem = | currentItem = wikibaseGetEntity(currentEntityId) | ||
else --currentEntityId == nil/unresolvable | else --currentEntityId == nil/unresolvable | ||
tCats[3] = '[[Turkum:Taxonbar pages requiring a Wikidata item]]' | tCats[3] = '[[Turkum:Taxonbar pages requiring a Wikidata item]]' | ||
| Qator 239: | Qator 333: | ||
if currentItem then | if currentItem then | ||
tCats[4] = '[[Turkum:Taxonbars on possible non-taxon pages]]' --unset if acceptable found | tCats[4] = '[[Turkum:Taxonbars on possible non-taxon pages]]' --unset if acceptable found | ||
for _, instanceOfState in pairs ( | for _, instanceOfState in pairs ( getBestStatements(currentItem, 'P31') ) do --instance of | ||
local instanceOf = instanceOfState.mainsnak.datavalue.value.id | local instanceOf = instanceOfState.mainsnak.datavalue.value.id | ||
if acceptableInstanceOf_All[instanceOf] then | if acceptableInstanceOf_All[instanceOf] then | ||
| Qator 354: | Qator 448: | ||
--Append basionym to arg list, if not already provided | --Append basionym to arg list, if not already provided | ||
if currentItem then | if currentItem then | ||
local currentBasState = currentItem | local currentBasState = getBestStatement(currentItem, 'P566') --basionym | ||
if currentBasState then | if currentBasState then | ||
local basionymId = currentBasState.mainsnak.datavalue.value.id | local basionymId = currentBasState.mainsnak.datavalue.value.id | ||
if basionymId and | if basionymId and resolveEntityId(basionymId) and tFroms[basionymId] == nil then | ||
--check that basionym is a strict instance of taxon | --check that basionym is a strict instance of taxon | ||
local basionymItem = | local basionymItem = wikibaseGetEntity(basionymId) | ||
if basionymItem then | if basionymItem then | ||
for _, instanceOfState in pairs ( | for _, instanceOfState in pairs ( getBestStatements(basionymItem, 'P31') ) do --instance of | ||
local instanceOf = instanceOfState.mainsnak.datavalue.value.id | local instanceOf = instanceOfState.mainsnak.datavalue.value.id | ||
if acceptableInstanceOf_Strict[instanceOf] then | if acceptableInstanceOf_Strict[instanceOf] then | ||
| Qator 376: | Qator 470: | ||
--Append original combination to arg list, if not already provided | --Append original combination to arg list, if not already provided | ||
if currentItem then | if currentItem then | ||
local currentOCState = currentItem | local currentOCState = getBestStatement(currentItem, 'P1403') --original combination | ||
if currentOCState then | if currentOCState then | ||
local orcoId = currentOCState.mainsnak.datavalue.value.id | local orcoId = currentOCState.mainsnak.datavalue.value.id | ||
if orcoId and | if orcoId and resolveEntityId(orcoId) and tFroms[orcoId] == nil then | ||
--check that orco is a strict instance of taxon | --check that orco is a strict instance of taxon | ||
local orcoItem = | local orcoItem = wikibaseGetEntity(orcoId) | ||
if orcoItem then | if orcoItem then | ||
for _, instanceOfState in pairs ( | for _, instanceOfState in pairs ( getBestStatements(orcoItem, 'P31') ) do --instance of | ||
local instanceOf = instanceOfState.mainsnak.datavalue.value.id | local instanceOf = instanceOfState.mainsnak.datavalue.value.id | ||
if acceptableInstanceOf_Strict[instanceOf] then | if acceptableInstanceOf_Strict[instanceOf] then | ||
| Qator 398: | Qator 492: | ||
--Append monotypic genus/species to arg list of monotypic species/genus, if not already provided | --Append monotypic genus/species to arg list of monotypic species/genus, if not already provided | ||
if currentItem then | if currentItem then | ||
for _, instanceOfState in pairs ( | for _, instanceOfState in pairs ( getBestStatements(currentItem, 'P31') ) do --instance of | ||
local taxonRank = nil | local taxonRank = nil | ||
local parentItem = nil | local parentItem = nil | ||
| Qator 406: | Qator 500: | ||
local instanceOf = instanceOfState.mainsnak.datavalue.value.id | local instanceOf = instanceOfState.mainsnak.datavalue.value.id | ||
if instanceOf and (instanceOf == 'Q310890' or instanceOf == 'Q47487597') then --monotypic/fossil taxon | if instanceOf and (instanceOf == 'Q310890' or instanceOf == 'Q47487597') then --monotypic/fossil taxon | ||
local taxonRankState = currentItem | local taxonRankState = getBestStatement(currentItem, 'P105') --taxon rank | ||
if taxonRankState then taxonRank = taxonRankState.mainsnak.datavalue.value.id end | if taxonRankState then taxonRank = taxonRankState.mainsnak.datavalue.value.id end | ||
if taxonRank and taxonRank == 'Q7432' then --species | if taxonRank and taxonRank == 'Q7432' then --species | ||
--is monotypic species; add genus | --is monotypic species; add genus | ||
local parentTaxonState = currentItem | local parentTaxonState = getBestStatement(currentItem, 'P171') --parent taxon | ||
if parentTaxonState then parentTaxon = parentTaxonState.mainsnak.datavalue.value.id end | if parentTaxonState then parentTaxon = parentTaxonState.mainsnak.datavalue.value.id end | ||
--confirm parent taxon rank == genus & monotypic | --confirm parent taxon rank == genus & monotypic | ||
if parentTaxon and | if parentTaxon and resolveEntityId(parentTaxon) then | ||
parentItem = | parentItem = wikibaseGetEntity(parentTaxon) | ||
if parentItem then | if parentItem then | ||
local parentTaxonRankState = parentItem | local parentTaxonRankState = getBestStatement(parentItem, 'P105') --taxon rank | ||
if parentTaxonRankState then parentTaxonRank = parentTaxonRankState.mainsnak.datavalue.value.id end | if parentTaxonRankState then parentTaxonRank = parentTaxonRankState.mainsnak.datavalue.value.id end | ||
if parentTaxonRank and parentTaxonRank == 'Q34740' then --parent == genus | if parentTaxonRank and parentTaxonRank == 'Q34740' then --parent == genus | ||
for _, parentInstanceOfState in pairs ( | for _, parentInstanceOfState in pairs ( getBestStatements(parentItem, 'P31') ) do --instance of | ||
local parentInstanceOf = parentInstanceOfState.mainsnak.datavalue.value.id | local parentInstanceOf = parentInstanceOfState.mainsnak.datavalue.value.id | ||
if parentInstanceOf and | if parentInstanceOf and | ||
| Qator 478: | Qator 572: | ||
end | end | ||
--Fetch Wikidata item | --Fetch Wikidata item | ||
local from = resolveEntityId(parentArgs['from'..f]) | |||
local item = wikibaseGetEntity(from) | |||
local label = nil | |||
if type(item) == 'table' then | |||
local statements = getBestStatement(item, 'P225') | |||
if statements | |||
and statements.mainsnak | |||
and statements.mainsnak.datavalue | |||
then | |||
label = statements.mainsnak.datavalue.value | |||
end | |||
label = label or getEntityLabel(item) | |||
else | |||
-- Ziyosfera'da Wikibase mavjud bo'lmasa QID'ni | |||
-- noto'g'ri deb belgilamaymiz. | |||
if hasWikibase then | |||
if parentArgs['from'..f] then | |||
tCats[1] = '' | |||
tCats[5] = | |||
'[[Turkum:Taxonbars with invalid from parameters]]' | |||
errors = errors .. | |||
mw.text.tag( | |||
'strong', | |||
{ class = 'error' }, | |||
'Error: "' .. | |||
parentArgs['from'..f] .. | |||
'" is not a valid Wikidata entity ID.<br />' | |||
) | |||
end | |||
else | |||
-- Wikibase yo'q: | |||
-- QID parametrini saqlaymiz, lekin tekshirmaymiz. | |||
if parentArgs['from'..f] then | |||
tCats[1] = '' | |||
end | end | ||
end | |||
end | |||
if label and label ~= '' then | if label and label ~= '' then | ||
title = mw.title.new(label) | title = mw.title.new(label) | ||
| Qator 659: | Qator 782: | ||
if not isNilOrEmpty( parentArgs['demo'] ) then | if not isNilOrEmpty( parentArgs['demo'] ) then | ||
outString = outString..mw.text.nowiki(table.concat(tCats))..'<br />' | outString = outString..mw.text.nowiki(table.concat(tCats))..'<br />' | ||
elseif currentTitle.namespace == 0 then | elseif currentTitle.namespace == 0 and not zs_no_wikibase then | ||
outString = outString..table.concat(tCats) | outString = outString..table.concat(tCats) | ||
end | end | ||
if zs_no_wikibase then errors = '' end | |||
return outString..errors | return outString..errors | ||
end | end | ||
return p | return p | ||