Module:Gutenberg: Difference between revisions
Appearance
Content deleted Content added
updates requested by User:Green Cardamom |
fixes and updates |
||
Line 16: | Line 16: | ||
local urlhead = nil |
local urlhead = nil |
||
-- Argument |id= |
|||
id = trimArg(args[1]) or trimArg(args.id) |
id = trimArg(args[1]) or trimArg(args.id) |
||
if not id then |
if not id then |
||
Line 24: | Line 25: | ||
else |
else |
||
urlhead = urlheadname |
urlhead = urlheadname |
||
id = mw.ustring.gsub(id," ", "+") |
|||
end |
end |
||
end |
end |
||
-- Argument |name= |
|||
name = trimArg(args[2]) or trimArg(args.name) |
name = trimArg(args[2]) or trimArg(args.name) |
||
if not name then |
if not name then |
||
Line 32: | Line 35: | ||
end |
end |
||
-- Argument |coda= |
|||
local stitle = mw.ustring.gsub(name," ", "+") -- replace "<space>" with "+" |
|||
if trimArg(args.coda) then |
|||
tagline = tagline .. " " .. trimArg(args.coda) |
|||
end |
|||
url = "[" .. urlhead .. id .. " Works by " .. name .. "] " .. tagline |
url = "[" .. urlhead .. id .. " Works by " .. name .. "] " .. tagline |
||
Line 57: | Line 63: | ||
local italic = "''" |
local italic = "''" |
||
-- Argument |id= |
|||
id = trimArg(args[1]) or trimArg(args.id) |
id = trimArg(args[1]) or trimArg(args.id) |
||
if not id then |
if not id then |
||
Line 62: | Line 69: | ||
end |
end |
||
-- Argument |name= |
|||
name = trimArg(args[2]) or trimArg(args.name) |
name = trimArg(args[2]) or trimArg(args.name) |
||
if not name then |
if not name then |
||
Line 67: | Line 75: | ||
end |
end |
||
-- Argument |author= |
|||
author = trimArg(args.author) |
author = trimArg(args.author) |
||
if author then |
if author then |
||
if mw.ustring.lower(author) == "yes" then |
|||
prefix = "Works by " |
|||
prefix = "Works by " |
|||
italic = "" |
|||
end |
|||
end |
|||
-- Argument |coda= |
|||
if trimArg(args.coda) then |
|||
tagline = tagline .. " " .. trimArg(args.coda) |
|||
end |
end |
||
url = |
url = "[" .. urlhead .. id .. " " .. prefix .. italic .. name .. italic .. "] " .. tagline |
||
return url |
return url |
Revision as of 16:41, 14 December 2015
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 12,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module uses the Wikidata property:
Usage
There are currently 3 templates that invoke this module, {{Gutenberg author}}
, {{Gutenberg Australia}}
and {{FadedPage}}
(Canada)
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 number. Name goes to search page, number goes direct to author page
local name = nil -- display name on Wikipedia (default: article title)
local url = nil
local tagline = "at [[Project Gutenberg]]"
local urlheadname = "http://www.gutenberg.org/author/" -- SSL problems with certain browsers. See [[Template_talk:Gutenberg_author#https_problem]]
local urlheadnumb = "http://www.gutenberg.org/ebooks/author/"
local urlhead = nil
-- Argument |id=
id = trimArg(args[1]) or trimArg(args.id)
if not id then
error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation")
else
if tonumber(id) then -- it's a number
urlhead = urlheadnumb
else
urlhead = urlheadname
id = mw.ustring.gsub(id," ", "+")
end
end
-- Argument |name=
name = trimArg(args[2]) or trimArg(args.name)
if not name then
name = mw.title.getCurrentTitle().text:gsub('%s+%([^%(]-%)$', '') -- Current page name without the final parentheses
end
-- Argument |coda=
if trimArg(args.coda) then
tagline = tagline .. " " .. trimArg(args.coda)
end
url = "[" .. urlhead .. id .. " Works by " .. name .. "] " .. tagline
return url
end
function p.Australia(frame)
local pframe = frame:getParent()
local args = pframe.args
local tname = "Gutenberg Australia" -- name of calling template. Change if template is renamed.
local id = nil -- ID. eg. http://gutenberg.net.au/plusfifty-n-z.html#shanks .. the ID = plusfifty-n-z.html#shanks
-- ID is the same for linking an individual book title, or all books by the author.
local name = nil -- display name on Wikipedia (default: article title)
local author = nil -- flag if an author (default: no)
local url = nil
local urlhead = "http://gutenberg.net.au/"
local prefix = ""
local tagline = "at [[Project Gutenberg Australia]]"
local italic = "''"
-- Argument |id=
id = trimArg(args[1]) or trimArg(args.id)
if not id then
error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation")
end
-- Argument |name=
name = trimArg(args[2]) or trimArg(args.name)
if not name then
name = mw.title.getCurrentTitle().text:gsub('%s+%([^%(]-%)$', '') -- Current page name without the final parentheses
end
-- Argument |author=
author = trimArg(args.author)
if author then
if mw.ustring.lower(author) == "yes" then
prefix = "Works by "
italic = ""
end
end
-- Argument |coda=
if trimArg(args.coda) then
tagline = tagline .. " " .. trimArg(args.coda)
end
url = "[" .. urlhead .. id .. " " .. prefix .. italic .. name .. italic .. "] " .. tagline
return url
end
function trimArg(arg)
if arg == "" or arg == nil then
return nil
else
return mw.text.trim(arg)
end
end
return p