Modul:Interwiki extra
Brug
{{#invoke:Interwiki extra|interwiki}}
Se også {{Interwiki extra}} — wrapper.
Sider, som bruger dette modul til at tilføje yderligere interwiki-links, er indholdet i sporingskategorien Kategori:Modul:Interwiki extra: Yderligere interwiki henvisninger (30).
{{#invoke:Interwiki extra|function_name}}
-- 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'
}
p460 = function(entity) -- access the first valid value of P460
if entity and entity.claims and entity.claims["P460"] then
for i, j in pairs(entity:getBestStatements( "P460" )) do
if j.mainsnak.snaktype == 'value' then
return 'Q' .. j.mainsnak.datavalue.value['numeric-id']
end
end
end
return nil
end
Prefix.interwiki = function(frame)
local s = {}
local entity = mw.wikibase.getEntity()
local qid = frame.args.qid or frame:getParent().args.qid or p460(entity) -- uses parameter qid of the module if it exists, otherwise follow P460
if frame.args.qid == '' or frame:getParent().args.qid == '' then
qid = p460(entity)
end
if qid then
local entity2 = mw.wikibase.getEntity(qid)
if entity2 and entity2.sitelinks then
for i, j in pairs(entity2.sitelinks) do
if j.site ~= 'dawiki' and j.site ~= 'wikidatawiki' and j.site ~= 'commonswiki' and j.site ~= 'specieswiki' and j.site ~= 'metawiki' and j.site ~= 'mediawikiwiki' then -- excludes the own wiki and some wikiprojects that are not Wikipedia, even if their code ends with 'wiki'
if mw.ustring.sub( j.site, mw.ustring.len(j.site) - 3 ) == 'wiki' then -- excludes Wikisource, Wikiquote, Wikivoyage etc
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 )
if (entity and not entity.sitelinks[j.site]) or not entity then -- excludes interwiki to projects that already have sitelinks in the present page
table.insert(s, '[[' .. lang .. ':' .. j.title .. ']]' ) -- put together a interwiki-link to other projects
end
end
end
end
end
end
if #s > 0 then
table.insert(s, "[[Kategori:Modul:Interwiki extra: Yderligere interwiki henvisninger]]")
end
return table.concat(s, '')
end
return Prefix
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
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









