Модуль:Wikidata/redLink

Для документации этого модуля может быть создана страница Модуль:Wikidata/redLink/doc

local p = {};function p.formatRedLink(title, text, entityId, infobox)if infobox == nil or infobox == '' theninfobox = 'Universal infocard'endreturn mw.ustring.format('<span class="plainlinks">[//ru.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: #ba0000; text-decoration: inherit; -moz-text-decoration-color: #ba0000; text-decoration-color: #ba0000;">%s</span>]</span>',mw.uri.encode(title), entityId, mw.uri.encode(title), string.gsub(infobox, ' ', '+') , mw.text.nowiki(text))endfunction p.formatRedLinkWithInfobox(title, text, entityId, defaultInfobox)return p.formatRedLink(title, text, entityId, p.getInfobox(entityId, defaultInfobox))endfunction p.getInfobox(entityId, defaultInfobox)if defaultInfobox thenreturn defaultInfoboxendif entityId thenlocal result = mw.wikibase.getBestStatements(entityId, 'P31')for _, statement in pairs(result) doif statement.mainsnak.datavalue thenlocal type = statement.mainsnak.datavalue.value.idiftype == 'Q5'then return p.getBioInfobox(entityId)elseiftype == 'Q523'then return 'Звезда'elseiftype == 'Q318'then return 'Галактика'endendendendreturn 'Universal infocard'endfunction p.getBioInfobox(entityId)if entityId thenlocal result = mw.wikibase.getBestStatements(entityId, 'P106')for _, statement in pairs(result) doif statement.mainsnak.datavalue thenlocal occupation = statement.mainsnak.datavalue.value.idif occupation == 'Q901' then return 'Учёный'endendendendreturn 'Персона'endfunction p.formatRedLinkFromTemplate(frame)local args = frame['args']if not args[1] then -- may be arguments are passed from the parent template?args = frame:getParent().argsendif not args[1] thenreturn '<span class="error">Не указан элемент Викиданных</span>'endlocal entityId = mw.text.trim(args[1])local title = mw.wikibase.label(entityId)if not title thenreturn mw.ustring.format('<span class="error">Нет метки у элемента %s</span>', entityId)elseif mw.ustring.match(title, '[%[%]:]') then -- cannot create page with this namereturn titleendlocal text = titleif args[2] thentext = mw.text.trim(args[2])endlocal sitelink = mw.wikibase.sitelink(entityId)if sitelink thenif text == sitelink thenreturn '[[' .. sitelink .. ']]'elsereturn '[[' .. sitelink .. '|' .. text .. ']]'endendreturn p.formatRedLinkWithInfobox(title, text, entityId, args[3])endreturn p