မေႃႇၵျူး:Link if exists
Appearance
| This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
| Lua module ဢၼ်ၼႆႉ လႆႈၸႂ်ႉဝႆႉ တီႈၼႃႈလိၵ်ႈ many ၼႃႈလိၵ်ႈ လႄႈ လွင်ႈလႅၵ်ႈလၢႆႈၸိူဝ်းၼႆႉ တေႁႂ်ႈၽၢင်ႉမႅၼ်ႈၺႃး ၵႂၢင်ႈၵႂၢင်ႈၶႂၢင်ၶႂၢင်။ ၸၢမ်းတူၺ်း လွင်ႈလႅၵ်ႈလၢႆႈ တီႈၼႂ်း မေႃႇၵျူး's /sandbox ဢမ်ႇၼၼ် ၼႃႈလိၵ်ႈၽႄ /testcases . ဝူၼ်ႉသွၼ်ႇ ဢုပ်ႇဢူဝ်း လွင်ႈလႅၵ်ႈလၢႆႈ တီႈၼႂ်း ၼႃႈလိၵ်ႈ တႃႇဢုပ်ႇ ၽွင်းမိူဝ်ႈပႆႇ ၵေႃႇသၢင်ႈၶဝ်ၼၼ်ႉ။
ႁူဝ်ၼပ်ႉ လွင်ႈၶဝ်ႈပႃးၼႆႉ မၼ်းႁဵတ်းဢၢပ်ႉတဵတ်ႉဝႆႉႁင်းမၼ်း (တူၺ်းတီႈ ၽိုၼ်လိၵ်ႈ)။ |
Implements {{Link if exists}}.
လွင်ႈၸႂ်ႉတိုဝ်း
[မႄးထတ်းငဝ်ႈငႃႇ]{{#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
require('strict')
local p = {}
local function titleExistsUnprotected(titleObject)
return titleObject.exists
end
-- test for title existing
-- if we get an error accessing titleObject.exists, assume it doesn't exist
local function titleExists(titleObject)
local success, exists = pcall(titleExistsUnprotected, titleObject)
return success and exists
end
function p._main(args)
local title = args[1]
if not title then
return title
end
local display = args[2] or title
title = args.prefix and args.prefix..':'..title or title
local titleObject = mw.title.new(title, args.nsp)
local result = ''
if titleObject and titleExists(titleObject) then
-- use prefix only if args[2] is empty/false
display = args[2] or title
result = result..'[['
result = result..(titleObject.namespace ~= 0 and ':' or '')
result = result..(titleObject.fullText ~= display and titleObject.fullText..'|' or '')
result = result..display..']]'
elseif not args.hide_display then
result = result..(args.color and '<span style="color:'..args.color..'">' or '')
result = result..display
result = result..(args.color and '</span>' or '')
end
return result
end
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
return p._main(args) or ""
end
return p