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. func{a, b, c}
means that you should invoke function as func{a = "whatever", b = "argument", c = "trolling"}
.
Whenever a property is defined, it is either read-only ([ro]
), write-only ([wo]
) or read-write ([rw]
).
All interfaces are the part mw package.
The time is passed in a following structure, which extends over Lua's standard date/time structure:
year
month
day
hour
min
sec
wday
— week day (Monday is 1)yday
— day of the yearmonthname
— localized month nametimezone
— the timezone in which timestamp is suppliedThe revision information is passed in the following structure:
id
author
timestamp
(always UTC)The titles have a special object, which is described in an individual section below.
Detailed interface description[edit]mw.lang.contentLanguage [ro]
— the language code of the content language, i.e. the main language of the wiki.mw.lang.UILanguage [ro]
— the language code of the UI language, i.e. language in which user has his interface now.mw.lang.languageName{code[, language]}
— returns the language name of language with code
. If language
is not specified, return in the language itself.mw.lang.message(messageName, ...)
— formats the message and returns it.mw.lang.plural(number, form1, form2...)
— similar to {{plural:number|form1|form2|...|}}
.mw.lang.formatNumber(number)
— formats the number according to the language conventions.mw.lang.gender(username, ...)
— picks the right version of the string depending on the user gender.mw.lang.specialPageName(page)
— returns the localized name of a given special page.mw.page.title [ro]
— returns the title structuremw.page.currentRevision [ro]
— returns the revision structuremw.page.defaultSort [wo]
— similar to {{DEFAULTSORT}}
mw.page.displayTitle [wo]
— similar to {{DISPLAYTITLE}}
The query module has different configurable limit-related variables:
blockSize
— defaults to 100listLimit
— defaults to 500In case when the limit is exceeded, the error is thrown.
mw.query.blockSize [ro]
— the blockSize
.mw.query.listLimit [ro]
— the listLimit
.mw.query.expensiveFunctionLimit [ro]
— the limit of allowed calls to expensive functions.mw.query.expensiveFunctionRemaining [ro]
— how much more calls to expensive functions are allowedmw.query.pagesExist(pages)
— checks whether the pages
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 blockSize
of pages this count is increased by 1.mw.query.pageInformation{pages, props}
— returns the information about pages
. The information to return is specified in props
array. Currently available are size
and is_redirect
. This is counted as one expensive query, but for every blockSize
of pages this count is increased by 1.mw.query.prefixIndex{prefix, startWith, limit}
— list the pages beginning with prefix
, starting with startWith
. Returns at most limit
pages, or listLimit
, whatever is smaller.mw.site.siteName [ro]
— returns the name of the site.mw.site.version [ro]
— returns MediaWiki software version.mw.site.namespaces [ro]
— returns localized namespace ID to namespace name map.mw.site.canonicalNamespaces [ro]
— returns non-localized namespace ID to namespace name map.mw.site.interwikiTable [ro]
— returns the interwiki table in format { interwiki prefix -> { url, api, wikiID, isLocal, isTrans } }mw.site.numberOfPages [ro]
mw.site.numberOfArticles [ro]
mw.site.numberOfFiles [ro]
mw.site.numberOfEdits [ro]
mw.site.numberOfViews [ro]
mw.site.numberOfUsers [ro]
mw.site.numberOfAdmins [ro]
mw.site.numberOfActiveUsers [ro]
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:
mw.Title(text)
— creates a title from its text form; returns nil if the title is invalid.mw.Title(data)
— creates a title from its data. Currently the only accepted fields are text
, namespaceID
and namespaceName
, 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
— namespace IDnamespaceName
— namespace name (localized)name
— the name of the page, without namespacefullName
— full name of the page, with namespacefullText
— the full normalized title, including interwiki prefixinterwiki
— the interwiki prefix, if is therefragment
— the destination fragmentIt also has the following methods:
titleObj:localURI([query])
— returns a local (relative) URL to the title, optionally with query
titleObj:fullURI([query])
— same as above, but uses full URL instead of local one (includes server name).titleObj:canonicalURI([query])
— same as above, but has a protocol prefix.This interface provides access to MediaWiki's advanced date and time handling, parsing and internationalization interfaces.
mw.time.UTC [ro]
— returns the current time in UTC.mw.time.local [ro]
— returns the current time in the wiki timezone.mw.time.unixTimestamp [ro]
— returns the exact Unix timestamp in seconds, but with highest floating-point precision possible.mw.time.toLocal(timestamp)
— translates the timestamp to the wiki timezone.mw.time.toUTC(timestamp)
— translates the timestamp to UTC.mw.time.parse(text)
— parses the text
and returns a timestamp object, assuming by default that timezone is timezone
(UTC if not specified).mw.time.format{timestamp, format}
— formats the date
according to the format
specification.mw.text.escape(text)
— escapes wikitext.mw.text.tag{name, contents, params}
— creates a tag marker for tag named name
. Similar to {{#tag}}
.mw.uri.encode(text)
— escapes a URL stringmw.uri.encodeAnchor(text)
— escapes a URL anchor stringmw.uri.server [ro]
— similar to {{SERVER}}
.mw.uri.serverName [ro]
— similar to {{SERVERNAME}}
.mw.uri.scriptPath [ro]
— similar to {{SCRIPTPATH}}
.The ustring
module provides UTF-8 strings manipulations. It aims to be similar to built-in string
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[1]. There are the following functions in the ustring library:
ustring.find(s, needle[, init])
— does a substring search, and returns the start and the end point of the match (or nil, if not found). Important differences:
ustring.len(s)
— returns the string length in code points.ustring.lower(s)
— converts the string to all-lowercaseustring.pairs(s[, start, end])
— allows to iterate over all codepoints in the string, or in a substring (from start
to end
).ustring.split(str, separator[, limit])
— splits the str
into at most limit
substrings (default limit is infinity)ustring.sub(s, i[, j])
— returns the substring; the syntax is similar to string.sub
.ustring.trim(s)
— trims all the whitespace at the beginning and at the end of the string.ustring.upper(s)
— converts the string to all-uppercaseustring.upperFirst(s)
— converts the first character of the string into uppercaseAll functions index the offsets in string by codepoints, not bytes. If invalid UTF-8 is supplied, an error is raised.
For all ustring
functions which accept target string as a first argument, a similar function with "u" prefix is provided in usual string metatable. For example, ustring.trim(str)
may also be called as str:utrim()
.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4