|
|
| Line 1: |
Line 1: |
| require('strict')
| |
|
| |
| local p = {} | | local p = {} |
|
| |
|
| local function titleExistsUnprotected(titleObject)
| | function p.main(frame) |
| return titleObject.exists
| | return '' |
| 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 | | end |
|
| |
|
| function p._main(args) | | function p._main(args) |
| local title = args[1]
| | return '' |
| 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 | | end |
|
| |
|
| return p | | return p |
Documentation for this module may be created at Module:Link if exists/doc
local p = {}
function p.main(frame)
return ''
end
function p._main(args)
return ''
end
return p