Jump to content

Wikipedia:Comparable Lua functions to wikitext

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 156.38.57.2 (talk) at 20:28, 1 July 2024 (MONTASAR). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

This is a list of Lua functions and the wikitext parser functions and magic words that they are comparable to.

It is slightly out of date for what wikitext parser functions can do.

Parser functions

Wikitext Lua
{{#if:x |not empty |empty}}
if x then
    'not empty'
else
    'empty'
end
{{#ifeq:x |y |identical |different}}
if x == y then
    'identical'
else
    'different'
end
{{#iferror:function |bad |good}}
 
if tostring(mw.getCurrentFrame():preprocess('function')):find('<strong class="error"') then
    'bad'
else
    'good'
end
{{#ifexpr:1+2=3 |true|false}}
if 1 + 2 == 3 then
    'true'
else
    'false'
end
[Expensive]
{{#ifexist:namespace:title |exists |doesn't exist}}
[Expensive]
if mw.title.new('title', 'namespace').exists == true then
    "exists"
else
    "doesn't exist"
end
{{#rel2abs:path |basepath}}
{{#switch:{{{1}}} |foo=Foo |Bar}}
local cases = {
    default = "Bar",
    foo = "Foo",
}

local pframe = mw.getCurrentFrame():getParent()
local arg = pframe.args[1]
cases[arg] or cases["default"]
{{#time:format |timestamp}}
mw.getContentLanguage():formatDate('format', 'timestamp')
{{#timel:format |timestamp}}
mw.getContentLanguage():formatDate('format', 'timestamp', 1)
{{#titleparts:pagename |number of segments to return |first segment to return}}

MONTASAR

Magic words

MONTASAR

Technical metadata

Wikicode Lua
{{SITENAME}}
mw.site.siteName
{{SERVER}}
mw.site.server
{{SERVERNAME}}
{{DIRMARK}}
mw.language.getContentLanguage():getDirMark()
{{SCRIPTPATH}}
mw.site.scriptPath
{{STYLEPATH}}
mw.site.stylePath
{{CURRENTVERSION}}
mw.site.currentVersion
{{CONTENTLANGUAGE}}
mw.getContentLanguage():getCode()
{{PAGEID}}
mw.title.getCurrentTitle().id
{{PAGESIZE:pagename}}
{{PAGESIZE:pagename|R}}
mw.getContentLanguage():formatNum(mw.title.new(pagename):getContent():len())
mw.title.new(pagename):getContent():len()
{{PROTECTIONLEVEL:edit}}
[Expensive]
{{PROTECTIONLEVEL:action|pagename}}
table.concat(mw.title.getCurrentTitle().protectionLevels["edit"])
[Expensive]
table.concat(mw.title.new(pagename).protectionLevels[action])
[Expensive]
{{CASCADINGSOURCES}}
{{CASCADINGSOURCES:pagename}}
[Expensive]
table.concat(mw.title.getCurrentTitle().cascadingProtection.sources, "|")
table.concat(mw.title.new(pagename).cascadingProtection.sources, "|")
{{REVISIONID}}
{{REVISIONDAY}}
{{REVISIONDAY2}}
{{REVISIONMONTH}}
{{REVISIONMONTH1}}
{{REVISIONYEAR}}
{{REVISIONTIMESTAMP}}
{{REVISIONUSER}}
{{DISPLAYTITLE:title}}
{{DEFAULTSORT:sortkey}}

Statistics

Wikicode Lua
{{NUMBEROFPAGES}}
mw.site.stats.pages
{{NUMBEROFARTICLES}}
mw.site.stats.articles
{{NUMBEROFFILES}}
mw.site.stats.files
{{NUMBEROFEDITS}}
mw.site.stats.edits
{{NUMBEROFVIEWS}}
mw.site.stats.views
{{NUMBEROFUSERS}}
mw.site.stats.users
{{NUMBEROFADMINS}}
mw.site.stats.admins
{{NUMBEROFACTIVEUSERS}}
mw.site.stats.activeUsers
[Expensive]
{{PAGESINCATEGORY:categoryname}}
[Expensive]
mw.site.stats.pagesInCategory('categoryname')
{{NUMBERINGROUP:groupname}}
mw.site.stats.usersInGroup('groupname')

Page names

Wikicode Lua
{{FULLPAGENAME}}
{{FULLPAGENAMEE}}
mw.title.getCurrentTitle().prefixedText
mw.uri.encode(mw.title.getCurrentTitle().prefixedText, "WIKI")
{{PAGENAME}}
{{PAGENAMEE}}
mw.title.getCurrentTitle().text
mw.uri.encode(mw.title.getCurrentTitle().text, "WIKI")
{{BASEPAGENAME}}
{{BASEPAGENAMEE}}
mw.title.getCurrentTitle().baseText
mw.uri.encode(mw.title.getCurrentTitle().baseText, "WIKI")
{{ROOTPAGENAME}}
{{ROOTPAGENAMEE}}
mw.title.getCurrentTitle().rootText
mw.uri.encode(mw.title.getCurrentTitle().rootText, "WIKI")
{{SUBPAGENAME}}
{{SUBPAGENAMEE}}
mw.title.getCurrentTitle().subpageText
mw.uri.encode(mw.title.getCurrentTitle().subpageText, "WIKI")
{{SUBJECTPAGENAME}}
{{ARTICLEPAGENAME}}

{{SUBJECTPAGENAMEE}}
{{ARTICLEPAGENAMEE}}
[Expensive]
mw.title.getCurrentTitle().subjectPageTitle

or a non-expensive alternative:

mw.title.getCurrentTitle().subjectNsText .. ':' .. mw.title.getCurrentTitle().text
[Expensive]
mw.uri.encode(mw.title.getCurrentTitle().subjectPageTitle, "WIKI")

or a non-expensive alternative:

mw.uri.encode(mw.title.getCurrentTitle().subjectNsText .. ':' .. mw.title.getCurrentTitle().text, "WIKI")
{{TALKPAGENAME}}
{{TALKPAGENAMEE}}
[Expensive]
mw.title.getCurrentTitle().talkPageTitle
mw.uri.encode(mw.title.getCurrentTitle().talkPageTitle, "WIKI")

Namespaces

Wikicode Lua
{{NAMESPACE}}
{{NAMESPACEE}}
mw.title.getCurrentTitle().nsText
mw.uri.encode(mw.title.getCurrentTitle().nsText, "WIKI")
{{NAMESPACENUMBER}}
mw.title.getCurrentTitle().namespace
{{SUBJECTSPACE}}
{{ARTICLESPACE}}
{{SUBJECTSPACEE}}
{{ARTICLESPACEE}}
mw.title.getCurrentTitle().subjectNsText

mw.uri.encode(mw.title.getCurrentTitle().subjectNsText, "WIKI")
{{TALKSPACE}}
{{TALKSPACEE}}
mw.site.namespaces[title.namespace].talk.canonicalName
mw.uri.encode(mw.site.namespaces[title.namespace].talk.canonicalName, "WIKI")

URL data

Wikicode Lua
{{localurl:page|query}}
mw.uri.localUrl('page', 'query')
{{fullurl:page|query}}
mw.uri.fullUrl('page', 'query')
{{canonicalurl:page|query}}
mw.uri.canonicalUrl('page', 'query')
{{filepath:file name}}
{{urlencode:string|QUERY}}
mw.uri.encode('string', QUERY)
{{anchorencode:string}}
mw.uri.anchorEncode('string')

Namespaces

Wikicode Lua
{{ns:0}}
mw.site.namespaces[0].name
{{ns:Project}}
mw.site.namespaces.Project.name

Formatting

Wikicode Lua
{{formatnum:number}}
mw.getContentLanguage():formatNum(number)
{{#formatdate:date}}
{{#dateformat:date|format}}
{{lc:string}}
mw.ustring.lower('string')
{{lcfirst:string}}
mw.getContentLanguage():lcfirst('string')
{{uc:string}}
mw.ustring.upper('string')
{{ucfirst:string}}
mw.getContentLanguage():ucfirst('string')
{{padleft:xyz|stringlength}}
{{padright:xyz|stringlength}}

Localisation

Wikicode Lua
{{plural:2|is|are}}
mw.getContentLanguage():plural(2, 'is', 'are')
{{grammar:N|noun}}
mw.getContentLanguage():grammar('N', 'noun')
{{gender:username|male|female|neutral}}
mw.getContentLanguage():gender('username', { 'male', 'female', 'neutral' })
{{int:message}}
{{int:editsectionhint|MediaWiki}}
mw.message.new('message'):plain()
mw.message.new('editsectionhint', 'MediaWiki'):plain()

Miscellaneous

Wikicode Lua
 {{#language:code|inlanguage}}
mw.language.fetchLanguageName('code', 'inLanguage')
{{#special:special page name}}
{{#speciale:special page name}}
{{#tag:tagname |some text |attribute1=value1 |attribute2=value2}}
mw.getCurrentFrame():callParserFunction('#tag', { 'tagname', 'some text', attribute1 = 'value1', attribute2 = 'value2' })
mw.getCurrentFrame():extensionTag('tagname', 'some text', { attribute1 = 'value1', attribute2 = 'value2' })