Изменения
Модуль:Wikidata/Interproject (посмотреть исходный код)
Версия от 20:44, 1 сентября 2023
, 2 года назадпроброс from из родителя (взято с https://ru.wikipedia.org/w/index.php?oldid=130779586#L-1462)
function p.getWikibooksLink( context )
function p.getWikibooksLink( context )
return p.getSisterProjectLink( 'b', 'wikibooks', context.args.from )
return p.getSisterProjectLink( 'b', 'wikibooks', context )
end
end
function p.getWikiquoteLink( context )
function p.getWikiquoteLink( context )
return p.getSisterProjectLink( 'q', 'wikiquote', context.args.from )
return p.getSisterProjectLink( 'q', 'wikiquote', context )
end
end
function p.getWikisourceLink( context )
function p.getWikisourceLink( context )
return p.getSisterProjectLink( 's', 'wikisource', context.args.from )
return p.getSisterProjectLink( 's', 'wikisource', context )
end
end
function p.getWikipediaLink( context )
function p.getWikipediaLink( context )
return p.getSisterProjectLink( 'w', 'wiki', context.args.from )
return p.getSisterProjectLink( 'w', 'wiki', context )
end
end
function p.getWiktionaryLink( context )
function p.getWiktionaryLink( context )
return p.getSisterProjectLink( 'wikt', 'wiktionary', context.args.from )
return p.getSisterProjectLink( 'wikt', 'wiktionary', context )
end
end
function p.getSisterProjectLink( projectInterwikiPrefix, projectName, entityId )
function p.getSisterProjectLink( projectInterwikiPrefix, projectName, context )
entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
-- проброс параметра from откуда угодно
local entityId = nil
local p_context = context
while p_context do
if p_context.args and p_context.args.from and p_context.args.from ~= '' then
entityId = p_context.args.from
else
entityId = mw.wikibase.getEntityIdForCurrentPage()
end
p_context = p_context:getParent()
end
-- По умолчанию старается достать ссылку на русском, иначе - на родном (P103)
-- По умолчанию старается достать ссылку на русском, иначе - на родном (P103)
local wbStatus, sitelink = pcall( mw.wikibase.getSitelink, entityId, 'ru' .. projectName )
local wbStatus, sitelink = pcall( mw.wikibase.getSitelink, entityId, 'ru' .. projectName )