Module:Make Wikisource link and Module:Make Wikisource link/sandbox: Difference between pages
(Difference between pages)
imported>HouseBlaster handle searching in authorspace correctly (by not searching in authorspace at all) |
imported>HouseBlaster sync with main |
||
| Line 4: | Line 4: | ||
function p.makeLink(frame) | function p.makeLink(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local lang = args['explicit_lang_param'] or args['implicit_lang_param'] or 'en' | local lang = args['explicit_lang_param'] or args['implicit_lang_param'] or 'en' | ||
local page = mw.title.getCurrentTitle() | local page = mw.title.getCurrentTitle() | ||
local pagename = page.text | local pagename = page.text | ||
local | local authorPrefix = args.works and frame:expandTemplate{ title = 'Wikisource/Author', args = { lang } } or '' | ||
local linkTarget | local linkTarget | ||
local displayText | local displayText | ||
local toReturn | local toReturn | ||
-- get the Wikidata sitelink | -- get the Wikidata sitelink | ||
local wikidataSitelink = mw.wikibase.getSitelink( | local wikidataSitelink = mw.wikibase.getSitelink( | ||
mw.wikibase.getEntityIdForCurrentPage() or '', | mw.wikibase.getEntityIdForCurrentPage() or '', | ||
lang .. 'wikisource' | |||
) | ) | ||
| Line 58: | Line 36: | ||
linkTarget = wikidataSitelink | linkTarget = wikidataSitelink | ||
else | else | ||
-- if Wikidata returns nothing, search for the {{PAGENAME}} | |||
linkTarget = 'Special:Search/' .. pagename | |||
-- we have no parameters and nothing at Wikidata, so we are flying blind | -- we have no parameters and nothing at Wikidata, so we are flying blind | ||
-- set | -- We set displayText now to avoid including the Special:Search in the display text | ||
displayText = pagename | |||
end | end | ||
-- clear | -- clear the Author: prefix for now; will add it back later if needed | ||
-- this prevents duplicate prefixes (Author:Author:Shakespeare | -- this prevents duplicate prefixes (Author:Author:Shakespeare) | ||
-- and avoids displayText with any author prefix | -- and avoids displayText with any author prefix | ||
linkTarget = string.gsub(linkTarget, '^' .. | linkTarget = string.gsub(linkTarget, '^' .. authorPrefix, '') | ||
--[[--------- | --[[--------- | ||
| Line 99: | Line 77: | ||
-- only care about mainspace | -- only care about mainspace | ||
setFalse() | setFalse() | ||
elseif string.match(pagename, '^ | elseif string.match(pagename, '^List') then | ||
-- we are on a list page, and those should not have Wikisource links | -- we are on a list page, and those should not have Wikisource links | ||
setFalse() | setFalse() | ||
| Line 121: | Line 99: | ||
-- build the link | -- build the link | ||
toReturn = '[[:s:' .. lang .. ':' .. | toReturn = '[[:s:' .. lang .. ':' .. authorPrefix .. linkTarget .. '|' .. displayText .. ']]' | ||
-- append the error category if needed | -- append the error category if needed | ||