Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  



























Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  














Module:Gutenberg






العربية
Авар
Azərbaycanca
تۆرکجه

 / Bân-lâm-gú

Español
فارسی

Հայերեն
Hrvatski
Bahasa Indonesia
Jawa

Bahasa Melayu


Română
Scots

Simple English
سنڌي
کوردی
Српски / srpski
Srpskohrvatski / српскохрватски
 
اردو
Tiếng Vit


 

Edit links
 









Module
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 

















Permanently protected module

From Wikipedia, the free encyclopedia
 


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  = "https://www.gutenberg.org/author/"          
  local urlheadnumb  = "https://www.gutenberg.org/ebooks/author/" 
  local urlhead  = nil

  -- Argument |id=
  id = trimArg(args[1]) or trimArg(args.id)
  if not id then
    local bestP1938 = mw.wikibase.getBestStatements(mw.wikibase.getEntityIdForCurrentPage(), 'P1938')[1]
    if bestP1938 and bestP1938.mainsnak.snaktype == 'value' then
      id = bestP1938.mainsnak.datavalue.value
      local entity = mw.wikibase.getEntityObject() or {}
      tagline = tagline .. " [[File:OOjs UI icon edit-ltr-progressive.svg |frameless |text-top |10px |alt=Edit this at Wikidata |link=https://www.wikidata.org/wiki/" .. entity.id .. "#P1938|Edit this at Wikidata]]" 
    else
      error("Parameter id is missing. See [[Template:" .. tname .. "]] documentation")
    end
  end 
  if tonumber(id) then -- it's a number
    urlhead = urlheadnumb
  else
    urlhead = urlheadname
    id = mw.ustring.gsub(id," ", "+")
  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 p.Canada(frame)
  
  local pframe = frame:getParent()
  local args = pframe.args

  local tname = "FadedPage"                                        -- name of calling template. Change if template is renamed.
 
  local id       = nil                                             -- ID for author, eg. http://fadedpage.com/csearch.php?author=Shortt%2C%20Adam .. the id = Shortt, Adam
                                                                   -- ID for book titles, eg. http://fadedpage.com/showbook.php?pid=20160704 .. the id = 20160704
  local name     = nil                                             -- display name on Wikipedia (default: article title)
  local author   = nil                                             -- flag if an author (default: no)
  local url      = nil
  local urlhead  = "https://fadedpage.com/"
  local urlbook  = "showbook.php?pid="
  local urlauth  = "csearch.php?author="
  local prefix   = ""
  local tagline  = "at [[Distributed Proofreaders Canada|Faded Page]] (Canada)"
  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
      id = mw.uri.encode( id, "PATH" )                                -- handle spaces within id argument string
      prefix = "Works by "
      italic = ""
      url = "[" .. urlhead .. urlauth .. id .. " " .. prefix .. italic .. name .. italic .. "] " .. tagline
      return url
    end
  end

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

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Gutenberg&oldid=1080438970"

Categories: 
Modules in beta
Modules using data from Wikidata
Hidden category: 
Wikipedia template-protected modules
 



This page was last edited on 1 April 2022, at 08:43 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki