Module:Gutenberg: Difference between revisions
From Zoophilia Wiki
Jump to navigationJump to search
meta>GreenC No edit summary |
meta>GreenC No edit summary |
||
| Line 16: | Line 16: | ||
local urlhead = nil | local urlhead = nil | ||
args.id = stripArgument(args.id) | |||
if not args.id then | |||
return error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation") | return error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation") | ||
else | else | ||
| Line 27: | Line 28: | ||
end | end | ||
args.name = stripArgument(args.name) | |||
if not args.name then | |||
name = mw.title.getCurrentTitle().basePageTitle | name = mw.title.getCurrentTitle().basePageTitle | ||
else | else | ||
| Line 36: | Line 38: | ||
return url | return url | ||
end | |||
function stripArgument(arg) | |||
if args.name == "" or args.name == nil then | |||
return nil | |||
else | |||
return arg | |||
end | |||
end | end | ||
return p | return p | ||
Revision as of 13:57, 4 October 2015
Documentation for this module may be created at Module:Gutenberg/doc
local p = {}
function p.author(frame)
local pframe = frame:getParent()
local args = pframe.args
local tname = "Gutenberg author" -- name of calling template. Change if template is renamed.
local id = nil -- author name, or author number. The later will go direct to the author page, the former to a search results page.
local name = nil -- display name on Wikipedia (default: article title)
local url = nil
local tagline = "at [[Project Gutenberg]]"
local urlheadname = "//www.gutenberg.org/author/"
local urlheadnumb = "//www.gutenberg.org/ebooks/author/"
local urlhead = nil
args.id = stripArgument(args.id)
if not args.id then
return error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation")
else
id = mw.text.trim(args.id)
if tonumber(id) ~= nil then -- it's a number
urlhead = urlheadnumb
else
urlhead = urlheadname
end
end
args.name = stripArgument(args.name)
if not args.name then
name = mw.title.getCurrentTitle().basePageTitle
else
name = mw.text.trim(args.name)
end
url = "[" .. urlhead .. id .. " Works by " .. name .. "] " .. tagline
return url
end
function stripArgument(arg)
if args.name == "" or args.name == nil then
return nil
else
return arg
end
end
return p