Module:Make Wikisource link
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This module depends on the following other modules: |
This module creates a link to a page at Wikisource. It is intended to be called from {{Wikisource/outer core}}; you probably should not use it anywhere else.
If the template is used in mainspace and no link at Wikidata is found, it sometimes populates Category:Wikisource templates with missing id. In the following cases, it will not populate the category:
|nocat=yesis provided- "Year in topic" articles (e.g. 1871 in Canada)
- "Decade in topic" articles (e.g. 2020s in music)
- The article is a list (title begins with
List) - Disambiguation page and set index articles
- Articles about species. Note that there is no all included species category, so we make use of Category:Articles with 'species' microformats to check whether the article is about a species.
If none of the above are true, the category is populated.
Usage
{{#invoke:Make Wikisource link|makeLink}}
local p = {}
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
function p.makeLink(frame)
--[[---------
Variable declaration
--]]---------
local args = getArgs(frame)
local lang = args['explicit_lang_param'] or args['implicit_lang_param'] or 'en'
local page = mw.title.getCurrentTitle()
local pagename = page.text
local wikisourceEdition
local linkTarget
local displayText
local toReturn
local prefix
--[[
Create the prefix for the interwiki link
It uses the lowest of:
1. 'Special:Search/', if using the enwiki pagename as the interwiki target
2. If not (1), an 'Author:' prefix, localized, if given a works parameter and not under (1)
3. If not (1) or (2), the empty string
We avoid 'Special:Search/Author:' intentionally; this is rarely helpful
Here we simply set it to (2) or (3), and override it when setting the link target if needed
--]]
prefix = args.works and frame:expandTemplate{ title = 'Wikisource/Author', args = { lang } } or ''
-- Handle multilingual Wikisource (aka old Wikisource) correctly
if lang == 'mul' then
wikisourceEdition = 'sourceswiki' -- siteid for multilingual Wikisource
else
wikisourceEdition = lang .. 'wikisource' -- other Wikisource editions are langcode + 'wikisource' (e.g. 'enwikisource')
end
-- get the Wikidata sitelink
local wikidataSitelink = mw.wikibase.getSitelink(
mw.wikibase.getEntityIdForCurrentPage() or '',
wikisourceEdition
)
-- if we have a language parameter, we look at the second unnamed parameter for the source title
local checkIndexForTarget = args['implicit_lang_param'] and 2 or 1
-- and then use the next index for display
local checkIndexForDisplay = checkIndexForTarget + 1
--[[---------
Set the link target
--]]---------
if args['wslink'] then
linkTarget = args['wslink']
elseif args[checkIndexForTarget] then
-- we have a source title parameter, so return that
linkTarget = args[checkIndexForTarget]
elseif wikidataSitelink then
-- use Wikidata
linkTarget = wikidataSitelink
else
-- we have no parameters and nothing at Wikidata, so we are flying blind
-- set the linkTarget to the pagename
linkTarget = pagename
-- and set prefix to 'Special:Search/' to find the appropriate link
prefix = 'Special:Search/'
end
-- clear prefixes for now; will add it back later if needed
-- this prevents duplicate prefixes (Author:Author:Shakespeare; Special:Search/Special:Search/)
-- and avoids displayText with any author prefix
linkTarget = string.gsub(linkTarget, '^' .. prefix, '')
--[[---------
Now build the displayText
--]]---------
if not displayText then
-- we did not set displayText in the above steps, so set it now
-- first we check for an explicit display text, or else we set it to be the link target
displayText = args['title'] or args[checkIndexForDisplay] or linkTarget
end
--[[---------
Now we check whether we should categorize in Category:Wikisource templates with missing id
--]]---------
-- initialize errorCategory as true
local errorCategory = true
-- helper to set errorCategory = false
local function setFalse() errorCategory = false end
if wikidataSitelink then
-- we do have a sitelink at Wikidata
setFalse()
elseif yesno(args.nocat, true) then
-- we have a |nocat parameter
setFalse()
elseif page.namespace ~= 0 then
-- only care about mainspace
setFalse()
elseif string.match(pagename, '^Lists? of ') then
-- we are on a list page, and those should not have Wikisource links
setFalse()
elseif string.match(pagename, '^%d%d?%d?%d?s? in') then
-- we are in a YEAR/DECADE in FOO page, and those also should not have anything else
setFalse()
else
-- Now we check categories and determine whether this is something which does not need a Wikisource links
-- Currently, we avoid categorizing:
-- 1. Disambiguation pages
-- 2. Set index articles
-- 3. Articles about species. There is no universal category; [[Category:Articles with 'species' microformats]] is a proxy
-- we do this check last to avoid using [[WP:EXPENSIVE]] parser calls if possible
for _, cat in ipairs(page.categories) do
if cat == "All disambiguation pages" or cat == "All set index articles" or cat == "Articles with 'species' microformats" then
setFalse()
break
end
end
end
-- build the link
toReturn = '[[:s:' .. lang .. ':' .. prefix .. linkTarget .. '|' .. displayText .. ']]'
-- append the error category if needed
if errorCategory then
toReturn = toReturn .. '[[Category:Wikisource templates with missing id|' .. pagename .. ']]'
end
return toReturn
end
return p
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.