Extension:Scribunto/Victor's API proposal

There are several packages which will be shipped with Scribunto by default.

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 — functions which allow to manipulate the titles
 * 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 parsed title data 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

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

 * — parses the text and returns either the title structure or nil
 * — normalizes the title; returns nil if the input is an invalid title
 * — returns true if the input is a valid title and is not an interwiki destination

mw.time

 * — 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
 * — parses the  and returns a timestamp object, assuming by default that timezone is   (UTC if not specified).
 * — formats the  according to the   specification.
 * — 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.url
Title input in those functions may be both text and the title structure.


 * — escapes a URL string
 * — escapes a URL anchor string
 * — returns a local (relative) URL to, optionally with
 * — same as above, but uses full URL instead of local one (includes server name).
 * — same as above, but has a protocol prefix.
 * — similar to.
 * — similar to.
 * — similar to.

ustring API
The  module is a module which provides manipulations with UTF-8 strings. 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 seperate 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). Note that the needle argument is not a pattern.
 * — 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.