Jump to content

Module:Cs1 documentation support

Permanently protected module
From Wikipedia, the free encyclopedia

require('strict');localgetArgs=require('Module:Arguments').getArgs;localcfg=mw.loadData('Module:Citation/CS1/Configuration');-- load the configuration modulelocalwhitelist=mw.loadData('Module:Citation/CS1/Whitelist');-- load the whitelist modulelocalexclusion_lists={-- TODO: move these tables into a separate ~/data module and mw.loadData() it['cite book']={['agency']=true,['air-date']=true,['arxiv']=true,['biorxiv']=true,['citeseerx']=true,['class']=true,['conference']=true,['conference-format']=true,['conference-url']=true,['degree']=true,['department']=true,['display-interviewers']=true,['docket']=true,['episode']=true,['interviewer#']=true,['interviewer-first#']=true,['interviewer-link#']=true,['interviewer-mask#']=true,['ismn']=true,['issn']=true,['issue']=true,['jfm']=true,['journal']=true,['jstor']=true,['mailinglist']=true,['message-id']=true,['minutes']=true,['MR']=true,['network']=true,['number']=true,['RFC']=true,['script-journal']=true,['season']=true,['section']=true,['sections']=true,['series-link']=true,['series-number']=true,['series-separator']=true,['sheet']=true,['sheets']=true,['SSRN']=true,['station']=true,['time']=true,['time-caption']=true,['trans-article']=true,['trans-journal']=true,['transcript']=true,['transcript-format']=true,['transcript-url']=true,['ZBL']=true,},['cite journal']={['agency']=true,['air-date']=true,['book-title']=true,['chapter']=true,['chapter-format']=true,['chapter-url']=true,['chapter-url-access']=true,['class']=true,['conference']=true,['conference-format']=true,['conference-url']=true,['contribution']=true,['contributor#']=true,['contributor-first#']=true,['contributor-link#']=true,['contributor-mask#']=true,['degree']=true,['department']=true,['display-interviewers']=true,['docket']=true,['edition']=true,['editor#']=true,['editor-first#']=true,['editor-link#']=true,['editor-mask#']=true,['editors']=true,['encyclopedia']=true,['episode']=true,['ignore-isbn-error']=true,['interviewer#']=true,['interviewer-first#']=true,['interviewer-link#']=true,['interviewer-mask#']=true,['isbn']=true,['ismn']=true,['LCCN']=true,['mailinglist']=true,['message-id']=true,['minutes']=true,['network']=true,['script-chapter']=true,['season']=true,['section']=true,['sections']=true,['series-link']=true,['series-number']=true,['series-separator']=true,['sheet']=true,['sheets']=true,['station']=true,['time']=true,['time-caption']=true,['trans-article']=true,['transcript']=true,['transcript-format']=true,['transcript-url']=true,},}--[[-------------------------< A D D _ T O _ L I S T >---------------------------------------------------------adds code/name pair to code_list and name/code pair to name_list; code/name pairs in override_list replace thosetaken from the MediaWiki list; these are marked with a superscripted dagger.|script-<param>= lang codes always use override names so dagger is omitted]]localfunctionadd_to_list(code_list,name_list,override_list,code,name,dagger)iffalse==daggerthendagger='';-- no dagger for |script-<param>= codes and nameselsedagger='<sup>†</sup>';-- dagger for all other lists using overrideendifoverride_list[code]then-- look in the override table for this codecode_list[code]=override_list[code]..dagger;-- use the name from the override table; mark with daggername_list[override_list[code]]=code..dagger;elsecode_list[code]=name;-- use the MediaWiki name and codename_list[name]=code;endend--[[-------------------------< L I S T _ F O R M A T >---------------------------------------------------------formats key/value pair into a string for rendering ['k'] = 'v' → k: v]]localfunctionlist_format(result,list)fork,vinpairs(list)dotable.insert(result,k..': '..v);endend--[[-------------------------< L A N G _ L I S T E R >---------------------------------------------------------Module entry pointCrude documentation tool that returns one of several lists of language codes and names.Used in Template:Citation Style documentation/language/doc{{#invoke:cs1 documentation support|lang_lister|list=<selector>|lang=<code>}}where <selector> is one of the values: 2char – list of ISO 639-1 codes and names sorted by code 3char – list of ISO 639-2, -3 codes and names sorted by code ietf – list of IETF language tags and names sorted by tag ietf2 – list of ISO 639-1 based IETF language tags and names sorted by tag ietf3 – list of list of ISO 639-2, -3 based IETF language tags and names sorted by tag name – list of language names and codes sorted by name all - list all language codes/tags and names sorted by code/tagwhere <code> is a MediaWiki supported 2, 3, or ietf-like language code; because of fall-back, language names maybe the English-language names.]]localfunctionlang_lister(frame)locallang=(frame.args.langand''~=frame.args.lang)andframe.args.langormw.getContentLanguage():getCode()localsource_list=mw.language.fetchLanguageNames(lang,'all');localoverride=cfg.lang_tag_remap;localcode_1_list={};localcode_2_list={};localietf_list={};localietf_list2={};localietf_list3={};localname_list={};ifnot({['2char']=true,['3char']=true,['ietf']=true,['ietf2']=true,['ietf3']=true,['name']=true,['all']=true})[frame.args.list]thenreturn'<span style="color:#d33">unknown list selector: '..frame.args.list..'</span>';endforcode,nameinpairs(source_list)doif'all'==frame.args.listthenadd_to_list(code_1_list,name_list,override,code,name);-- use the code_1_list because why not?elseif2==code:len()thenadd_to_list(code_1_list,name_list,override,code,name);elseif3==code:len()thenadd_to_list(code_2_list,name_list,override,code,name);elseifcode:match('^%a%a%-.+')then-- ietf with 2-character language tagadd_to_list(ietf_list,name_list,override,code,name);-- add to main ietf list for |list=ietfadd_to_list(ietf_list2,name_list,override,code,name);-- add to ietf2 listelseifcode:match('^%a%a%a%-.+')then-- ietf with 3-character language tagadd_to_list(ietf_list,name_list,override,code,name);-- add to main ietf list for |list=ietfadd_to_list(ietf_list3,name_list,override,code,name);-- add to ietf3 listendendlocalresult={};localout={};if'2char'==frame.args.listor'all'==frame.args.listthen-- iso 639-1list_format(result,code_1_list);elseif'3char'==frame.args.listthen-- iso 639-2, 3list_format(result,code_2_list);elseif'ietf'==frame.args.listthen-- all ietf tagslist_format(result,ietf_list);elseif'ietf2'==frame.args.listthen-- 2-character ietf tagslist_format(result,ietf_list2);elseif'ietf3'==frame.args.listthen-- 3 character ietf tagslist_format(result,ietf_list3);else--must be 'name'list_format(result,name_list);endlocaltemplatestyles=frame:extensionTag{name='templatestyles',args={src="Div col/styles.css"}}table.sort(result);table.insert(result,1,templatestyles..'<div class="div-col" style="column-width:16em">');table.insert(out,table.concat(result,'\n*'));table.insert(out,'</div>');returntable.concat(out,'\n');end--[[--------------------------< S C R I P T _ L A N G _ L I S T E R >------------------------------------------Module entry pointCrude documentation tool that returns list of language codes and names supported by the various |script-<param>= parameters.used in Help:CS1 errors{{#invoke:cs1 documentation support|script_lang_lister}}]]localfunctionscript_lang_lister(frame)locallang_code_src=cfg.script_lang_codes;-- get list of allowed script language codeslocaloverride=cfg.lang_tag_remap;localthis_wiki_lang=mw.language.getContentLanguage().code;-- get this wiki's languagelocalcode_list={};-- interim list of aliaseslocalname_list={};-- not used; defined here so that we can reuse add_to_list() localout={};-- final output (for now an unordered list)for_,codeinipairs(lang_code_src)do-- loop through the list of codeslocalname=mw.language.fetchLanguageName(code,this_wiki_lang);-- get the language name associated with this codeadd_to_list(code_list,name_list,override,code,name,false);-- name_list{} not used but provided so that we can reuse add_to_list(); don't add superscript daggerendlocalresult={};localout={};list_format(result,code_list);localtemplatestyles=frame:extensionTag{name='templatestyles',args={src="Div col/styles.css"}}table.sort(result);table.insert(result,1,templatestyles..'<div class="div-col" style="column-width:16em">');table.insert(out,table.concat(result,'\n*'));table.insert(out,'</div>');returntable.concat(out,'\n');end--[[--------------------------< A L I A S _ L I S T E R >------------------------------------------------------experimental code that lists parameters and their aliases. Perhaps basis for some sort of documentation?{{#invoke:cs1 documentation support|alias_lister}}]]localfunctionalias_lister()localalias_src=cfg.aliases;-- get master list of aliaseslocalkey;-- key for k/v in a new tablelocallist={};-- interim list of aliaseslocalout={};-- final output (for now an unordered list)for_,aliasesinpairs(alias_src)do-- loop throu the master list of aliasesif'table'==type(aliases)then-- table only when there are aliasesfori,aliasinipairs(aliases)do-- loop through all of the aliasesif1==ithen-- first 'alias' is the canonical parameter namekey=alias;-- so it becomes the key in listelselist[key]=list[key]and(list[key]..', '..alias)oralias;-- make comma-separated list of aliaseslist[alias]='see '..key;-- make a back reference from this alias to the canonical parameterendendendendfork,vinpairs(list)do-- loop through the list to make a simple unordered listtable.insert(out,table.concat({'*',k,': ',v}));endtable.sort(out);-- sort itreturntable.concat(out,'\010');-- concatenate with \n-- return (mw.dumpObject (list))end--[[--------------------------< C A N O N I C A L _ P A R A M _ L I S T E R >----------------------------------experimental code that lists canonical parameter names. Perhaps basis for some sort of documentation?returns a comma separated, alpha sorted, list of the canonical parameters. If given a template name, excludesparameters listed in that template's exclusion_list[<template>]{} table (if a table has been defined).{{#invoke:cs1 documentation support|canonical_param_lister|<template>}}]]localfunctioncanonical_param_lister(frame)localtemplate=frame.args[1];if''==templatethentemplate=nil;endiftemplatethentemplate=mw.text.trim(template:lower());endlocalalias_src=cfg.aliases;-- get master list of aliaseslocalid_src=cfg.id_handlers;-- get master list of identifierslocallist={};-- interim list of aliaseslocalout={};-- final output (for now an unordered list)for_,aliasesinpairs(alias_src)do-- loop through the master list of aliaseslocalname;if'table'==type(aliases)then-- table only when there are aliasesname=aliases[1];-- first member of an aliases table is declared canonicalelsename=aliases;-- for those parameters that do not have any aliases, the parameter is declared canonicalendifnottemplatethen-- no template name, add this parametertable.insert(list,name);elseifnotexclusion_lists[template]then-- template name but no exclusion listtable.insert(list,name);elseifnotexclusion_lists[template][name]then-- template name and exclusion list but name not in listtable.insert(list,name);endendfork,idsinpairs(id_src)do-- spin through the list of identifierslocalname=id_src[k].parameters[1];-- get the first (left-most) parameter namelocalaccess=id_src[k].custom_access;-- get the access-icon parameter if it exists for this identifierifnottemplatethen-- no template nametable.insert(list,name);-- add this parameterifaccessthentable.insert(list,access);-- add this access-icon parameterendelseifnotexclusion_lists[template]then-- template name but no exclusion listtable.insert(list,name);ifaccessthentable.insert(list,access);endelseifnotexclusion_lists[template][name]then-- template name and exclusion list but name not in listtable.insert(list,name);ifaccessthentable.insert(list,access);endendendfor_,paraminipairs(list)do-- loop through the list to make a simple unordered listtable.insert(out,table.concat({'*',param}));endlocalfunctioncomp(a,b)-- used in following table.sort()returna:lower()<b:lower();endtable.sort(out,comp);-- sort the listreturntable.concat(out,'\010');-- concatenate with \n-- return (mw.dumpObject (list))end--[[--------------------------< C A N O N I C A L _ N A M E _ G E T >------------------------------------------returns first (canonical) name when metaparameter is assigned a table of namesreturns name when metaparameter is assigned a single namereturns empty string when metaparameter name not found in alias_src{}, id_src{}, or id_src[meta].custom_accessmetaparameter <metaparam> is the key in Module:Citation/CS1 aliases{} table or id_handlers{} table. Because access-icondon't have <metaparam> keys, per se, we create pseudo <metaparam> keys by appending 'access' to the identifier <metaparam>: the <metaparam> for |doi-access= is, for the purposes of this function, DOIaccess, etcSome lists of aliases might be better served when a particular alias is identified as the canonical alias for a particular use case. If, for example, <metaparam> Perodical lists: 'journal', 'magazine', 'newspaper', 'periodical', 'website', 'work'that order works fine for {{cite journal}} documentation but doesn't work so well for {{cite magazine}}, {{cite news}},or {{cite web}}. So, for using this function to document {{cite magazine}} the returned value should be theparameter best suited for that template so we can specify magazine in the override (frame.args[2])While for this function, it would be just as simple to not use the function, this mechanism is implemented here to match similar functionality in alias_names_get() (there are slight differences) <override> must exist in the alias list does not apply to the access icon parameters (ignored - these have no aliases)(and which would be best for {{cite news}}? |newspaper= or |work=? can't solve all of the worlds problems at once).output format is controlled by |format= plain - renders in plain text in a <span> tag; may have id attribute para - renders as it would in {{para|<param>}}{{#invoke:cs1 documentation support|canonical_name_get|<metaparam>|<override>|id=<attribute>|format=[plain|para]}}]]localfunctioncanonical_name_get(frame)localalias_src=cfg.aliases;-- get master list of aliaseslocalid_src=cfg.id_handlers;-- get master list of identifierslocalargs=getArgs(frame);localname;localmeta=args[1]localoverride=args[2];localaccess;-- for id-access parametersifmeta:match('^(%u+)access')then-- the metaparameter (which is not used in ~/Configuration) is id_handlers key concatenated with access: BIBCODEaccessmeta,access=meta:gsub('^(%u+)access','%1');-- strip 'access' text from meta and use returned count value as a flagendifalias_src[meta]thenname=alias_src[meta];-- name is a string or a tableif'table'==type(name)then-- table only when there are aliasesifnotoverridethenname=name[1];-- first member of an aliases table is declared canonicalelsefor_,vinipairs(name)do-- here when override is set; spin throu the aliases to make sure override matches alias in tableifv==overridethenname=v;-- declare override to be the canonical param for this use casebreak;endendendendelseifid_src[meta]then-- if there is an id handlerifaccessthen-- and if this is a request for the handler's custom access parameterifid_src[meta].custom_accessthen-- if there is a custom access parametername=id_src[meta].custom_access;-- use itelsereturn'';-- nope, return empty stringendelseifnotoverridethenname=id_src[meta].parameters[1];-- get canonical id handler parameterelsefor_,vinipairs(id_src[meta].parameters)do-- here when override is set; spin throu the aliases to make sure override matches alias in tableifv==overridethenname=v;-- declare override to be the canonical param for this use casebreak;endendendendelsereturn'';-- metaparameter not specified, or no such metaparameterendif'plain'==args.formatthen-- format and return the outputifargs.idthenreturnstring.format('<span id="%s">%s</span>',args.id,name);-- plain text with id attributeelsereturnname;-- plain textendelseif'para'==args.formatthenreturnstring.format('<code class="nowrap">|%s=</code>',name);-- same as {{para|<param>}}endreturnstring.format('<b id="%s">%s</b>',args.idor'',name);-- because {{csdoc}} bolds param namesend--[[--------------------------< A L I A S _ N A M E S _ G E T >------------------------------------------------returns list of aliases for metaparameter <metaparam>returns empty string when there are no aliasesreturns empty string when <metaparam> name not found in alias_src{} or id_src{}; access icon parameters have no aliases so ignoredmetaparameter <metaparam> is the key in Module:Citation/CS1 aliases{} table or id_handlers{} table.Some lists of aliases might be better served when a particular alias is identified as the canonical alias for a particular use case. If, for example, <metaparam> Perodical lists: 'journal', 'magazine', 'newspaper', 'periodical', 'website', 'work'that order works fine for {{cite journal}} documentation but doesn't work so well for {{cite magazine}}, {{cite news}},or {{cite web}}. So, for using this function to document {{cite magazine}} the returned value should be thealiases that are not best suited for that template so we can specify magazine in the override (frame.args[2])to be the canonical parameter so it won't be listed with the rest of the aliases (normal canonical journal will be) <override> must exist in the alias list except: when <override> value is 'all', returns the canonical parameter plus all of the aliasesoutput format is controlled by |format= plain - renders in plain text in a <span> tag; may have id attribute para - renders as it would in {{para|<param>}} when not specified, refurns the default bold format used for {{csdoc}}{{#invoke:cs1 documentation support|alias_name_get|<metaparam>|<override>|format=[plain|para]}}]]localfunctionalias_names_get(frame)localalias_src=cfg.aliases;-- get master list of aliaseslocalid_src=cfg.id_handlers;-- get master list of identifierslocalargs=getArgs(frame);localmeta=args[1];localoverride=args[2];localout={};localsource;-- selected parameter or id aliases listlocalaliases;source=alias_src[meta]or(id_src[meta]andid_src[meta].parameters);ifnotsourcethenifmeta:match('%u+access')thenreturn'no'==args.noneand''or'none';-- custom access parameters don't have aliaseselsereturn'';-- no such metaendelseifnotsource[2]then-- id_source[meta] is always a table; if no second member, no aliasesreturn'no'==args.noneand''or'none';endifnotoverridethenaliases=source;-- normal skip-canonical param caseelselocalflag='all'==overrideandtrueornil;-- so that we know that <override> parameter is a valid alias; spoof when override == 'all'aliases={[1]=''};-- spoof to push alias_src[meta][1] and id_src[meta][1] into aliases[2]for_,vinipairs(source)do-- here when override is set; spin through the aliases to make sure override matches alias in tableifv~=overridethentable.insert(aliases,v);-- add all but overridden param to the the aliases list for this use caseelseflag=true;-- set the flag so we know that <override> is a valid aliasendendifnotflagthenaliases={}-- unset the table as error indicatorendendif'table'==type(aliases)then-- table only when there are aliasesfori,aliasinipairs(aliases)doif1~=ithen-- aliases[1] is the canonical name; don't include itif'plain'==args.formatthen-- format and return the outputtable.insert(out,alias);-- plain textelseif'para'==args.formatthentable.insert(out,string.format('<code class="nowrap">|%s=</code>',alias));-- same as {{para|<param>}}elsetable.insert(out,string.format("'''%s'''",alias));-- because csdoc bolds param namesendendendreturntable.concat(out,', ');-- make pretty list and quitendreturn'no'==args.noneand''or'none';-- no metaparameter with that name or no aliasesend--[[--------------------------< I S _ B O O K _ C I T E _ T E M P L A T E >------------------------------------fetch the title of the current page; if it is a preprint template, return true; empty string else]]localbook_cite_templates={['citation']=true,['cite book']=true,}localfunctionis_book_cite_template()localtitle=mw.title.getCurrentTitle().rootText;-- get title of current page without namespace and without sub-pages; from Template:Cite book/new -> Cite booktitle=titleandtitle:lower()or'';returnbook_cite_templates[title]or'';end--[[--------------------------< I S _ L I M I T E D _ P A R A M _ T E M P L A T E >----------------------------fetch the title of the current page; if it is a preprint template, return true; empty string else]]locallimited_param_templates={-- if ever there is a need to fetch info from ~/Whitelist then['cite arxiv']=true,-- this list could also be fetched from there['cite biorxiv']=true,['citeseerx']=true,['ssrn']=true,}localfunctionis_limited_param_template()localtitle=mw.title.getCurrentTitle().rootText;-- get title of current page without namespace and without sub-pages; from Template:Cite book/new -> Cite booktitle=titleandtitle:lower()or'';returnlimited_param_templates[title]or'';end--[[--------------------------< H E A D E R _ M A K E >--------------------------------------------------------makes a section header from <header_text> and <level>; <level> defaults to 2; cannot be less than 2]]localfunction_header_make(args)ifnotargs[1]thenreturn'';-- no header textendlocallevel=args[2]andtonumber(args[2])or2;level=string.rep('=',level);returnlevel..args[1]..level;end--[[--------------------------< H E A D E R _ M A K E >--------------------------------------------------------Entry from an {{#invoke:}}makes a section header from <header_text> and <level>; <level> defaults to 2; cannot be less than 2]]localfunctionheader_make(frame)localargs=getArgs(frame);return_header_make(args);end--[[--------------------------< I D _ L I M I T S _ G E T >----------------------------------------------------return the limit values for named identifier parameters that have <id> limits (pmc, pmid, ssrn, s2cid, oclc, osti, rfc); the returnvalue used in template documentation and error message help-text{{#invoke:Cs1 documentation support|id_limits_get|<id>}}]]localfunctionid_limits_get(frame)localargs=getArgs(frame);localhandlers=cfg.id_handlers;-- get id_handlers {} table from ~/Configurationreturnargs[1]andhandlers[args[1]:upper()].id_limitor('<span style="color:#d33">No limit defined for identifier: '..(args[1]or'<unknown name>')..'</span>');end--[[--------------------------< C A T _ L I N K _ M A K E >----------------------------------------------------]]localfunctioncat_link_make(cat)returntable.concat({'[[:Category:',cat,']]'});end--[[--------------------------< S C R I P T _ C A T _ L I S T E R >--------------------------------------------utility function to get script-language categories]]locallang_list_t=mw.language.fetchLanguageNames('en','all');localfunctionscript_cat_lister(script_lang_codes_t,lang_tag_remap_t,cats_list_t)for_,lang_codeinipairs(script_lang_codes_t)dolocallang_name=lang_tag_remap_t[lang_code]orlang_list_t[lang_code];-- use remap table to get Bengali instead of Bangla and the like; else use standard MediaWiki nameslocalcat='CS1 uses '..lang_name..'-language script ('..lang_code..')';-- build a category namecats_list_t[cat]=1;-- and save itendend--[[--------------------------< C S 1 _ C A T _ L I S T E R >--------------------------------------------------This is a crude tool that reads the category names from Module:Citation/CS1/Configuration, makes links of them,and then lists them in sorted lists. A couple of parameters control the rendering of the output: |select= -- (required) takes one of three values: error, maint, prop |sandbox= -- takes one value: no |hdr-lvl= -- base header level (number of == that make a header); default:2 min:2This tool will automatically attempt to load a sandbox version of ~/Configuration if one exists.Setting |sandbox=no will defeat this.{{#invoke:cs1 documentation support|cat_lister|select=<error|maint|prop>|sandbox=<no>}}]]localfunctioncat_lister(frame)localargs=getArgs(frame);locallist_live_cats={};-- list of live categorieslocallist_sbox_cats={};-- list of sandbox categorieslocallive_sbox_out={}-- list of categories that are common to live and sandbox moduleslocallive_not_in_sbox_out={}-- list of categories in live but not sandboxlocalsbox_not_in_live_out={}-- list of categories in sandbox but not livelocalout={};-- final output assembled herelocalsandbox;-- boolean; true: evaluate the sandbox modulelocalhdr_lvl;-- localsb_cfg;localsandbox,sb_cfg=pcall(mw.loadData,'Module:Citation/CS1/Configuration/sandbox');-- get sandbox configurationlocalcat;localselect=args.select;if'no'==args.sandboxthen-- list sandbox?sandbox=false;-- no, live onlyendifhdr_lvlthen-- if set andiftonumber(hdr_lvl)then-- can be converted to numberif2>tonumber(hdr_lvl)then-- min is 2hdr_lvl=2;-- so set to minendelse-- can't be convertedhdr_lvl=2;-- so default to minendelsehdr_lvl=2;-- not set so default to minendif'error'==selector'maint'==selectthen-- error and main categorys handling different from poperties catsfor_,tinpairs(cfg.error_conditions)do-- get the live module's categoriesif('error'==selectandt.message)or('maint'==selectandnott.message)thencat=t.category:gsub('|(.*)$','');-- strip sort key if anylist_live_cats[cat]=1;-- add to the listendendifsandboxthen-- if ~/sandbox module exists and |sandbox= not set to 'no'for_,tinpairs(sb_cfg.error_conditions)do-- get the sandbox module's categoriesif('error'==selectandt.message)or('maint'==selectandnott.message)thencat=t.category:gsub('|(.*)$','');-- strip sort key if anylist_sbox_cats[cat]=1;-- add to the listendendendelseif'prop'==selectthen-- prop catsfor_,catinpairs(cfg.prop_cats)do-- get the live module's categoriescat=cat:gsub('|(.*)$','');-- strip sort key if anylist_live_cats[cat]=1;-- add to the listendscript_cat_lister(cfg.script_lang_codes,cfg.lang_tag_remap,list_live_cats);-- get live module's foriegn language script catsifsandboxthen-- if ~/sandbox module exists and |sandbox= not set to 'no'for_,catinpairs(sb_cfg.prop_cats)do-- get the sandbox module's categoriescat=cat:gsub('|(.*)$','');-- strip sort key if anylist_sbox_cats[cat]=1;-- add to the listendscript_cat_lister(sb_cfg.script_lang_codes,sb_cfg.lang_tag_remap,list_sbox_cats);-- get sandbox module's foriegn language script catsendelsereturn'<span style="color:#d33; font-style:normal;">error: unknown selector: '..select..'</span>'endfork,_inpairs(list_live_cats)do-- separate live/sbox common cats from cats not in sboxifnotlist_sbox_cats[k]andsandboxthentable.insert(live_not_in_sbox_out,cat_link_make(k));-- in live but not in sboxelsetable.insert(live_sbox_out,cat_link_make(k));-- in both live and sboxendendfork,_inpairs(list_sbox_cats)do-- separate sbox/live common cats from cats not in liveifnotlist_live_cats[k]thentable.insert(sbox_not_in_live_out,cat_link_make(k));-- in sbox but not in liveendendlocalfunctioncomp(a,b)-- local function for case-agnostic category name sortingreturna:lower()<b:lower();endlocalheader;-- initialize section header with name of selected category listif'error'==selectthenheader='error';elseif'maint'==selectthenheader='maintenance';elseheader='properties';endheader=table.concat({-- build the main header'Live ',-- always include this((sandboxand'and sandbox ')or''),-- if sandbox evaluated, mention thatheader,-- add the list name' categories (',-- finish the name and add#live_sbox_out,-- count of categories listed')'-- close})localtemplatestyles=frame:extensionTag{name='templatestyles',args={src="Div col/styles.css"}}header=table.concat({-- make a useable header_header_make({header,hdr_lvl}),'\n'..templatestyles..'<div class="div-col">'-- opening <div> for columns});table.sort(live_sbox_out,comp);-- sort case agnostic acsendingtable.insert(live_sbox_out,1,header);-- insert the header at the toptable.insert(out,table.concat(live_sbox_out,'\n*'));-- make a big string of unordered list markuptable.insert(out,'</div>\n');-- close the </div> and add new line so the next header worksif0~=#live_not_in_sbox_outthen-- when there is something in the tableheader=table.concat({-- build header for subsection'In live but not in sandbox (',#live_not_in_sbox_out,')'});header=table.concat({-- make a useable header_header_make({header,hdr_lvl+1}),'\n'..templatestyles..'<div class="div-col">'});table.sort(live_not_in_sbox_out,comp);table.insert(live_not_in_sbox_out,1,header);table.insert(out,table.concat(live_not_in_sbox_out,'\n*'));table.insert(out,'</div>\n');endif0~=#sbox_not_in_live_outthen-- when there is something in the tableheader=table.concat({-- build header for subsection'In sandbox but not in live (',#sbox_not_in_live_out,')'});header=table.concat({-- make a useable header_header_make({header,hdr_lvl+1}),'\n'..templatestyles..'<div class="div-col">'});table.sort(sbox_not_in_live_out,comp);table.insert(sbox_not_in_live_out,1,header);table.insert(out,table.concat(sbox_not_in_live_out,'\n*'));table.insert(out,'</div>\n');endreturntable.concat(out);-- concat into a huge string and doneend--[=[--------------------------< H E L P _ T E X T _ C A T S >--------------------------------------------------To create category links at the bottom of each error help text section and on the individual error category pages;fetches category names from ~/Configuration; replaces this: {{#ifeq:{{FULLPAGENAME}}|Category:CS1 errors: bioRxiv|Category:CS1 errors: bioRxiv|[[:Category:CS1 errors: bioRxiv]]}}with this: {{#invoke:Cs1 documentation support|help_text_cats|err_bad_biorxiv}}where {{{1}}} is the error_conditions key from Module:Citation/CS1/Configurationadd |pages=yes to append the number of pages in the category]=]localfunctionhelp_text_cats(frame)localargs_t=getArgs(frame);localerror_conditions_t=cfg.error_conditions;-- get the table of error conditionslocalreplacements_t={};-- table to hold replacement parameters for $1 etc placeholders in category namesfork,vinpairs(args_t)do-- look for |$1=<replacement> parametersif'string'==type(k)andk:match('^$%d+$')then-- if foundreplacements_t[k]=v;-- save key and valueendendifargs_t[1]anderror_conditions_t[args_t[1]]then-- must have error_condition key and it must existlocalerror_cat=error_conditions_t[args_t[1]].category;-- get error category from cs1|2 configurationiferror_cat:match('$%d')then-- look for placeholders in <error_cat>error_cat=error_cat:gsub('$%d',replacements_t)-- replace place holders with matching value from replacements_tendlocaltitle_obj=mw.title.getCurrentTitle();-- get a title object for the currently displayed pagelocalname_space=title_obj.nsText;if('Category'==name_space)and(error_cat==title_obj.text)then-- if this is the category page for the error messagereturntable.concat({'Category:',error_cat});-- no link; just category nameelse-- here when currently displayed page is other than the error message categorylocalpages='';-- default empty strin for concatenationif'yes'==args_t.pagesthen-- if we should display category page count: TODO: do we need to keep this?pages=mw.site.stats.pagesInCategory(error_cat,'all');-- get category page countpages=table.concat({' (',mw.language.getContentLanguage():formatNum(pages),' page',(1==pages)and')'or's)'});-- make renderable textendreturntable.concat({'[[:Category:',error_cat,']]',pages});-- link to category with or without page countendelsereturn'<span style="color:#d33">unknown error_conditions key: '..(args_t[1]or'key missing')..'</span>';endend--[[--------------------------< H E L P _ T E X T _ E R R O R _ M E S S A G E >--------------------------------to render help text example error messages {{#invoke:Cs1 documentation support|help_text_error_messages|err_bad_biorxiv}}assign a single underscore to any of the |$n= parameters to insert an empty string in the error message: {{#invoke:Cs1 documentation support|help_text_error_messages|err_bad_issn|$1=_}} -> Check |issn= value {{#invoke:Cs1 documentation support|help_text_error_messages|err_bad_issn|$1=e}} -> Check |eissn= valueerror message is rendered at 120% font size; to specify another font size use |size=; must include unit specifier (%, em, etc)]]localfunctionhelp_text_error_messages(frame)localargs_t=getArgs(frame);localerror_conditions=mw.loadData('Module:Citation/CS1/Configuration').error_conditions;-- local span_o = '<span class="cs1-visible-error citation-comment">';localspan_o='<span class="citation-comment" style="color:#d33; font-size:'..((args_t.sizeandargs_t.size)or'120%')..'">';localspan_c='</span>';localmessage;localout={};-- output goes hereifargs_t[1]anderror_conditions[args_t[1]]then-- must have error_condition key and it must existmessage=error_conditions[args_t[1]].message;locali=1;localcount;localrep;repeatrep='$'..iargs_t[rep]=args_t[rep]andargs_t[rep]:gsub('^%s*_%s*$','')ornil;-- replace empty string marker with actual empty stringmessage,count=message:gsub(rep,args_t[rep]orrep)i=i+1;until(0==count);table.insert(out,span_o);table.insert(out,message);table.insert(out,span_c);elsereturn'<span style="color:#d33">unknown error_conditions key: '..(args_t[1]or'key missing')..'</span>';endlocalout_str=table.concat(out);returntable.concat({frame:extensionTag('templatestyles','',{src='Module:Citation/CS1/styles.css'}),out_str});end--[[--------------------------< T E M P L A T E S _ T >--------------------------------------------------------This table is a k/v table of sequence tables. The keys in this table are collapsed lowercase form of the cs1|2template names ({{ROOTPAGENAME}}): Template:Cite AV media -> citeavmediaEach subsequence table holds: [1] documentation page where the TemplateData json is stored ({{cite book}} is the oddball) [2] key to 'preprint_arguments_t' and unique_arguments_t' tables in Module:Citation/CS1/Whitelist; these keys dictate which of the basic or limited arguments and numbered arguments tables will be used to validate the content of the TemplateData]]localtemplates_t={citearxiv={'Template:Cite_arXiv/doc','arxiv'},-- preprint arguments citeavmedia={'Template:Cite AV media/doc','audio-visual'},-- unique argumentsciteavmedianotes={'Template:Cite AV media notes/doc'},-- no template datacitebiorxiv={'Template:Cite bioRxiv/doc','biorxiv'},-- preprint argumentscitebook={'Template:Cite book/TemplateData'},citeciteseerx={'Template:Cite CiteSeerX/doc','citeseerx'},-- no template data; preprint uses limited argumentsciteconference={'Template:Cite conference/doc','conference'},-- unique argumentscitedocument={'Template:Cite document/doc','document'},-- special case; uses whitelist.document_parameters_tciteencyclopedia={'Template:Cite encyclopedia/doc'},citeepisode={'Template:Cite episode/doc','episode'},-- unique argumentsciteinterview={'Template:Cite interview/doc'},citejournal={'Template:Cite journal/doc'},citemagazine={'Template:Cite magazine/doc'},citemailinglist={'Template:Cite mailing list/doc','mailinglist'},-- unique arguments -- no template datacitemap={'Template:Cite map/TemplateData','map'},-- unique argumentscitemedrxiv={'Template:Cite medRxiv/doc','medrxiv'},-- preprint argumentscitenews={'Template:Cite news/doc'},citenewsgroup={'Template:Cite newsgroup/doc','newsgroup'},-- unique argumentscitepodcast={'Template:Cite podcast/doc'},citepressrelease={'Template:Cite press release/doc'},citereport={'Template:Cite report/doc','report'},-- unique argumentsciteserial={'Template:Cite serial/doc','serial'},-- unique arguments -- no template datacitesign={'Template:Cite sign/doc'},citespeech={'Template:Cite speech/doc','speech'},-- unique arguments -- no template datacitessrn={'Template:Cite SSRN/doc','ssrn'},-- preprint arguments -- no template datacitetechreport={'Template:Cite tech report/doc'},citethesis={'Template:Cite thesis/doc','thesis'},-- unique argumentsciteweb={'Template:Cite web/doc'},citation={'Template:Citation/doc'},}--[[--------------------------< N O _ P A G E _ T E M P L A T E S _ T >----------------------------------------]]localno_page_templates_t={};--[[--------------------------< I D E N T I F I E R _ A L I A S E S _ T >--------------------------------------a table of the identifier aliases]]localidentifier_aliases_t={}foridentifier,handlerinpairs(cfg.id_handlers)do-- for each identifierlocalaliases_t={};-- create a tablefor_,aliasinipairs(handler.parameters)do-- get the alaisesaliases_t[alias]=true;-- and add them to the table in a form that mimics the whitelist tablesendidentifier_aliases_t[identifier:lower()]=aliases_t;-- add new table to the identifier aliases table; use lowercase identifier base name for the keyend--[[--------------------------< T E M P L A T E _ D A T A _ J S O N _ G E T >----------------------------------get template doc page content and extract the content of the TemplateData tags (case insensitive)<template> is the canonical name of the template doc page (with namespace) that holds the template data; usuallyTemplate:Cite xxx/doc (except Template:Cite book/TemplateData)]]localfunctiontemplate_data_json_get(template)localjson=mw.title.new(template):getContent()or'';-- get the content of the article or ''; new pages edited w/ve do not have 'content' until saved; ve does not preview; phab:T221625json=json:match('<[Tt]emplate[Dd]ata>(.-)</[Tt]emplate[Dd]ata>');-- remove everything exept the content of the TemplatData tagsreturnjsonandmw.text.jsonDecode(json);-- decode the json string and return as a table; nil if not foundend--[[--------------------------< V A L I D A T E _ D O C U M E N T _ P A R A M >--------------------------------looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.document_parameters_t.When found, returns true; nil else<param> is the parameter's name as listed in the TemplateData]]localfunctionvalidate_document_param(param)iftrue==whitelist.document_parameters_t[param]thenreturntrue;endend--[[--------------------------< V A L I D A T E _ U N I Q U E _ P A R A M >------------------------------------looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.basic_arguments{} and ifnecessary in whitelist.numbered_arguments{}. When found, returns true; nil else<param> is the parameter's name as listed in the TemplateData]]localfunctionvalidate_basic_param(param)iftrue==whitelist.common_parameters_t[param]thenreturntrue;endend--[[--------------------------< V A L I D A T E _ P R E P R I N T _ P A R A M >--------------------------------looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.preprint_arguments_t{} orwhitelist.limited_basic_arguments{} or whitelist.limited_numbered_arguments{}. When found, returns true; nil else<param> is the parameter's name as listed in the TemplateData<key> is key neccessary to look in the appropriate subtable of whitelist.preprint_arguments_t{}]]localfunctionvalidate_preprint_param(param,key)iftrue==whitelist.preprint_arguments_t[key][param]ortrue==whitelist.limited_parameters_t[param]then-- true == whitelist.limited_basic_arguments_t[param] or-- true == whitelist.limited_numbered_arguments_t[param] thenreturntrue;endend--[[--------------------------< V A L I D A T E _ U N I Q U E _ P A R A M >------------------------------------looks for <param> (can be the canonical parameter name or can be an alias) in whitelist.unique_arguments_t{} orwhitelist.basic_arguments{} or whitelist.numbered_arguments{}. When found, returns true; nil else<param> is the parameter's name as listed in the TemplateData<key> is key neccessary to look in the appropriate subtable of whitelist.unique_arguments_t{}]]localfunctionvalidate_unique_param(param,key,cfg_aliases_t)iftrue==whitelist.unique_arguments_t[key][param]ortrue==validate_basic_param(param)thenreturntrue;endend--[[--------------------------< V A L I D A T E _ I D _ P A R A M >--------------------------------------------looks for <param> <alias> in identifier_aliases_t{}. When found, returns true; nil else<param> is the parameter's name as listed in the TemplateData<alias> is the alias that we're looking for]]localfunctionvalidate_id_alias(param,alias)returnidentifier_aliases_t[param]andidentifier_aliases_t[param][alias];end--[[--------------------------< P A R A M _ E R R O R_ M S G >-------------------------------------------------]]localfunctionparam_error_msg(param)return'<span style="font-family:"monospace">|'..param..'=</span> is not a valid parameter';end--[[--------------------------< D U P _ A L I A S _ E R R O R_ M S G >-----------------------------------------]]localfunctiondup_alias_error_msg(param,alias)return'<span style="font-family:"monospace">|'..param..'=</span> has duplicate aliases: <span font-family:"monospace";>|'..alias..'=</span>';end--[[--------------------------< D U P _ A L I A S E S _ C H E C K >--------------------------------------------create an associative array of <param> aliases. if <alias> already present in <aliases_t> add an error messageto <out>]]localfunctiondup_aliases_check(param,alias,aliases_t,out_t)ifnotaliases_t[alias]thenaliases_t[alias]=true;elsetable.insert(out_t,dup_alias_error_msg(param,alias));endend--[[--------------------------< A L I A S _ E R R O R_ M S G >-------------------------------------------------]]localfunctionalias_error_msg(param,alias)return'<code style="color: inherit; background: inherit; border: none; padding: inherit">|'..alias..'=</code> is not a valid alias of: <code style="color: inherit; background: inherit; border: none; padding: inherit">|'..param..'=</code>';end--[[--------------------------< C F G _ A L I A S E S _ T _ M A K E >------------------------------------------convert this from cfg.aliases{}: ['AccessDate'] = {'access-date', 'accessdate'}to this in out_t{} ['access-date'] = 'AccessDate', ['accessdate'] = 'AccessDate',to test if |accessdate= is an aliases of |access-date=: if out_t['access-date'] == out_t['accessdate']]]localfunctioncfg_aliasts_t_make()localout_t={};formeta,params_tinpairs(cfg.aliases)doif'table'==type(params_t)then-- metaparameters that are assigned string values do not have aliasesfor_,paraminipairs(params_t)do-- for each aliasparam=param:gsub('#','');-- get rid of enumeratorsout_t[param]=meta;-- add it to the output tableendendend--error (mw.dumpObject (out_t))returnout_t;end--[[--------------------------< T E M P L A T E _ D A T A _ V A L I D A T E >----------------------------------compairs parameter names listed in a cs1|2 template's TemplateData structure (everything between <TemplateData>and </TemplateData> tag case insensitive). Returns error messages when errors found, empty string else. {{#invoke:Cs1 documentation support|template_data_validate|{{ROOTPAGENAME}}}}When called from a different page: {{#invoke:cs1 documentation support|template_data_validate|<canonical template name>}}where the <canonical template name> is the template's canonical name with or without namespace and or subpages]]localfunctiontemplate_data_validate(frame)localargs_t=getArgs(frame);ifnotargs_t[1]thenreturn'<span style="color:#d33">Error: cs1|2 template name required</span>';endlocaltemplate_idx=args_t[1]:lower():match('cit[ae][^/]+');-- args_t[1] has somethingifnottemplate_idxthen-- but if not a cs1|2 template abandon with error messagereturn'<span style="color:#d33">Error: cs1|2 template name required</span>';elsetemplate_idx=template_idx:gsub(' ','');-- is what appears to be a cs1|2 template so strip spacesendlocalcfg_aliases_t=cfg_aliasts_t_make();localtemplate_t=templates_t[template_idx];localout={};localtemplate_doc=template_t[1];localjson_t=template_data_json_get(template_doc);ifnotjson_tthentable.insert(out,'Error: can\'t find TemplateData');elseforparam,param_tinpairs(json_t['params'])dolocalparam_i;-- this will be the parameter name that gets validatedifparam:find('[Ss]2[Cc][Ii][Dd]')then-- |s2cid*= parameters are not enumerated ...param_i=param;-- ... so don't convert the '2' to '#'elseparam_i=param:gsub('%d+','#');-- for enumerated parameters, convert the enumerator digits to a single '#' character; all others unmolestedendlocalparam_is_valid;-- boolean true when param is valid; nil elseiftemplate_t[2]then-- if template is a preprint or uses unique parameters of 'document' parametersif'document'==template_t[2]then-- if a {{cite document}} templateparam_is_valid=validate_document_param(param_i,template_t[2]);ifparam_is_validthenlocalaliases_t={};-- used by dup_aliases_checkifparam_t['aliases']thenfor_,aliasinipairs(param_t['aliases'])dodup_aliases_check(param,alias,aliases_t,out);localalias_i=alias:gsub('%d+','#');-- in case an enumerated parameter, convert the enumerator digits to a single '#' characterifnotvalidate_document_param(alias_i,template_t[2])then-- is 'alias' a known parameter?table.insert(out,alias_error_msg(param,alias));-- may be known but is not supportedelseifcfg_aliases_t[param_i:gsub('#','')]~=cfg_aliases_t[alias_i:gsub('#','')]then-- is 'alias' known to be an alias of 'param'?table.insert(out,alias_error_msg(param,alias));endendendelse-- here when param not valid preprint paramtable.insert(out,param_error_msg(param))endelseifwhitelist.preprint_arguments_t[template_t[2]]then-- if a preprint templateparam_is_valid=validate_preprint_param(param_i,template_t[2]);ifparam_is_validthenlocalaliases_t={};-- used by dup_aliases_checkifparam_t['aliases']thenfor_,aliasinipairs(param_t['aliases'])dodup_aliases_check(param,alias,aliases_t,out);localalias_i=alias:gsub('%d+','#');-- in case an enumerated parameter, convert the enumerator digits to a single '#' characterifnotvalidate_preprint_param(alias_i,template_t[2])then-- is 'alias' a known parameter?table.insert(out,alias_error_msg(param,alias));-- may be known but is not supportedelseifcfg_aliases_t[param_i:gsub('#','')]~=cfg_aliases_t[alias_i:gsub('#','')]then-- is 'alias' known to be an alias of 'param'?table.insert(out,alias_error_msg(param,alias));endendendelse-- here when param not valid preprint paramtable.insert(out,param_error_msg(param))endelseifwhitelist.unique_arguments_t[template_t[2]]then-- if a unique parameters templateparam_is_valid=validate_unique_param(param_i,template_t[2]);ifparam_is_validthenlocalaliases_t={};-- used by dup_aliases_checkifparam_t['aliases']thenfor_,aliasinipairs(param_t['aliases'])dodup_aliases_check(param,alias,aliases_t,out);localalias_i=alias:gsub('%d+','#');-- in case an enumerated parameter, convert the enumerate digits to a single '#' characterifnotvalidate_unique_param(alias_i,template_t[2])then-- is 'alias' a known parameter?table.insert(out,alias_error_msg(param,alias));elseifcfg_aliases_t[param_i:gsub('#','')]~=cfg_aliases_t[alias_i:gsub('#','')]then-- is 'alias' known to be an alias of 'param'?table.insert(out,alias_error_msg(param,alias));endendendelse-- here when param not valid unique parametertable.insert(out,param_error_msg(param))endelse-- should never be here if coder is doing the right thing ...table.insert(out,'internal error: unexpected keyword in templates_t: '..template_t[2]);break;endelse-- here when not unique or preprintparam_is_valid=validate_basic_param(param_i);ifparam_is_validthenlocalaliases_t={};-- used by dup_aliases_checkifparam_t['aliases']thenfor_,aliasinipairs(param_t['aliases'])dodup_aliases_check(param,alias,aliases_t,out)localalias_i=alias:gsub('%d+','#');-- in case an enumerated parameter, convert the enumerate digits to a single '#' characterifnotvalidate_basic_param(alias_i)andnotvalidate_id_alias(param,alias)then-- for isbn13 (while still supported) must not mask the digitstable.insert(out,alias_error_msg(param,alias));elseifcfg_aliases_t[param_i:gsub('#','')]~=cfg_aliases_t[alias_i:gsub('#','')]then-- is 'alias' known to be an alias of 'param'?table.insert(out,alias_error_msg(param,alias));endendendelse-- here when param not validtable.insert(out,param_error_msg(param))endendendend---------- this emits errors when page/pages/at listed in templatedata of templates that don't support those parameters ------------ if json_t then-- if ({['citeavmedia']=true, ['citeepisode']=true, ['citemailinglist']=true, ['citenewsgroup']=true, ['citepodcast']=true, ['citeserial']=true, ['citesign']=true, ['citespeech']=true})[template_idx] then-- local insource_params_t = {}; -- build sequence of pagination params not supported by these templates-- for _, meta_param in ipairs ({'At', 'Page', 'Pages', 'QuotePage', 'QuotePages'}) do-- if 'table' == type (cfg.aliases[meta_param]) then-- for _, alias in ipairs (cfg.aliases[meta_param]) do -- metaparameter is a sequence-- table.insert (insource_params_t, alias); -- add the aliases from the metaparameter sequence to the table-- end-- else -- metaparameter is plain text-- table.insert (insource_params_t, cfg.aliases[meta_param]); -- add the alias to the table-- end-- end-- -- for _, param in ipairs (insource_params_t) do-- if json_t.params[param] then-- table.insert (out, param_error_msg (param)); -- error; this parameter not supported by this template-- end-- end-- end-- end---------- end page/pages/at error detection ----------if0~=#outthentable.sort(out);out[1]='*'..out[1];-- add a splat to the first error message-- return table.concat ({'[[' .. template_doc .. ']] TemplateData has errors:<div style="color:#d33; font-style: normal">\n', table.concat (out, '\n*'), '</div>'});returntable.concat({'[[Template:'..args_t[1]..']] uses ',whitelist.preprint_arguments_t[template_t[2]]and'preprint and limited parameter sets'or(whitelist.unique_arguments_t[template_t[2]]and'unique and standard parameter sets'or'standard parameter set'),'; TemplateData has errors:\n','<div style="color:#d33; font-style: normal">\n',table.concat(out,'\n*'),'</div>'});elsereturn;-- no errors detected; return nothingendend--[[--------------------------< E R R O R _ C A T _ P A G E _ T A L L Y >--------------------------------------loop through Module:Citation/CS1/Configuration error_conditions {} fetching error category names. For each errorcategory add the number of pages in the category to the tally. Render the number when done.{{#invoke:cs1 documentation support|error_cat_page_tally}}]]localfunctionerror_cat_page_tally()localerror_conditions_t=cfg.error_conditions;-- get the table of error conditionslocaltally=0;localcat_t={};-- some error message share a category; save tallied cats here so we don't recount the already countedlocali=0;-- number of categoriesfork,v_tinpairs(error_conditions_t)doifk:match('^err')thenifnotcat_t[v_t.category]thencat_t[v_t.category]=true;tally=tally+mw.site.stats.pagesInCategory(v_t.category,'pages');-- get category page count; ignore subcats and filesi=i+1;endendendreturnmw.language.getContentLanguage():formatNum(tally)end--[[--------------------------< M A I N T _ C A T _ P A G E _ T A L L Y >--------------------------------------loop through Module:Citation/CS1/Configuration error_conditions {} fetching error category names. For each errorcategory add the number of pages in the category to the tally. Render the number when done.{{#invoke:cs1 documentation support|maint_cat_page_tally}}Dynamic subcats of CS1 maint: DOI inactive not counted because these names come and go as time goes by.]]localfunctionmaint_cat_page_tally()localerror_conditions_t=cfg.error_conditions;-- get the table of error conditionslocaltally=0;localcat_t={};-- some error message share a category; save tallied cats here so we don't recount the already countedlocali=0;-- number of categoriesfork,v_tinpairs(error_conditions_t)doifnotk:match('^err')then-- if not an error key its a maint keyifnotcat_t[v_t.category]thencat_t[v_t.category]=true;if'maint_mult_names'==kor'maint_numeric_names'==kthenlocalspecial_case_translation_t=cfg.special_case_translation;for_,nameinipairs({'AuthorList','ContributorList','EditorList','InterviewerList','TranslatorList'})dolocalcat_name=v_t.category:gsub('$1',special_case_translation_t[name]);-- replace $1 with translated list nametally=tally+mw.site.stats.pagesInCategory(cat_name,'pages');-- get category page count; ignore subcats and filesi=i+1;endelsetally=tally+mw.site.stats.pagesInCategory(v_t.category,'pages');-- get category page count; ignore subcats and filesi=i+1;endendendendreturnmw.language.getContentLanguage():formatNum(tally)end--[[--------------------------< U N C A T E G O R I Z E D _ N A M E S P A C E _ L I S T E R >------------------For use in the Help:CS1 error §NotesGet namespace names and identifiers from MediaWiki. Make a human readable list of namespace names and identifiersthat cs1|2 does not categorize.{{#invoke:cs1 documentation support|uncategorized_namespace_lister}}For convenience, {{#invoke:cs1 documentation support|uncategorized_namespace_lister|all=<anything>}}returns a list of all namespace names and identifiers used on the current wiki. Any namespace with anidentifier less than 1, currently Mainspace (0), Special (-1), and Media (-2), is excluded from the list.]]localfunctionuncategorized_namespace_lister(frame)locallist_t={};localfunctioncompare(a,b)-- local function to sort namespaces numerically by the identifierslocala_num=tonumber(a:match('%d+'));-- get identifiers and convert to numberslocalb_num=tonumber(b:match('%d+'));returna_num<b_num;-- do the comparisonendfori,_inpairs(mw.site.namespaces)do-- for each namespace in the tableif''==frame.args.allornotframe.args.allthen-- when |all= not set, make a list of uncategorized namespacesifcfg.uncategorized_namespaces[i]then-- if the identifier is listed in our uncategorized namespace listtable.insert(list_t,table.concat({mw.site.namespaces[i].name,' (',i,')'}))-- add name and identifier to our local listendelseif0<ithen-- |all=<anything>: all namespace names and identifiers; ignore identifiers less than 1table.insert(list_t,table.concat({'*',mw.site.namespaces[i].name,' (',i,')'}))-- add name and identifier as an unordered list itemendendtable.sort(list_t,compare);-- ascending numerical sort by identifierifnotframe.args.allthen-- when |all= not set, format list of uncategorized namespaces and identifierslist_t[#list_t]='and '..list_t[#list_t];-- add 'and ' to the last name/identifier pairreturntable.concat(list_t,', ');-- make a big string and doneelse-- make list of all namespaces and identifiersreturntable.concat(list_t,'\n');-- make a big string and doneendend--[[--------------------------< S I N G L E _ L T R _ 2 N D _ L V L _ D O M A I N _ L I S T E R >-------------for Help:CS1_errors#bad_url, list the supported top level domains that support single-letter 2nd level names {{#invoke:Module:cs1 documentation support|single_ltr_2nd_lvl_domain_lister}}]]localfunctionsingle_ltr_2nd_lvl_domain_lister()localout_t={};-- output goes herefor_,tldinipairs(cfg.single_letter_2nd_lvl_domains_t)do-- fetch each tldtable.insert(out_t,'.'..tld);-- prefix with a dot and save in out_t{}endreturntable.concat(out_t,', ');-- make a big string and doneend--[[--------------------------< C O D E _ N A M E _ P A I R _ E X I S T S >----------------------------------------Returns language code if pair exists, nil if either code doesn't exist or the name doesn't match.Intended for use by Template:CS1 language sources/coreargs[1] is language codeargs[2] is language name]]localfunctioncode_name_pair_exists(frame)localwiki_language=mw.getContentLanguage():getCode()localsource_list=mw.language.fetchLanguageNames(wiki_language,'all');localcode_list={};localname_list={};localoverride=cfg.lang_tag_remap;forcode,nameinpairs(source_list)doadd_to_list(code_list,name_list,override,code,name);endlocalargs=getArgs(frame);locallanguage_code=args[1]locallanguage_name=args[2]-- Check if the language code exists and the corresponding name matchesifcode_list[language_code]==language_namethen-- Both code and name are a valid pairreturnlanguage_codeelse-- Either code doesn't exist or the name doesn't matchreturnnilendend--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------]]return{alias_lister=alias_lister,alias_names_get=alias_names_get,canonical_param_lister=canonical_param_lister,canonical_name_get=canonical_name_get,cat_lister=cat_lister,code_name_pair_exists=code_name_pair_exists,error_cat_page_tally=error_cat_page_tally,header_make=header_make,help_text_cats=help_text_cats,help_text_error_messages=help_text_error_messages,id_limits_get=id_limits_get,is_book_cite_template=is_book_cite_template,is_limited_param_template=is_limited_param_template,lang_lister=lang_lister,maint_cat_page_tally=maint_cat_page_tally,script_lang_lister=script_lang_lister,single_ltr_2nd_lvl_domain_lister=single_ltr_2nd_lvl_domain_lister,template_data_validate=template_data_validate,uncategorized_namespace_lister=uncategorized_namespace_lister,};
close