Global Lua Modules/Ref

Ref is a module for creating references for different types of referenced material. Its purpose is to provide a consistent reference format across all types of media, without the need to create multiple reference templates that may be inconsistent with one another. Ref can be used to create one or many templates.
In addition to being able to construct any reference using a standard set of inputs, Ref is also designed to be able to auto-fill references to entries from a wiki's series. This is done by importing a wiki's local module containing data tables with information for entries in that series, meaning one only needs reference a shorthand for the piece of media from that series to create a full reference to it.
The default format Ref uses is known as "wiki-style" format. This is adapted from Wikipedia's Citation Style 1—which in turn uses elements from APA style and The Chicago Manual of Style—with some modifications that more closely resemble APA style.The main modification made by the wiki-style in this reference as opposed to Wikipedia's CS1 is the use of "[media]" identifiers, similar to APA style. This allows a reference to easily distinguish between, for instance, a game or movie of the same name. The other difference is the consistent use of a date at the start of a reference regardless of if an author is present; while CS1 would move the date to follow the publisher when an author is present, wiki-style in Ref always places it first for simplicity. However, the module is designed to allow for different reference styles to be used to suit a wiki's needs (meaning functions for pure APA style, pure Chicago-style, or Harvard referencing could be added if desired).
== Features ==
* Creates references for any type of reference material (games, movies, TV series, books, web pages, etc.).
* Auto-fill references to entries from a wiki's series, based on a local wiki's module table(s).
* References created across a standard referencing style, based on Wikipedia's Citation Style 1 and APA style.
== ==
=== Main module ===
First thing is the module itself. You don't need to copy the code. Just create a module titled Module:Ref (or any other—just remember to adjust #invoke calls) and put this in the code.
return require('Dev:Ref')
=== Template ===
The module is designed to be used as a regular template. To do that just create a template (ex: Template:Ref) with following content:
{{#invoke:Ref|main}}
Now the template you created will accept the parameters documented here. They should follow the style guide as depicted in below examples.
These parameters can also be passed directly to the #invoke and will act as defaults. Their values will be overridden by same ones passed to the template.
=== Auto-fill modules (optional) ===
A local wiki module can be filled with data for releases from that wiki in order for auto-fill functions to create references to them based on shorthand.
For example, creating Module:Sources with a data table similar to Module:Ref/example, and then importing like this:
return require('Dev:Ref').custom_sourcedata(
	mw.loadData('Module:Sources')
)
will make those auto-fill shorthands available.
== Parameters ==
=== Auto-fill ===
These parameters are used to auto-fill a reference based on a sourcedata module. Individual parts of the references can be overridden with other parameters.
Parameter name	Description
version 	Switches between the version of the work to be auto-filled.
game 	Auto-fills a game reference based on table. See example.
movie 	Auto-fills a movie reference based on table. See example.
series 	Auto-fills a series reference based on table. See example.
episode 	Auto-fills an episode reference based on table. See example.
book 	Auto-fills a book release reference based on table. See example.
guide 	Auto-fills a game's guide based on table. See example.
db 	Auto-fills a game's design bible based on table. See example.
=== Core components ===
These parameters are core components for constructing any type of reference. Only title is mandatory.
Parameter name 	Description 	Related to
id 	A custom unique ID to use when linking to the reference from a citation. This is optional, as the reference will generate an ID automatically based on the last/author and year. 	ID
year[n] 	The year that the material was originally released. Use year when material has only one author, or year1 up to year10 for multiple. 	Date
month 	The month that the material was originally released. Follows same rules as year. 	Date
day 	The day that the material was originally released. Follows same rules as day. 	Date
last[n] 	The last name of the author of the work being referenced, if the author is a person. Use last when material has only one author, or last1 up to last10 for multiple. 	Author
first[n] 	The first name of the author of the work being referenced, if the author is a person. Follows same rules as last. 	Author
author[n] 	The author of the work being referenced, if the author is an organization or uses a stage name. Follows same rules as last. 	Author
author-link[n] 	A page on the wiki for the author to point to. Interwiki links can also be used, but not URL links. 	Author
title 	The title of the work being referenced. This is a mandatory field. Italicized by default. See Style and Examples for how it is used. 	Title
link 	A page on the wiki for the title to point to. Interwiki links can also be used, but not URL links (see Specific components for referencing web pages). 	Title
entry 	The title of the entry of the material being referenced. If the referenced material is an entry in a larger body of work (i.e. article title, comic book story arc, etc.), this should be used. 	Title
entry-link 	A page on the wiki for the entry to point to. Interwiki links can also be used, but not URL links (see below). 	Title
noitalictitle 	Set this parameter to true for the title to not be italicized. Per Style, titles should only be italicized if they qualify as a full "work", like with a game, movie, series, book, magazine, etc.; articles, episodes, wiki interviews, etc. should not be italicized.	Title
additional-authors	Additional authors of the work being referenced, if applicable. This can serve as a catch-all for any additional individuals or entities responsible for the creation and publication of the work. 	Additional authors
publisher 	The publisher(s) of the work being referenced. This can be a book's publisher, a film's distributor, a TV series' production company, or otherwise. Unlike author, no additional parameter is needed, and all publishers and their links. 	Publisher
media 	The media type of the work being referenced. Can be all lowercase, as the first letter will be capitalized. 	Media
platform 	The platform on or medium through which the work being cited was published, for example the specific video game console, website name (if different from publisher), etc. 	Platform
extra 	Any additional content to be placed at the end of the reference, separated by a period and a space. 	Additional
=== Specific components ===
These parameters are only used for specific components for certain types of references. The majority of references will not need them.
Parameter name 	Description 	Related to
season 	The season of the episode being referenced. The full descriptor should be used in addition to the number, i.e. "Season 3" instead of simply "3", allowing links to or alternate names for the season if desired. 	Episode
number 	The number of the episode being referenced. The full descriptor should be used in addition to the episode number, i.e. "Episode 3" instead of simply "3", allowing links to or alternate names for the season if desired.	Episode
location 	The location in the material being referenced, such as a chapter in a work. The majority of references can simply reference the full work, but if only a specific chapter is cited, this can be used. 	Book
p 	The page of the work being referenced. The majority of references can simply reference the full work, but if only a specific page is cited, this can be used. 	Book
isbn 	The International Standard Book Number of the work. 	Book
volume 	The volume of the periodical work (i.e. magazine) being referenced. 	Magazine/journal
issue 	The issue of the periodical work (i.e. magazine) being referenced. 	Magazine/journal
access-date 	If the work being referenced is or is hosted on a website, set this parameter to the date of using this template. This way if the link dies, a future editor may be able to find the correct archive based on the date. 	Web pages, YouTube, Twitter, Instagram
url 	An external URL for the entry name or title to point to. 	Web pages
archive-url 	The URL to a backup or archive of a work. Only specify if you need to include a specific URL, as otherwise, one will be automatically generated based on the url parameter. 	Web pages
archive-date 	The date of the backup or archive used (only required in combination with archive-url). 	Web pages
brokenlink 	Set to true if the original, non-archive link has gone down. If so, the primary link used to wrap the title contents will be the archive-url, rather than the original. 	Web pages
youtube-id 	The ID fragment from the referenced YouTube video's URL. Also sets the reference to be a video reference. 	YouTube
channel 	The name of the YouTube channel posting the referenced material. Can alternatively use author-id. 	YouTube
channel-id (Deprecated)	Previously the ID fragment from the referenced YouTube channel's URL. However, this is now deprecated, as YouTube uses the channel name instead. 	YouTube
tweet-id 	The ID fragment from the referenced tweet, used in combination with author-id. Also sets the reference to be a tweet reference. 	Social media posts
instagram-id 	The ID fragment from the referenced Instagram post. Also sets the reference to be a tweet reference. 	Social media posts
author-id 	The handle (YouTube, Twitter, or Instagram) of the user posting the referenced post. 	Social media posts
== Style ==
=== General ===
Ref's default wiki-style generally presents a reference as follows:
:Author (n.d.). "Entry". Title. Source. Additional authors. Identifiers.
The author(s)If a reference material has multiple main authors, each are listed in the author section. Additional, contributing authors are listed after the source. and date of the reference material will precede any reference. "n.d." is used when no date is available, and the author left blank if unavailable.
If the material referenced is an entry of a work (such as an article in a journal/website/magazine, or an episode of a series), the author and date of the entry are used, followed by the name of the entry in quotations, the title of the work (such as the place the article was published, or the name of the series) in italics, and then the source (typically the publisher) of the work. After this are any identifiers for the work.
If the material referenced is a full body of work (such as a video game, movie, or a book), the author and date of the work are used, followed by the title of the work in italics. After this, the source/publisher of the work, and any identifiers (such as the platform the game was released on, or the channel used by a YouTube video).
The preferred use for references with Ref is with two-part citations. This allows for list of references presented in a way that is cleaner, more academically professional, and avoids repetition if multiple in-part citations need to point to different parts of the same work.
=== Audiovisual media ===
Type 	Author 	Source
Video game 	Developing studio 	Publishing studio
Film 	Director 	Distributing studio
TV series 	Executive producer(s) 	Production company
TV series episode 	Writer and director of episode 	Production company
Music album or song 	Recording artistFor classical music, the artist is instead the composer.	Record label
Podcast 	Host or executive producer 	Podcast platform
Podcast episode 	Host of episode 	Publisher, hosted platform
Webinar 	Instructor 	Hosted platform
Artwork 	Artist 	N/A
Online streaming video	Person or group who uploaded the video 	Hosted platform
Photograph 	Photographer 	Hosted platform
;Video game
:Developer (Year). Title [Video game]. Publisher. Platform.
The author of a video game is the studio that developed the game. If multiple studios are listed as co-developing the game, they will be listed separated by parentheses ("Developer 1, Developer 2"); if additional studios contributed to the game (but are not the main developers), they are considered additional authors (and are listed after the publisher).
;Movie
:Last, First (Director) (Year). Title [Film]. Distributor.
The author of a movie is the movie's director, followed by the (Director) qualifier. If a movie had multiple directors, they will be listed delimited by semicolons ("Last, First (Director); Last, First (Director)"). If a movie was published in another language, the translated title can appear after the title in non-italics, as [translated title]. If multiple studios are involved, they are also delimited by semicolons (Studio 1; Studio 2).
;TV series
:Last, First (Executive Producer) (First year-End year). Title [Series]. Production company.
The author of a full TV series is the series' executive producer, followed by the (Executive Producer) qualifier. As with movies, multiple studios are delimited by semicolons.
;TV series episode
:Last, First (Director & Writer); (Year, Month Day). "Episode" (Season No., Episode No.) [Episode]. From Series. Production company.
The author of a TV episode is each writer and director, with writers taking precedence. If they are the same person, the (Writer & Director) qualifier is used; otherwise, each is listed with either a (Writer) or (Director) qualifier. Beyond this, the reference follows the same rules as that of a normal series.
;Music album
:Artist (Year). Title [Album]. Label.
The author of a music album is the recording artist' name. If the artist uses a real name, their name is listed in the "Last, First" format; otherwise, the artist's name (such as a band name or stage name) is used. If multiple labels are involved, they are also delimited by semicolons (Label 1; Label 2).
;Song
:Artist (Year). "Title" [Song]. From Album. Label.
As with the music album, the author of a song is the recording artist' name, and the same rules apply. This only applies to the main artist(s) of a song: featured artists can be listed as additional authors, but this is not necessary.
=== Textual works ===
;Book
:Last, First (Year). Title [Book]. Publisher. ISBN.
A book that is a complete work needs its author, title, and publisher. The International Standard Book Number (ISBN) should be used if available (though books published before 1970 will not have it). As with movies, if the book was originally published in another language, the translated title can appear after the title in non-italics, as [translated title].
;Periodicals
:Last, First (Year). "Article title". From Publication title (Volume No., Issue No.). Archived from the original on archive-date.
Periodicals refer to works published on a continuous basis. These include articles in journals, magazines, newspapers, newsletters, and even blogs and other online platforms. This is the appropriate format for comic books. For magazines and journals, the volume no./issue no. is needed; for online articles, it is generally preferred to also archive the page on the Wayback Machine and link to it, and the access-date must be provided.
;Comic books
:Last, First (Year). Title (Volume No., Issue No.). [Comic book]. Publisher.
The author of the comic book is the writer of the book or story arc referenced. If referencing a specific story arc in a comic book containing multiple arcs, the story arc should be used as the entry.
=== Online media ===
;YouTube video
:Last, First (Year). Title [Video]. Channel. YouTube. Accessed on access-date.
The author is the creator(s) of the video. This is typically the uploader, though not always (for instance: a re-upload from another creator should credit the original creator of the video). The channel name will be listed after the title. Listing the access date is also ideal, as videos can be taken down.
;Tweet
:Last, First [@handle] (Year). Tweet text [Tweet]. Twitter. Accessed on access-date.
The author is the person or group under which the tweet was posted. Their Twitter handle will follow the author name. The text of the tweet is used in place of the title. Only original content should be cited from tweets, and cited directly. Listing the access date is also ideal, as tweets can be taken down.
;Podcast
:Last, First (Host). Title [Podcast series]. Platform.
The author of a podcast is its host(s). If a URL link to the podcast is known, the title should contain a URL link to the podcast.
;Podcast episode
:Last, First (Host). "Title" (Episode No.) [Podcast episode]. From Series. Platform.
The episode of a podcast follows the same rules as those of a podcast series, and any guests on the episodes are listed as additional authors.
== Examples==
=== General ===
The preferred use of Ref is with two-part citations, as follows:
Lorem ipsum dolor sit amet.<ref name="Example">[[#Example2022|Example 2022]], specific information</ref>
==Citations==
{{citations}}
==References==
* {{ref |id=Example2022 |author= |date= |title= |url= |wikilink= |section= |additional-authors= |platform= |publisher= |isbn= |access-date= |archive-url= |archive-date= |deadurl= }}
However, references created by Ref can be used in inline citations, if desired:
Lorem ipsum dolor sit amet.<ref>{{ref |author= |date= |title= |url= |wikilink= |section= |additional-authors= |platform= |publisher= |isbn= |access-date= |archive-url= |archive-date= |deadurl= }}</ref>
==References==
{{citations}}
=== Video game ===
{{ref|author=[[w:c:finalfantasy:Square Co., Ltd.|Square Co., Ltd.]] |year=1997 |title=[[w:c:finalfantasy:Final Fantasy VII|Final Fantasy VII]] |platform=[[wikipedia:PlayStation|PlayStation]] |publisher=Square Co., Ltd. |media=game}}
produces:
:
When using autofill, with the following in a source data module:
['ffvii'] = {
	title = 'Final Fantasy VII',
	link = 'Final Fantasy VII',
	media = 'game',
 year = '1997',
 month = '1',
 day = '31',
	platform = '[[PlayStation]]',
	developer = '[[Square Co., Ltd.]]',
	publisher = '[[Square Co., Ltd.]]',
	versions = {
	 ['nintendo switch'] = {
	 name = '(Nintendo Switch)',
	 developer = '[[Square Enix]], DotEmu',
	 publisher = '[[Square Enix]]',
	 platform = '[[Nintendo Switch]]',
	 year = '2019',
 month = '3',
 day = '26',
	 },
	},
 }
then 
{{ref|game=ffvii}}
produces:
:
and
{{ref|game=ffvii|version=nintendo switch}}
produces:
:
=== Movie ===
{{ref|author=[[wikipedia:Sam Raimi|Raimi, Sam]] |author-type=Director |year=2002 |title=[[wikipedia:Spider-Man (2002 film)|Spider-Man]] |publisher=Sony Pictures Releasing |media=film}}
produces:
:
When using autofill, with the following in a source data module:
['sm1'] = {
	title = 'Spider-Man',
	link = 'Spider-Man (2002 film)',
	media = 'film',
 year = '2002',
 month = '5',
 day = '3',
	director = {'Sam', 'Raimi'},
	studio = 'Sony Pictures Releasing',
 }
then 
{{ref|movie=sm1}}
produces:
:
=== TV show ===
{{ref|first1=Michael Dante |last1=DiMartino |author-link1=w:c:avatar:Michael Dante DiMartino |first2=Bryan |last2=Konietzko |author-link2=w:c:avatar=Bryan Konietzko |author-type=Executive Producer |year=2005-2008 |title=[[w:c:avatar:Avatar: The Last Airbender|Avatar: The Last Airbender]] |publisher=[[w:c:avatar:Nickelodeon|Nickelodeon Animation Studios]] |media=series}}
produces:
:
When using autofill, with the following in a source data module:
['atla'] = {
	title = 'Avatar: The Last Airbender',
	link = 'Avatar: The Last Airbender',
	media = 'series',
 year = '2005-2008',
	executive = {{'Michael Dante', 'DiMartino'}, {'Bryan', 'Konietzko'}},
	studio = '[[Nickelodeon|Nickelodeon Animation Studios]]',
 }
then 
{{ref|series=atla}}
produces:
:
=== TV episode ===
{{ref|first1=Eric |last1=Horsted |author-type1=Writer |first2=Ron |last2=Hugart |author-type2=Director |year=2000 |month=11 |day=26 |entry=[[w:c:futurama:War Is the H-Word|War Is the H-Word]] |season=Season 3 |number=Episode 17 |title=[[w:c:futurama:Futurama|Futurama]] |publisher=The Curiosity Company; 20th Century Fox Television |media=episode}}
produces:
:
When using autofill, with the following in a source data module:
['war is the h-word'] = {
	title = 'War Is the H-Word',
	link = 'War Is the H-Word',
	media = 'episode',
 year = '2000',
 month = '11',
 day = '26',
   season = 'Season 3',
 number = 'Episode 17',
	writer = {'Eric', 'Horsted'},
 director = {'Ron', 'Hugart'},
	studio = 'The Curiosity Company; 20th Century Fox Television',
 series = 'futurama'
 }
then 
{{ref|episode=war is the h-word}}
produces:
:
=== Music album ===
{{ref|first=Kendrick |last=Lamar |year=2015 |title=[[wikipedia:To Pimp a Butterfly|To Pimp a Butterfly]] |publisher=Aftermath Entertainment; Interscope Records; Top Dawg Entertainment |media=album}}
produces:
:
When using autofill, with the following in a source data module:
['tpab'] = {
	title = 'To Pimp a Butterfly',
	link = 'To Pimp a Butterfly',
	media = 'album',
 year = '2015',
 month = '3',
 day = '15',
 artist = {'Kendrick', 'Lamar'},
	label = {'Aftermath Entertainment', 'Interscope Records', 'Top Dawg Entertainment'}
 }
then 
{{ref|album=tpab}}
produces:
:
=== Song ===
{{ref|author=[[wikipedia:2Pac|2Pac]] |year=1993 |month=10 |day=28 |entry=[[wikipedia:Keep Ya Head Up|Keep Ya Head Up]] |title=[[wikipedia:Strictly 4 My N.I.G.G.A.Z...|Strictly 4 My N.I.G.G.A.Z...]] |additional-authors=Hollister, Dave |publisher=Interscope Records; Jive Records |media=song}}
produces:
:
When using autofill, with the following in a source data module:
['keep ya head up'] = {
	title = 'Keep Ya Head Up',
	link = 'Keep Ya Head Up',
 album = '[[Strictly 4 My N.I.G.G.A.Z...]]',
	media = 'song',
 year = '1993',
 month = '10',
 day = '28',
 artist = '2Pac',
 featured = 'Hollister, Dave',
	label = {'Interscope Records', 'Jive Records'}
 }
then 
{{ref|song=keep ya head up}}
produces:
:
=== Book (full release) ===
A book released before 1970 does not need the ISBN. For example:
{{ref|first=Octavia E. |last= Butler |year=1993 |title=[[wikipedia:Parable of the Sower (novel)|Parable of the Sower]] |publisher=Four Walls Eight Windows |isbn=0-941423-99-9 |media=book}}
produces:
:
{{ref|first=Jane |last=Austen |year=1813 |month=1 |day=28 |title=[[wikipedia:Pride and Preduce|Pride and Preduce]] |publisher=T. Egerton, Whitehall |media=book}}
produces:
:
When using autofill, with the following in a source data module:
['pots'] = {
	title = 'Parable of the Sower',
	link = 'Parable of the Sower (novel)',
	media = 'book',
 year = '1993',
 author = {'Octavia E.', 'Butler'},
 publisher = 'Four Walls Eight Windows',
 isbn = '0-941423-99-9'
 }
then 
{{ref|book=pots}}
produces:
:
=== Book (accompaniment to release) ===
Sometimes, a book that is an accompaniment to a release may be included in the main release' source code. This includes guides or design bibles for a game. Multiple versions can be given for guides or design bibles.
For example, given input:
['jak2'] = {
 ['title'] = 'Jak II',
 ['pagename'] = 'Jak II',
 ['year'] = '2003',
 ['month'] = '10',
 ['day'] = '14',
 ['media'] = 'game',
 ['developer'] = '[[wikipedia:Naughty Dog|Naughty Dog]]',
 ['platform'] = '[[wikipedia:PlayStation 2|PlayStation 2]]',
 ['publisher'] = '[[wikipedia:Sony Interactive Entertainment|Sony Computer Entertainment]]',
 ['guide'] = {
			['piggyback'] = {
				['author'] = { 'Nathali', 'Schrader' },
		 ['year'] = '2003',
		 ['month'] = '10',
		 ['day'] = '13',
				['title'] = 'The Complete Official Guide to Jak II: Renegade',
				['additional-authors'] = '[[wikipedia:Naughty Dog|Naughty Dog]]',
				['publisher'] = 'Piggyback Interactive, [[wikipedia:Sony Interactive Entertainment|Sony Computer Entertainment]]',
				['isbn'] = '1903511453',
			},
			['bradygames'] = {
				['author'] = { 'Greg', 'Off' },
		 ['year'] = '2003',
		 ['month'] = '10',
		 ['day'] = '18',
				['title'] = 'Jak II Official Strategy Guide',
				['additional-authors'] = '[[wikipedia:Naughty Dog|Naughty Dog]]',
				['publisher'] = '[[wikipedia:DK (publisher)#BradyGames|BradyGames]], [[wikipedia:Sony Interactive Entertainment|Sony Computer Entertainment]]',
				['isbn'] = '0744003016',
			},
 },
		['db'] = {
			['author'] = '[[wikipedia:Naughty Dog|Naughty Dog]]',
	 ['year'] = {'2002', '2019'},
			['title'] = 'Jak II Design Bible — Original Production Binder',
			['additional-authors'] = '[[wikipedia:Limited Run Games|Limited Run Games]]',
			['publisher'] = '[[wikipedia:Sony Interactive Entertainment|Sony Interactive Entertainment]]',
		},
 },
the input:
{{ref|db=jak2}}
produces:
:
And the input:
{{ref|guide=jak2|version=bradygames}}
produces:
:
while the other input could be used if desired.
=== Comic book ===
{{ref|first=Gail |last=Simone |author-link=w:c:dc:Gail Simone |month=1 |year=2008 |title=Wonder Woman |volume=[[w:c:dc:Wonder Woman Vol 3|Volume 3]] |issue=[[w:c:dc:Wonder Woman Vol 3 14|#14]] |publisher=[[w:c:dc:DC Comics|DC Comics]]}}
produces:
:
When using autofill, with the following in a source data module:
	['wonder woman vol 3 14'] = {
		title = 'Wonder Woman',
		media = 'book',
		volume = '[[w:c:dc:Wonder Woman Vol 3|Volume 3]]',
		issue = '[[w:c:dc:Wonder Woman Vol 3 14|#14]]',
		year = '2008',
		month = '1',
		author = {'Gail', 'Simone'},
		publisher = '[[w:c:dc:DC Comics|DC Comics]]'
	},
then 
{{ref|book=wonder woman vol 3 14}}
produces:
:
=== Web article ===
{{ref|first=Josh |last=West |day=21 |month=4 |year=2020 |entry=Meet Britt Baron and Briana White, the voice actors behind Tifa and Aerith in Final Fantasy 7 Remake |url=https://www.gamesradar.com/final-fantasy-7-remake-aerith-briana-white-tifa-britt-baron-interview/ |title=GamesRadar |access-date=April 24, 2020 }}
produces:
:
=== YouTube ===
{{ref|first1=Mike |last1=Stout |first2=Tony |last2=Garcia |day=21 |month=6 |year=2011 |title=Ratchet & Clank 2 Dev Commentary: 4A - Maktar Resort |youtube-id=1Le54_8tFaU |author-id=uselesspodcasts |access-date=November 8, 2019}}
produces:
:
=== Twitter ===
{{ref|author=TJ Fixman|day=10 |month=7 |year=2013 |title=If you thought Courtney Gears was evil, wait until you meet Vendra Prog. #IntoTheNexus|tweet-id=355171730014224387|noitalictitle=true|author-id=TJFixman|access-date=November 8, 2019}}
produces:
:
== Notes ==