Modul:Wikidata/redLink
Körüniş
Bu modül için bir Modul:Wikidata/redLink/belge belgelendirmesi oluşturabilirsiniz
local p = {};
local altScript = require( 'Modul:Alternativ elifbe' )
function p.formatRedLink(title, text, entityId, infobox, altScriptText, textLanguageCode)
if infobox == nil or infobox == '' then
infobox = 'Universal infocard'
end
local altScriptEscaped
if altScriptText then altScriptEscaped = mw.text.nowiki(altScriptText) end
-- TODO rus Vikipediydan "Template:Нет статьи/editintro" ve "Template:Нет статьи/preload"-nı kopiya yapmalı, mında qullanmalı
--[[
return mw.ustring.format(
'<span class="plainlinks">[//crh.wikipedia.org/w/index.php?title=%s&action=edit&editintro=T:Нет_статьи/editintro&preload=T:Нет_статьи/preload&preloadparams%%5B%%5D=%s&preloadparams%%5B%%5D=%s&preloadparams%%5B%%5D=%s <span style="color: var(--color-link-red, #d73333); text-decoration: inherit; text-decoration-color: var(--color-link-red, #d73333);">%s</span>]</span>',
mw.uri.encode(title), entityId, mw.uri.encode(title), string.gsub(infobox, ' ', '+') , altScript.format(mw.text.nowiki(text), altScriptEscaped, textLanguageCode)
)
]]
-- "Template:Нет статьи/editintro" ve ".../preload" şablonlarsız daa sade bir versiya:
return mw.ustring.format(
'<span class="plainlinks">[//crh.wikipedia.org/w/index.php?title=%s&action=edit <span style="color: var(--color-link-red, #d73333); text-decoration: inherit; text-decoration-color: var(--color-link-red, #d73333);">%s</span>]</span>',
mw.uri.encode(title), altScript.format(mw.text.nowiki(text), altScriptEscaped, textLanguageCode)
)
end
function p.formatRedLinkWithInfobox(title, text, entityId, defaultInfobox, altScriptText, textLanguageCode)
return p.formatRedLink(title, text, entityId, p.getInfobox(entityId, defaultInfobox), altScriptText, textLanguageCode)
end
function p.getInfobox(entityId, defaultInfobox)
-- TODO qullanmalı (şimdi bizim "Template:Нет статьи/editintro" ve ".../preload" şablonlarmız yoq, bu kod qullanmay)
if defaultInfobox then
return defaultInfobox
end
if entityId then
local result = mw.wikibase.getBestStatements(entityId, 'P31')
for _, statement in pairs(result) do
if statement.mainsnak.datavalue then
local type = statement.mainsnak.datavalue.value.id
-- TODO qırımtatar Vikipediyasınıñ şablon adları qullanmalı
if type == 'Q5' then return p.getBioInfobox(entityId)
elseif type == 'Q523' then return 'Звезда'
elseif type == 'Q318' then return 'Галактика'
end
end
end
end
return 'Universal infocard'
end
function p.getBioInfobox(entityId)
if entityId then
local result = mw.wikibase.getBestStatements(entityId, 'P106')
for _, statement in pairs(result) do
if statement.mainsnak.datavalue then
local occupation = statement.mainsnak.datavalue.value.id
-- TODO qırımtatar Vikipediyasınıñ şablon adı qullanmalı
if occupation == 'Q901' then return 'Учёный'
end
end
end
end
-- TODO qırımtatar Vikipediyasınıñ şablon adı qullanmalı
return 'Персона'
end
function p.formatRedLinkFromTemplate(frame)
local args = frame['args']
if not args[1] then -- may be arguments are passed from the parent template?
args = frame:getParent().args
end
if not args[1] then
return '<span class="error">Vikimalümat element belgilenmegen</span>'
end
local entityId = mw.text.trim(args[1])
local title = mw.wikibase.label(entityId)
if not title then
return mw.ustring.format('<span class="error">%s elementnıñ belgisi yoq</span>', entityId)
elseif mw.ustring.match(title, '[%[%]:]') then -- cannot create page with this name
return title
end
local text = title
if args[2] then
text = mw.text.trim(args[2])
end
local sitelink = mw.wikibase.sitelink(entityId)
if sitelink then
if text == sitelink then
return '[[' .. sitelink .. ']]'
else
return '[[' .. sitelink .. '|' .. text .. ']]'
end
end
return p.formatRedLinkWithInfobox(title, text, entityId, args[3])
end
return p