Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Format link/doc
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Use from other Lua modules== To load this module from another Lua module, use the following code: <syntaxhighlight lang="lua"> local mFormatLink = require('Module:Format link') </syntaxhighlight> You can then use the functions as documented below. === _formatLink === <syntaxhighlight lang="lua"> mFormatLink._formatLink{ link = 'Link', display = 'Display', target = 'Target', italicizePage = true, italicizeSection = true, categorizeMissing = 'Pages using formatted red links' } </syntaxhighlight> Formats <var>link</var> as a wikilink. Categories and files are automatically escaped with the [[Help:Colon trick|colon trick]], and links to sections are automatically formatted as ''page § section'', rather than the MediaWiki default of ''page#section''. Several options modify the output: * If the <var>display</var> value is present, then it will be used as a display value. Any manual piping (using the <code><nowiki>{{!}}</nowiki></code> magic word or similar) present in <var>link</var> will be overridden by the <var>display</var> value if present. * If the <var>target</var> value is present, then it will override <var>link</var> as a target, but the result will still be ''displayed'' using either the value from <var>display</var>, or the result of formatting <var>link</var>. * If <var>italicizePage</var> is true, then the page portion of the link is italicized if present. * If <var>italicizeSection</var> is true, then the section portion of the link is italicized if present. * If <var>categorizeMissing</var> is a non-empty string, then that value is used as a category name, and that category will be applied if the resulting target of the link (no matter whether through <var>link</var> or through <var>target</var>) doesn't exist. ;Examples: : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = 'Foo#Bar'}</syntaxhighlight> → <nowiki>[[:Foo#Bar|Foo §&nbsp;Bar]]</nowiki> → {{format link|Foo#Bar}} : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = 'Baz', display = 'Qux'}</syntaxhighlight> → <nowiki>[[:Baz|Qux]]</nowiki> → {{format link|Baz|Qux}} : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = 'Foo|Bar', display = 'Baz'}</syntaxhighlight> → <nowiki>[[:Foo|Baz]]</nowiki> → {{format link|Foo{{!}}Bar|Baz}} : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = '#Foo', target = 'Example#Foo'}</syntaxhighlight> → <nowiki>[[:Example#Foo|§&nbsp;Foo]]</nowiki> → {{format link|#Foo||Example#Foo}} : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = 'The Lord of the Rings#Plot', italicizePage = true}</syntaxhighlight> → <nowiki>[[:The Lord of the Rings#Plot|''The Lord of the Rings'' §&nbsp;Plot]]</nowiki> → {{format link|The Lord of the Rings#Plot|italicizepage=true}} : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = 'Cybercrime Prevention Act of 2012#Disini v. Secretary of Justice', italicizeSection = true}</syntaxhighlight> → <nowiki>[[:Cybercrime Prevention Act of 2012#Disini v. Secretary of Justice|Cybercrime Prevention Act of 2012 §&nbsp;''Disini v. Secretary of Justice'']]</nowiki> → {{format link|Cybercrime Prevention Act of 2012#Disini v. Secretary of Justice|italicizesection=true}} : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = 'Nonexistent page', categorizeMissing = 'Example'}</syntaxhighlight> → <nowiki>[[:Nonexistent page]][[Category:Example]]</nowiki> → {{format link|Nonexistent page}} : <syntaxhighlight lang="lua" inline>mFormatLink._formatLink{link = 'Existing', categorizeMissing = 'Example'}</syntaxhighlight> → <nowiki>[[:Existing]]</nowiki> → {{format link|Existing}} === formatPages === <syntaxhighlight lang="lua"> mFormatLink.formatPages(options, pages) </syntaxhighlight> This derived function is useful for lists that format many links. It formats an array of pages using the [[#_formatLink|_formatLink]] function, and returns the result as an array. Options in the <var>options</var> table are applied, and use the same names as the options for <var>_formatLink</var>. ;Example :{{code|<nowiki>mFormatLink.formatPages({categorizeMissing = 'Example'}, {'Foo#Bar', 'Nonexistent page'})</nowiki>|lua}} → {{code|<nowiki>{'[[:Foo#Bar|Foo § Bar]]', '[[:Nonexistent page]][[Category:Example]]'}</nowiki>|lua}}
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)