forked from Liquipedia/Lua-Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.lua
More file actions
58 lines (47 loc) · 1.3 KB
/
Copy pathpage.lua
File metadata and controls
58 lines (47 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Page
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
local Class = require('Module:Class')
local String = require('Module:StringUtils')
local page = {}
function page.exists(link)
local existingPage = mw.title.new(link)
-- In some cases we might have gotten an external link,
-- which will mean `existingPage` will equal nil
if existingPage == nil then
return false
end
return existingPage.exists
end
function page.makeInternalLink(options, display, customLink)
-- if no options are passed along (e.g. if the module is invoked from wiki code)
-- we need to shift the vars around to account for that
if type(options) == 'string' then
customLink = display
display = options
end
if String.isEmpty(display) then
return nil
elseif String.isEmpty(customLink) then
customLink = display
end
if (options or {}).onlyIfExists == true and (not page.exists(customLink)) then
return nil
end
return '[[' .. customLink .. '|' .. display .. ']]'
end
function page.makeExternalLink(display, link)
if String.isEmpty(display) or String.isEmpty(link) then
return nil
end
local output = '[' .. link
if not String.isEmpty(display) then
output = output .. ' ' .. display
end
return output .. ']'
end
return Class.export(page)