Jump to content

Module:Gutenberg: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
use explicit http per request by User:Green Cardamom
updates requested by User:Green Cardamom
Line 6: Line 6:
local args = pframe.args
local args = pframe.args
local tname = "Gutenberg author" -- name of calling template. Change if template is renamed.
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 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 name = nil -- display name on Wikipedia (default: article title)
local url = nil
local url = nil
local tagline = "at [[Project Gutenberg]]"
local tagline = "at [[Project Gutenberg]]"
Line 31: Line 31:
name = mw.title.getCurrentTitle().text:gsub('%s+%([^%(]-%)$', '') -- Current page name without the final parentheses
name = mw.title.getCurrentTitle().text:gsub('%s+%([^%(]-%)$', '') -- Current page name without the final parentheses
end
end

local stitle = mw.ustring.gsub(name," ", "+") -- replace "<space>" with "+"


url = "[" .. urlhead .. id .. " Works by " .. name .. "] " .. tagline
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 = "''"

id = trimArg(args[1]) or trimArg(args.id)
if not id then
error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation")
end

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

author = trimArg(args.author)
if author then
prefix = "Works by "
italic = ""
end

url = prefix .. "[" .. urlhead .. id .. " " .. italic .. name .. italic .. "] " .. tagline


return url
return url

Revision as of 11:28, 8 October 2015

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

  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
    end
  end 

  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

  local stitle = mw.ustring.gsub(name," ", "+")                       -- replace "<space>" with "+"

  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   = "''"

  id = trimArg(args[1]) or trimArg(args.id)
  if not id then
    error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation")
  end 

  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

  author = trimArg(args.author)
  if author then
    prefix = "Works by "
    italic = ""
  end

  url = prefix .. "[" .. urlhead .. id .. " " .. 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