Module:Cite source/doc

Module:Cite source is the module that forms the guts of. You should aim to be familiar with Lua before editing it.

Broadly, the module is broken up into 2 major sections. The first is for formatting and storing information gathered from. The second is for acessing this information and producing citations. The main method used by this module for storing data is LuaCache with Semantic MediaWiki as a backup. Variables is used for caching queries on individual pages.

The module opens by importing other util libraries. Currently, these are named in snake_case for some reason but this may be changed to camelCase in future. PREFIX is a constant used by Lua Cache and Variables to name the data stores used by the module. In the case of something going seriously wrong, incriment the number in the prefix. This will reset all data stored by the module. The p table stores the functions returned by the module. These are accesible by the wider wiki. The h table stores the functions only used by other functions in this module.

Following this, there is a short function taken from Stack Overflow that inverts tables, swapping keys and values.

Generating and saving citations
The first major part of this module deals with gathering information from, formatting it into citations and saving it. The main functions here are p.infoboxStore and p.variantStore, the others being called from these 2. The general idea is that each of these 2 functions put together a table containing raw data from the infobox that is then processed by various helper functions to produce the output. These will now be discussed in more detail in the same order as in the module.

h.getAndFormatUnlinkedItems
This function deals with anything that is enterred into the infobox unlinked and comma-separated in the case of multiple entries. Namely, these are the source's anthology, writer, publisher, network and the source that it was adapted from. None of these will be aplicable to every source but they are all handled at the same time by this function.

The function takes as an argument the full table of infobox arguments. A data table is then created with blank entries for each piece of data handled by this function. The keys in this table must match the corresponding keys in the args table and hence the names of the parameters in.

The function then iterates through each entry in this data table and checks if there's a non-empty corresponding entry in the args</tt> table. This way, it processes only the entries in the data</tt> that actually have information in the infobox. The potentially comma-separated string passed to the infobox is then converted into a table. This occurs whever there are actually multiple values for infobox field or not. Either way, we get a table, even if it only has 1 entry.

If this table has more than 4 items, only the first will be assigned to the relevant entry in the data</tt> table, followed by "et al.". This phrase is wrapped in a span with the other values in the table placed in the span's title attribute, displaying them when "et al." is hovered over on desktop. Otherwise (in most cases), all values will be listed in the relevant data</tt> table entry. Each of these are linked with the display text set to the undabbed page name.

The data</tt> table is then returned. This table will be added to by subsequent functions before being converted into an output string.

h.getAndFormatIssuesText</tt> (unused)
Following this is an old unused function which formatted issues for comics. However, this information is not currently being displayed in finished citations and so it has been removed.

It worked very similarly to the above but without links (and without the whole "et al." thing when more than 4 items are given.

h.getAndFormatSeriesText</tt>
This function creates the bit of text stating the source's series. There are multiple places that this could come from in the infobox, none of which are ideal or one-size-fits-tall, which are dealt with here. Therefore, it takes the args</tt> table as an argument.

The simplest case is if citation series</tt> is specified. This is an overide field that allows the exact series to be used to be specified. No further formatting occurs here.

The slightly more complex fallback is if range</tt> is specified. In this case, the field is linked and that is used.

Failing this, series</tt> is used. This infobox field is primarily used for navigation and so is unideal but is often the best that we have. The overrides</tt> (not variable is a data module, Module:Cite source/series overrides, that holds common overrides that should be applied automatically. For example, " Doctor Who television stories </tt>" is very commonly given in the series</tt> infobox field and this data module contains a rule to automatically convert this to " Doctor Who </tt>". If an override does exist, it is used. Otherwise, the raw text passed to series</tt> is used. <tt>series</tt> is a freeform variable which should already have links and hence no additional formatting is applied. Finally, the <tt>season number</tt> entry in the <tt>args</tt> table is checked and, if this exists, the season/series is added to the end of the series text.

The series text produced is this return. Note that, if no series is specified anywhere, this may be blank and this is fine.

<tt>h.getReleaseYearText</tt>
This function formats the release year presented in the infobox. This should be presented unlinked in accordance with and hence a lot of formatting must be done here.

more technical documentation to be added


 * visit Module:Cite_source/doc to edit this page