Jump to content

Module:See also if exists: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Created page with '--v1.0 local p = {} function doesCatExist(catname) local catPage = mw.title.new( catname, "Category" ) if catPage == nil then return false end if ca...'
 
convert
Line 3: Line 3:
local p = {}
local p = {}


function doesCatExist(catname)
function doesPageExist(thisPage)
local catPage = mw.title.new( catname, "Category" )
local thisPage = mw.title.new( thisPage )
if catPage == nil then
if thisPage == nil then
return false
return false
end
end
if catPage.exists then
if thisPage.exists then
return true
return true
end
end
Line 16: Line 16:


function p.main(frame)
function p.main(frame)
local rawcats = {}
local rawpages = {}
local nvalid = 0
local nvalid = 0
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)
thisArg = mw.ustring.gsub(thisArg, "^[Cc]ategory:%s*", "", 1)
if (thisArg ~= "") then
if (thisArg ~= "") then
if ( doesCatExist(thisArg)) then
if ( doesPageExist(thisArg)) then
table.insert(rawcats, "Category:" .. thisArg)
table.insert(rawpages, thisArg)
nvalid = nvalid + 1
nvalid = nvalid + 1
end
end
Line 34: Line 33:
end
end
local mLabelledList = require('Module:Labelled list hatnote')
local mLabelledList = require('Module:Labelled list hatnote')
local pages = mLabelledList._labelledList(rawcats, "See also", "")
local pages = mLabelledList._labelledList(rawpages, "See also", "")
return pages
return pages
end
end

Revision as of 21:11, 30 October 2018

--[[ v1.0
]]
local p = {}

function doesPageExist(thisPage)
	local thisPage = mw.title.new( thisPage )
	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
	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)) then
					table.insert(rawpages, 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