Wikipedia:Porównanie funkcji Lua z wikitekstem

Poniższa lista zawiera porównianie funkcji Lua z odpowiadającymi im wikitekstowymi funkcjami parsera i magicznymi słowami.

Funkcje parsera edytuj

Wikitekst Lua
{{#if: x | not empty | empty}}
if x then
    'not empty'
else
    'empty'
end
{{#ifeq: x | y | identical | different}}
if 1 == 3 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
[kosztowna]
{{#ifexist: namespace:title | exists | doesn't exist }}
[kosztowna]
if mw.title.new( 'title', 'namespace' ).exists == true then
    "exists"
else
    "doesn't exist"
end
rel2abs
{{#switch: {{{1}}} | foo = Foo | Bar }}
local cases = {
    default = "Bar",
    foo = "Foo",
}

local pframe = frame: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

Matematyczne edytuj

W przeciwieństwie do wikikodu, Lua nie wykorzystuje funkcji typu {{#ifexpr}}, czy {{#expr}}. Dodaj operatory i funkcje Lua bezprośrednio do twojego modułu.

Grupowanie
Wikikod Lua
() ()
Liczby
Wikikod Lua
1234.5 1234.5
2e3 2e3
pi math.pi
e
2+2 2+2
2-1 2-1
Jedynkowe
Wikikod Lua
not not
ceil1.2 math.ceil(1.2)
trunc
floor1.2 math.floor(1.2)
abs-2 math.abs(-2)
exp43 math.exp(43)
ln2 math.log(2)
cos0.1 math.cos(0.1)
tan0.1 math.tan(0.1)
acos0.1 math.acos(0.1)
asin0.1 math.asin(0.1)
atan0.1 math.atan(0.1)
Binarne
Wikikod Lua
2^3 2^3
2*3 2*3
2/3
2div3
2/3
30mod7 30%7
+2 2
-2 -2
Logiczne
Wikikod Typ danych Lua Typ danych
3.0=3 Integer (0 or 1) 3.0==3 Boolean (true or false)
3!=4
3<>4
Integer 3~=4 Boolean
4>3 Integer 4>3 Boolean
4>=3 Integer 4>=3 Boolean
3<=4 Integer 3<=4 Boolean
3<=4 Integer 3<=4 Boolean
and Integer and Boolean
or Integer or Boolean


Magiczne słowa edytuj

Data i czas edytuj

Wikikod Lua
{{CURRENTYEAR}}
os.date( "%Y" )
{{CURRENTMONTH}}
os.date( "%m" )
{{CURRENTMONTHNAME}}
mw.getContentLanguage():formatDate( 'F' )
{{CURRENTMONTHNAMEGEN}}
mw.getContentLanguage():formatDate( 'xg' )
{{CURRENTMONTHABBREV}}
mw.getContentLanguage():formatDate( 'M' )
{{CURRENTDAY}}
os.date( "%e" )
{{CURRENTDAY2}}
os.date( "%d" )
{{CURRENTDOW}}
os.date( "%w" )
{{CURRENTDAYNAME}}
mw.getContentLanguage():formatDate( 'l' )
{{CURRENTTIME}}
os.date( "%R" )
{{CURRENTHOUR}}
os.date( "%H" )
{{CURRENTWEEK}}
mw.getContentLanguage():formatDate( 'W' )
{{CURRENTTIMESTAMP}}

Techniczne metadane edytuj

Wikikod 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}} [kosztowna]
local protection = mw.title.getCurrentTitle().protectionLevels["edit"]
table.concat(protection)
{{REVISIONID}}
{{REVISIONDAY}}
{{REVISIONDAY}}
{{REVISIONMONTH}}
{{REVISIONMONTH1}}
{{REVISIONYEAR}}
{{REVISIONTIMESTAMP}}
{{REVISIONUSER}}
{{DISPLAYTITLE:title}}
{{DEFAULTSORT:sortkey}}

Statystyczne edytuj

Wikikod 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
[kosztowna]
{{PAGESINCATEGORY:categoryname}}
[kosztowna]
mw.site.stats.pagesInCategory( 'categoryname' )
{{NUMBERINGROUP:groupname}}
mw.site.stats.usersInGroup( 'groupname' )

Nazwy stron edytuj

Wikikod Lua
{{FULLPAGENAME}}
mw.title.getCurrentTitle().prefixedText
{{PAGENAME}}
mw.title.getCurrentTitle().text
{{BASEPAGENAME}}
mw.title.getCurrentTitle().baseText
{{SUBPAGENAME}}
mw.title.getCurrentTitle().subpageText
{{SUBJECTPAGENAME}} [kosztowna]
mw.title.getCurrentTitle().subjectPageTitle

lub niekosztowna alternatywa:

mw.title.getCurrentTitle().subjectNsText .. ":" .. mw.title.getCurrentTitle().text
{{TALKPAGENAME}} [kosztowna]
mw.title.getCurrentTitle().talkPageTitle

Przestrzenie nazw edytuj

Wikikod Lua
{{NAMESPACE}}
mw.title.getCurrentTitle().nsText
{{NAMESPACENUMBER}}
mw.title.getCurrentTitle().namespace
{{SUBJECTSPACE}}
mw.title.getCurrentTitle().subjectNsText
{{TALKSPACE}}
{{ns:0}}
mw.site.namespaces[0].name
{{ns:Project}}
mw.site.namespaces.Project.name

Dane URL edytuj

Wikikod 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' )

Formatowanie edytuj

Wikikod 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}}

Lokalizacyjne edytuj

Wikikod 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' ):text()
{{int:editsectionhint|MediaWiki}}
mw.message.new( 'editsectionhint', 'MediaWiki' ):text()

Różne edytuj

Wikikod 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'
} )