ਮੌਡਿਊਲ:Interwiki extra
Usage
See also {{Interwiki extra}} — wrapper. Pages that use this module to add additional interwiki links are contained in the tracking category Category:Module:Interwiki extra: additional interwiki links (0). -- This module provides functions and objects for dealing with interwiki links.
local checkType = require('libraryUtil').checkType
local interwikiData = mw.loadData('Module:Interwiki extra/data')
--------------------------------------------------------------------------------
-- Prefix class
--------------------------------------------------------------------------------
local Prefix = {}
Prefix.__index = Prefix
function Prefix.new(code)
checkType('Prefix.new', 1, code, 'string')
local obj = setmetatable({}, Prefix)
local data = interwikiData.prefixes[code]
if not data then
return nil
end
for k, v in pairs(data) do
obj[k] = v
end
return obj
end
function Prefix:makeUrl(page)
checkType('makeUrl', 1, page, 'string')
-- In MediaWiki, interlanguage links are wiki-encoded (spaces are encoded
-- as underscores), even if the site is not a wiki and underscores don't
-- make sense. So we do the same here.
page = mw.uri.encode(page, 'WIKI')
return mw.message.newRawMessage(self.url, page):plain()
end
function Prefix:isValidUrl(url)
checkType('isValidUrl', 1, url, 'string')
local obj1 = mw.uri.new(self.url)
local obj2 = mw.uri.new(url)
if not obj2 then
return false
elseif obj1.protocol and obj1.protocol ~= obj2.protocol then
-- Protocols only have to match if the prefix URL isn't protocol-relative
return false
elseif obj1.host ~= obj2.host then
return false
end
local function makePathQuery(obj)
return obj.path .. (obj.queryString or '')
end
local pathQuery1 = makePathQuery(obj1)
local pathQuery2 = makePathQuery(obj2)
-- Turn pathQuery1 into a string pattern by escaping all punctuation, then
-- replacing the "$1" parameter (which will have become "%$1") with ".*"
local pattern = pathQuery1:gsub('%p', '%%%0'):gsub('%%$1', '.*')
pattern = '^' .. pattern .. '$'
return pathQuery2:find(pattern) ~= nil
end
local langcode = {
['bat_smg'] = 'bat-smg',
['be_x_old'] = 'be-x-old',
['cbk_zam'] = 'cbk-zam',
['fiu_vro'] = 'fiu-vro',
['map_bms'] = 'map-bms',
['nds_nl'] = 'nds-nl',
['roa_rup'] = 'roa-rup',
['roa_tara'] = 'roa-tara',
['zh_classical'] = 'zh-classical',
['zh_min_nan'] = 'zh-min-nan', -- a comma have to be added when new lines are added
['zh_yue'] = 'zh-yue'
}
local siteexcludes = {
['metawiki'] = true,
['mediawikiwiki'] = true,
['commonswiki'] = true,
['wikidatawiki'] = true,
['specieswiki'] = true,
['enwiki'] = true
}
function Prefix.interwiki(frame)
local s = setmetatable({}, {__index = table})
local entity = mw.wikibase.getEntity()
-- use qid parameter if provided, otherwise follow P460
local qid = frame.args.qid or frame:getParent().args.qid or frame.args[1] or frame:getParent().args[1] or ''
if not mw.wikibase.isValidEntityId(qid) then
qid = nil
-- access the first valid value of P460
for i, statement in pairs(entity:getBestStatements[[P460]]) do
if statement.mainsnak.snaktype == 'value' then
qid = statement.mainsnak.datavalue.value['id']
break
end
end
end
if qid then
local entity2 = mw.wikibase.getEntity(qid)
if entity2 and entity2.sitelinks then
for i, j in pairs(entity2.sitelinks) do
-- exclude the own wiki and some wikiprojects that are not Wikipedia, even if their code ends with 'wiki'
if not siteexcludes[j.site] then
-- exclude Wikisource, Wikiquote, Wikivoyage etc
if mw.ustring.sub( j.site, mw.ustring.len(j.site) - 3 ) == 'wiki' then
local lang = langcode[mw.ustring.sub( j.site, 1, mw.ustring.len(j.site) - 4 )] or mw.ustring.sub( j.site, 1, mw.ustring.len(j.site) - 4 )
-- exclude interwiki to projects that already have sitelinks in the present page
if (entity and not entity.sitelinks[j.site]) or not entity then
-- put together a interwiki-link to other projects
s:insert( '[[' .. lang .. ':' .. j.title .. ']]' )
end
end
end
end
end
end
if #s > 0 then
s:insert("[[Category:Module:Interwiki extra: additional interwiki links]]")
end
return s:concat('')
end
return Prefix
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia