Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:Link if exists

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
Thismodule is rated asready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
Page template-protectedThis module is currentlyprotected from editing.
See theprotection policy andprotection log for more details. Please discuss any changes on thetalk page; you maysubmit an edit request to ask anadministrator to make an edit if it isuncontroversial or supported byconsensus. You may alsorequest that this page be unprotected.
WarningThis Lua module is used onapproximately 293,000 pages.
To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on thetalk page before implementing them.

Implements{{Link if exists}}.

Usage

{{#invoke:Link if exists|main}}

Arguments

1
title of page to link to
2
text to display
prefix
prepend this string to title
nsp
namespace for title, does not display
color
Color of text if no link is found
hide_display
If page does not exist, do not display anything
The abovedocumentation istranscluded fromModule:Link if exists/doc.(edit |history)
Editors can experiment in this module'ssandbox(edit |diff) andtestcases(edit |run) pages.
Subpages of this module.

require('strict')localp={}localfunctiontitleExistsUnprotected(titleObject)returntitleObject.existsend-- test for title existing-- if we get an error accessing titleObject.exists, assume it doesn't existlocalfunctiontitleExists(titleObject)localsuccess,exists=pcall(titleExistsUnprotected,titleObject)returnsuccessandexistsendfunctionp._main(args)localtitle=args[1]ifnottitlethenreturntitleendlocaldisplay=args[2]ortitletitle=args.prefixandargs.prefix..':'..titleortitlelocaltitleObject=mw.title.new(title,args.nsp)localresult=''iftitleObjectandtitleExists(titleObject)then-- use prefix only if args[2] is empty/falsedisplay=args[2]ortitleresult=result..'[['result=result..(titleObject.namespace~=0and':'or'')result=result..(titleObject.fullText~=displayandtitleObject.fullText..'|'or'')result=result..display..']]'elseifnotargs.hide_displaythenresult=result..(args.colorand'<span style="color:'..args.color..'">'or'')result=result..displayresult=result..(args.colorand'</span>'or'')endreturnresultendfunctionp.main(frame)localgetArgs=require('Module:Arguments').getArgslocalargs=getArgs(frame)returnp._main(args)or""endreturnp
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Link_if_exists&oldid=1324017476"
Categories:
Hidden category:

[8]ページ先頭

©2009-2026 Movatter.jp