사용자:하늘/루아: 두 판 사이의 차이

잔글 (Chirho님이 사용자:Cerulean/루아 문서를 넘겨주기를 만들지 않고 사용자:하늘/루아 문서로 이동했습니다: "Cerulean" 사용자의 이름을 "하늘"(으)로 바꿀 때 문서를 자동으로 이동했습니다)
 
(다른 사용자 한 명의 중간 판 7개는 보이지 않습니다)
131번째 줄: 131번째 줄:
| 2*3 || 2*3
| 2*3 || 2*3
|-
|-
| 2/3 <br> 2div3 || 2/3
| 2/3 <br/> 2div3 || 2/3
|-
|-
| 30mod7 || 30%7
| 30mod7 || 30%7
147번째 줄: 147번째 줄:
| 3.0=3 || Integer (0 or 1) || 3.0==3 || Boolean (true or false)  
| 3.0=3 || Integer (0 or 1) || 3.0==3 || Boolean (true or false)  
|-
|-
| 3!=4 <br> 3<>4 || Integer || 3~=4 ||  Boolean
| 3!=4 <br/> 3<>4 || Integer || 3~=4 ||  Boolean
|-
|-
| 4>3 || Integer || 4>3 || Boolean   
| 4>3 || Integer || 4>3 || Boolean   
397번째 줄: 397번째 줄:


=== HTML library ===
=== HTML library ===
<!--T:1832-->


