MediaWiki:Scribunto/Central modules reference manual
Central modules in brief
In 2019, they are multi languages using i18n translations tables for each language.
They are also multi languages as able to use in one run the content language, the page language and the user langage.
They are multi wikis using the future Phabricator task T121470 "Begin T121470 Central Global Repository for Templates, Lua modules, and Gadgets"
This task permit to use in local any central Lua module.
The Lua part of central modules support contains 10 libraries used by central modules.
The first test is dated of Xmas 2013.
On january 2019 they are based on 10 libraries installed by the Module:Centralizer which must be used in each wiki/language in the last version.
These continue until they become parts of Scribunto
.
In this document, Library: is not a namespace, only a way to shortly express that an object is understood as a library.
Each new language need only to translate 300 short texts.
See convert a module as central
.
The central system permits to convert any module as central.
Central libraries are intimately dependent of each other. Examples: the Library:versions
installs others and the Library:viewers
is usefull anywhere.
Why central modules
Current modules are made for one wiki and one language. They need Lua-coders to translate and adapt them for another wiki or language.
Errors in them are corrected in one wiki/language but continue in others.
Small wikis do not have Lua-coders to translate them and can not use them.
In this way, many small wikis have no or few modules. Existing ones are not easy to debug elsewhere. The effort to re-use them is very heavy.
Then central modules can solve many questions.
Documentations and cooperation
This manual documents the Lua part of central modules support for any central modules in w:Lua as they are used in MediaWiki with the Scribunto extension.
See also the Tactics Manual:Developing libraries.
- Guideline of central modules.
- MediaWiki:Scribunto/Central modules reference manual
- The main present Module:Central installs central libraries. It is in French Wikisource.
- Template example: Modèle:Central
- Main module example: Module:Author3
- Example of module for an author: fr:Utilisateur:Rical/Victor_Hugo
- Small wiki example of central tests: Vietnamese Module Documentation
- Translations support: Translating:MediaWiki, and its statistics.
- Scribunto extension
- Extension:Wikibase Client/Lua
The Phabricator task T20180527 "Begin to use central modules", invite you to cooperate about the transfert of know-how.
During this phase Lua-coders need to cooperate.
They could dialogate in Discussion MediaWiki:Scribunto/Central guideline.
Tests pages
Central libraries: Module:Central.
Simple examples of uses: Module:Central/Documentation
Full example: User:Rical/Victor_Hugo.
Stability
Central modules specially must be stable. Some supports for stability:
- Central modules must follow S.O.L.I.D recommendations. Lua-coders can ask help from their pairs if necessary, see https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
- Which kind and level of stability do we need to begin to use central modules?
- Which kind and level of stability do we need to really centralize?
- How to insure a hight level of stability?
- Run many tests for key functions.
- Display groups of tests for Lua-coders. Then they can detect errors or missing tests cases.
- Notify and alert central Lua-coders using errors and categories.
- Document all functions supporting stability and listing all actual fonctions to not miss some ones.
- Save and restore main configurations for each group of tests to better avoid mutual perturbations between them.
- Display tests in any documentations pages, always up-to-date.
- Search other means to increase the stability and report them.
Stability Tactic
Some questions are especially important for all developers in the early phase of the deployment of central modules.
Libraries and functions names must be stable before a large deployment to reduce the renaming of them.
That could imply heavy corrections after the begin phase.
Stability questions:
- How to name central libraries ?
- How to name functions in these libraries ?
- How to distribute the functions in one or some libraries ?
Some examples:
- The Library:lua_table enhances the
table
library from the Lua language, to avoid ambiguities.
- To enhance
Scribunto
table
, we could write:lua_table = table
.
- Too diversity in the styles of variables names result in difficulties to remember their names for Lua-coders. They are sources of errors and of losts of time.
- How to distribute the functions in one or some libraries ?
- The categories
"Module with internal error"
and"Module with usage error"
duplicate and group some other categories for an easier help from Lua-coders. Also they need different competences from helpers. How to enhance these supports?
- Do we want a library
args
separed from the existing librarymodes
, to easier identity the main job of each function?
Stability tasks
- The versions library installs sought sub-modules using versions support.
- Drop boxes and tables views help to easy format new tests.
- The activity library help to manage sub-tasks and phabricator tasks, between Lua-coders, projects and languages.
- The tracker object supports parametrable track objects to help to debug the Lua code.
- The events library formats events as errors, warnings and categories.
- In many functions in the Lua code, strict type checks of values reduce errors risks.
- The initial development in the same text file enhance the cohesion in values, variables and functions.
- The function
viewers.save_restore_balance_report
checks and reports known couples of save and restore global configurations to reduce interferences between tests.
Central supports
The central system permit some new supports.
Languages support
Central modules support translations in many languages, using i18n tables.
They support also the content, page and user languages.
The system can also suggest a default local language depending where the module is used.
For these goals, central modules get these languages from the system, modes, options, arguments and tests cases.
Translations support
The langs library supports i18n translations.
- It merges translations together from libraries, sub-modules and the main module.
- It also detects missing translations between languages.
- It also detects the translations changes in the main module compared to more inner other translations.
In i18n tables, each translation key begin with the module or library name, to not disturb other and future translations.
Where to place the translations:
A central module containing all translations would become too big and would always be in change for each correction of translations. That is not possible.
Each module or sub-module has its own /I18N
submodule. See langs
.
Proposed method to use them: Include 3 or 4 most used languages in the main central module and add some other languages for each case: project + language.
Then the versions.bind_modules
function follows these rules:
An alternative version can modify any translation of the normal version.
A main module can modify any translation from any submodule to adapt it to a new context.
Versions support
To activate the versions support of a module, start it with a definition of alternative versions of its sub-modules.
Tactic for versions numbers: They follow the format major.minor.release.
The major number is incremented when there's a big change in functionality.
Template or invoke arguments can replace soughtversions
and knownversions
.
In known versions, the first of each group of versions is the normal
one and can replace any other if not available.
The versions support require()
adequate versions of submodules, following known and sought versions, like Module:Box 2
.
The versions support reports: versions used, errors, missing or replaced by normal ones.
Then Lua-coders can better understand what happens.
Any Lua-coder of main module can select versions of its submodules from internal arguments or from template arguments.
Each module or sub-module must document its version and date-time.
For the typical version description see convert a module as central
.
How to convert a module as central
The support of central modules needs some dedicated functions and descriptions of arguments, translations, modes, options, versions...
Rough example of code:
-- Example to define its version and sub-modules:
p.version = { -- Modules dependencies. Dependencias del módulo. Dépendances du module.
versionName = "Central-s-fr", versionNumber = "1.0.0(180726T10:42)", versionDate = "2018-07-26T17:53:00",
-- UTC version structure : main.fonction.task(yymmddThh:mm)
mainDescription = "Begin to use", functionDescription = "first functional support", taskDescription = "T198107 Begin to use central modules",
sought = "Central;Centralizer/I18N;Mathroman;TestRequire", -- Sought module and submodules versions
known = "Central;Central-s-fr;Central-14 * Centralizer/I18N;Central/i18n * Mathroman22;Mathroman34", -- Known module and submodules versions
}
-- Before the conversion to define arguments:
modes.frame = mw.getCurrentFrame()
modes.args_template = modes.frame:getParent().args
-- After, Example to define arguments:
p.known_arguments = { -- Table of the definitions of all known arguments at module level. -- ric (p.box1)
["mode"] = { ["typ"] = "config", ["need"] = 0, ["keyword"] = "mode"}, -- To change the mode from an argument
["userlang"] = { ["typ"] = "config", ["need"] = 0, ["keyword"] = "userlang"}, -- To change the user language from an argument
["image"] = { ["typ"] = "dat", ["need"] = 2, ["image"] = "description",["prop"] = "P18", }, -- for an image
["birthyear"] = { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "birthyear", ["prop"] = "P569", ["format"] = "year", }, -- for the birthyear
["itemid"] = { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "QITEM", ["prop"] = "Q16222597", ["syn"] = 2, }, -- for a synonym of a Wikibase item
}
-- Example to initialise languages, including arguments names:
p.i18n = {} -- translations tables known in the module
p.i18n.en = {
["mode"] = 'mode',
["userlang"] = 'userlang',
["itemid"] = 'itemid',
["example_user_sentence"] = 'You speek French.',
["example_user_mode"] = 'You are in mode: %1', -- where %1 will be replaced
} -- p.i18n.en
p.i18n.es = {
["mode"] = 'mode',
["userlang"] = 'userlang',
["itemid"] = 'itemid',
["example_user_sentence"] = 'Usted habla francés.',
["example_user_mode"] = 'Estás en modo: %1', -- donde %1 será reemplazado
} -- p.i18n.es
p.i18n.fr = {
["mode"] = 'mode',
["userlang"] = 'userlang',
["itemid"] = 'itemid',
["example_user_sentence"] = 'Vous parlez français.',
["example_user_mode"] = 'Vous êtes en mode : %1', -- où %1 sera remplacé
} -- p.i18n.fr
-- Example to define options for modes...
p.options_for_modes = { -- module options_for_modes
["read"] = " box1 catview ",
["doc"] = " nobox1 noerr nocatview ",
["edit"] = " box1 catview docdef docline docsrc docdata docview : ",
["tests"] = " box1 catview docdef docline docsrc docdata docview : tests ",
}
-- Example to initialise a mode.
function Central.read(frame) -- The read mode generates the normal result for read only users.
-- Helpers or admins can add options to include edit or tests or user language...
local res = ""
res = res .. p.init_central_module(frame, mode_name, known_arguments, options_for_modes, QITEM) -- FAMLTVQDR replaces function Central.init(...
res = res .. p.form_result(modes.args_final)
res = res .. "\n* " .. datas.track_val
return res
end -- function Central.read(frame)
Central.init
Installs all central libraries
until they become parts of the Scribunto extension
.
The Central.init
function is roughly equivalent to:
function Central.init(frame, Central_version, mode_name, known_arguments, options_for_modes)
function versions.init(frame, Central_version, mode_name, known_arguments, options_for_modes, QITEM)
versions.bind_the_main_module() -- Bind the main module, all sub-modules and all their i18n translations.
versions.setup_central_libraries(versions.bindable_libraries) -- Actual installation of central bindable libraries in package.loaded.
versions.bind_all_sub_modules() -- Bind all sub-modules of the main module.
versions.bind_reverse_i18n_translations(main_versions, loaded_pack) -- Bind all i18n translations from modules and their /I18N translations sub-modules.
versions.detect_MediaWiki_changes() -- Detects to display versions of MediaWiki for 3 months.
end
modes.init_modes_translate_events(frame, Central_version, mode_name, modes.known_arguments, options_for_modes, QITEM or itemid)
datas.get_item(known_arguments, QITEM) -- Get datas from mw.Wikibase for the page.
modes.init_args_mode_options(mix, mode_name, modes.args_template) -- Import and mix args mode and options from template and invoke
modes.import_arguments(known_arguments, args_source, content_translations, args_wikidata)
p.interact_args_final(modes.args_import)
modes.get_args(known_arguments)
langs.init_content_page_user_lang()
end
Central.read
Formats the result for the read
mode. See standard central modes
.
Typical code from Module:Central:
function Central.read(frame) -- Normal use for simple readers of pages
Central.init(frame, p.known_arguments, "read", p.options_for_modes) -- Default mode init.
res = res .. p.form_result() -- Formats only the read resulting wikitext.
end
Central.doc
Formats the result of the doc
mode. See standard central modes
.
Typical code from Module:Central:
function Central.doc(frame) -- Forms a Dropbox for technical documentations about the module.
Central.init(frame, p.Module_Central_version, "doc", p.known_arguments, p.options_for_modes, "Q535") -- Default mode init.
modes.args_final = p.interact_args_final(modes.args_import) -- Interactions between argumensts
local dockey = modes.args_final.dockey or modes.args_final[1]
if dockey then
local selector = mw.text.trim(dockey)
res = res .. viewers.doc_group(selector, QITEM)
end
return res
end
Central.edit
Formats the result of the edit
mode. See standard central modes
.
Typical code from Module:Central:
function p.edit(frame) -- Normal use for simple readers of pages
Central.init(frame, p.known_arguments, "edit", p.options_for_modes) -- Default mode init.
res = res .. viewers.formDocBox() -- A box to help helpers when they tests/change the use of a template or a module.
res = res .. p.form_result() -- Formats the resulting wikitext like in read mode.
end
Central.tests
Begins to format the result of the tests
mode. See standard central modes
.
Typical code from Module:Central:
function Central.tests(frame) -- To support the user to modify arguments in case of errors. To support helpers in their own laguages.
Central.init(frame, p.known_arguments, "tests", p.options_for_modes) -- Default mode init.
res = res .. viewers.formDocBox() -- A box to help helpers when they tests/change the use of a template or a module.
res = res .. p.form_result() -- Formats the resulting wikitext with extended tests.
end
p.interact_args_final
This function is the last step in the arguments values acquisition.
It tries to find values for all missing needed arguments.
Some extracts from the initial Module:Central:
-- if absent, synonym of basic arguments, syn = 2
if not a.firstname then i.firstname = (i.firstname2 or a.firstname2) end
if not a.initial then -- If initial is undefined, enforce it.
if a.lastname then
i.initial = string.sub( a.lastname, 1, 1 ) -- selects the first letter
i.initial = string.upper( i.initial or "*" ) -- in upercase
end
end
Initialize a module
As a fisrt step, define the options to select which part to format or to discard.
Each option like "box1" have an oposite like "nobox1" and the oposite has the priority if the two are present.
p.options_for_modes = { -- default options<!--Doc 20171103 DocTodo DocOK -->
read = " noerr ",
doc = " noerr nobox1 nocatview ",
edit = " : catview docview docdef docline docsrc docdata ",
tests = " : catview docview docdef docline docsrc docdata tests ",
-- Option nocatview means "Do not categorize and do not show categories."
}
Minimal centalisable module
Any module, even those without direct text for wiki pages, can format errors or categories in any function.
It can also use translated arguments and/or format reports.
For most details see Arguments: their process and translations
.
Any module using central libraries can contain internal translations for some MediaWiki languages in i18n
tables:
p.i18n.en = { -- Define translations of arguments names, categories names, and errors messages to produce.
["birthyear"] = "birthyear", -- Translated argument name
langs_select_lang_test_err = "Internal error : langs.select_lang(lang) has no tests table.", -- Translated error
} -- p.i18n.en
p.known_arguments = { -- Define all known arguments at the main module level.
["birthyear"] = { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "birthyear", ["prop"]prop = "P569", ["format"] = "year"},
} -- p.known_arguments
p.options_for_modes = { -- default options. Very simple modules do not need this part of the interface.
["read"] = " noerr ",
}
function p.read(frame) -- Formats the text to read for readers of Wikipedia.
local res = ""
Central.init(frame, p.known_arguments, "read", p.options_for_modes) -- Default init from the versions library.
res = res .. "Hello world !" -- Formats the resulting wikitext only in English.
res = res .. viewers.form9user("activity_central_count_admins_active_users", admins, active) -- Translates and formats the resulting wikitext.
return res
end -- function p.read(frame)
Modes and options
Modes are modifiable in any way in the main module, even making new ones or masking them.
The 4 standard central modes are ways to display the result of a central module:
- The
read
mode is for simple readers of wikipedia, the default mode. - The
doc
mode is to display, up-to-date, one Dropbox to include in technical documentations about the module. - The
edit
mode serves to help wikipedia users when they edit a page containing a module which is bad used. - The
tests
mode is to support Lua-coders who change a module and who need to see the results of several tests.
Modes are adaptable using options to adjust what and how to display the result:
- Arguments can change default options and modes like in
{{Central|doc|dockey=versions_support_desk_title|docitem=Q535}}
. - Default modes and options come from
p.options_for_modes
:
p.options_for_modes = { -- default options
read = " box1 noerr ", -- For simple readers of a page.
doc = " noerr nobox1 nocatview ", -- To display a live example in a documentation page.
edit = " box1 docdef docline docsrc docdata catview docview ", -- To support the user who edit a page.
tests = " box1 catview docdef docline docsrc docdata docview tests docGroup ", -- To report several tests cases for each function.
-- Option nocatview means "Do not show categories."
}
Default options permit to adapt modes:
- Each option has its canceller, as for
catview
andnocatview
, and the canceller has the priority over the option. - The
box1
option asks to display the box 1 andnobox1
to mask it. - The
err
option asks to display errors and warnings andnoerr
to mask it. - The
catview
option asks to display the categories to activate andnocatview
to mask it. - The
docdef
option asks to display origin of arguments and others details andnodocdef
to mask it - The
docline
option asks to display these details in a single line andnodocline
in a list of line. - The
docsrc
option asks to display the origins of arguments andnodocsrc
to mask it. - The
docdata
option asks to display datas coming from the Wikibase andnodocdata
to mask it. - The
tests
option asks to display the tests part of the result, after boxes to view andnotests
to mask it. That includeviewers.doc_page
,viewers.doc_module
andviewers.doc_internal
.
Process and translations of arguments
The main module defines all arguments, and all must have translations in all available languages.
modes.args_source
: The source arguments come from template, else from #invoke, for each argument.
modes.args_config
: Memorizes direct configuration arguments.
modes.args_wikidata
: An argument can come from wikidata if its definition have a wikidata property like prop = "P21"
.
The priority in origin of an argument is always: first the template, else the { {#invoke:module
, else the internal interaction between arguments in the module, else the internal default value in the module.
modes.args_config
: The config arguments come from source arguments and translations are identical in all languages.
Rough summary of the process of integration of arguments and translations:
modes.known_arguments = {} -- Known arguments, at main module level
modes.args_template = {} -- Template arguments, at {{Template| ...}} level
modes.args_invoke = {} -- Invoke arguments, at {{#invoke: ...}} level
modes.args_source = {} -- Source arguments = args_template + args_invoke
modes.args_unknown = {} -- Unknown arguments
modes.args_wikidata = {} -- Wikidata arguments, from Wikibase
modes.args_import = {} -- Import arguments
modes.args_final = p.interact_args_final() -- Final arguments, after interactions between them
modes.args_selected = {} -- Selected arguments, in some modules
langs.wiki_translations = {} -- Wiki translations
langs.user_translations = {} -- User translations
langs.page_translations = {} -- Page translations
events.errors_list = {} -- Errors list to collect, display or activate arguments errors and warnings
events.categories_list = {} -- Categories lists to collect, display or activate arguments errors and warnings
langs.init_content_page_user_lang(modes.args_source.contentlang, modes.args_source.pagelang, modes.args_source.userlang)
Available options to define one argument:
["birthyear"] = { -- Key of the argument.
--
["keyword"] = "birthyear", -- The keyword is the same as Key to identify the argument in some cases.
["syn"] = 1, -- A synonym of an argument defined in the known_arguments table.
["keyword"] = "birthyear2", -- For a synonym, the keyword identify the referral argument.
-- A synonym can be another argument. Then interact_args_final(args_import) mixes them.
--
["typ"] = "dat", -- The type "dat" is the basic type of arguments.
["typ"] = "config", -- The type "config" groups direct arguments from modes.args_source, without translation.
--
["need"] = 1, -- If need == 1 the argument can be automatic.
["need"] = 2, -- If need == 2 the argument must come from the template or wikidata.
--
["prop"] = "P569", -- Wikidata property to automatic import an argument, if available.
["format"] = "year", -- Extract the year from a Wikidata property.
},
}
Erreur de script : le module « Centralizer » n’existe pas.
Arguments properties
They can be needed, synonym, limited to some values ... typical examples:
["language"] = { ["keyword"] = "language", ["typ"] = "dat", ["need"] = 0, ["prop"] = "P103", }, -- Simple argument, with wikidata property.
[1] = { ["keyword"] = "mode", ["typ"] = "sys", ["need"] = 0, ["syn"] = 2, }, -- Synonym or alias of an argument defined by position.
["c"] = { ["keyword"] = "c", ["typ"] = "dat", ["need"] = 0, ["syn"] = 1, }, -- Synonym or alias arguments.
["options"] = { ["keyword"] = "c", ["typ"] = "dat", ["need"] = 0, ["syn"] = 2, }, -- Synonym or alias arguments.
-- Argument limited to some values.
["region"] = { ["keyword"] = "region", ["typ"] = "dat", ["need"] = 0, -- like Simple argument
["arg_values"] = "region_values", ["key_values"] = "other,china,india,century" }, -- arg_values translation key for
["region_values"] = "autre,chine,inde,siècle", -- i18n french translations for region argument.
["region_values"] = 'otros,china,india,siglo', -- i18n spanish translations for region argument.
-- Argument and its description.
["options"] = 'options', -- Arguments can be described for documentation in tests or in doc mode.
["options_descr"] = 'Options to add with mode options.',
Erreur de script : le module « Centralizer » n’existe pas.
Arguments from template
They drive directly supports aspects, without translations, examples:
contentlang = "en", -- content language for i18n translations.
pagelang = "fr", -- page language for i18n translations.
userlang = "fr", -- user language for i18n translations.
mode = "read", -- default mode
options = "", -- to change options for modes
c = "", -- for the catview option, to really categorise
c = ":", -- for the catview option, to display categories
soughtversions = "", -- Lua-coders can change sought versions when they change a module.
knownversions = "", -- Lua-coders can change known versions when they change a module.
-- for datas from the Wikibase
dockey = "tools_known_arguments_structure_title", -- key to select a Dropbox to display in doc mode.
docitem = "Q535", -- wikidata element to display in doc mode.
Translations keys
They follow the Tactic below. There suffix have a functional role.
- Translations keys are always formated with only underlines names like in
begin_central_modules_support
. - The structure of keys must respect this rules:
- They begin with the library name like in
langs_lang_table_err_cat
- They finish with
_cat
to translate a category name. - They finish with
_err
to translate an error string. - They finish with
_headers
to translate headers for a table in lines and colums. - They finish with
_msg
to translate a message like:"Verify the automatic argument: %1 = %2."
. - They finish with
_report
to translate a title for a documentation, in or out of a Dropbox. - They finish with
_title
to translate a title for a documentation in a Dropbox. - They can finish with
_i_cat
to generate a second category for internal errors.
- Then Lua-coders able to change the Lua code find all this kind of errors in a same place and become more efficient.
- They can finish with
_u_cat
to generate a second category for user errors.
- Then helpers able to modify the arguments to better use a template find all this kind of errors in a same place and become more efficient.
- Some examples of keys:
langs.i18n = {}
langs.i18n.en = { -- English translations, begin
langs_lang_not_exist_err = "Error: The language <b>%1</b> is not available.", -- Example of error
langs_lang_table_err_cat = "Module with internal error", -- Example of category
langs_missing_one_translation_i_cat = "Missing at least one translation", -- + "Module with internal error"
modes_auto_val_warning_msg = "Verify the automatic argument: %1 = <b>%2</b>.", -- Example of message
modes_no_known_arguments_i_cat = "Module without known arguments table.", -- + "Module with internal error"
viewers_section_title_page = "Tests of this page",
versions_sort_central_modules_headers = "Titre; Version; Date; Traductions / Langues", -- Example of headers
versions_versions_management_title = "versions.versions_management_test() Tests du management de versions.", -- Example of title of Dropbox
options = 'options', -- Argument to describe.
options_descr = 'Options to add to mode options.', -- Description for an argument. The key ends with "_descr".
} -- langs.i18n.en -- English translations, end
langs.i18n.es = { -- Spanish translations, begin ...
Translate types
To add a new language, only do add dedicated i18n tables in the main module or the sub-module /I18N.
Proposed method: Include 3 or 4 most used languages in the central module and add some other languages for each case: project + language.
The recognition of MediaWiki languages is automatic, the others are not available.
For an easier support of translations, the Lua-coders group them in Module:Library/langs/I18N
.
Erreur de script : le module « Centralizer » n’existe pas.
- Examples of translated arguments names, their descriptions, errors, categories, titles...
p.i18n.en = { -- English
mode = "mode", -- All arguments must be translated in all languages to operate.
mode_descr = "Type of use of the module or template: read, edit, doc, tests...", -- Describe the argument for documentation.
options = "options",
options_descr = "Options to format the module or template result.",
firstname = 'firstname', -- Other argument and description
firstname_descr = "First name. Please, specify it to help to compute the sort key.",
mathroman_J_before_end_err = "character J before the end", -- Example of error.
mathroman_roman2int_test_title = "Test from digital to roman numbers", -- Example of title of a group of tests.
modes_language_cat = 'Speaking %1', -- Example of category.
modes_date_to_part_call_cat = "Module with internal error", -- Several errors are grouped in a same category, defined at translation level.
modes_needed_to_verify = "(required, to be checked)", -- In the list of arguments, an argument is needed
}
Define arguments
- All arguments must be translated in all needed languages to operate.
- And all known arguments must be defined to operate. Even if they are not used at template or invoke level.
p.known_arguments = { -- Too small example of definitions of all known arguments at the main module level.
birthyear = {typ = "dat", need = 0, keyword = "birthyear", prop = "P569", format = "year"},
country = {typ = "dat", need = 0, keyword = "country", prop = "P27", },
mode = {typ = "sys", need = 0, keyword = "mode"},
}
Available parameters to define an argument:
typ
: type of the argument.typ = "dat"
; type of the argument in:dat
for data values.typ = "sys"
; type of the argument in:dat
for data values.typ = "autority"
; type of the argument in:dat
for data values.need: type of the argument in:
dat
for data values.need = 0
; type of the argument in:dat
for data values.need = 1
; type of the argument in:dat
for data values.need = 2
; type of the argument in:dat
for data values.keyword
: type of the argument in:dat
for data values.keyword = 1
; type of the argument in:dat
for data values.prop
: defines the property to import from Wikidata like P569 for birthyear.format
: selects the sought format for the prop parameter.syn
: the argument is it a synonym?syn = 0
; this value is the default and means: the argument is not a synonym.syn = 1
; this value means: the argument is a synonym.syn = 1
; this option can be used several times.syn = 2
; this value is the same as syn = 1. It permit to remember that an argument have several synonyms.
- Examples of data bases:
["ARCHIVE"] = { ["typ"] = "not", ["need"] = 0, deprecated = 1,
keyword = "ARCHIVE", base_base = "ARC", base_id = "ARCHIVE", not_type = "Author",
base_test = "1234",
base_name = "National Archives and Records Administration",
not_link = "http://www.archive.org/details/REF_1", },
["ARCHIVEbook"] = { ["typ"] = "not", ["need"] = 0,
keyword = "ARCHIVEbook", base_base = "ARC", base_id = "ARCHIVEbook", not_type = "Book",
base_test = "lesmisrable03hugouoft", -- Les misérables (Volume 3) - Hugo, Victor, 1802-1885 OK
base_name = "National Archives and Records Administration",
not_link = "http://archive.org/details/REF_1", },
["CANTIC"] = { ["typ"] = "not", ["need"] = 0,
keyword = "CANTIC", ["prop"] = "P1273", base_base = "CANTIC", base_id = "CANTIC", not_type = "Author",
base_test = "12972/259446", -- pape Víctor III, 1027-1087
base_name = "CANTIC", -- Catálogo de autoridades de nombres y títulos de Cataluña
not_link = "http://cantic.bnc.cat/registres/marc/20692/1/REF_1", },
-- http://cantic.bnc.cat/registres/fitxa/20692/1/12972/259446
["CiNii"] = { ["typ"] = "not", ["need"] = 0,
keyword = "CiNii", ["prop"] = "P1687", base_base = "CiNii", base_id = "CiNii", not_type = "Author",
base_test = "9000009556470", -- CiNii = ID: 9000009556470 = KIKUYAMA Sakae
base_name = "Scholarly and Academic Information Navigator", -- Q10726338
not_link = "http://ci.nii.ac.jp/nrid/REF_1", },
["DNB"] = { ["typ"] = "not", ["need"] = 0,
keyword = "DNB", base_base = "DNB", base_id = "DNB", not_type = "Author",
base_test = "3684200072", -- , DNB = "3684200072"
base_name = "Bibliothèque nationale allemande", -- Deutsche National Bibliothek
not_link = "http://d-nb.info/gnd/REF_1", },
config
: defines the property to import from Wikidata like P569 for birthyear.
soughtversions = { typ = config , keyword = soughtversions , need = 0 }
example of use: soughtversions = { typ = config , keyword = soughtversions , need = 0 }
format
: selects the sought format for the prop parameter.
opt
: defines the property to import from Wikidata like P569 for birthyear.
format
: selects the sought format for the prop parameter.
example of use: debug = { typ = opt , keyword = debug , need = 0 }
Central libraries descriptions
Descriptions of the Central libraries:#
- The Library:
Library:activity
supports Lua-coders sub-tasks and inter-wikis central modules.", },
- The Library:
Library:datas
gets datas from the Wikibase.
- The Library:
Library:events
formats events like erros, warnings and categories.
- The Library:
Library:langs
supports i18n translations.
- The Library:
Library:lua_table
enhances the native Lua table library, to avoid ambiguities.
- The Library:
Library:mathroman
converts roman numbers and detect errors. It is here as an example of very small central library.
- The Library:
Library:modes
supports the modes and their options, like p.read(frame).
- The Library:
Library:versions
installs all central libraries, modules, their i18n translations and versions.
- The Library:
Library:viewers
translates and formats strings to document texts and table views.
Objects have a function object.new() to format several objects:
- The Object:Dropbox, in the Library:viewers, formats dropboxes and their styles.
- The Object:central_library, in the Library:versions, formats the basis of libraries and their properties.
- The Object:tableview, in the Library:viewers, formats some viewers for tables, in lines and columns.
- The Object:tracker, in the Library:activity, formats parametrables tracks to help to debug the code.
Erreur de script : le module « Centralizer » n’existe pas.
activity
The activity
library help Lua-coders to cooperate in begin phase.
activity
Import all Wikidatas from Wikibase.
activity.begin_central_modules_support
To support the first uses of Central modules:
- Report the sub-tasks support from inside central modules.
- For each, it reports: Projet, Language, Admins count, Actives count, Used from, by which Lua-coder.
- For all, it counts: Projects, Versions, Languages and Lua-coders.
Erreur de script : le module « Centralizer » n’existe pas.
activity.central_functions_report
Lists actual functions for documentations:
- To help to format this Central modules reference manual.
- Also to know up-to-date actual availabe functions.
- It sorts and lists them, in bold for functions to document, from a dedicated list.
- It also counts all and to document functions.
The dedicated dedicated list lookalikes:
activity.functions_to_doc = "viewers.form9user;viewers.styles_color_usual;viewers.form_image;viewers.doc_internal;viewers.rough_view_test;"
Erreur de script : le module « Centralizer » n’existe pas.
activity.bold_tags_to_check
Reports imbalances of beginnings and ends of bold tags in code.
Results are normal case
or ABNORMAL case
.
Each imbalance is based upon a sequence of 4 bold tags then result in 3 ABNORMAL case
.
This imbalances search uses a long string of level 1 as [=[ ... ]=].
To use it you must avoid any other long string of level 1 and use only deaper levels like [==[ ... ]==].
Begin of code with some cautions for Lua-coders:
activity.bold_tags_to_check = [=[
-- This activity.bold_tags_to_check() must be near the end of the entire code to not disturb the search.
-- This starter permit to begin the search of bold tags and to test this search. Keep it carefully:
-- These 3 <b>1356<b> imbalances </b>1353</b> come from here. Others are probably these what you search.
-- After this needed starter, you can duplicate the code here to check it:
activity_central_count_admins_active_users = "This site count <b>%1</b> administrators for <b>%2</b> active users.",
do not translate parts like these: </b>%1</b> ; <b>%1</b> = <b>%2</b> (%3) ; <code>Q535</code> ; <br/> ;
do not translate parts like these: <b>%1</b> = <b>%2</b> (%3) ; <code>Q535</code> ; <br/> ; \n* ;
-- End of checked code ]=]
-- Example of result for the just before case:
activity.bold_tags_to_check(bold_tags_to_check) : bold_length = 693 , code_size = 693 ,
normal case : prev_begin = 410 , prev_end = 415 , begin = 439 , end = 444 ,
ABNORMAL case : prev_begin = 439 , prev_end = 444 , begin = 514 , end = 501 ,
ABNORMAL case : prev_begin = 514 , prev_end = 501 , begin = 514 , end = 507 ,
ABNORMAL case : prev_begin = 514 , prev_end = 507 , begin = 514 , end = 519 ,
normal case : prev_begin = 514 , prev_end = 519 , begin = 526 , end = 531 ,
normal case : prev_begin = 526 , prev_end = 531 , begin = 607 , end = 612 ,
normal case : prev_begin = 607 , prev_end = 612 , begin = 619 , end = 624 ,
ABNORMAL case : prev_begin = 619 , prev_end = 624 , begin = 693 , end = 693 ,
activity.central_subtasks_report
Reports the current state of subtasks defined by Lua-coders. See "NOW",
.
"todo" tasks are automatic shifted in time, after the last "NOW" sub-task.
Each sub-tasks description contains:
- bug.start is the begin date.
- bug.end is the end date.
- bug.plan is "todo" when the sub-task is to do.
- bug.plan is "NOW" when the sub-task is change by a Lua-coder.
- bug.plan is "done" when the sub-task is closed.
- bug.user is the Lua-coder driving the sub-task.
- bug.subid is the unique identifier of the sub-task.
- bug.description describes it.
- bug.duration is the diffrence between bug.end and bug.start.
activity.report_subtasks_list = { -- Examples of descriptors:
-- Automatic shift of below "todo" subtasks.
{ "20180425", "20180427", "todo", "Rical", "S171210arg", "Check all arguments: known_args/unknow_args missing/levenstein description", },
{ "20180423", "20180424", "todo", "Rical", "S180128lit", "Show details link to internal error cat ending _i_cat, _u_cat in events.add_record()", },
-- NOW, in change.
{ "20180421", "20180422", "NOW", "Rical", "S180421upa", "For 'Begin' Update all phabtask in activity.phabricator_tasks_report()", },
{ "20180417", "20180420", "NOW", "Rical", "S170705ust", "For 'Begin' Update all important tasks to support central modules", },
-- Already done.
{ "20180329", "20180407", "done", "Rical", "S180329uma", "For 'Begin' Update ModuleAuthor3.lua.", },
{ "20180322", "20180323", "done", "Rical", "S180322crm", "For 'Begin' Update Stability in Central modules reference manual", },
}
Erreur de script : le module « Centralizer » n’existe pas.
activity.MW_Versions_report
Reports versions of MediaWiki for 3 months.
It helps Lua-coders to better report detected bugs and t o link them to the adequate MediaWiki version.
Each MediaWiki version description contains:
- version.site like "www.MediaWiki" or "fr.wikisource".
- version.verstime is the UTC time-stamp of the version itself, like "2018-03-27T21:01:26".
- version.versid is the referral version number, like "1.31.0-wmf.27 (06af291)".
- version.seen_time is the UTC time when the Lua-coder has seen the new version in the site, like "2018-03-28T21:01:00".
Examples of descriptors:
versions.MediaWiki_Versions = { -- Examples of descriptors:
{ site = "www.MediaWiki", verstime = "2018-05-22T23:18:01", versid = "1.32.0-wmf.5 (82c3307)", seen_time = "2018-05-23T07:35:00", },
{ site = "fr.wikisource", verstime = "2018-05-23T16:24:49", versid = "1.32.0-wmf.5 (fda06ee)", seen_time = "2018-05-24T05:19:00", },
}
activity.phabricator_tasks_report
Reports the Phabricator tasks linked with central modules.
It helps Lua-coders to interact with MediaWiki developers.
Each Phabricator task description contains:
- task.sort only to manual sort.
- task.importance group. Values: Important, Central, Other, Obsolete.
- task.date when the Lua-coder reports in the table the state of the task from the referral Phabricator.
- task.task is the unique key to refer to one Phabricator task.
- task.state is the step in the development process or rejection. Values: ToCreate, Open, Stalled, Assigned, Resolved, Declined, Invalid, Gerrit.
- task.title synthetise the description of the task.
activity.phabricator_tasks_Group = { -- Examples of descriptors:
-- Importance: Important
{ 114, "Important", "20180326", "T135845", 0, "Assigned", "Convert any module as central or centralisable", "Convert as central", },
{ 126, "Important", "20170522", "T68051", 1, "Open", "Central modules need the user language to display errors and category names", "user language for errors", },
-- Importance: Central
{ 192, "Central", "20180408", "T20180410", 0, "ToCreate", "Begin to use central modules in 7 wikis S180408btu", "Begin use central", },
{ 204, "Central", "20180321", "T52329", 0, "Stalled", "We need a common repository for Scribunto modules and templates", "common repository", },
-- Importance: Other
{ 302, "Other", "20170526", "T104109", 0, "Close", "No syntax highlight for large JavaScript/CSS/Lua/API pages", "loadTemplateData", },
{ 320, "Other", "20170213", "T20170213", 0, "ToCreate", "Some languages have not French names in French language", "languages in stranger names", },
-- Importance: Obsolete: Already closed or Do not create.
{ 442, "Obsolete", "20160813", "T75460", 0, "Resolved", "[Story] Make Lua functions default to the user's language on multilingual wikis", "multilingual wikis", },
}
Erreur de script : le module « Centralizer » n’existe pas.
central_library
The Object:central_library is built in the Library:versions
.
central_library.binded_in
Detects if the object
is binded in _G
space or in package.loaded
.
central_library.new
Installs a library in package.loaded
. The new library must be a Lua table.
Each library must be install only once to not disturb subsequent processes.
name
is the referral name of the library in package.loaded
.
library
is the table containing the library.
options
could optimize the installation of the library.
options
can modify the installation of the library.
Some extracts of the code:
function central_library.new(name, library, options)
if (type(options.library) == "table") then
options.library.libname = options.name
end
function object.setupInterface(options) -- key instruction to install
...
end
object = object.setupInterface(options)
options.binded_in = central_library.binded_in(object, options.name)
return package.loaded[options.name], options.err
end
}
datas
The Library:datas
gets datas from the mw.Wikibase.
datas.get_image
Gets the sought image for one page o one item.
- The argument
prop
is the property name for an image, "P18" as default.
- The argument
QITEM
asks an image from another Wikibase item.
- The result is the name of the image.
- Images come from Commons.
datas.get_item
Gets datas from mw.Wikibase for one page from one item, in a simple way for developers.
It bases mainly its datas upon the property prop
of p.known_arguments = {...}
. See Convert a module as central or centralisable
.
It gets properties on the function datas.property(pp)
which gets datas from the Wikibase available properties for the page.
It returns and memorizes:
- All collected datas from all properties in
datas.props
.
- All collected values for properties in
datas.prop
.
The QITEM
argument is necessary if the image is not the default for the page.
This is roughly equivalent to:
function datas.get_item(known_arguments, QITEM)
datas.QITEM = QITEM or mw.Wikibase.getEntityIdForCurrentPage()
datas.item = mw.Wikibase.getEntity(datas.QITEM)
for key, pp in pairs(known_arguments) do -- For all known parameters
pp = datas.property(pp) -- Get datas from the mw.Wikibase for one property of the page.
if pp.prop then -- If a known argument ask a data value.
props[pp.keyword] = mw.clone(pp)
prop[pp.keyword] = pp.val -- get the data value for the known argument.
end
end
datas.prop = prop
datas.props = props
return prop, props
end
}
datas.get_item_report
Reports the mw.Wikibase available properties for one page.
Some extracts of the result:
function datas.get_item_report(t)
for key, val in pairs(props) do
t = t .. "\n* get_item: " .. key .. "=" .. val
end
return t
end
Erreur de script : le module « Centralizer » n’existe pas.
datas.property
function datas.property(prop) -- Get datas from mwwikibase for one property of the page.
Gets datas from the mw.Wikibase for one property of the page.
It is called once for each sought property.
- The argument
QITEM
asks an image from another eventual item.
- The result is the name of the image.
Some extracts of the code:
function datas.property(pp) -- Get datas from mwwikibase for one property of the page.
if pp.prop == "QITEM" then val = mw.Wikibase.getEntityIdForCurrentPage()
if pp.prop == "label" then val = datas.item:getLabel(QITEM) -- default label
if pp.prop == "description" then val = mw.Wikibase.description(QITEM)
if pp.prop == "labeluser" then val = mw.Wikibase.getLabelByLang(QITEM, langs.user_lang or "es") -- user_lang label
if pp.prop == "labelbylang" then val = mw.Wikibase.getLabelByLang(QITEM, langs.user_lang or "it") -- user_lang label
else
val = formatPropertyValues.value
end
return val
end
Dropbox
The Object:Dropbox, in the Library:viewers
, formats dropboxes and their styles.
drop_box.new
Returns a new Dropbox for documentation.
It follows these Tactics from these arguments:
selector
: Mainly checks to format a new Dropbox, or not.
content
: As a string, it is the content of the Dropbox. As a function, the content comes from it.
options
: permit to customise the style of the result.
To avoid ambiguities, these options are the last argument and are in a table which contains a variable named "drop_opt" and with the value "drop_opt".
Typical use:
res = res .. drop_box.new(selector, "modes_get_args_report_title", modes.get_args_report)
The content
argument, if it is a function, can need arguments which are after le function in content
.
In this case the argument options
becomes the last argument of drop_box.new
.
The code to get options is roughly:
-- The last argument can be a drop_opt to change the look of the Dropbox.
if ( i == lua_table.level_count(args) ) and ( type(args_tab) == "table" ) and ( args_tab["drop_opt"] == "drop_opt" ) then
drop_opt = mw.clone( args_tab )
end
events
The Library:events formats events like errors, warnings and categories.
Categories are bilingual. They categorize in the content language and they display in the user language.
Erreur de script : le module « Centralizer » n’existe pas.
events.add_cat
Adds a category in the actual table of events.
- The argument
key
is a i18n key to translate in an available language.
- The arguments
v1
to v9
replace %1
to %9
in the translation.
This event is not added if the key
and the arguments v1
to v9
are already present in the table of events.
Some extracts of the code:
function events.add_cat(ref, v1, v2, v3, v4, v5, v6, v7, v8, v9)
return events.add_record("cat", key, ...)
end
events.add_cat_group
Adds some categories in the actual table of events.
- The argument
groupCat
is a i18n key to translate in an available language, or a simple string.
- The arguments
groupList
is separated by some semicolumns ";" to format some categories based upon groupCat
.
These events are not added if the key
and the arguments from groupList
are already present in the table of events.
Some extracts of the code:
function events.add_cat_group(groupCat, groupList)
for i, str in mw.text.gsplit(groupList, ";", true) do ...
end
events.add_err
Adds an error in the actual table of events.
- The argument
key
is a i18n key to translate in an available language.
- The arguments
v1
to v9
replace %1
to %9
in the translation.
This event is not added if the key
and the arguments v1
to v9
are already present in the table of events.
Some extracts of the code:
function events.add_err(ref, v1, v2, v3, v4, v5, v6, v7, v8, v9)
return events.add_record("err", key, ...)
end
events.add_wng
Adds a warning in the actual table of events.
- The argument
key
is a i18n key to translate in an available language.
- The arguments
v1
to v9
replace %1
to %9
in the translation.
This event is not added if the key
and the arguments v1
to v9
are already present in the table of events.
Some extracts of the code:
function events.add_wng(ref, v1, v2, v3, v4, v5, v6, v7, v8, v9)
return events.add_record("wng", key, ...)
end
events.all_kinds_test
Tests all kinds of events (err, wng, cat).
events.categories_lister
Categorizes or display categories, already grouped in events.all_events_group
.
- The argument
c
permit to choose to categorize or to display. The default is to categorize.
events.errors_lister
Returns the list of errors messages, if any, in the user language.
events.gener_categories
Only display categories, as a text line, using categories_lister
.
langs
The Library:langs supports i18n translations.
Each module or sub-module has its own /I18N
submodule. For the distribution of translations in modules and sub-modules, see Translations support
.
Then the versions.bind_modules
function follows these rules:
- Starts with the libraries translations,
- starts with the internal translations,
- then add or mix translations from normal
/I18N
,
- then add or mix translations from the
/I18N
alternative versions.
- Continue with the modules translations,
- starts with the internal translations,
- then add or mix translations from normal
/I18N
,
- then add or mix translations from the
/I18N
alternative versions.
- In doc and tests modes, a report display missing or modified translations.
langs.dummy_languages
Report the characteristics of some languages
- isTag: Returns true if a language code is known to MediaWiki.
- isLang: Returns true if the language is localisable in MediaWiki.
- isBuilt: Returns true if the language is customisable in MediaWiki.
- langname: is the English name of the language.
- native: is the native name of the language.
langs.init_content_page_user_lang
Initialise or update the 3 usual languages: langs.content_lang, langs.page_lang, langs.user_lang
.
langs.list_MediaWiki_languages
Reports the list of available languages from mw.language.fetchLanguageName(lang)
.
For each languages it displays the code, the native name and the english name.
It is used in versions.main_i18n_languages_list
and in langs.dummy_languages
.
langs.main_i18n_languages_list
Formats a text which list available languages in the main module, to include in documentations.
- For all available languages it reports: the mean number of translations for one language, and the number of languages.
- For each language, it reports: the available number of translations, the native name of the language, its international code and its English name.
t = t .. "\n*" .. langs.main_i18n_languages_list() -- Lists available translations in available languages.
langs.missing_translations
Reports some first misses in translations for one language compared to another.
These changes indicate in which languages update the translations, even many more if necessary.
Erreur de script : le module « Centralizer » n’existe pas.
langs.translations_counts
Formats a table reporting for some or all languages the number of available translations.
That permit to fastly estimate the advancement of translations for them.
In future versions, this function could reports the most and the least translated languages, to fastly alert translators.
lua_table
The Library:lua_table enhances previous table library, to avoid ambiguities. To enhance, we could write: lua_table = table.
lua_table.count_all
Counts all objects, of all types, in a table, including all levels in the table. Examples of uses:
local max_tab = lua_table.count_all(tab)
lua_table.count_tests
Reports some examples of available types of counts.
- Tested counts:
{ "count_all", { "name", 111, "other", function() end, true, false, { 33 }, function() end }, },
{ "count_types", { "name", 111, "other", function() end, true, false, { 33 }, function() end }, },
{ "count_values", { "name", 111, "other", function() end, true, false, { 33 }, function() end }, },
{ "count_all", { a = "abc", 11, z = "xyz", t = true, false, n = nil, min = 11, 33, nil, 33, max = 55, "abc", }, },
{ "count_types", { a = "abc", 11, z = "xyz", t = true, false, n = nil, min = 11, 33, nil, 33, max = 55, "abc", }, },
{ "count_values", { "abc", 11, "xyz", true, false, nil, 11, 33, nil, 33, 55, "abc", }, },
{ "level_list", { "abc", 11, "xyz", true, false, nil, 11, 33, nil, 33, 55, "abc", }, "key", "3", },
lua_table.count_types
Counts in a table, for each type, the number of objects of the this type.
lua_table.count_values
Counts in a table, for each value, the number of objects of the this value.
lua_table.from_subnames_object
Get the last sub-object from its sub-names, but not a table.
arguments
sub_names
: a string to search the object like lua_table.from_subnames_object_names
.
base_table
: any table where to search. The default is package.loaded
.
lua_table.from_subnames_table
Get the last sub-table from its sub-names. Arguments like in lua_table.from_subnames_object
lua_table.level_count
Counts all objects in the table, only in the first level of the table. No matter if the table is a sequence or not.
It can be used in any sub-table in a table.
It returns 0
if the sole argument tab
is not a table. Example of call:
local one_level_count = lua_table.level_count(tab)
lua_table.level_get
Gets only the first level of the table. Gets only one key type if asked.
Arguments:
tab
: table to search.
typ
: type to select, else any types.
lua_table.level_list
Lists all keys, or selected one's, in the first level of the table.
It could be used in any sub-table in a table.
Arguments:
tab
: is the part of a table to list.
typ
: is the type selector of values to restrict the list.
select
: selects the field as key if defined.
field
: selects a value only if the field is defined, and if the value in the table is equal to the value of field
.
typ
, select
, and field
: restrict the list in conjonction.
The selection to list in this function is roughly equivalent to:
if ((type(keyval) == typ) and (viewers.is_in(select, keyval)) and (field) and (keyval == field) then
list = list .. ", the field " .. field .. " = " .. keyval
end
list = list .. "."
lua_table.named_sub_counts
This function, first, select a sub-table from its sub-name.
Then it counts inside all objects of all types in all levels.
It can be used in any sub-table in a table.
It returns 0 if the sub-table do not exist.
subnames_in
is the part of a table to list, selected by a string.
base_table
is the table in which search the sub-table. The default value is package.loaded
.
This function, first, select a sub-table from its sub-name.
lua_table.obj_from_subnames
Gets the last sub-object from its sub-names.
It returns nil
if the sub-object do not exist.
subnames_in
is the last sub-object to get, selected by a string.
base_table
is the table in which search the sub-table. The default value is package.loaded
.
lua_table.sort_onkey
Sorts a table based upon any type of keys.
It converts the table in another sortable table. Then it sorts the sortable table on the base of the keys in the 2 records compared in the sortable table.
tab
is the table to sort.
key
: the keys in 2 records compared must be of the same type. Other comparisons are not in the resulting sortable table.
lua_table.sort_types
Sorts a table, with any types of fields, even of differents types as strings.
It converts the table in another sortable table. Then it sorts the sortable table on the base of the keys in the 2 records compared in the sortable table.
tab
is the table to sort.
key
: if the keys in 2 records are of the same type the comparison uses their values.
key
: else the comparison uses the conversion of their values in strings .
Other comparisons are not in the resulting sortable table.
decrease
: if decrease == ">"
then the sort is in decreasing order, else increasing.
lua_table.structure
Formats the structure of a table.
Arguments of the function lua_table.structure(table, tablename, opt)
:
table
is the table to report.
tablename
is the name of this table.
opt
are the options transmitted for sub-tables.
- options:
level_maxi
is the limit of table levels to format.
max_n
is the maximum number of reported and counted objects in any levels of the sub-tables.
exclude1
: do not report an element of this value, including eventual sub-tables.
exclude2
: do not report an element of this value, including eventual sub-tables.
exclude3
: do not report an element of this value, including eventual sub-tables.
opt
are the options transmitted for sub-tables.
Example of results:
Table .lua_table.tablim, 5 vars: string - 1 = one , string - 2 = two , string - max1 = MAX1 , string - max2 = MAX2 , string - max3 = MAX3 ,
Table .lua_table.tablim, 0 functions:
Table .lua_table.tablim, 3 tables: life, comfort, house,
lua_table.structure_recursive_report
Reports the structure of a table. See lua_table.structure
lua_table.tab_from_subnames
Gets the last sub-table from its sub-names.
It returns the last sub-table, else nil
.
Arguments of the function lua_table.tab_from_subnames(sub_names, base_table)
:
sub_names
is the last sub-table to get, selected by a string.
base_table
is the table in which search the sub-table. The default value is package.loaded
.
lua_table.to_list
From any Lua table, this function returns a list of variables names with their values.
Argument:
tab
is the table to list.
Example of results:
{ [1] = 123, [2] = abc, ["key"] = txt, } -- this table
[1] = 123 , [2] = abc , -- results in this string
lua_table.to_list_tests
Reports some tests to check the lua_table.to_list
function.
Example of results:
lua_table.to_table
From a table of words, this function formats a Lua table.
See: lua_table.to_table_test
.
lua_table.to_table_test
Reports some tests to check the lua_table.to_table
function.
Example of results:
Erreur de script : le module « Centralizer » n’existe pas.
mathroman
The Library:mathroman convert roman numbers and detect errors. It is here as an example of very small central library.
mathroman.int2roman
Converts an integer to a roman number, also if int
is a string.
It returns the roman number first, then the eventual text of error(s).
Argument:
int
is the integer to convert.
mathroman.int2roman_test
Reports some unitary tests of mathroman.int2roman
function.
Example of results:
{ ["int"] = 0, ["roman"] = 0, ["error"] = "The integer "0" is not a convertible in Roman number", }
{ ["int"] = 12, ["roman"] = XII, ["error"] = "", }
{ ["int"] = 17, ["roman"] = XVII, ["error"] = "", }
{ ["int"] = 3.14, ["roman"] = 0, ["error"] = "The non-integer number 3.14 is not convertible to Roman number", }
{ ["int"] = 4999, ["roman"] = MMMMCMXCIX, ["error"] = "", }
{ ["int"] = 5000, ["roman"] = 0, ["error"] = "The integer "5000" is not a convertible in Roman number", }
mathroman.roman2int
Converts a roman number in a string to an integer.
It returns the integer first, then the eventual text of error(s).
Argument:
rm
is the roman number to convert.
mathroman.roman2int_tests
Reports some unitary tests of mathroman.int2roman
function.
Example of results:
{ ["int"] = 0, ["roman"] = 0, ["error"] = "The integer "0" is not a convertible in Roman number", }
{ ["int"] = 12, ["roman"] = XII, ["error"] = "", }
{ ["int"] = 17, ["roman"] = XVII, ["error"] = "", }
{ ["int"] = 3.14, ["roman"] = 0, ["error"] = "The non-integer number 3.14 is not convertible to Roman number", }
{ ["int"] = 4999, ["roman"] = MMMMCMXCIX, ["error"] = "", }
{ ["int"] = 5000, ["roman"] = 0, ["error"] = "The integer "5000" is not a convertible in Roman number", }
modes
The Library:modes support modes and their options, for p.read(frame) and others.
modes.all_categories_list
Reports available categories in the main module.
Their keys in i18n translations contain "_cat".
modes.all_errors_list
Reports available errors in the main module.
Their keys in i18n translations contain "err_".
Example of results:
Erreur de script : le module « Centralizer » n’existe pas.
modes.get_args
Updates arguments values in their default definitions.
It updates the value, in the field val
, and the significant origins, in the field src
.
- Origins of arguments are in the increasig priority:
known
, import
, datas
, template
, final
.
Argument:
known_arguments
is the default definitions table, to not disturb: p.known_arguments{ , , , }.
Key points in code:
local known_arguments = known_arguments or modes.known_arguments or p.known_arguments or {}
local arguments_known = mw.clone(known_arguments) -- Do not disturb original definitions
modes.get_args_report
Reports arguments definitions and values from modes.get_args
. See the result:
Erreur de script : le module « Centralizer » n’existe pas.
modes.levenshtein
For arguments names, this function detects small writing errors to suggest replacement.
And even replace them.
It uses the Levenshtein distance.
Erreur de script : le module « Centralizer » n’existe pas.
modes.multiple_selection_tests
Reports examples of multiple selections for some persons, objects or entities, using strings.
Arguments of the function modes.multiple_selection(opt, selector, to_select)
:
Selector
asks some signs to get the sought selection.
To selector
show how selectors signs are understood in the function.
Selected
displays the resulting selections.
In Selector
, options can mix some signs:
;
wich meens "keep all selections". ;
is the separator of all selections.
;U
wich meens " distinguish the lowercases and uppercases".
;=
wich meens "recognize only equal string".
;t
wich meens "recognize after trim". That is to say delete, before and after all selections, any space, coma...
See the result:
Erreur de script : le module « Centralizer » n’existe pas.
modes.options_from_args_tests
Try some combinaisons of options and display the resulting combinaison.
That permits at Lua-coders to verify these results, and to alert if needed.
See the result:
Erreur de script : le module « Centralizer » n’existe pas.
modes.recursive_normal
Normalizes a recursiveLevel
and a recursive_limit
.
That interact with an internal modes.recursive_limit
which as an initial recursive_limit
.
- The normalization maintains
recursiveLevel
from 1 to recursive_limit
.
- If the
recursiveLevel
input is higher than recursive_limit
, this function formats an error.
Then the module can alert Lua-coders if needed.
modes.recursive_normal_tests
Reports some tests cases of the function modes.recursive_normal
. See the result:
Erreur de script : le module « Centralizer » n’existe pas.
modes.similar_args_list
For an unknown argument, this function searches the closest name of the among translated known arguments.
Argument:
known_arguments
is the default definitions table.
Results:
- A list of translated known arguments in the decreasing
Levenshtein distance
from the given argument.
tableview
The Object:tableview, in the Library:viewers, formats a viewer for tables, in lines and columns.
tableview.form_one_case
Almost all uses of tableview need an adaptation of this function.
For typical use, see:tableview.new
.
Typical call:
function tableview.form_one_case(case, tab_view) -- Default: Convert a case from test_group to rowGroup.
tableview.new
Formats a table view with lines and columns.
It easy replaces: table_head
, table_row
, table_col
, table_dat
and table_end
.
Typical use:
local tab_view = {
test_group = modes.central_libraries, -- List of central libraries.
title_memo = "activity_display_central_libraries_title",
headers = "activity_monitor_central_libraries_headers",
headers_class = "wikitable alternative center sortable",
rowGroup = {},
form_one_case = function(case) -- Convert a case from test_group to rowGroup.
return { case.key, case.val or "-", case.typ, case.need, case.keyword, case.syn, case.prop, case.format, case.src or "-", }
end,
-- track_on == "details",
}
t = t .. tableview.new(tab_view) -- Formats a table view with lines and columns.
tracker
- The tracker object supports parametrable track objects to help to debug the Lua code.
tracker.new
Initializes a new track list.
Argument:
opt
is a group of options.
In opt
, options can define:
form
formats the begin or each track line, like "\n* %1 in=%2"
.
groupname
selects the track list in which add a track line.
level
is the level of detail of each track line.
limit
is the limit of detailed lines.
more
formats next parts of each track line, like ", arg%1=%2"
.
name
is the name of the track.
t
is the resulting text with all track lines. The initial value is ""
.
trackon
tracks (if trackon == 1) or not (if trackon == 1), for one track object.
tracker.initadd
Adds, or not, a new track line to the track list.
Argument:
opt
is the same group of options as in tracker.new
.
level
is a group of options.
opt
is a group of options.
In opt
, options can define:
form
formats the begin or each track line, like "\n* %1 in=%2"
.
Examples of uses:
ARGS = tracker.initadd({ ["name"] = "ARGS", ["limit"] = 2 }) -- Initialize a track
CNT = tracker.initadd({ ["name"] = "CNT", ["limit"] = 2 }) -- Initialize a track
if not CMD then CMD = tracker.initadd({ ["name"] = "CMD", ["limit"] = 2 }) end -- Initialize a track
CMD.add(CMD, 1, "descriptor admins assets hostPort", { ["admins"] = wiki.admins, ["assets"] = wiki.assets, } )
res = res .. CMD.t
versions
The Library:versions installs all central libraries, the main and sub-modules and their i18n translations. It also support the versions support.
version descriptor
Each version of a central module is characterised by these values:
versionName
: like Central
for the main version or like Central-s-fr
for a variant.
versionNumber
: like 1.0.0(180506:07:55)
following the UTC version structure : main.fonction.task(yymmdd:hh:mm)
.
versionDate
: like 2018-05-06T07:55:00
following the UTC rules.
mainDescription
: like Begin to use
following the main task goal.
functionDescription
: like first functional support
a step inside the main task goal.
taskDescription
: like Update to 'Begin' at T20180510 approximately
unambiguous detailed subtask.
sought
is the sought module and submodules versions.
known
are known module and submodules versions.
sought
and known
are inputs for versions.bind_the_main_module
and versions.bind_all_sub_modules
.
Typical header code:
local Central = {} -- The main central module install central libraries and bind the main and sub modules
local p = Central
p.version = { -- Modules dependencies. Dependencias del módulo. Dépendances du module.
versionName = "Central-s-fr", versionNumber = "1.0.0(180506:07:55)", versionDate = "2018-05-06T07:55:00",
-- UTC version structure : main.fonction.task(yymmdd:hh:mm)
mainDescription = "Begin to use", functionDescription = "first functional support", taskDescription = "Update to 'Begin' at T20180510 approximately",
sought = "Central-s-fr;Central;Mathroman22;TestRequire", -- Sought module and submodules versions
known = "Central-s-fr;Central;Central-14 * Mathroman22;Mathroman34", -- Known module and submodules versions
}
versions.all_G_and_loaded_list
Lists variables in the _G
global space or in package.loaded
.
It permits to check if some variable is in the global space _G
from a coding error.
Colors used distinguish the kinds of values: central library in bold blue, library in blue, function in red, track in grey or others in black.
Erreur de script : le module « Centralizer » n’existe pas.
versions.get_one_module_or_library
require()
or installs a module or a library in package.loaded
.
Then it formats and records its descriptor.
There are 2 uses, with changes of types of arguments:
local get = versions.central_library(given_module, title)
local get, module = versions.get_one_module_or_library("Module:Central")
Rought structure of the descriptor:
get.title = title -- The name of the object, like "Module:Example" for a module.
get.module = module -- The module or the library itself (compiled).
get.isNil = not get.module
get.isLoaded = true -- if the object is in package.loaded[title].
get.isFunction = true -- if the object is a function.
get.isTable = true -- if the object is a table.
get.isModule = true -- if get.title lookalikes to "Module:Example".
get.isLibrary = true -- if get.title lookalikes to "example".
get.i18n = true -- if the object contains i18n translations, like "module.i18n".
get.hasi18n = true -- if get.i18n translations are available.
get.subI18N = get.title .. "/I18N" -- eventual sub-module "/I18N".
get.isI18N = true -- if title include "/I18N".
get.versionI18N = lookalikes -- to "Module:Example/I18N".
get.lessI18N = title -- do not lookalikes to "Module:Example/I18N".
get.simplename = title -- without "Module:" and without "/I18N".
get.revistamp = time -- This compact format of the last update date-time of the module lookalikes to "20180512150600".
get.versions = module.versions -- descriptor for the versions support {sought, known...}.
get.versionName = get.title -- without "Module:", but perhaps with "/I18N".
Examples of use, see versions
:
local get = versions.central_library(given_module, title)
local get, module = versions.get_one_module_or_library("Module:Central") -- The types of arguments differ to require a module or a library.
versions.setup_central_libraries
Binds libraries in package.loaded
.
It is used in p.init_central_module
.
viewers
The Library:viewers can formats texts to document in some languages: tableview(in lines and columns), dropboxes, recursive Lua tables...
viewers.day_to_stamp
Converts a date in a time stamp, limited to the date.
Examples of code for a similar result:
return "@" .. tostring( jj*86400 + mm*30*86400 + (aaaa-1970)*31556926 )
return viewers.day_to_stamp(jj, mm, aaaa)
viewers.day_to_UTC
Converts a date in UTC format, limited to the date.
Examples of code for a similar result:
return aaaa .. "-" .. mm .. "-" .. jj
return viewers.day_to_UTC(jj, mm, aaaa)
viewers.discreet_main_version
Returns the main version in light grey for attentive readers only.
viewers.doc_group
Displays all drop_box.new
.
viewers.doc_internal
Displays only internal tests or reports drop_box.new
.
viewers.doc_module
Displays only reports drop_box.new
dedicated to the module.
viewers.doc_page
Displays only reports drop_box.new
dedicated to the page.
viewers.doc_section
Formats the title of a group of drop_box.new
, typicaly for each library.
Example of use:
res = res .. viewers.doc_section(selector, "Library:lua_table", "h3")
viewers.form99content
Similar to viewers.form9user
for 99 values in content
language.
viewers.form99page
Similar to viewers.form9user
for 99 values in page
language.
viewers.form99user
Similar to viewers.form9user
for 99 values in user
language.
viewers.form9content
Similar to viewers.form9user
for 9 values in content
language.
viewers.form9en
Similar to viewers.form9user
for 9 values in user
language.
But in English only for tests.
viewers.form9page
Similar to viewers.form9user
for 9 values in page
language.
viewers.form9user
Formats a parametrable text and is the most used in all central libraries.
If the text is a key in i18n tables, it replaces the key by its translation in the user language.
Then it replaces "%1" to "%9" in the text by v1 to v9 arguments.
Example of use:
viewers.form9user(ref, v1, v2, v3, v4, v5, v6, v7, v8, v9) -- reference call
viewers.form9user("Module with internal error") -- example with simple text
viewers.form9user("luaTable_structure_level_maxi", recursiveLevel) -- example with key.
viewers.form9user(" %1 variables, %2 functions, %3 sub-tables.\n", vr, fn, tb) -- example with text and values.
Result in a parametrable string based on ref
.
- If
ref
is a key of translatable string in a i18n table, it is first translated.
- If
ref
is not a translatable key, this function uses it as translated.
- If the translated string contains
%1
to %9
this function replaces them by v1
to v9
respectively.
- If
ref
is any other string, the function returns it as is.
This is roughly equivalent to:
function viewers.form9user(ref, v1, v2, v3, v4, v5, v6, v7, v8, v9)
if translations[ref] then wt = tostring(translations[ref])
elseif ref then wt = tostring(ref)
else wt = tostring("noref") end
v1 = v1 or " 1"
...
v9 = v9 or " 9"
if v1 then wt = string.gsub(wt, "%%1", tostring(v1) ) end
...
if v9 then wt = string.gsub(wt, "%%9", tostring(v9) ) end
return tostring(wt)
end
viewers.form9user_test
Reports some unitary tests of the viewers.form9user
function.
Do not translate the i18n translation key and separate the arguments with semicolons.
Example of results:
"langs_form99user_all_types_values;abc;4;nil;function;55;xyz",
"replace: abc%1efg%2ijk;<b>D</b>;<b>H</b>",
viewers.form_image
Formats an image from its file name, to the size in pixels.
Options are added as string.
Arguments:
file
is the file name of the image.
size
permit to change the size of the viewed image.
options
is a string to acurately display the file
.
This is roughly equivalent to:
function viewers.form_image(file, size, options) -- Formats an image from its file name, to the size in pixels
return '[[File:' .. file .. '|' .. size .. 'px|' .. options .. ']]' -- options must begin with "|"
end
viewers.is_in
Returns true
if the word is in the text, even inside another word. Else return false
.
Apart some precautions, this is roughly equivalent to:
function viewers.is_in(word, text)
return string.find(text, word)
end
viewers.is_in_sp
Returns true
if the word is in the text, beetwen spaces or separators, not inside another word. Else return false
.
Arguments:
word
is the separator to limit the word, or any string, to find.
text
is the string where search the word.
sep
is the separator to limit the word to find. The default is a space.
This is roughly equivalent to:
function viewers.is_in_sp(word, text, sep)
sep = sep or " "
return string.find(sep .. text .. sep, sep .. word .. sep)
end
viewers.main_view
Formats all results of the main module, following main options
.
In each mode, options ask to adapt the result to display.
This is roughly equivalent to:
function viewers.main_view(args_final, main_module) -- Formats all results of this module and its sub-modules.
local main_module = main_module or versions.main_module
events.gener_categories(args_final) -- Formats all categories without activate them
if modes.option("docview") or modes.option(":") or modes.option("tests") or (modes.args_final.mode == "edit") then
res = res .. p.formDocBox(modes.args_final)
end
if modes.option("box1") then res = res .. p.box1(props) end
if modes.option("box1") or modes.option("catview") then
res = res .. " catview = " .. events.categories_lister(":") -- Display categories
end
events.categories_lister("") -- really link to categories
if modes.option("tests") then res = res .. viewers.doc_group("allwaysview") end
return res
end
viewers.restore_configs
Restores global configurations, after eventual changes, saved by viewers.save_configs
.
If needed, it creates an error which is roughly equivalent to:
events.add_err("events_close_without_memo_err", versions.main_versions.versionName) -- Add an error in the actual table of events.
It is roughly equivalent to:
function viewers.restore_configs(memo, where) -- Restore global configurations after eventual changes.
events.categories_list = memo.memo_categories_list
events.tab_options = memo.memo_tab_options
events.tab_view = memo.memo_tab_view
events.test_group = memo.memo_test_group
--
langs.content_lang = memo.memo_content_lang
langs.content_translations = memo.memo_content_translations
langs.main_i18n = memo.memo_langs_main_i18n
langs.page_lang = memo.memo_page_lang
langs.page_translations = memo.memo_page_translations
langs.user_lang = memo.memo_user_lang
langs.user_translations = memo.memo_user_translations
langs.wiki_lang = memo.memo_wiki_lang
langs.wiki_translations = memo.memo_wiki_translations
langs.init_content_page_user_lang(langs.content_lang, langs.page_lang, langs.user_lang)
--
modes.known_arguments = memo.memo_known_arguments
modes.args_template = memo.memo_args_template
modes.cat_view = memo.memo_modes_cat_view
modes.invoke_options = memo.memo_invoke_options
modes.mode_name = memo.memo_mode_name
modes.mode_options = memo.memo_mode_options
modes.options_for_modes = memo.memo_options_for_modes
modes.recursive_limit = memo.memo_recursive_limit
modes.report_track_options = memo.memo_report_track_options
modes.template_options = memo.memo_template_options
modes.used_options = memo.memo_used_options
--
versions.actual_modules = memo.memo_versions_actual_modules
versions.main_i18n = memo.memo_versions_main_i18n
end -- function viewers.restore_configs(memo, where)
viewers.rough_view
Formats a string to describe a value of any type, even nil
or a Lua table.
The string is a rough view of the value, like: true, 123.456, "abcd", func() or table{}
.
viewers.rough_view_test
Reports some tests of viewers.rough_view
.
viewers.save_configs
Saves global configurations, before eventual changes, restored by viewers.restore_configs
.
It is roughly equivalent to:
function viewers.save_configs() -- Save global configurations before eventual changes.
local memo = {}
memo.memo_categories_list = events.categories_list
memo.memo_tab_options = events.tab_options
memo.memo_tab_view = events.tab_view
memo.memo_group = events.test_group
--
memo.memo_content_lang = langs.content_lang
memo.memo_content_translations = langs.content_translations
memo.memo_langs_main_i18n = langs.main_i18n
memo.memo_page_lang = langs.page_lang
memo.memo_page_translations = langs.page_translations
memo.memo_user_lang = langs.user_lang
memo.memo_user_translations = langs.user_translations
memo.memo_wiki_lang = langs.wiki_lang
memo.memo_wiki_translations = langs.wiki_translations
--
memo.memo_known_arguments = modes.known_arguments
memo.memo_args_template = modes.args_template
memo.memo_modes_cat_view = modes.cat_view
memo.memo_invoke_options = modes.invoke_options
memo.memo_mode_name = modes.mode_name
memo.memo_mode_options = modes.mode_options
memo.memo_options_for_modes = modes.options_for_modes
memo.memo_recursive_limit = modes.recursive_limit
memo.memo_report_track_options = modes.report_track_options
memo.memo_template_options = modes.template_options
memo.memo_used_options = modes.used_options
--
memo.memo_versions_actual_modules = versions.actual_modules
memo.memo_versions_main_i18n = versions.main_i18n
return memo
end -- function viewers.save_configs()
Use of save and restore functions:
function viewers.save_configs(where) -- Save global configuration before eventual changes.
local memo = viewers.save_configs() -- Save global configuration before eventual changes.<!--Doc 20171103 DocTodo DocOK -->
-- Any code which could disturb global configurations
viewers.restore_configs(memo) -- Restore global configurations after eventual changes.
end
viewers.save_restore_balance_report
This function must run after any other tests to be efficient.
Checks and reports known couples of save and restore global configurations, mainly to protect them against tests which can disturb anything.
It uses the results of viewers.save_configs
and viewers.restore_configs
.
viewers.simple_list
Splits a string in parts limited by 1 to 4 separators. It can also trim and sort these parts.
Arguments:
- The
list
is the input string to split...
- The 4 arguments
sep1
, sep2
, sep2
, sep2
, have similar roles.
- Their default role is to split
list
in parts.
- The value
"sort"
asks to sort the resulting parts.
- The value
"trim"
asks to delete, before and after each part, any space, coma...
viewers.simple_list_test
Uses the viewers.simple_list
function in some cases and reports them.
It uses the results of viewers.restore_configs
.
Arguments:
- The
list
is the input string to split...
- The 4 arguments
sep1
, sep2
, sep2
, sep2
, have similar roles.
See the result:
Erreur de script : le module « Centralizer » n’existe pas.
viewers.styles_small_caps
Changes the style of a displaid text to the functional style "small caps".
Extract from the code:
return '<span style="font-variant: small-caps">' .. t .. '</span>'
viewers.ta
Formats a variable and its value in a documentation.
Arguments:
txt
finishes with the name of the variable, and can begin with any complement.
val
is the value of the variable.
sep
can replace the equal sign.
You can code for the same result:
return viewers.ta("\n* pi", 3.14)
return "* pi = <b>3.14</b>, "
viewers.tam
Uses viewers.ta
.
If val
is nil
then viewers.tam
return an empty string.
viewers.table_col
Begins a new column in a table. See also tableview.new
.
A column become fix and not triable with the option: class="unsortable".
viewers.table_dat
Displays a string in a column of a table.
function viewers.table_dat(t) return "\n| " .. tostring( t or " ") end -- Table data -- or " "
Uses viewers.ta
.
If val
is nil
then viewers.tam
return en empty string.
viewers.table_end
Finishes a table of rows.
function viewers.table_end(t) return "\n|}" end -- Table end
Uses viewers.ta
.
If val
is nil
then viewers.tam
return en empty string.
viewers.table_head
Begins a row of headers in bold in a table, even between two rows of usual strings.
Is used viewers.ta
.
A triable table start with the option: class="wikitable sortable"
Argument:
t
defines the options values. The default is "wikitable alternative center"
.
Rough code:
return '\n{| class="' .. tostring( t or 'wikitable alternative center' ) .. '" | '
viewers.table_row
Begins a row of usual strings.
A row become fix and not triable with the option: class="sortbottom"
.
See how to use options in viewers.table_end
.
viewers.styles_color_add
See viewers.usual_color
.
viewers.styles_color_colargs
See viewers.usual_color
.
viewers.styles_color_delete
See viewers.usual_color
.
viewers.styles_color_discreet
See viewers.usual_color
.
viewers.styles_color_error
See viewers.usual_color
.
viewers.styles_color_mask
See viewers.usual_color
.
viewers.styles_color_normal
See viewers.usual_color
.
viewers.styles_color_warning
See viewers.usual_color
.
viewers.styles_color_wikidata
See viewers.usual_color
.
viewers.usual_color
Colors a text to display using the second argument. The first one is the text.
Available colors for styles in viewers.usual_colors
:
add
for add in blue = "blue", for a better accessible contrast see the task T156048.
colargs
for invoked args in brown = "#804020".
delete
for delete in yellow = "#C0C000", for a better accessible contrast see the task T156048.
discreet
for discreet in light grey = "#B0B0B0".
error
for error in modified red = "#AA6688".
mask
to mask in white = "white".
normal
for other standard in normal text = "black".
warning
for warnings in brown = "#804020".
wikidata
. for wikidata in green = "green".
These corresponding functions change the colors of a displayed text for available functional styles:
They need only the text argument:
viewers.styles_color_add(t)
viewers.styles_color_delete(t)
viewers.styles_color_discreet(t)
viewers.styles_color_error(t)
viewers.styles_color_colargs(t)
viewers.styles_color_mask(t)
viewers.styles_color_normal(t)
viewers.styles_color_warning(t)
viewers.styles_color_wikidata(t)
Used code for these functions:
function viewers.styles_color_add(t) return viewers.usual_color(t, "add") end
function viewers.styles_color_delete(t) return viewers.usual_color(t, "delete") end
function viewers.styles_color_discreet(t) return viewers.usual_color(t, "discreet") end --For attentive readers only.
function viewers.styles_color_error(t) return viewers.usual_color(t, "error") end
function viewers.styles_color_colargs(t) return viewers.usual_color(t, "colargs") end
function viewers.styles_color_mask(t) return viewers.usual_color(t, "mask") end
function viewers.styles_color_normal(t) return viewers.usual_color(t, "normal") end
function viewers.styles_color_warning(t) return viewers.usual_color(t, "warning") end
function viewers.styles_color_wikidata(t) return viewers.usual_color(t, "wikidata") end