Jump to content

Module:Article history/doc

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 14:48, 10 December 2014 (Object documentation: add Message class documentation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

This module implements Template:Article history (edit | talk | history | links | watch | logs). It has a configuration module at Module:Article history/config (edit | talk | history | links | watch | logs), and a Category class at Module:Article history/Category (edit | talk | history | links | watch | logs).

Class documentation

Message

Methods from the Message mixin are available in all classes. They are:

  • Message:message(key, ...) - fetches a message with the key key from the config's msg table, and substitutes parameters $1, $2 etc. with the subsequent values it is passed.
  • Message:raiseError(msg, help) - formats msg and uses it to raise an error. help is an optional page that will provide help for the error that the user encountered. This is intended to be caught with ArticleHistory:try, and is for errors after which further processing in that object becomes impossible.
  • Message:addWarning(msg, help) - formats msg and uses it to add a warning. help is an optional page that will provide help for the error that the user encountered. This is for errors that should be fixed, but that do not prevent the module from outputting something useful for that object.
  • Message:getWarnings() - returns an array of all warnings added for the object.

ArticleHistory

ArticleHistory objects have the following public properties:

  • args - a table of the arguments passed to the module by the user.
  • currentTitle - the title object for the current page.
  • cfg - 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 { foo = {"a value", aliases = {"bar", "baz"} } } would become {foo = {"a value"}, bar = {"a value"}, baz = {"a value"} }. (Although "bar" and "baz" would actually be references to the "foo" table, rather than completely new tables.)
  • isSmall - a boolean showing whether the module is outputting a small banner or not.
  • prefixArgs - 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 {a1x = 'eggs', a1y = 'spam', a2x = 'chips', b1z = 'beans', b3x = 'bacon'} would translate into the prefixArgs table {a = { {1, x = 'eggs', y = 'spam'}, {2, x = 'chips'} }, b = { {1, z = 'beans'}, {3, x = 'bacon'} } }.

They have the following public methods:

  • ArticleHistory:try(func, ...) - calls the function func with the arguments passed, and returns the first value produced by it. If any errors are encountered, they are caught and added to the object's internal errors table for later rendering by ArticleHistory:getErrorMessages.
  • ArticleHistory:getActionObjects() - returns an array containing the Action objects for any actions specified by the user.
  • ArticleHistory:getStatusIdForCode(code) - for the status code code, returns the canonical status ID.
  • ArticleHistory:getStatusObj() - gets the status object for the template. This returns nil if no current status can be found.
  • ArticleHistory:getStatusId() - returns the status ID for the template. This returns nil if no current status can be found.
  • ArticleHistory:getNoticeObjects() - returns an array containing the template's Notice objects.
  • ArticleHistory:getCollapsibleNoticeObjects() - returns an array containing the template's CollapsibleNotice objects.
  • ArticleHistory:getAllObjects(addSelf) - returns an array containing all Status/MultiStatus, Notice, Action and CollapsibleNotice objects. if addSelf is true, the ArticleHistory object is appended to the array as well.
  • ArticleHistory:getErrorMessages() - returns an array containing all error and warning strings. Errors are typically raised with Message:raiseError and caught with ArticleHistory:try, and warnings are added to individual objects with Message:addWarning.
  • ArticleHistory:renderHtml() - renders the HTML table comprising all the visible output of the template, including status, notices, actions, collapsible notices, error messages and warnings. The result is returned as a string.
  • ArticleHistory:renderCategories() - renders all category links and returns them as a string.

Calling tostring() on an ArticleHistory object gives you the HTML table made with ArticleHistory:renderHtml concatenated with the category links made with ArticleHistory:renderCategories.