<!--T:1833-->
 
 
<code>mw.html</code> is a fluent interface for building complex HTML from Lua. A mw.html object can be created using [[<tvar|anchor>#mw.html.create</>|<code>mw.html.create</code>]].
<code>mw.html</code> is a fluent interface for building complex HTML from Lua. A mw.html object can be created using [[<tvar|anchor>#mw.html.create</>|<code>mw.html.create</code>]].
</translate>
 


{{anchor|mw.html-object}}
{{anchor|mw.html-object}}
<translate>
 
<!--T:1834-->
 
Functions documented as <code>mw.html.<var>name</var></code> are available on the global <code>mw.html</code> table; functions documented as <code>mw.html:<var>name</var></code> and <code>html:<var>name</var></code> are methods of an mw.html object (see [[<tvar|anchor>#mw.html.create</>|<code>mw.html.create</code>]]).
Functions documented as <code>mw.html.<var>name</var></code> are available on the global <code>mw.html</code> table; functions documented as <code>mw.html:<var>name</var></code> and <code>html:<var>name</var></code> are methods of an mw.html object (see [[<tvar|anchor>#mw.html.create</>|<code>mw.html.create</code>]]).


<!--T:1835-->
 
A basic example could look like this:
A basic example could look like this:
</translate>
 


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
425번째 줄: 425번째 줄:
==== mw.html.create ====
==== mw.html.create ====
태그 생성
태그 생성
<code style="white-space:nowrap"><translate><!--T:1836--> mw.html.create( tagName, args )</translate></code>
<code style="white-space:nowrap"> mw.html.create( tagName, args )</code>
 
 


<translate>
<!--T:1837-->
Creates a new mw.html object containing a <code>tagName</code> html element. You can also pass an empty string or nil as <code>tagName</code> in order to create an empty mw.html object.
Creates a new mw.html object containing a <code>tagName</code> html element. You can also pass an empty string or nil as <code>tagName</code> in order to create an empty mw.html object.


<!--T:1838-->
 
<code>args</code> can be a table with the following keys:
<code>args</code> can be a table with the following keys:


<!--T:1839-->
 
* <code>args.selfClosing</code>: Force the current tag to be self-closing, even if mw.html doesn't recognize it as self-closing
* <code>args.selfClosing</code>: Force the current tag to be self-closing, even if mw.html doesn't recognize it as self-closing
* <code>args.parent</code>: Parent of the current mw.html instance (intended for internal usage)
* <code>args.parent</code>: Parent of the current mw.html instance (intended for internal usage)
</translate>
 


==== mw.html:node ====
==== mw.html:node ====
<code style="white-space:nowrap"><translate><!--T:1840--> [[#mw.html-object|html]]:node( builder )</translate></code>
<code style="white-space:nowrap"> [[#mw.html-object|html]]:node( builder )</code>
 
 


<translate>
<!--T:1841-->
Appends a child mw.html (<code>builder</code>) node to the current mw.html instance. If a nil parameter is passed, this is a no-op. A (<code>builder</code>) node is a string representation of an html element.
Appends a child mw.html (<code>builder</code>) node to the current mw.html instance. If a nil parameter is passed, this is a no-op. A (<code>builder</code>) node is a string representation of an html element.
</translate>
 


==== mw.html:wikitext ====
==== mw.html:wikitext ====
451번째 줄: 451번째 줄:
<code style="white-space:nowrap">[[#mw.html-object|html]]:wikitext( ... )</code>
<code style="white-space:nowrap">[[#mw.html-object|html]]:wikitext( ... )</code>


<translate>
 
<!--T:1842-->
 
Appends an undetermined number of wikitext strings to the mw.html object.
Appends an undetermined number of wikitext strings to the mw.html object.


<!--T:1843-->
 
Note that this stops at the first ''nil'' item.
Note that this stops at the first ''nil'' item.
</translate>
 


==== mw.html:newline ====
==== mw.html:newline ====
463번째 줄: 463번째 줄:
<code style="white-space:nowrap">[[#mw.html-object|html]]:newline()</code>
<code style="white-space:nowrap">[[#mw.html-object|html]]:newline()</code>


<translate>
 
<!--T:1844-->
 
Appends a newline to the mw.html object.
Appends a newline to the mw.html object.
</translate>
 


==== mw.html:tag ====
==== mw.html:tag ====
자식노드 삽입
자식태그 삽입
<code style="white-space:nowrap"><translate><!--T:1845--> [[#mw.html-object|html]]:tag( tagName, args )</translate></code>
<code style="white-space:nowrap"> [[#mw.html-object|html]]:tag( tagName, args )</code>
 


<translate>
<!--T:1846-->
Appends a new child node with the given <code>tagName</code> to the builder, and returns a mw.html instance representing that new node. The <code>args</code> parameter is identical to that of [[<tvar|anchor>#mw.html.create</>|<code>mw.html.create</code>]]
Appends a new child node with the given <code>tagName</code> to the builder, and returns a mw.html instance representing that new node. The <code>args</code> parameter is identical to that of [[<tvar|anchor>#mw.html.create</>|<code>mw.html.create</code>]]
</translate>


==== mw.html:attr ====
==== mw.html:attr ====
<code style="white-space:nowrap"><translate><!--T:1847--> [[#mw.html-object|html]]:attr( name, value )</translate></code>
속성 추가
<code style="white-space:nowrap"> [[#mw.html-object|html]]:attr( name, value )</code>
<br/>
<br/>
<code style="white-space:nowrap"><translate><!--T:1848--> [[#mw.html-object|html]]:attr( table )</translate></code>
<code style="white-space:nowrap"> [[#mw.html-object|html]]:attr( table )</code>
 


<translate>
<!--T:1849-->
Set an HTML attribute with the given <code>name</code> and <code>value</code> on the node. Alternatively a table holding name->value pairs of attributes to set can be passed. In the first form, a value of nil causes any attribute with the given name to be unset if it was previously set.
Set an HTML attribute with the given <code>name</code> and <code>value</code> on the node. Alternatively a table holding name->value pairs of attributes to set can be passed. In the first form, a value of nil causes any attribute with the given name to be unset if it was previously set.
</translate>


==== mw.html:getAttr ====
==== mw.html:getAttr ====
<code style="white-space:nowrap"><translate><!--T:1850--> [[#mw.html-object|html]]:getAttr( name )</translate></code>
속성 get
<code style="white-space:nowrap"> [[#mw.html-object|html]]:getAttr( name )</code>
 


<translate>
<!--T:1851-->
Get the value of a html attribute previously set using [[<tvar|anchor>#mw.html:attr</>|<code>html:attr()</code>]] with the given <code>name</code>.
Get the value of a html attribute previously set using [[<tvar|anchor>#mw.html:attr</>|<code>html:attr()</code>]] with the given <code>name</code>.
</translate>


==== mw.html:addClass ====
==== mw.html:addClass ====
<code style="white-space:nowrap"><translate><!--T:1852--> [[#mw.html-object|html]]:addClass( class )</translate></code>
<code style="white-space:nowrap"> [[#mw.html-object|html]]:addClass( class )</code>
 
 


<translate>
<!--T:1853-->
Adds a class name to the node's class attribute. If a nil parameter is passed, this is a no-op.
Adds a class name to the node's class attribute. If a nil parameter is passed, this is a no-op.
</translate>
 


==== mw.html:css ====
==== mw.html:css ====
<code style="white-space:nowrap"><translate><!--T:1854--> [[#mw.html-object|html]]:css( name, value )</translate></code>
<code style="white-space:nowrap"> [[#mw.html-object|html]]:css( name, value )</code>
<br/>
<br/>
<code style="white-space:nowrap"><translate><!--T:1855--> [[#mw.html-object|html]]:css( table )</translate></code>
<code style="white-space:nowrap"> [[#mw.html-object|html]]:css( table )</code>
 
 


<translate>
<!--T:1856-->
Set a CSS property with the given <code>name</code> and <code>value</code> on the node. Alternatively a table holding name->value pairs of properties to set can be passed. In the first form, a value of nil causes any property with the given name to be unset if it was previously set.
Set a CSS property with the given <code>name</code> and <code>value</code> on the node. Alternatively a table holding name->value pairs of properties to set can be passed. In the first form, a value of nil causes any property with the given name to be unset if it was previously set.
</translate>
 


==== mw.html:cssText ====
==== mw.html:cssText ====
<code style="white-space:nowrap"><translate><!--T:1857--> [[#mw.html-object|html]]:cssText( css )</translate></code>
<code style="white-space:nowrap"> [[#mw.html-object|html]]:cssText( css )</code>
 
 


<translate>
<!--T:1858-->
Add some raw <code>css</code> to the node's style attribute. If a nil parameter is passed, this is a no-op.
Add some raw <code>css</code> to the node's style attribute. If a nil parameter is passed, this is a no-op.
</translate>
 


==== mw.html:done ====
==== mw.html:done ====
<code  style="white-space:nowrap">[[#mw.html-object|html]]:done()</code>
<code  style="white-space:nowrap">[[#mw.html-object|html]]:done()</code>


<translate>
 
<!--T:1859-->
 
Returns the parent node under which the current node was created. Like jQuery.end, this is a convenience function to allow the construction of several child nodes to be chained together into a single statement.
Returns the parent node under which the current node was created. Like jQuery.end, this is a convenience function to allow the construction of several child nodes to be chained together into a single statement.
</translate>
 


==== mw.html:allDone ====
==== mw.html:allDone ====
533번째 줄: 529번째 줄:




<!--T:1860-->
 
Like [[<tvar|anchor>#mw.html:done</>|<code>html:done()</code>]], but traverses all the way to the root node of the tree and returns it.
Like [[<tvar|anchor>#mw.html:done</>|<code>html:done()</code>]], but traverses all the way to the root node of the tree and returns it.


=== Title library === <!--T:2089-->
== Title library ==
== mw.title.equals ==
두 제목 일치 여부
<code style="white-space:nowrap"> mw.title.equals( a, b )</code>




==== mw.title.equals ====
<code style="white-space:nowrap"><!--T:2090--> mw.title.equals( a, b )</code>
<!--T:2091-->
Test for whether two titles are equal. Note that fragments are ignored in the comparison.
Test for whether two titles are equal. Note that fragments are ignored in the comparison.


== mw.title.compare ==
<code style="white-space:nowrap"> mw.title.compare( a, b )</code>


==== mw.title.compare ====
<code style="white-space:nowrap"><!--T:2092--> mw.title.compare( a, b )</code>


Returns -1, 0, or 1 to indicate whether the title <code>a</code> is less than, equal to, or greater than title <code>b</code>.


<!--T:2093-->
Returns -1, 0, or 1 to indicate whether the title <code>a</code> is less than, equal to, or greater than title <code>b</code>.


<!--T:2094-->
This compares titles by interwiki prefix (if any) as strings, then by namespace number, then by the unprefixed title text as a string. These string comparisons use Lua's standard <code>&lt;</code> operator.
This compares titles by interwiki prefix (if any) as strings, then by namespace number, then by the unprefixed title text as a string. These string comparisons use Lua's standard <code>&lt;</code> operator.


 
== mw.title.getCurrentTitle ==
==== mw.title.getCurrentTitle ====
현재 문서 제목 객체 얻기
<code style="white-space:nowrap">mw.title.getCurrentTitle()</code>
<code style="white-space:nowrap">mw.title.getCurrentTitle()</code>




<!--T:2095-->
Returns the title object for the current page.
Returns the title object for the current page.


 
== mw.title.new ==
==== mw.title.new ====
새 제목 객체 만들기
<code style="white-space:nowrap"><!--T:2096--> mw.title.new( text, namespace )</code>
<code style="white-space:nowrap"> mw.title.new( text, namespace )</code>
<br/>
<br/>
<code style="white-space:nowrap"><!--T:2097--> mw.title.new( id )</code>
<code style="white-space:nowrap"> mw.title.new( id )</code>




<!--T:2098-->
: {{red|This function is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]] when called with an ID}}
: {{red|This function is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]] when called with an ID}}


Creates a new title object.
Returns type "nil" if the pagename (in parameter "text") is invalid, but succeeds if it is valid but only does not exist.


<!--T:2099--> Creates a new title object.
<!--T:2523--> Returns type "nil" if the pagename (in parameter "text") is invalid, but succeeds if it is valid but only does not exist.


If a number <code>id</code> is given, an object is created for the title with that page_id. The title referenced will be counted as linked from the current page. If the page_id does not exist, returns nil. The expensive function count will be incremented if the title object created is not for a title that has already been loaded.


<!--T:2100-->
If a number <code>id</code> is given, an object is created for the title with that page_id. The title referenced will be counted as linked from the current page. If the page_id does not exist, returns nil. The expensive function count will be incremented if the title object created is not for a title that has already been loaded.


<!--T:2101-->
If a string <code>text</code> is given instead, an object is created for that title (even if the page does not exist). If the text string does not specify a namespace, <code>namespace</code> (which may be any key found in <code>[[<tvar name=anchor>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>) will be used. If the text is not a valid title, nil is returned.
If a string <code>text</code> is given instead, an object is created for that title (even if the page does not exist). If the text string does not specify a namespace, <code>namespace</code> (which may be any key found in <code>[[<tvar name=anchor>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>) will be used. If the text is not a valid title, nil is returned.


== mw.title.makeTitle ==
<code style="white-space:nowrap"> mw.title.makeTitle( namespace, title, fragment, interwiki )</code>


==== mw.title.makeTitle ====
<code style="white-space:nowrap"><!--T:2102--> mw.title.makeTitle( namespace, title, fragment, interwiki )</code>


Creates a title object with title <code>title</code> in namespace <code>namespace</code>, optionally with the specified <code>fragment</code> and <code>interwiki</code> prefix. <code>namespace</code> may be any key found in <code>[[<tvar name=anchor>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>. If the resulting title is not valid, returns nil.


<!--T:2103-->
Creates a title object with title <code>title</code> in namespace <code>namespace</code>, optionally with the specified <code>fragment</code> and <code>interwiki</code> prefix. <code>namespace</code> may be any key found in <code>[[<tvar name=anchor>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>. If the resulting title is not valid, returns nil.


<!--T:2104-->
Note that, unlike <tvar name=mw_title_new_function><code>[[#mw.title.new|mw.title.new()]]</code></tvar>, this method will always apply the specified namespace. For example, <code style="white-space:nowrap">mw.title.makeTitle( 'Template', 'Module:Foo' )</code> will create an object for the page Template:Module:Foo, while <code style="white-space:nowrap">mw.title.new( 'Module:Foo', 'Template' )</code> will create an object for the page Module:Foo.
Note that, unlike <tvar name=mw_title_new_function><code>[[#mw.title.new|mw.title.new()]]</code></tvar>, this method will always apply the specified namespace. For example, <code style="white-space:nowrap">mw.title.makeTitle( 'Template', 'Module:Foo' )</code> will create an object for the page Template:Module:Foo, while <code style="white-space:nowrap">mw.title.new( 'Module:Foo', 'Template' )</code> will create an object for the page Module:Foo.


==== Title objects ==== <!--T:2105-->
== Title objects ==  


<!--T:2106-->
A title object has a number of properties and methods. Most of the properties are read-only.
A title object has a number of properties and methods. Most of the properties are read-only.


<!--T:2107-->
 
Note that fields ending with <code>text</code> return titles as string values whereas the fields ending with <code>title</code> return title objects.
Note that fields ending with <code>text</code> return titles as string values whereas the fields ending with <code>title</code> return title objects.


<!--T:2108-->
* '''id''': The page_id. 0 if the page does not exist. {{red|1=<!--T:2524--> This [[<tvar name=anchor>#Expensive properties</tvar>|may be expensive]]}}.


<!--T:2525-->
* '''id''': The page_id. 0 if the page does not exist. {{red|1= This [[<tvar name=anchor>#Expensive properties</tvar>|may be expensive]]}}.
 
 
* '''interwiki''': The interwiki prefix, or the empty string if none.
* '''interwiki''': The interwiki prefix, or the empty string if none.


<!--T:2526-->
 
* '''namespace''': The namespace number.
* '''namespace''': The namespace number.


<!--T:2527-->
 
* '''fragment''': The fragment (aka section/anchor linking), or the empty string. May be assigned.
* '''fragment''': The fragment (aka section/anchor linking), or the empty string. May be assigned.


<!--T:2528-->
 
* '''nsText''': The text of the namespace for the page.
* '''nsText''': The text of the namespace for the page.


<!--T:2529-->
 
* '''subjectNsText''': The text of the subject namespace for the page.
* '''subjectNsText''': The text of the subject namespace for the page.


<!--T:2530-->
 
* '''text''': The title of the page, without the namespace or interwiki prefixes.
* '''text''': The title of the page, without the namespace or interwiki prefixes.


<!--T:2531-->
 
* '''prefixedText''': The title of the page, with the namespace and interwiki prefixes.
* '''prefixedText''': The title of the page, with the namespace and interwiki prefixes.


<!--T:2532-->
 
* '''fullText''': The title of the page, with the namespace and interwiki prefixes and the fragment. Interwiki is not returned if equal to the current.
* '''fullText''': The title of the page, with the namespace and interwiki prefixes and the fragment. Interwiki is not returned if equal to the current.


<!--T:2533-->
 
* '''rootText''': If this is a subpage, the title of the root page without prefixes. Otherwise, the same as <code>title.text</code>.
* '''rootText''': If this is a subpage, the title of the root page without prefixes. Otherwise, the same as <code>title.text</code>.


<!--T:2534-->
 
* '''baseText''': If this is a subpage, the title of the page it is a subpage of without prefixes. Otherwise, the same as <code>title.text</code>.
* '''baseText''': If this is a subpage, the title of the page it is a subpage of without prefixes. Otherwise, the same as <code>title.text</code>.


<!--T:2535-->
 
* '''subpageText''': If this is a subpage, just the subpage name. Otherwise, the same as <code>title.text</code>.
* '''subpageText''': If this is a subpage, just the subpage name. Otherwise, the same as <code>title.text</code>.


<!--T:2536-->
 
* '''canTalk''': Whether the page for this title could have a talk page.
* '''canTalk''': Whether the page for this title could have a talk page.


<!--T:2537-->
 
* '''exists''': Whether the page exists. Alias for '''file.exists''' for Media-namespace titles. For File-namespace titles this checks the existence of the file description page, not the file itself. {{red|This [[<tvar name=anchor1>#Expensive properties</tvar>|may be expensive]]}}. It is always expensive if the title object was created by "mw.title.new" or "mw.title.makeTitle", and the call will throw an exception rather than returning "false" if the limit (500 on most wikis) is reached.
* '''exists''': Whether the page exists. Alias for '''file.exists''' for Media-namespace titles. For File-namespace titles this checks the existence of the file description page, not the file itself. {{red|This [[<tvar name=anchor1>#Expensive properties</tvar>|may be expensive]]}}. It is always expensive if the title object was created by "mw.title.new" or "mw.title.makeTitle", and the call will throw an exception rather than returning "false" if the limit (500 on most wikis) is reached.


<!--T:2539-->
 
* '''file''', '''fileExists''': See [[#File metadata]] below.
* '''file''', '''fileExists''': See [[#File metadata]] below.


<!--T:2540-->
 
* '''isContentPage''': Whether this title is in a content namespace.
* '''isContentPage''': Whether this title is in a content namespace.


<!--T:2541-->
 
* '''isExternal''': Whether this title has an interwiki prefix.
* '''isExternal''': Whether this title has an interwiki prefix.


<!--T:2542-->
 
* '''isLocal''': Whether this title is in this project. For example, on the English Wikipedia, any other Wikipedia is considered "local" while Wiktionary and such are not.
* '''isLocal''': Whether this title is in this project. For example, on the English Wikipedia, any other Wikipedia is considered "local" while Wiktionary and such are not.


<!--T:2543-->
 
* '''isRedirect''': Whether this is the title for a page that is a redirect. {{red|This [[<tvar name=anchor2>#Expensive properties</tvar>|may be expensive]]}}.
* '''isRedirect''': Whether this is the title for a page that is a redirect. {{red|This [[<tvar name=anchor2>#Expensive properties</tvar>|may be expensive]]}}.


<!--T:2544-->
 
* '''isSpecialPage''': Whether this is the title for a possible special page (i.e. a page in the Special: namespace).
* '''isSpecialPage''': Whether this is the title for a possible special page (i.e. a page in the Special: namespace).


<!--T:2545-->
 
* '''isSubpage''': Whether this title is a subpage of some other title.
* '''isSubpage''': Whether this title is a subpage of some other title.


<!--T:2546-->
* '''isTalkPage''': Whether this is a title for a talk page.
* '''isTalkPage''': Whether this is a title for a talk page.


<!--T:2547-->
* '''isSubpageOf( title2 )''': Whether this title is a subpage of the given title.
* '''isSubpageOf( title2 )''': Whether this title is a subpage of the given title.


<!--T:2548-->
 
* '''inNamespace( ns )''': Whether this title is in the given namespace. Namespaces may be specified by anything that is a key found in <code>[[<tvar name=anchor3>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>.
* '''inNamespace( ns )''': Whether this title is in the given namespace. Namespaces may be specified by anything that is a key found in <code>[[<tvar name=anchor3>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>.


<!--T:2549-->
 
* '''inNamespaces( ... )''': Whether this title is in any of the given namespaces. Namespaces may be specified by anything that is a key found in <code>[[<tvar name=anchor4>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>.
* '''inNamespaces( ... )''': Whether this title is in any of the given namespaces. Namespaces may be specified by anything that is a key found in <code>[[<tvar name=anchor4>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>.


<!--T:2550-->
 
* '''hasSubjectNamespace( ns )''': Whether this title's subject namespace is in the given namespace. Namespaces may be specified by anything that is a key found in <code>[[<tvar name=anchor5>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>.
* '''hasSubjectNamespace( ns )''': Whether this title's subject namespace is in the given namespace. Namespaces may be specified by anything that is a key found in <code>[[<tvar name=anchor5>#mw.site.namespaces</tvar>|mw.site.namespaces]]</code>.


<!--T:2551-->
 
* '''contentModel''': The content model for this title, as a string. {{red|This [[<tvar name=anchor6>#Expensive properties</tvar>|may be expensive]]}}.
* '''contentModel''': The content model for this title, as a string. {{red|This [[<tvar name=anchor6>#Expensive properties</tvar>|may be expensive]]}}.


<!--T:2552-->
 
* '''basePageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.baseText )</code>.
* '''basePageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.baseText )</code>.


<!--T:2553-->
 
* '''rootPageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.rootText )</code>.
* '''rootPageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.rootText )</code>.


<!--T:2554-->
 
* '''talkPageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( mw.site.namespaces[title.namespace].talk.id, title.text )</code>, or nil if this title cannot have a talk page.
* '''talkPageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( mw.site.namespaces[title.namespace].talk.id, title.text )</code>, or nil if this title cannot have a talk page.


<!--T:2555-->
 
* '''subjectPageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( mw.site.namespaces[title.namespace].subject.id, title.text )</code>.
* '''subjectPageTitle''': The same as <code style="white-space:nowrap">mw.title.makeTitle( mw.site.namespaces[title.namespace].subject.id, title.text )</code>.


<!--T:2556-->
 
* '''redirectTarget:''' Returns a title object of the target of the redirect page if the page is a redirect and the page exists, returns false otherwise.
* '''redirectTarget:''' Returns a title object of the target of the redirect page if the page is a redirect and the page exists, returns false otherwise.


<!--T:2557-->
 
* '''protectionLevels''': The page's protection levels. This is a table with keys corresponding to each action (e.g., "edit" and "move"). The table values are arrays, the first item of which is a string containing the protection level. If the page is unprotected, either the table values or the array items will be nil. {{red|This is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]]}}.
* '''protectionLevels''': The page's protection levels. This is a table with keys corresponding to each action (e.g., "edit" and "move"). The table values are arrays, the first item of which is a string containing the protection level. If the page is unprotected, either the table values or the array items will be nil. {{red|This is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]]}}.


<!--T:2558-->
 
* '''cascadingProtection''': The cascading protections applicable to the page. This is a table with keys "restrictions" (itself a table with keys like '''protectionLevels''' has) and "sources" (an array listing titles where the protections cascade from). If no protections cascade to the  page, "restrictions" and "sources" will be empty. {{red|This is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]]}}.
* '''cascadingProtection''': The cascading protections applicable to the page. This is a table with keys "restrictions" (itself a table with keys like '''protectionLevels''' has) and "sources" (an array listing titles where the protections cascade from). If no protections cascade to the  page, "restrictions" and "sources" will be empty. {{red|This is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]]}}.


<!--T:2559-->
 
* '''subPageTitle( text )''': The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.text .. '/' .. text )</code>.
* '''subPageTitle( text )''': The same as <code style="white-space:nowrap">mw.title.makeTitle( title.namespace, title.text .. '/' .. text )</code>.


<!--T:2560-->
 
* '''partialUrl()''': Returns <code>title.text</code> encoded as it would be in a URL.
* '''partialUrl()''': Returns <code>title.text</code> encoded as it would be in a URL.


<!--T:2561-->
 
* '''fullUrl( query, proto )''': Returns the full URL (with optional query table/string) for this title. <code>proto</code> may be specified to control the scheme of the resulting url: "http", "https", "relative" (the default), or "canonical".
* '''fullUrl( query, proto )''': Returns the full URL (with optional query table/string) for this title. <code>proto</code> may be specified to control the scheme of the resulting url: "http", "https", "relative" (the default), or "canonical".


<!--T:2562-->
 
* '''localUrl( query )''': Returns the local URL (with optional query table/string) for this title.
* '''localUrl( query )''': Returns the local URL (with optional query table/string) for this title.


<!--T:2563-->
 
* '''canonicalUrl( query )''': Returns the canonical URL (with optional query table/string) for this title.
* '''canonicalUrl( query )''': Returns the canonical URL (with optional query table/string) for this title.


<!--T:2564-->
 
* '''getContent()''': Returns the (unparsed) content of the page, or nil if there is no page. The page will be recorded as a transclusion.
* '''getContent()''': Returns the (unparsed) content of the page, or nil if there is no page. The page will be recorded as a transclusion.




<!--T:2109-->
 
Title objects may be compared using [[<tvar name=anchor1>#Relational operators</tvar>|relational operators]]. <code style="white-space:nowrap">[[<tvar name=anchor2>#tostring</tvar>|tostring]]( title )</code> will return <code>title.prefixedText</code>.
Title objects may be compared using [[<tvar name=anchor1>#Relational operators</tvar>|relational operators]]. <code style="white-space:nowrap">[[<tvar name=anchor2>#tostring</tvar>|tostring]]( title )</code> will return <code>title.prefixedText</code>.


<!--T:2400-->
 
Since people find the fact surprising, note that accessing any [[#Expensive properties|expensive]] field on a title object records a "link" to the page (as shown on [[Special:WhatLinksHere]], for example). Using the title object's <code>getContent()</code> method or accessing the <code>redirectTarget</code> field records it as a "{{int|istemplate}}", and accessing the title object's <code>file</code> or <code>fileExists</code> fields records it as a "{{int|isimage}}".
Since people find the fact surprising, note that accessing any [[#Expensive properties|expensive]] field on a title object records a "link" to the page (as shown on [[Special:WhatLinksHere]], for example). Using the title object's <code>getContent()</code> method or accessing the <code>redirectTarget</code> field records it as a "{{int|istemplate}}", and accessing the title object's <code>file</code> or <code>fileExists</code> fields records it as a "{{int|isimage}}".


===== File metadata ===== <!--T:2110-->
=== File metadata ===  
 


<!--T:2415-->
Title objects representing a page in the File or Media namespace will have a property called <code>file</code>. {{red|This is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]].}} This is a table, structured as follows:
Title objects representing a page in the File or Media namespace will have a property called <code>file</code>. {{red|This is [[<tvar name=page>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive]].}} This is a table, structured as follows:


<!--T:2111-->
 
* '''exists''': Whether the file exists. It will be recorded as an image usage. The <code>fileExists</code> property on a Title object exists for backwards compatibility reasons and is an alias for this property. If this is false, all other file properties will be nil.
* '''exists''': Whether the file exists. It will be recorded as an image usage. The <code>fileExists</code> property on a Title object exists for backwards compatibility reasons and is an alias for this property. If this is false, all other file properties will be nil.


<!--T:2620-->
 
* '''width''': The width of the file. If the file contains multiple pages, this is the width of the first page.
* '''width''': The width of the file. If the file contains multiple pages, this is the width of the first page.


<!--T:2621-->
 
* '''height''': The height of the file. If the file contains multiple pages, this is the height of the first page.
* '''height''': The height of the file. If the file contains multiple pages, this is the height of the first page.


<!--T:2622-->
* '''pages''': If the file format supports multiple pages, this is a table containing tables for each page of the file; otherwise, it is nil. The [[<tvar name=anchor>#Length operator</tvar>|# operator]] can be used to get the number of pages in the file. Each individual page table contains a width and height property.


<!--T:2623-->
* '''pages''': If the file format supports multiple pages, this is a table containing tables for each page of the file; otherwise, it is nil. The [[#Length operator|# operator]] can be used to get the number of pages in the file. Each individual page table contains a width and height property.
 
 
* '''size''': The size of the file in bytes.
* '''size''': The size of the file in bytes.


<!--T:2624-->
 
* '''mimeType''': The [[:en:MIME type|MIME type]] of the file.
* '''mimeType''': The [[:en:MIME type|MIME type]] of the file.


<!--T:2504-->
 
* '''length''': The length (duration) of the media file in seconds. Zero for media types which do not support length.
* '''length''': The length (duration) of the media file in seconds. Zero for media types which do not support length.


===== Expensive properties ===== <!--T:2112-->
=== Expensive properties ===  
 
 
The properties id, isRedirect, exists, and contentModel require fetching data about the title from the database. For this reason, the [[Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit|expensive function count]] is incremented the first time one of them is accessed for a page other than the current page. Subsequent accesses of any of these properties for that page will not increment the expensive function count again.


<!--T:2113-->
The properties id, isRedirect, exists, and contentModel require fetching data about the title from the database. For this reason, the [[<tvar name=help>Special:MyLanguage/Manual:$wgExpensiveParserFunctionLimit</tvar>|expensive function count]] is incremented the first time one of them is accessed for a page other than the current page. Subsequent accesses of any of these properties for that page will not increment the expensive function count again.


<!--T:2114-->
Other properties marked as expensive will always increment the expensive function count the first time they are accessed for a page other than the current page.
Other properties marked as expensive will always increment the expensive function count the first time they are accessed for a page other than the current page.
== 문서 제목 ==
* 제목 전체
*:<code><nowiki>mw.title.new('시리즈:리브레 한자사전/漢').prefixedText</nowiki></code> 시리즈:리브레 한자사전/漢
* 이름 공간
*:<code><nowiki>mw.title.new('시리즈:리브레 한자사전/漢').nsText</nowiki></code> 시리즈
* 이름공간 제외한 제목
*: <code><nowiki>mw.title.new('시리즈:리브레 한자사전/漢').text</nowiki></code> 리브레 한자사전/漢
* 최상위 제목
*: <code><nowiki>mw.title.new('시리즈:리브레 한자사전/漢').rootText</nowiki></code> 리브레 한자사전
* 하위문서 이름
*: <code><nowiki>mw.title.new('시리즈:리브레 한자사전/漢').subpageText</nowiki></code> 漢
* 토론 문서가 있는지
*: <code><nowiki>mw.title.new('시리즈:리브레 한자사전/漢').canTalk</nowiki></code> true

2022년 5월 11일 (수) 10:30 기준 최신판

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
{{#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

Math[편집 | 원본 편집]

Unlike in wikicode, lua does not use functions like ifexpr and expr. Add the lua operators and functions straight into your module.

Grouping

Wikicode Lua
() ()

Numbers

Wikicode Lua
1234.5 1234.5
2e3 2e3
pi math.pi
e
2+2 2+2
2-1 2-1

Unary

Wikicode 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)

Binary

Wikicode Lua
2^3 2^3
2*3 2*3
2/3
2div3
2/3
30mod7 30%7
+2 2
-2 -2

Logic

Wikicode Data type Lua Data type
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

틀:Clear

Magic words[편집 | 원본 편집]

Date and time[편집 | 원본 편집]

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

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

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

HTML library[편집 | 원본 편집]

mw.html is a fluent interface for building complex HTML from Lua. A mw.html object can be created using [[<tvar|anchor>#mw.html.create</>|mw.html.create]].


틀:Anchor


Functions documented as mw.html.name are available on the global mw.html table; functions documented as mw.html:name and html:name are methods of an mw.html object (see [[<tvar|anchor>#mw.html.create</>|mw.html.create]]).


A basic example could look like this:


local div = mw.html.create( 'div' )
div
     :attr( 'id', 'testdiv' )
     :css( 'width', '100%' )
     :wikitext( 'Some text' )
     :tag( 'hr' )
return tostring( div )
-- Output: <div id="testdiv" style="width:100%;">Some text<hr /></div>

mw.html.create[편집 | 원본 편집]

태그 생성 mw.html.create( tagName, args )


Creates a new mw.html object containing a tagName html element. You can also pass an empty string or nil as tagName in order to create an empty mw.html object.


args can be a table with the following keys:


  • args.selfClosing: Force the current tag to be self-closing, even if mw.html doesn't recognize it as self-closing
  • args.parent: Parent of the current mw.html instance (intended for internal usage)


mw.html:node[편집 | 원본 편집]

html:node( builder )


Appends a child mw.html (builder) node to the current mw.html instance. If a nil parameter is passed, this is a no-op. A (builder) node is a string representation of an html element.


mw.html:wikitext[편집 | 원본 편집]

텍스트 출력? html:wikitext( ... )


Appends an undetermined number of wikitext strings to the mw.html object.


Note that this stops at the first nil item.


mw.html:newline[편집 | 원본 편집]

새로운 행 html:newline()


Appends a newline to the mw.html object.


mw.html:tag[편집 | 원본 편집]

자식태그 삽입 html:tag( tagName, args )


Appends a new child node with the given tagName to the builder, and returns a mw.html instance representing that new node. The args parameter is identical to that of [[<tvar|anchor>#mw.html.create</>|mw.html.create]]

mw.html:attr[편집 | 원본 편집]

속성 추가 html:attr( name, value )
html:attr( table )


Set an HTML attribute with the given name and value on the node. Alternatively a table holding name->value pairs of attributes to set can be passed. In the first form, a value of nil causes any attribute with the given name to be unset if it was previously set.

mw.html:getAttr[편집 | 원본 편집]

속성 get html:getAttr( name )


Get the value of a html attribute previously set using [[<tvar|anchor>#mw.html:attr</>|html:attr()]] with the given name.

mw.html:addClass[편집 | 원본 편집]

html:addClass( class )


Adds a class name to the node's class attribute. If a nil parameter is passed, this is a no-op.


mw.html:css[편집 | 원본 편집]

html:css( name, value )
html:css( table )


Set a CSS property with the given name and value on the node. Alternatively a table holding name->value pairs of properties to set can be passed. In the first form, a value of nil causes any property with the given name to be unset if it was previously set.


mw.html:cssText[편집 | 원본 편집]

html:cssText( css )


Add some raw css to the node's style attribute. If a nil parameter is passed, this is a no-op.


mw.html:done[편집 | 원본 편집]

html:done()


Returns the parent node under which the current node was created. Like jQuery.end, this is a convenience function to allow the construction of several child nodes to be chained together into a single statement.


mw.html:allDone[편집 | 원본 편집]

html:allDone()


Like [[<tvar|anchor>#mw.html:done</>|html:done()]], but traverses all the way to the root node of the tree and returns it.

Title library[편집 | 원본 편집]

mw.title.equals[편집 | 원본 편집]

두 제목 일치 여부 mw.title.equals( a, b )


Test for whether two titles are equal. Note that fragments are ignored in the comparison.

mw.title.compare[편집 | 원본 편집]

mw.title.compare( a, b )


Returns -1, 0, or 1 to indicate whether the title a is less than, equal to, or greater than title b.


This compares titles by interwiki prefix (if any) as strings, then by namespace number, then by the unprefixed title text as a string. These string comparisons use Lua's standard < operator.

mw.title.getCurrentTitle[편집 | 원본 편집]

현재 문서 제목 객체 얻기 mw.title.getCurrentTitle()


Returns the title object for the current page.

mw.title.new[편집 | 원본 편집]

새 제목 객체 만들기 mw.title.new( text, namespace )
mw.title.new( id )


틀:Red
Creates a new title object.
Returns type "nil" if the pagename (in parameter "text") is invalid, but succeeds if it is valid but only does not exist.


If a number id is given, an object is created for the title with that page_id. The title referenced will be counted as linked from the current page. If the page_id does not exist, returns nil. The expensive function count will be incremented if the title object created is not for a title that has already been loaded.


If a string text is given instead, an object is created for that title (even if the page does not exist). If the text string does not specify a namespace, namespace (which may be any key found in [[<tvar name=anchor>#mw.site.namespaces</tvar>|mw.site.namespaces]]) will be used. If the text is not a valid title, nil is returned.

mw.title.makeTitle[편집 | 원본 편집]

mw.title.makeTitle( namespace, title, fragment, interwiki )


Creates a title object with title title in namespace namespace, optionally with the specified fragment and interwiki prefix. namespace may be any key found in [[<tvar name=anchor>#mw.site.namespaces</tvar>|mw.site.namespaces]]. If the resulting title is not valid, returns nil.


Note that, unlike <tvar name=mw_title_new_function>mw.title.new()</tvar>, this method will always apply the specified namespace. For example, mw.title.makeTitle( 'Template', 'Module:Foo' ) will create an object for the page Template:Module:Foo, while mw.title.new( 'Module:Foo', 'Template' ) will create an object for the page Module:Foo.

Title objects[편집 | 원본 편집]

A title object has a number of properties and methods. Most of the properties are read-only.


Note that fields ending with text return titles as string values whereas the fields ending with title return title objects.


  • id: The page_id. 0 if the page does not exist. 틀:Red.


  • interwiki: The interwiki prefix, or the empty string if none.


  • namespace: The namespace number.


  • fragment: The fragment (aka section/anchor linking), or the empty string. May be assigned.


  • nsText: The text of the namespace for the page.


  • subjectNsText: The text of the subject namespace for the page.


  • text: The title of the page, without the namespace or interwiki prefixes.


  • prefixedText: The title of the page, with the namespace and interwiki prefixes.


  • fullText: The title of the page, with the namespace and interwiki prefixes and the fragment. Interwiki is not returned if equal to the current.


  • rootText: If this is a subpage, the title of the root page without prefixes. Otherwise, the same as title.text.


  • baseText: If this is a subpage, the title of the page it is a subpage of without prefixes. Otherwise, the same as title.text.


  • subpageText: If this is a subpage, just the subpage name. Otherwise, the same as title.text.


  • canTalk: Whether the page for this title could have a talk page.


  • exists: Whether the page exists. Alias for file.exists for Media-namespace titles. For File-namespace titles this checks the existence of the file description page, not the file itself. 틀:Red. It is always expensive if the title object was created by "mw.title.new" or "mw.title.makeTitle", and the call will throw an exception rather than returning "false" if the limit (500 on most wikis) is reached.



  • isContentPage: Whether this title is in a content namespace.


  • isExternal: Whether this title has an interwiki prefix.


  • isLocal: Whether this title is in this project. For example, on the English Wikipedia, any other Wikipedia is considered "local" while Wiktionary and such are not.


  • isRedirect: Whether this is the title for a page that is a redirect. 틀:Red.


  • isSpecialPage: Whether this is the title for a possible special page (i.e. a page in the Special: namespace).


  • isSubpage: Whether this title is a subpage of some other title.
  • isTalkPage: Whether this is a title for a talk page.
  • isSubpageOf( title2 ): Whether this title is a subpage of the given title.


  • inNamespace( ns ): Whether this title is in the given namespace. Namespaces may be specified by anything that is a key found in [[<tvar name=anchor3>#mw.site.namespaces</tvar>|mw.site.namespaces]].


  • inNamespaces( ... ): Whether this title is in any of the given namespaces. Namespaces may be specified by anything that is a key found in [[<tvar name=anchor4>#mw.site.namespaces</tvar>|mw.site.namespaces]].


  • hasSubjectNamespace( ns ): Whether this title's subject namespace is in the given namespace. Namespaces may be specified by anything that is a key found in [[<tvar name=anchor5>#mw.site.namespaces</tvar>|mw.site.namespaces]].


  • contentModel: The content model for this title, as a string. 틀:Red.


  • basePageTitle: The same as mw.title.makeTitle( title.namespace, title.baseText ).


  • rootPageTitle: The same as mw.title.makeTitle( title.namespace, title.rootText ).


  • talkPageTitle: The same as mw.title.makeTitle( mw.site.namespaces[title.namespace].talk.id, title.text ), or nil if this title cannot have a talk page.


  • subjectPageTitle: The same as mw.title.makeTitle( mw.site.namespaces[title.namespace].subject.id, title.text ).


  • redirectTarget: Returns a title object of the target of the redirect page if the page is a redirect and the page exists, returns false otherwise.


  • protectionLevels: The page's protection levels. This is a table with keys corresponding to each action (e.g., "edit" and "move"). The table values are arrays, the first item of which is a string containing the protection level. If the page is unprotected, either the table values or the array items will be nil. 틀:Red.


  • cascadingProtection: The cascading protections applicable to the page. This is a table with keys "restrictions" (itself a table with keys like protectionLevels has) and "sources" (an array listing titles where the protections cascade from). If no protections cascade to the page, "restrictions" and "sources" will be empty. 틀:Red.


  • subPageTitle( text ): The same as mw.title.makeTitle( title.namespace, title.text .. '/' .. text ).


  • partialUrl(): Returns title.text encoded as it would be in a URL.


  • fullUrl( query, proto ): Returns the full URL (with optional query table/string) for this title. proto may be specified to control the scheme of the resulting url: "http", "https", "relative" (the default), or "canonical".


  • localUrl( query ): Returns the local URL (with optional query table/string) for this title.


  • canonicalUrl( query ): Returns the canonical URL (with optional query table/string) for this title.


  • getContent(): Returns the (unparsed) content of the page, or nil if there is no page. The page will be recorded as a transclusion.


Title objects may be compared using [[<tvar name=anchor1>#Relational operators</tvar>|relational operators]]. [[<tvar name=anchor2>#tostring</tvar>|tostring]]( title ) will return title.prefixedText.


Since people find the fact surprising, note that accessing any expensive field on a title object records a "link" to the page (as shown on Special:WhatLinksHere, for example). Using the title object's getContent() method or accessing the redirectTarget field records it as a "틀:Int", and accessing the title object's file or fileExists fields records it as a "틀:Int".

File metadata[편집 | 원본 편집]

Title objects representing a page in the File or Media namespace will have a property called file. 틀:Red This is a table, structured as follows:


  • exists: Whether the file exists. It will be recorded as an image usage. The fileExists property on a Title object exists for backwards compatibility reasons and is an alias for this property. If this is false, all other file properties will be nil.


  • width: The width of the file. If the file contains multiple pages, this is the width of the first page.


  • height: The height of the file. If the file contains multiple pages, this is the height of the first page.


  • pages: If the file format supports multiple pages, this is a table containing tables for each page of the file; otherwise, it is nil. The # operator can be used to get the number of pages in the file. Each individual page table contains a width and height property.


  • size: The size of the file in bytes.



  • length: The length (duration) of the media file in seconds. Zero for media types which do not support length.

Expensive properties[편집 | 원본 편집]

The properties id, isRedirect, exists, and contentModel require fetching data about the title from the database. For this reason, the expensive function count is incremented the first time one of them is accessed for a page other than the current page. Subsequent accesses of any of these properties for that page will not increment the expensive function count again.


Other properties marked as expensive will always increment the expensive function count the first time they are accessed for a page other than the current page.

문서 제목[편집 | 원본 편집]

  • 제목 전체
    mw.title.new('시리즈:리브레 한자사전/漢').prefixedText 시리즈:리브레 한자사전/漢
  • 이름 공간
    mw.title.new('시리즈:리브레 한자사전/漢').nsText 시리즈
  • 이름공간 제외한 제목
    mw.title.new('시리즈:리브레 한자사전/漢').text 리브레 한자사전/漢
  • 최상위 제목
    mw.title.new('시리즈:리브레 한자사전/漢').rootText 리브레 한자사전
  • 하위문서 이름
    mw.title.new('시리즈:리브레 한자사전/漢').subpageText
  • 토론 문서가 있는지
    mw.title.new('시리즈:리브레 한자사전/漢').canTalk true