Lua/Title Library

Lua modules based on the Scribunto/Lua extension are stored in resource pages using the Module: namespace. Each module uses a table to hold functions and variables, and that containing table is returned at the end of the module code. This lesson will show you how to use the Lua Title library in your scripts.

Prerequisites
This lesson assumes you have already completed the Tables lesson.

Create a Lua Script that Uses the Title Library
To create a Lua script that uses the Title library: ""
 * 1) Navigate to Module:Sandbox.
 * 2) Clear all existing code.
 * It's a sandbox. Everyone is free to play in the sandbox.  But if you find another user is actively editing the sandbox at the same time, you may also use Module:Sandbox/Username, where Username is your Wikiversity username.
 * 1) Add the following code and save the page:

Test Your Lua Script
To test your Lua script:
 * 1) Navigate to either the Module_talk:Sandbox page, the Sandbox page, or your own user or sandbox page.
 * 2) Add the following code and save the page:

The result should be similar to:
 * baseText
 * Sandbox


 * canTalk
 * true


 * exists
 * true


 * fileExists
 * false


 * fragment
 * fullText
 * Module talk:Sandbox
 * Module talk:Sandbox


 * getContent
 * == Welcome == Welcome to the Wikiversity Sandbox. Feel free to experiment with edits on this page.


 * id
 * 150785


 * inNamespace
 * false


 * inNamespaces
 * false


 * interwiki
 * isContentPage
 * false
 * false


 * isExternal
 * false


 * isLocal
 * true


 * isRedirect
 * false


 * isSpecialPage
 * false


 * isSubpage
 * false


 * isTalkPage
 * true


 * isSubpageOf
 * false


 * new
 * 150784


 * nsText
 * Module_talk


 * prefixedText
 * Module talk:Sandbox


 * rootText
 * Sandbox


 * subjectNsText
 * Module


 * subpageText
 * Sandbox


 * text
 * Sandbox

Understand Your Lua Script
To understand your Lua script:
 * 1)   gets the title object for the current page and assigns it to the variable named.
 * 2)   returns whether the title can have a talk page.
 * 3)   returns the base title text or parent page text if this is a subpage.
 * 4)   returns whether the title exists.
 * 5)   returns whether the file or image exists.
 * 6)   returns the title fragment.
 * 7)   returns the full text of the page title, with the namespace prefix.
 * 8)   returns the page content for the title.
 * 9)   returns the title id.
 * 10)   returns whether the title is in the given namespace.
 * 11)   returns whether the title is in the given namespaces.
 * 12)   returns the title interwiki prefix, if any.
 * 13)   returns whether the title is in a content namespace.
 * 14)   returns whether the title has an interwiki prefix.
 * 15)   returns whether the title is in this wiki project.
 * 16)   returns whether the title is a redirect.
 * 17)   returns whether the title is a special page.
 * 18)   returns whether the title is a subpage.
 * 19)   returns whether the title is a talk page.
 * 20)   returns whether the title is a subpage of.
 * 21)   gets the title object for the given page and namespace.
 * 22)   returns the namespace text for the title.
 * 23)   returns the title of the page, with the namespace and interwiki prefixes.
 * 24)   returns the title of the root page without prefixes.
 * 25)   returns the text of the subject namespace for the title.
 * 26)   returns the subpage name for the title.
 * 27)   returns The title text without namespace or interwiki prefixes.

Conclusion
Congratulations! You've now created, tested, and understood a Lua script that uses the Title library. Return to the main Lua page to learn about other Lua code libraries.