Wikipedia:Comparable Lua functions to wikitext
Appearance
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.
Magic words
Date and time
Wikicode | Lua |
---|---|
{{CURRENTYEAR}} | mw.getContentLanguage():formatDate( 'Y' )
os.date( "%Y" )
|
{{CURRENTMONTH}} | mw.getContentLanguage():formatDate( 'm' )
os.date( "%m" )
|
{{CURRENTMONTH1}} | mw.getContentLanguage():formatDate( 'n' )
|
{{CURRENTMONTHNAME}} | mw.getContentLanguage():formatDate( 'F' )
|
{{CURRENTMONTHNAMEGEN}} | mw.getContentLanguage():formatDate( 'xg' )
|
{{CURRENTMONTHABBREV}} | mw.getContentLanguage():formatDate( 'M' )
|
{{CURRENTDAY}} | mw.getContentLanguage():formatDate( 'j' )
|
{{CURRENTDAY2}} | mw.getContentLanguage():formatDate( 'd' )
os.date( "%d" )
|
{{CURRENTDOW}} | mw.getContentLanguage():formatDate( 'w' )
os.date( "%w" )
|
{{CURRENTDAYNAME}} | mw.getContentLanguage():formatDate( 'l' )
|
{{CURRENTTIME}} | mw.getContentLanguage():formatDate( 'H:i' )
os.date( "%R" )
|
{{CURRENTHOUR}} | mw.getContentLanguage():formatDate( 'H' )
os.date( "%H" )
|
{{CURRENTWEEK}} | mw.getContentLanguage():formatDate( 'W' )
|
{{CURRENTTIMESTAMP}} | mw.getContentLanguage():formatDate( 'YmdHis' )
|
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:page name}} | |
{{PROTECTIONLEVEL:edit}} | [Expensive]local protection = mw.title.getCurrentTitle().protectionLevels["edit"]
table.concat(protection)
|
{{REVISIONID}} | |
{{REVISIONDAY}} | |
{{REVISIONDAY}} | |
{{REVISIONMONTH}} | |
{{REVISIONMONTH1}} | |
{{REVISIONYEAR}} | |
{{REVISIONTIMESTAMP}} | |
{{REVISIONUSER}} | |
{{DISPLAYTITLE:title}} | |
{{DEFAULTSORT:sortkey}} |
Page names
Wikicode | Lua |
---|---|
{{FULLPAGENAME}} | mw.title.getCurrentTitle().prefixedText
|
{{PAGENAME}} | mw.title.getCurrentTitle().text
|
{{BASEPAGENAME}} | mw.title.getCurrentTitle().baseText
|
{{SUBPAGENAME}} | mw.title.getCurrentTitle().subpageText
|
{{SUBJECTPAGENAME}} | [Expensive]mw.title.getCurrentTitle().subjectPageTitle
or an non expensive alternative: mw.title.getCurrentTitle().subjectNsText .. ":" .. mw.title.getCurrentTitle().text
|
{{TALKPAGENAME}} | [Expensive]mw.title.getCurrentTitle().talkPageTitle
|
Namespaces
Wikicode | Lua |
---|---|
{{NAMESPACE}} | mw.title.getCurrentTitle().nsText
|
{{NAMESPACENUMBER}} | mw.title.getCurrentTitle().namespace
|
{{SUBJECTSPACE}} | mw.title.getCurrentTitle().subjectNsText
|
{{TALKSPACE}} |
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 )
|
#dateformat | |
{{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}} | mw.message.new( 'message' ):plain()
|
{{int:editsectionhint|MediaWiki}} | 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 }} | frame:extensionTag( 'tagname', 'some text', {
attribute1 = 'value1', attribute2 = 'value2'
} )
|