Difference between revisions of "Module:See also if exists/sandbox"
Jump to navigation
Jump to search
blackwiki>Pppery (Create sandbox version of Module:See also if exists) |
blackwiki>Pppery (Implementing merger') |
||
| Line 3: | Line 3: | ||
local p = {} | local p = {} | ||
| − | function doesPageExist(thisPage) | + | function doesPageExist(thisPage, ns) |
| − | local thisPage = mw.title.new( thisPage ) | + | local thisPage = mw.title.new( thisPage ,ns) |
if thisPage == nil then | if thisPage == nil then | ||
return false | return false | ||
| Line 18: | Line 18: | ||
local rawpages = {} | local rawpages = {} | ||
local nvalid = 0 | local nvalid = 0 | ||
| + | local namespace = frame.args.ns | ||
for i, v in ipairs(mw.getCurrentFrame():getParent().args) do | for i, v in ipairs(mw.getCurrentFrame():getParent().args) do | ||
if (v ~= nil) then | if (v ~= nil) then | ||
local thisArg = mw.text.trim(v) | local thisArg = mw.text.trim(v) | ||
if (thisArg ~= "") then | if (thisArg ~= "") then | ||
| − | if ( doesPageExist(thisArg)) then | + | if ( doesPageExist(thisArg, namespace)) then |
| − | table.insert(rawpages, thisArg) | + | table.insert(rawpages, namespace .. thisArg) |
nvalid = nvalid + 1 | nvalid = nvalid + 1 | ||
end | end | ||
Revision as of 05:08, 20 February 2019
Documentation for this module may be created at Module:See also if exists/sandbox/doc
--[[ v1.0
]]
local p = {}
function doesPageExist(thisPage, ns)
local thisPage = mw.title.new( thisPage ,ns)
if thisPage == nil then
return false
end
if thisPage.exists then
return true
end
return false
end
function p.main(frame)
local rawpages = {}
local nvalid = 0
local namespace = frame.args.ns
for i, v in ipairs(mw.getCurrentFrame():getParent().args) do
if (v ~= nil) then
local thisArg = mw.text.trim(v)
if (thisArg ~= "") then
if ( doesPageExist(thisArg, namespace)) then
table.insert(rawpages, namespace .. thisArg)
nvalid = nvalid + 1
end
end
end
end
if (nvalid == 0) then
return ""
end
local mLabelledList = require('Module:Labelled list hatnote')
local pages = mLabelledList._labelledList(rawpages, "See also", "")
return pages
end
return p