Module:Article history/doc: Difference between revisions

Content deleted Content added
ArticleHistory: add ArticleHistory:getNoticeBarIcons
 
(14 intermediate revisions by 8 users not shown)
Line 1:
{{Module rating|protected}}
This module implements {{lt|Article history}}. It has a configuration module at {{lmd|Article history/config}}, and a Category class at {{lmd|Article history/Category}}.
{{High-use}}
{{Lua|Module:Article history/config|Module:Article history/Category|Module:Yesno|Module:Arguments}}
{{Uses TemplateStyles|Module:Message box/tmbox.css|Module:Article history/styles.css}}
This module implements {{lt|Article history}}. Please see the template page for documentation of how to use it.
 
== Technical details ==
 
This module has a configuration module at [[Module:Article history/config]], which can be used to translate/modify the template for use on other wikis. See the config module for instructions on how to modify it. The configuration for the English Wikipedia is very complicated, but it is also possible to use it much more simply. If you want to use the more advanced features provided by the module, you can consult the class documentation below.
 
There is also a Category class at [[Module:Article history/Category]], which is used by both the main module and the config module.
 
== Class documentation ==
 
This is technical documentation for Lua programmers who are looking to adapt this module for use on different wikis.
 
=== Category ===
 
The Category class is used to generate all of the module's categories. It is loaded in both [[Module:Article history]] and [[Module:Article history/config]]. You can create a category with Category.new:
 
<syntaxhighlight lang="lua">Category.new(cat, sort)</syntaxhighlight>
 
The <var>cat</var> variable is the category text, and <var>sort</var> is its sort key.
 
Once category objects are created, they have the following properties:
* <code>category</code> - the category name
* <code>sortKey</code> - the sort key
 
They can be rendered into category links by calling <code>tostring()</code> on them.
 
=== Message ===
 
The Message mixin contains common message-related methods which areavailableare available in all classes apart from the Category class. These methods are:
 
* <code>Message:message(key, ...)</code> - fetches a message with the key <var>key</var> from the config's msg table, and substitutes parameters $1, $2 etc. with the subsequent values it is passed.
Line 19 ⟶ 45:
* <code>currentTitle</code> - the [[mw:Extension:Scribunto/Lua reference manual|title object]] for the current page.
* <code>cfg</code> - the module config table. This is taken from the config module at [[Module:Article history/config]], but is structured slightly differently due to preprocessing by the main module. Any table with an "aliases" subtable has this table removed, and the aliases are added as keys that the table can be accessed from. Conceptually, the config table {{code|1={ foo = {"a value", aliases = {"bar", "baz"} } }|2=lua}} would become {{code|1={foo = {"a value"}, bar = {"a value"}, baz = {"a value"} }|2=lua}}. (Although "bar" and "baz" would actually be references to the "foo" table, rather than completely new tables.)
* <code>isSmall</code> - a boolean showing whether the module is outputting a small banner or not.
* <code>prefixArgs</code> - a table of the arguments passed to the module by the user, sorted by their prefix and then their number. Non-string keys and keys that don't contain a number are ignored. (This means that positional parameters are ignored, as they are numbers, not strings.) The parameter numbers are stored in the first positional parameter of the subtables, and any gaps are removed so that the tables can be iterated over with ipairs. For example, the arguments {{code|1={a1x = 'eggs', a1y = 'spam', a2x = 'chips', b1z = 'beans', b3x = 'bacon'}|2=lua}} would translate into the prefixArgs table {{code|1={a = { {1, x = 'eggs', y = 'spam'}, {2, x = 'chips'} }, b = { {1, z = 'beans'}, {3, x = 'bacon'} } }|2=lua}}.
 
Line 45 ⟶ 70:
* <code>currentTitle</code> - the same as ArticleHistory.currentTitle.
* <code>cfg</code> - the same as ArticleHistory.cfg.
* <code>isSmall</code> - the same as ArticleHistory.isSmall.
 
Row objects have the following public methods:
 
* <code>Row:getData(articleHistoryObj)</code> - get memoized data for the object that has been created with a makeData function in the module config page. This mechanism is used to stop config page functions from having to do the same data processing more than once. It must be passed an ArticleHistory object to find the data from. This returns nil if no data was generated or an error was encountered while generating the data.
* <code>Row:setIconValues(icon, caption, size, smallSize)</code> - set icon values for the object. <var>icon</var> is the icon filename without any namespace prefix, <var>caption</var> is a caption to use with the icon, and <var>size</var> is the size of the icon when output with a large banner, and <var>smallSize</var> is the size of the icon when output with a small banner. <var>icon</var> and <var>caption</var> can be functions which take an ArticleHistory object as input and return the icon or caption value respectively. Sizes should include any suffixes, e.g. "30px".
* <code>Row:getIcon(articleHistoryObj)</code> - get the icon filename. It must be passed an ArticleHistory object. Returns nil if no icon was set.
* <code>Row:getIconCaption(articleHistoryObj)</code> - get the icon caption. It must be passed an ArticleHistory object. Returns nil if no caption was set.
Line 111 ⟶ 135:
 
}}</includeonly>
<noinclude>
[[Category:Module documentation pages]]
</noinclude>