Extension:Scribunto/Victor's API proposal

MediaWiki Lua API
The aim of Scribunto Lua in-script API is to provide the scripts an interface to certain features of MediaWiki software which are written in PHP and most of which are not feasible to implement in Lua. The first-priority target is to provide access to all those interfaces which were previously exposed to parser as magic words and parser functions.

Here we try to keep to the table arguments convention whenever it is feasible. means that you should invoke function as.

Whenever a property is defined, it is either read-only, write-only or read-write.

Provided interfaces
All interfaces are the part mw package.
 * mw.lang — internationalization-related functions.
 * mw.page — interface to provide information about the current page (title, etc) and do direct manipulations with it.
 * mw.query — functions which require database queries in order to work. The total amount of calls to those functions is limited; the limit is shared with parser's expensive function count.
 * mw.site — functions which provide the information about the site.
 * mw.time — functions which provide interfaces for time manipulations.
 * mw.Title — provides an object which represents title
 * mw.text — functions which are used to handle the wikitext.
 * mw.url — functions which provide access to URL-related functions.

Data structures
The time is passed in a following structure, which extends over Lua's standard date/time structure:
 * Standard members:
 * — week day (Monday is 1)
 * — day of the year
 * Extensions:
 * — localized month name
 * — the timezone in which timestamp is supplied
 * — week day (Monday is 1)
 * — day of the year
 * Extensions:
 * — localized month name
 * — the timezone in which timestamp is supplied
 * — the timezone in which timestamp is supplied

The revision information is passed in the following structure:
 * (always UTC)
 * (always UTC)
 * (always UTC)

The titles have a special object, which is described in an individual section below.

mw.lang

 * — the language code of the content language, i.e. the main language of the wiki.
 * — the language code of the UI language, i.e. language in which user has his interface now.
 * — returns the language name of language with . If   is not specified, return in the language itself.
 * — formats the message and returns it.
 * — similar to.
 * — formats the number according to the language conventions.
 * — picks the right version of the string depending on the user gender.
 * — returns the localized name of a given special page.

mw.page

 * — returns the title structure
 * — returns the revision structure
 * — similar to
 * — similar to

mw.query
The query module has different configurable limit-related variables:
 * — defaults to 100
 * — defaults to 500

In case when the limit is exceeded, the error is thrown.


 * — the.
 * — the.
 * — the limit of allowed calls to expensive functions.
 * — how much more calls to expensive functions are allowed
 * — checks whether the  exist and returns the result in form of page->existence table. Note that page name in the resulting table is normalized. This is counted as one expensive query, but for every   of pages this count is increased by 1.
 * — returns the information about . The information to return is specified in   array. Currently available are   and  . This is counted as one expensive query, but for every   of pages this count is increased by 1.
 * — list the pages beginning with, starting with  . Returns at most   pages, or  , whatever is smaller.
 * there will be more at the later stage

mw.site

 * — returns the name of the site.
 * — returns MediaWiki software version.
 * — returns localized namespace ID to namespace name map.
 * — returns non-localized namespace ID to namespace name map.
 * — returns the interwiki table in format { interwiki prefix -> { url, api, wikiID, isLocal, isTrans } }

mw.Title
Unlike other packages, this is an object class. It may be returned by any API method or be constructed by user using one of the following constructors:
 * — creates a title from its text form; returns nil if the title is invalid.
 * — creates a title from its data. Currently the only accepted fields are,   and  , allowing to create a title object from namespace + text data. If the data is insufficient, conflicting or invalid, nil is returned.

The title object has the following fields:
 * — namespace ID
 * — namespace name (localized)
 * — the name of the page, without namespace
 * — full name of the page, with namespace
 * — the full normalized title, including interwiki prefix
 * — the interwiki prefix, if is there
 * — the destination fragment

It also has the following methods:
 * — returns a local (relative) URL to the title, optionally with
 * — same as above, but uses full URL instead of local one (includes server name).
 * — same as above, but has a protocol prefix.

mw.time
This interface provides access to MediaWiki's advanced date and time handling, parsing and internationalization interfaces.


 * — returns the current time in UTC.
 * — returns the current time in the wiki timezone.
 * — returns the exact Unix timestamp in seconds, but with highest floating-point precision possible.
 * — translates the timestamp to the wiki timezone.
 * — translates the timestamp to UTC.
 * — parses the  and returns a timestamp object, assuming by default that timezone is   (UTC if not specified).
 * — formats the  according to the   specification.

mw.text

 * — escapes wikitext.
 * — creates a tag marker for tag named . Similar to.

mw.uri

 * — escapes a URL string
 * — escapes a URL anchor string
 * — similar to.
 * — similar to.
 * — similar to.

ustring API
The  module provides UTF-8 strings manipulations. It aims to be similar to built-in  module in Lua; however, it extends it in some features and it does not provide pattern matching (a separate regular expression library will be provided for that later). Also, it does not provide an OOP interface to strings. There are the following functions in the ustring library:
 * — does a substring search, and returns the start and the end point of the match (or nil, if not found). Important differences:
 * The needle argument is not a pattern.
 * In case of using empty string as a needle, raises an error.
 * The first two returns are start- and endpoint as a string offset in characters; the third and fourth arguments are raw byte offsets.
 * — returns the string length in code points.
 * — converts the string to all-lowercase
 * — allows to iterate over all codepoints in the string, or in a substring (from  to  ).
 * — splits the  into at most   substrings (default limit is infinity)
 * — returns the substring; the syntax is similar to.
 * — trims all the whitespace at the beginning and at the end of the string.
 * — converts the string to all-uppercase
 * — converts the first character of the string into uppercase

All functions index the offsets in string by codepoints, not bytes. If invalid UTF-8 is supplied, an error is raised.

For all  functions which accept target string as a first argument, a similar function with "u" prefix is provided in usual string metatable. For example,  may also be called as.