Dungeons & Dragons Lore Wiki

Welcome to the Dungeons & Dragons Lore Wiki, an encyclopedia of official first-party D&D canon from 1974 to the current day.

We need editors! See the editing guidelines for ways to contribute.

READ MORE

Dungeons & Dragons Lore Wiki
Advertisement

This module is for making links to D&D books. It is usually invoked via the following templates:

  • {{book}}, which creates a wikilink to a book
  • {{cite book}}, which creates a <ref> citation to a book

Data format

Data for practically every first-party D&D sourcebook appears in Module:Book/data, which is held in a Lua table. Take great care when adding a new entry, as a syntax error may break citations across the entire wiki. Here's an example entry in the database:

  ["Queen of the Spiders"] = {
    year="1986",
    abbr="gdq17-1986",
    code="9179",
    series_code="GDQ1-7",
    isbn="0-88038-321-6"
  },

The fields are as follows:

  • Key: The official name of the book.
  • year: The year the book was first published. Don't put the whole date here; just the four-digit year.
  • abbr: An internal code used in the <ref name=""> field. It can be anything, but it must be unique in the list, and must contain at least one non-numeric character. Usually, it's the book's initials followed by the year, e.g. dmg-2014.
  • code: TSR or WotC's official four-digit or five-digit product code for the book. Sometimes found prefixed with "TSR" or "WTC", and/or suffixed with "0000", "7200", or "7400". The code isn't currently used by the book function, but should be included to help uniquely identify the book. You should verify this with a physical book; codes ending with "?" have not been found by online sources and not independently verified yet. The code can be "none" (if it has none) or "unknown" (if it is unknown whether it has one).
  • series_code: (optional) An official TSR/WotC code generally used for adventure module series, e.g. "G3", "T1-4".
  • isbn: (optional) ISBN for the book. Currently not used by the book function, but may be use in future.

Instead of these fields, an entry may have an alias_for entry like so:

  ["The World of Greyhawk Folio"] = { alias_for = "The World of Greyhawk Fantasy World Setting"},
  • alias_for: This name is a synonym for another book. Any time this name is encountered, it is corrected to its alias_for entry. This is used for common misspellings, e.g. omitting "The" from the name, capitalization, "and" vs "&", "2" vs "II" vs "Two", etc.

Magazines don't appear in this list (see e.g. {{DragonMagazine}}), but magazine annuals do.


local p = {}
local bookData = mw.loadData( 'Module:Book/data' )

function p.Book( frame )
  local title = frame.args["title"] or "default"
  local page = frame.args["page"] or ""
  local sub = frame.args["sub"] or ""
  local isbn = frame.args["isbn"] or ""

  local year = ""
  local abbr = "unknown"
  local series_code = ""

  if bookData[title] then
    if bookData[title]["alias_for"] then
      title = bookData[title]["alias_for"] or ""
    end
    year = bookData[title]["year"] or ""
    abbr = bookData[title]["abbr"] or "unknown"
    series_code = bookData[title]["series_code"] or ""
  end

  if not (series_code == "") then
    series_code = series_code .. " "
  end

  if not (abbr == "unknown") then
    title = "[[" .. title .. "]]"
  else
    title = "''" .. title .. "''{{UnknownBook}}"
  end

  if not (sub == "") then
    sub = ", ''" .. sub .. "''"
  end

  if not (page == "") then
    page = ", p." .. page
  end

  if not (isbn == "") then
    isbn = ". ISBN " .. isbn
  end

  if not (year == "") then
    year = " (" .. year .. ")"
  end

  return ( series_code .. title .. sub .. year .. page .. isbn)
end

function p.RefID ( frame )
  local title = frame.args["title"] or "default"
  local page = frame.args["page"] or ""
  local sub = frame.args["sub"] or ""

  local abbr = "unknown"
  local out = ""

  if bookData[title] then
    if bookData[title]["alias_for"] then
      title = bookData[title]["alias_for"] or ""
    end
    abbr = bookData[title]["abbr"] or "unknown"
  end

  if not (sub == "") then
    sub = "-" .. string.gsub( string.lower(sub), "[^%l]", "" )
  end

  if not (page == "") then
--    page = "-" .. string.gsub ( page, "%-.*", "")
-- The line above does not allow citing a page singly and in a range in the same document
-- It throws an error if you use {{Cite book|XYZ|5}} and {{Cite book|XYZ|5-8}} on the same page.
    page = "-" .. page
  end

  if not (abbr == "unknown") then
    out = abbr .. sub .. page
  else
    out = ""
  end

  return ( out )
end

return p
Advertisement