پرش به محتوا

پودمان:پیوند ویکی‌داده: تفاوت میان نسخه‌ها

از ویکی‌نبشته
محتوای حذف‌شده محتوای افزوده‌شده
Darafsh (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
Darafsh (بحث | مشارکت‌ها)
بدون خلاصۀ ویرایش
برچسب: برگردانده‌شده
خط ۲: خط ۲:


-- Get a link to the given Wikidata item's page on the first of the following places:
-- Get a link to the given Wikidata item's page on the first of the following places:
-- 1. Wikisource
-- 1. Persian Wikisource
-- 2. Wikipedia
-- 2. Persian Wikipedia
-- 3. Commons
-- 3. Commons
-- 4. Reasonator
-- 4. Reasonator
function p.link(frame)
function p.link(frame)
-- Check input.
-- Check input.
if frame.args.wikidata == nil or frame.args.wikidata == '' then
if frame.args.wikidata == nil or frame.args.wikidata == '' then
return "<span class='error'>Please specify 'wikidata' parameter.</span>"
return "<span class='error'>لطفا پارامتر 'wikidata' را مشخص کنید.</span>"
end
end
local itemId = frame.args.wikidata
local itemId = frame.args.wikidata
if not mw.wikibase.isValidEntityId(itemId) then
if not mw.wikibase.isValidEntityId(itemId) then
return "<span class='error'>" .. itemId .. "' is not a valid Wikidata item.</span>"
return "<span class='error'>" .. itemId .. "' شناسه معتبری در ویکی‌داده نیست.</span>"
end
end
if not mw.wikibase.entityExists(itemId) then
if not mw.wikibase.entityExists(itemId) then
return "<span class='error'>" .. itemId .. "' does not exist on Wikidata.</span>"
return "<span class='error'>" .. itemId .. "' در ویکی‌داده وجود ندارد.</span>"
end
end
local label = mw.wikibase.getLabel(itemId)
local label = mw.wikibase.getLabel(itemId)
if frame.args.label ~= nil and frame.args.label ~= '' then
if frame.args.label ~= nil and frame.args.label ~= '' then
label = frame.args.label
label = frame.args.label
end
end


-- Look through the site hierarchy for a matching sitelink.
-- Look through the site hierarchy for a matching sitelink.
-- These two variables are in the same order.
-- These two variables are in the same order.
local sitelinks = {'fawikisource', 'fawiki', 'commonswiki'}
local sitelinks = {'fawikisource', 'fawiki', 'commonswiki'}
local interwikis = {'', 'wikipedia', 'commons'}
local interwikis = {'', 'ویکی‌پدیا', 'commons'}
for i = 1, #sitelinks do
for i = 1, #sitelinks do
local sitelink = mw.wikibase.getSitelink(itemId, sitelinks[i])
local sitelink = mw.wikibase.getSitelink(itemId, sitelinks[i])
if sitelink then
if sitelink then
return '<span class="module-wikidata-link">[[' .. interwikis[i] .. ':' .. sitelink .. '|' .. label .. ']]</span>';
return '<span class="module-wikidata-link">[[' .. interwikis[i] .. ':' .. sitelink .. '|' .. label .. ']]</span>';
end
end
end
end


-- Fall back on Reasonator if no sitelink found.
-- Fall back on Reasonator if no sitelink found.
return '<span class="plainlinks module-wikidata-link reasonator-link">[https://reasonator.toolforge.org/?q=' .. itemId .. ' ' .. label .. ']</span>'
return '<span class="plainlinks module-wikidata-link reasonator-link">[https://reasonator.toolforge.org/?q=' .. itemId .. ' ' .. label .. ']</span>'
end
end



نسخهٔ ‏۱۰ مهٔ ۲۰۲۴، ساعت ۲۱:۳۳

توضیحات این پودمان می‌تواند در پودمان:پیوند ویکی‌داده/توضیحات قرار گیرد.

local p = {}

-- Get a link to the given Wikidata item's page on the first of the following places:
--  1. Persian Wikisource
--  2. Persian Wikipedia
--  3. Commons
--  4. Reasonator
function p.link(frame)
    -- Check input.
    if frame.args.wikidata == nil or frame.args.wikidata == '' then
        return "<span class='error'>لطفا پارامتر 'wikidata' را مشخص کنید.</span>"
    end
    local itemId = frame.args.wikidata
    if not mw.wikibase.isValidEntityId(itemId) then
        return "<span class='error'>" .. itemId .. "' شناسه معتبری در ویکی‌داده نیست.</span>"
    end
    if not mw.wikibase.entityExists(itemId) then
        return "<span class='error'>" .. itemId .. "' در ویکی‌داده وجود ندارد.</span>"
    end
    
    local label = mw.wikibase.getLabel(itemId)
    if frame.args.label ~= nil and frame.args.label ~= '' then
        label = frame.args.label
    end

    -- Look through the site hierarchy for a matching sitelink.
    -- These two variables are in the same order.
    local sitelinks = {'fawikisource', 'fawiki', 'commonswiki'}
    local interwikis = {'', 'ویکی‌پدیا', 'commons'}
    for i = 1, #sitelinks do
        local sitelink = mw.wikibase.getSitelink(itemId, sitelinks[i])
        if sitelink then
            return '<span class="module-wikidata-link">[[' .. interwikis[i] .. ':' .. sitelink .. '|' .. label .. ']]</span>';
        end
    end

    -- Fall back on Reasonator if no sitelink found.
    return '<span class="plainlinks module-wikidata-link reasonator-link">[https://reasonator.toolforge.org/?q=' .. itemId .. ' ' .. label .. ']</span>'
end

return p