Módulo:Interwiki

Un artíkolo de la Vikipedya, la ansiklopedya líbera

Purpose. This module provides a way to supply interwiki links to pages that cannot be fully served by Wikidata for a variety of reasons, such as:

  1. Two pages are substantially identical, but only one can be directly linked to Wikidata.
    Example: most Hebrew-script pages on this wiki, which are substantially identical to corresponding Latin-script pages.
  2. Pages that have exact analogues in only a few wikis, but near analogues in many wikis.
    This commonly happens in Template (Xablón), Project/Wikipedia (Vikipedya), and Help (Ayudo) name spaces.
  3. Page does not have its own entry in Wikidata.
    All pages are allowed to have entries in Wikidata, but in some of the cases above, it may or may not seem entirely necessary to create them.

Instructions[trocar el manadero]

In case of reason 1 above[trocar el manadero]

  1. Open tabs in your browser for the following pages:
    • The page having Wikidata links (example: Astronomiya)
    • The substantially identical page without its own Wikidata links (example: אסטרונומייה)
    • The Wikidata item of the first page (example: d:Q333)
    • The Wikidata item of the second page (example: d:Q20819872)
  2. In the Wikidata item of the second page, add the following to "Statements": "permanent duplicated item" with the value of the Wikidata item of the first page. (Note: "permanent duplicated item" is property d:Property:P2959.)
    • Ideally, also add "instance of (P31)" "Wikimedia permanent duplicated page (d:Q21286738)" to that Wikidata item.
  3. Edit the second page on this Wiki with the following code, at the bottom, just before categories. (If the page is a template, be sure this code is included within the <noinclude></noinclude> tags.)
    • {{#invoke:Interwiki|interwiki}}
    • Ideally, in the Wikidata item of the first page, add "permanent duplicated item" with the value of the Wikidata item of the second page.
  4. Save all changes.

The second page should now include all the interwiki links of the first page.

If you have any questions, please contact User:StevenJ81, who will be glad to help.

In case of reason 2 above[trocar el manadero]

  1. Open tabs in your browser for the following pages:
  2. Edit the first page on this Wiki with the following code, at the bottom, just before categories. (If the page is a template, be sure this code is included within the <noinclude></noinclude> tags.)
    • {{#invoke:Interwiki|interwiki|qid=Qnnnnnnn}}, where Qnnnnnnn is the Wikidata item number of the near-analogue page.
  3. Save all changes.

The first page should now include all the interwiki links of the second page, except where an exact analogue already exists in the first page's own Wikidata item.

In case of reason 3 above[trocar el manadero]

  1. Consider creating a Wikidata item for the page, and proceed as in reason 1 above.
  2. Otherwise, proceed as in reason 2 above.

local p = { }

thiswiki = 'ladwiki' -- the code of this wiki, HAVE TO BE CHANGED WHEN COPYING MODULE
thislanguage = 'lad' -- the code of the present language

-- language-codes with underscore '_', have to be translated to '-', to be readable for MediaWiki
-- add more codes, when new are added to the Wikimedia-family
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 P2959 and thereafter P460
	if entity and entity.claims and entity.claims["P2959"] then
		for i, j in pairs(entity:getBestStatements( "P2959" )) do
			if j.mainsnak.snaktype == 'value' then
				return 'Q' .. j.mainsnak.datavalue.value['numeric-id']
			end
		end
	end
	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

p.interwiki = function(frame)
	local s = {}
	local entity = mw.wikibase.getEntity()
	local qid = frame.args.qid or p460(entity) -- uses parameter qid of the module if it exists, otherwise follow P460
	if frame.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 ~= thiswiki 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
	return table.concat(s, '')

end

return p