Title: Module:Citation/CS1/COinS - freem URL Source: https://freemwiki.com/wiki/Module:Citation/CS1/COinS Published Time: Thu, 30 Jul 2026 16:56:29 GMT Markdown Content: [Jump to content](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#bodyContent) - [x] Main menu Main menu move to sidebar hide Navigation * [Main page](https://freemwiki.com/wiki/Main_Page "Visit the main page [alt-shift-z]") * [Recent changes](https://freemwiki.com/wiki/Special:RecentChanges "A list of recent changes in the wiki [alt-shift-r]") * [Random page](https://freemwiki.com/wiki/Special:Random "Load a random page [alt-shift-x]") * [Help about MediaWiki](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents) Legal * [Terms](https://freemwiki.com/wiki/Terms_of_Service) * [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Contact](https://freemwiki.com/wiki/Contact) [![Image 1](https://freemwiki.com/images/freem.svg)**freem**](https://freemwiki.com/wiki/Main_Page) [Search](https://freemwiki.com/wiki/Special:Search "Search freem [alt-shift-f]") Search - [x] Appearance * [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3ACitation%2FCS1%2FCOinS "You are encouraged to create an account and log in; however, it is not mandatory") * [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3ACitation%2FCS1%2FCOinS "You are encouraged to log in; however, it is not mandatory [alt-shift-o]") - [x] Personal tools * [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3ACitation%2FCS1%2FCOinS "You are encouraged to create an account and log in; however, it is not mandatory") * [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3ACitation%2FCS1%2FCOinS "You are encouraged to log in; however, it is not mandatory [alt-shift-o]") Pages for logged out editors [learn more](https://freemwiki.com/wiki/Help:Introduction) * [Contributions](https://freemwiki.com/wiki/Special:MyContributions "A list of edits made from this IP address [alt-shift-y]") * [Talk](https://freemwiki.com/wiki/Special:MyTalk "Discussion about edits from this IP address [alt-shift-n]") # Module:Citation/CS1/COinS - [x] 1 language * [English](https://freemwiki.com/wiki/Module:Citation/CS1/ "Module:Citation/CS1/ – English") * [Module](https://freemwiki.com/wiki/Module:Citation/CS1/COinS "View the module page [alt-shift-c]") * [Discussion](https://freemwiki.com/index.php?title=Module_talk:Citation/CS1/COinS&action=edit&redlink=1 "Discussion about the content page (page does not exist) [alt-shift-t]") - [x] English * [Read](https://freemwiki.com/wiki/Module:Citation/CS1/COinS) * [Edit source](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&action=edit "Edit the source code of this page [alt-shift-e]") * [View history](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&action=history "Past revisions of this page [alt-shift-h]") - [x] Tools Tools move to sidebar hide Actions * [Read](https://freemwiki.com/wiki/Module:Citation/CS1/COinS) * [Edit source](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&action=edit "Edit the source code of this page [alt-shift-e]") * [View history](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&action=history) General * [What links here](https://freemwiki.com/wiki/Special:WhatLinksHere/Module:Citation/CS1/COinS "A list of all wiki pages that link here [alt-shift-j]") * [Related changes](https://freemwiki.com/wiki/Special:RecentChangesLinked/Module:Citation/CS1/COinS "Recent changes in pages linked from this page [alt-shift-k]") * [Special pages](https://freemwiki.com/wiki/Special:SpecialPages "A list of all special pages [alt-shift-q]") * [Printable version](javascript:print(); "Printable version of this page [alt-shift-p]") * [Permanent link](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&oldid=579720 "Permanent link to this revision of this page") * [Page information](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&action=info "More information about this page") Appearance move to sidebar hide From freem <[Module:Citation/CS1](https://freemwiki.com/wiki/Module:Citation/CS1 "Module:Citation/CS1") _Documentation for this module may be created at [Module:Citation/CS1/COinS/doc](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS/doc&action=edit&redlink=1 "Module:Citation/CS1/COinS/doc (page does not exist)")_ [](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-1)--[[--------------------------< F O R W A R D D E C L A R A T I O N S >--------------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-2)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-3)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-4)local has_accept_as_written, is_set, in_array, remove_wiki_link, strip_apostrophe_markup;-- functions in Module:Citation/CS1/Utilities[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-5)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-6)local cfg;-- table of configuration tables that are defined in Module:Citation/CS1/Configuration[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-7)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-8)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-9)--[[--------------------------< M A K E _ C O I N S _ T I T L E >----------------------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-10)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-11)Makes a title for COinS from Title and / or ScriptTitle (or any other name-script pairs)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-12)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-13)Apostrophe markup (bold, italics) is stripped from each value so that the COinS metadata isn't corrupted with strings[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-14)of %27%27...[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-15)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-16)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-17)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-18)local function make_coins_title (title, script)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-19)title = has_accept_as_written (title);[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-20)if is_set (title) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-21)title = strip_apostrophe_markup (title);-- strip any apostrophe markup[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-22)else[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-23)title = '';-- if not set, make sure title is an empty string[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-24)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-25)if is_set (script) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-26)script = script:gsub ('^%l%l%s*:%s*', '');-- remove language prefix if present (script value may now be empty string)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-27)script = strip_apostrophe_markup (script);-- strip any apostrophe markup[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-28)else[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-29)script = '';-- if not set, make sure script is an empty string[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-30)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-31)if is_set (title) and is_set (script) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-32)script = ' ' .. script;-- add a space before we concatenate[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-33)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-34)return title .. script;-- return the concatenation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-35)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-36)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-37)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-38)--[[--------------------------< E S C A P E _ L U A _ M A G I C _ C H A R S >----------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-39)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-40)Returns a string where all of Lua's magic characters have been escaped. This is important because functions like[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-41)string.gsub() treat their pattern and replace strings as patterns, not literal strings.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-42)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-43)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-44)local function escape_lua_magic_chars (argument)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-45)argument = argument:gsub("%%", "%%%%");-- replace % with %%[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-46)argument = argument:gsub("([%^%$%(%)%.%[%]%*%+%-%?])", "%%%1");-- replace all other Lua magic pattern characters[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-47)return argument;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-48)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-49)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-50)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-51)--[[--------------------------< G E T _ C O I N S _ P A G E S >------------------------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-52)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-53)Extract page numbers from external wikilinks in any of the |page=, |pages=, or |at= parameters for use in COinS.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-54)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-55)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-56)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-57)local function get_coins_pages (pages)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-58)local pattern;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-59)if not is_set (pages) then return pages; end-- if no page numbers then we're done[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-60)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-61)while true do[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-62)pattern = pages:match("%[(%w*:?//[^ ]+%s+)[%w%d].*%]");-- pattern is the opening bracket, the URL and following space(s): "[url "[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-63)if nil == pattern then break; end-- no more URLs[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-64)pattern = escape_lua_magic_chars (pattern);-- pattern is not a literal string; escape Lua's magic pattern characters[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-65)pages = pages:gsub(pattern, "");-- remove as many instances of pattern as possible[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-66)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-67)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-68)pages = pages:gsub("[%[%]]", "");-- remove the brackets[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-69)pages = pages:gsub("–", "-" );-- replace endashes with hyphens[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-70)pages = pages:gsub("&%w+;", "-" );-- and replace HTML entities (– etc.) with hyphens; do we need to replace numerical entities like and the like?[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-71)pages = pages:gsub ('%b<>', '');-- remove html-like tags; spans are added to by utilities.hyphen_to_dash() which should not appear in COinS metadata[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-72)return pages;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-73)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-74)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-75)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-76)--[=[-------------------------< C O I N S _ R E P L A C E _ M A T H _ S T R I P M A R K E R >------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-77)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-78)There are three options for math markup rendering that depend on the editor's math preference settings. These[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-79)settings are at [[[Special:Preferences#mw-prefsection-rendering]]](https://freemwiki.com/wiki/Special:Preferences "Special:Preferences") and are[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-80) PNG images[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-81) TeX source[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-82) MathML with SVG or PNG fallback[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-83)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-84)All three are heavy with HTML and CSS which doesn't belong in the metadata.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-85)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-86)Without this function, the metadata saved in the raw wikitext contained the rendering determined by the settings[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-87)of the last editor to save the page.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-88)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-89)This function gets the rendered form of an equation according to the editor's preference before the page is saved. It[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-90)then searches the rendering for the text equivalent of the rendered equation and replaces the rendering with that so[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-91)that the page is saved without extraneous HTML/CSS markup and with a reasonably readable text form of the equation.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-92)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-93)When a replacement is made, this function returns true and the value with replacement; otherwise false and the initial[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-94)value. To replace multipe equations it is necessary to call this function from within a loop.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-95)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-96)]=][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-97)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-98)local function coins_replace_math_stripmarker (value)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-99)local stripmarker = cfg.stripmarkers['math'];[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-100)local rendering = value:match (stripmarker);-- is there a math stripmarker[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-101)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-102)if not rendering then-- when value doesn't have a math stripmarker, abandon this test[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-103)return false, value;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-104)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-105)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-106)rendering = mw.text.unstripNoWiki (rendering);-- convert stripmarker into rendered value (or nil? ''? when math render error)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-107)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-108)if rendering:match ('alt="[^"]+"') then-- if PNG math option[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-109)rendering = rendering:match ('alt="([^"]+)"');-- extract just the math text[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-110)elseif rendering:match ('$%s+.+%s+%$') then-- if TeX math option; $ is legit character that is escapes as \$[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-111)rendering = rendering:match ('$%s+(.+)%s+%$')-- extract just the math text[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-112)elseif rendering:match (']+>.+') then-- if MathML math option[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-113)rendering = rendering:match (']+>(.+)')-- extract just the math text[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-114)else[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-115)return false, value;-- had math stripmarker but not one of the three defined forms[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-116)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-117)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-118)return true, value:gsub (stripmarker, rendering, 1);[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-119)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-120)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-121)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-122)--[[--------------------------< C O I N S _ C L E A N U P >----------------------------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-123)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-124)Cleanup parameter values for the metadata by removing or replacing invisible characters and certain HTML entities.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-125)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-126)2015-12-10: there is a bug in mw.text.unstripNoWiki (). It replaces math stripmarkers with the appropriate content[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-127)when it shouldn't. See [https://phabricator.wikimedia.org/T121085](https://phabricator.wikimedia.org/T121085) and Wikipedia_talk:Lua#stripmarkers_and_mw.text.unstripNoWiki.28.29[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-128)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-129)TODO: move the replacement patterns and replacement values into a table in /Configuration similar to the invisible[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-130)characters table?[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-131)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-132)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-133)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-134)local function coins_cleanup (value)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-135)local replaced = true;-- default state to get the do loop running[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-136)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-137)while replaced do-- loop until all math stripmarkers replaced[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-138)replaced, value = coins_replace_math_stripmarker (value);-- replace math stripmarker with text representation of the equation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-139)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-140)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-141)value = value:gsub (cfg.stripmarkers['math'], "MATH RENDER ERROR");-- one or more couldn't be replaced; insert vague error message[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-142)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-143)value = mw.text.unstripNoWiki (value);-- replace nowiki stripmarkers with their content[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-144)value = value:gsub (''(s?)', "'%1");-- replace {{['](https://freemwiki.com/wiki/Template:%27 "Template:'")}} or {{['s](https://freemwiki.com/wiki/Template:%27s "Template:'s")}} with simple apostrophe or apostrophe-s[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-145)value = value:gsub (' ', ' ');-- replace   entity with plain space[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-146)value = value:gsub ('\226\128\138', ' ');-- replace hair space with plain space[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-147)if not mw.ustring.find (value, cfg.indic_script) then-- don't remove zero-width joiner characters from indic script[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-148)value = value:gsub ('‍', '');-- remove ‍ entities[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-149)value = mw.ustring.gsub (value, '[\226\128\141\226\128\139\194\173]', '');-- remove zero-width joiner, zero-width space, soft hyphen[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-150)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-151)value = value:gsub ('[\009\010\013 ]+', ' ');-- replace horizontal tab, line feed, carriage return with plain space[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-152)return value;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-153)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-154)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-155)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-156)--[[--------------------------< C O I N S >--------------------------------------------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-157)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-158)COinS metadata (see <[http://ocoins.info/](http://ocoins.info/)>) allows automated tools to parse the citation information.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-159)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-160)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-161)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-162)local function COinS(data, class)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-163)if 'table' ~= type(data) or nil == next(data) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-164)return '';[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-165)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-166)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-167)for k, v in pairs (data) do-- spin through all of the metadata parameter values[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-168)if 'ID_list' ~= k and 'Authors' ~= k then-- except the ID_list and Author tables (author nowiki stripmarker done when Author table processed)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-169)data[k] = coins_cleanup (v);[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-170)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-171)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-172)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-173)local ctx_ver = "Z39.88-2004";[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-174)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-175)-- treat table strictly as an array with only set values.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-176)local OCinSoutput = setmetatable( {}, {[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-177)__newindex = function(self, key, value)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-178)if is_set(value) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-179)rawset( self, #self+1, table.concat{ key, '=', mw.uri.encode( remove_wiki_link( value ) ) } );[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-180)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-181)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-182)});[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-183)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-184)if in_array (class, {'arxiv', 'biorxiv', 'citeseerx', 'medrxiv', 'ssrn', 'journal', 'news', 'magazine'}) or[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-185)(in_array (class, {'conference', 'interview', 'map', 'press release', 'web'}) and is_set(data.Periodical)) or[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-186)('citation' == class and is_set(data.Periodical) and not is_set (data.Encyclopedia)) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-187)OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:journal";-- journal metadata identifier[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-188)if in_array (class, {'arxiv', 'biorxiv', 'citeseerx', 'medrxiv', 'ssrn'}) then-- set genre according to the type of citation template we are rendering[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-189)OCinSoutput["rft.genre"] = "preprint";-- cite arxiv, cite biorxiv, cite citeseerx, cite medrxiv, cite ssrn[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-190)elseif 'conference' == class then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-191)OCinSoutput["rft.genre"] = "conference";-- cite conference (when Periodical set)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-192)elseif 'web' == class then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-193)OCinSoutput["rft.genre"] = "unknown";-- cite web (when Periodical set)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-194)else[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-195)OCinSoutput["rft.genre"] = "article";-- journal and other 'periodical' articles[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-196)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-197)OCinSoutput["rft.jtitle"] = data.Periodical;-- journal only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-198)OCinSoutput["rft.atitle"] = data.Title;-- 'periodical' article titles[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-199)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-200)-- these used only for periodicals[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-201)OCinSoutput["rft.ssn"] = data.Season;-- keywords: winter, spring, summer, fall[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-202)OCinSoutput["rft.quarter"] = data.Quarter;-- single digits 1->first quarter, etc.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-203)OCinSoutput["rft.chron"] = data.Chron;-- free-form date components[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-204)OCinSoutput["rft.volume"] = data.Volume;-- does not apply to books[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-205)OCinSoutput["rft.issue"] = data.Issue;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-206)OCinSoutput['rft.artnum'] = data.ArticleNumber;-- {{[cite journal](https://freemwiki.com/wiki/Template:Cite_journal "Template:Cite journal")}} only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-207)OCinSoutput["rft.pages"] = data.Pages;-- also used in book metadata[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-208)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-209)elseif 'thesis' ~= class then-- all others except cite thesis are treated as 'book' metadata; genre distinguishes[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-210)OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:book";-- book metadata identifier[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-211)if 'report' == class or 'techreport' == class then-- cite report and cite techreport[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-212)OCinSoutput["rft.genre"] = "report";[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-213)elseif 'conference' == class then-- cite conference when Periodical not set[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-214)OCinSoutput["rft.genre"] = "conference";[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-215)OCinSoutput["rft.atitle"] = data.Chapter;-- conference paper as chapter in proceedings (book)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-216)elseif in_array (class, {'book', 'citation', 'encyclopaedia', 'interview', 'map'}) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-217)if is_set (data.Chapter) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-218)OCinSoutput["rft.genre"] = "bookitem";[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-219)OCinSoutput["rft.atitle"] = data.Chapter;-- book chapter, encyclopedia article, interview in a book, or map title[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-220)else[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-221)if 'map' == class or 'interview' == class then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-222)OCinSoutput["rft.genre"] = 'unknown';-- standalone map or interview[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-223)else[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-224)OCinSoutput["rft.genre"] = 'book';-- book and encyclopedia[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-225)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-226)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-227)else-- {'audio-visual', 'AV-media-notes', 'DVD-notes', 'episode', 'interview', 'mailinglist', 'map', 'newsgroup', 'podcast', 'press release', 'serial', 'sign', 'speech', 'web'}[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-228)OCinSoutput["rft.genre"] = "unknown";[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-229)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-230)OCinSoutput["rft.btitle"] = data.Title;-- book only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-231)OCinSoutput["rft.place"] = data.PublicationPlace;-- book only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-232)OCinSoutput["rft.series"] = data.Series;-- book only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-233)OCinSoutput["rft.pages"] = data.Pages;-- book, journal[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-234)OCinSoutput["rft.edition"] = data.Edition;-- book only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-235)OCinSoutput["rft.pub"] = data.PublisherName;-- book and dissertation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-236)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-237)else-- cite thesis[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-238)OCinSoutput.rft_val_fmt = "info:ofi/fmt:kev:mtx:dissertation";-- dissertation metadata identifier[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-239)OCinSoutput["rft.title"] = data.Title;-- dissertation (also patent but that is not yet supported)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-240)OCinSoutput["rft.degree"] = data.Degree;-- dissertation only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-241)OCinSoutput['rft.inst'] = data.PublisherName;-- book and dissertation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-242)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-243)-- NB. Not currently supported are "info:ofi/fmt:kev:mtx:patent", "info:ofi/fmt:kev:mtx:dc", "info:ofi/fmt:kev:mtx:sch_svc", "info:ofi/fmt:kev:mtx:ctx"[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-244)-- and now common parameters (as much as possible)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-245)OCinSoutput["rft.date"] = data.Date;-- book, journal, dissertation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-246)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-247)for k, v in pairs( data.ID_list ) do-- what to do about these? For now assume that they are common to all?[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-248)if k == 'ISBN' then v = v:gsub( "[^-0-9X]", "" ); end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-249)local id = cfg.id_handlers[k].COinS;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-250)if string.sub( id or "", 1, 4 ) == 'info' then-- for ids that are in the info:registry[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-251)OCinSoutput["rft_id"] = table.concat{ id, "/", v };[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-252)elseif string.sub (id or "", 1, 3 ) == 'rft' then-- for isbn, issn, eissn, etc. that have defined COinS keywords[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-253)OCinSoutput[ id ] = v;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-254)elseif 'url' == id then-- for urls that are assembled in ~/Identifiers; |asin= and |ol=[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-255)OCinSoutput["rft_id"] = table.concat ({data.ID_list[k], "#id-name=", cfg.id_handlers[k].label});[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-256)elseif id then-- when cfg.id_handlers[k].COinS is not nil so urls created here[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-257)OCinSoutput["rft_id"] = table.concat{ cfg.id_handlers[k].prefix, v, cfg.id_handlers[k].suffix or '', "#id-name=", cfg.id_handlers[k].label };-- others; provide a URL and indicate identifier name as #fragment (human-readable, but transparent to browsers)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-258)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-259)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-260)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-261)local last, first;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-262)for k, v in ipairs( data.Authors ) do[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-263)last, first = coins_cleanup (v.last), coins_cleanup (v.first or '');-- replace any nowiki stripmarkers, non-printing or invisible characters[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-264)if k == 1 then-- for the first author name only[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-265)if is_set(last) and is_set(first) then-- set these COinS values if |first= and |last= specify the first author name[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-266)OCinSoutput["rft.aulast"] = last;-- book, journal, dissertation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-267)OCinSoutput["rft.aufirst"] = first;-- book, journal, dissertation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-268)elseif is_set(last) then [](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-269)OCinSoutput["rft.au"] = last;-- book, journal, dissertation -- otherwise use this form for the first name[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-270)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-271)else-- for all other authors[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-272)if is_set(last) and is_set(first) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-273)OCinSoutput["rft.au"] = table.concat{ last, ", ", first };-- book, journal, dissertation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-274)elseif is_set(last) then[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-275)OCinSoutput["rft.au"] = last;-- book, journal, dissertation[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-276)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-277)-- TODO: At present we do not report "et al.". Add anything special if this condition applies?[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-278)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-279)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-280)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-281)OCinSoutput.rft_id = data.URL;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-282)OCinSoutput.rfr_id = table.concat{ "info:sid/", mw.site.server:match( "[^/]*$" ), ":", data.RawPage };[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-283)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-284)-- TODO: Add optional extra info:[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-285)-- rfr_dat=#REVISION (referrer private data)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-286)-- ctx_id=# (identifier for the context object)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-287)-- ctx_tim= (timestamp in format yyyy-mm-ddThh:mm:ssTZD or yyyy-mm-dd)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-288)-- ctx_enc=info:ofi/enc:UTF-8 (character encoding)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-289)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-290)OCinSoutput = setmetatable( OCinSoutput, nil );[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-291)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-292)-- sort with version string always first, and combine.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-293)-- table.sort( OCinSoutput );[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-294)table.insert( OCinSoutput, 1, "ctx_ver=" .. ctx_ver ); -- such as "Z39.88-2004"[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-295)return table.concat(OCinSoutput, "&");[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-296)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-297)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-298)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-299)--[[--------------------------< S E T _ S E L E C T E D _ M O D U L E S >--------------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-300)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-301)Sets local cfg table and imported functions table to same (live or sandbox) as that used by the other modules.[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-302)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-303)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-304)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-305)local function set_selected_modules (cfg_table_ptr, utilities_page_ptr)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-306)cfg = cfg_table_ptr;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-307)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-308)has_accept_as_written = utilities_page_ptr.has_accept_as_written;-- import functions from selected Module:Citation/CS1/Utilities module[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-309)is_set = utilities_page_ptr.is_set;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-310)in_array = utilities_page_ptr.in_array;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-311)remove_wiki_link = utilities_page_ptr.remove_wiki_link;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-312)strip_apostrophe_markup = utilities_page_ptr.strip_apostrophe_markup;[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-313)end[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-314)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-315)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-316)--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-317)]][](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-318)[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-319)return {[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-320)make_coins_title = make_coins_title,[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-321)get_coins_pages = get_coins_pages,[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-322)COinS = COinS,[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-323)set_selected_modules = set_selected_modules,[](https://freemwiki.com/wiki/Module:Citation/CS1/COinS#L-324)} Retrieved from "[https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&oldid=579720](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&oldid=579720)" * This page was last edited on 21 October 2025, at 06:18. * Content is available under [Creative Commons Attribution-ShareAlike 4.0](https://creativecommons.org/licenses/by-sa/4.0/) unless otherwise noted. FreemWiki is operated by **FINGERPOWER DIGITAL TECHNOLOGY LLC** (Colorado, Entity ID 20221978727). * [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service) * [Mobile view](https://freemwiki.com/index.php?title=Module:Citation/CS1/COinS&mobileaction=toggle_view_mobile)