Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Library citation: Difference between revisions

From ProleWiki, the proletarian encyclopedia
m (Using function to return table)
m (Comp function)
Line 1: Line 1:
local p = {}
local p = {}
function is_lib_work(s)
return mw.getCurrentFrame():callParserFunction('#ifexist',"Library:" .. s,true) == "1"
end


local function checkset(var)
local function checkset(var)
Line 9: Line 5:
if not (var == nil or var == '') then
if not (var == nil or var == '') then
rtn = var
rtn = var
end
return rtn
return rtn
end
local function compFunc(s1,s2)
local s1split = mw.text.split(string.lower(s1),"")
local s2split = mw.text.split(string.lower(s2),"")
local c1 = ""
local c2 = ""
if s1split[1] == "\"" then
c1 = s1plit[2]
end
end
if s2split[1] == "\"" then
c2 = s2plit[2]
end
return c1 > c2
end
end


Line 42: Line 52:
return listOfWorks(author)
return listOfWorks(author)
end
end
return p
return p

Revision as of 12:12, 7 October 2024

local p = {}

local function checkset(var)
	local rtn = ""
	if not (var == nil or var == '') then
		rtn = var
	end
	return rtn
end

local function compFunc(s1,s2)
	local s1split = mw.text.split(string.lower(s1),"")
	local s2split = mw.text.split(string.lower(s2),"")
	local c1 = ""
	local c2 = ""
	if s1split[1] == "\"" then
		c1 = s1plit[2]
	end
	if s2split[1] == "\"" then
		c2 = s2plit[2]
	end
	return c1 > c2
end

function listOfWorks(author) 
	local newMethod = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","titleregexp=" .. author .. "/[^/]+$","format=,%TITLE%\\n")
	local catMethod = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","category=Library works by " .. author ,"format=,%TITLE%\\n")
	local list = ""
	-- Picks whatever method of recovering pages has the higher count, usually categories
	if string.len(newMethod) > string.len(catMethod) then
		list = newMethod
		else
			list = catMethod
	end
	titleTable = mw.text.split(string.gsub(mw.text.trim(list),author .. "/",""),"\n")
	linkTable=mw.text.split(mw.text.trim(list),"\n")
	for i,v in ipairs(linkTable) do
		linkTable[i] = "Library:" .. v
	end
	return {links=linkTable,titles=titleTable}
end

function p.cite(frame)
	-- Parent frame to get parameters from template calls instead of from {{#invoke: ...
	local parentFrame = frame:getParent()
	-- get arguments from "args" table pre-defined by MediaWiki/Scribunto
	local link = checkset(parentFrame.args.link)
	local author = checkset(parentFrame.args.author)
	-- error("error message") to send error messages
	-- mw.log(mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","titleregexp=Vladimir Lenin/[^/]+$","format=,%PAGE%\\n"))
	-- mw.log(mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","category=Library works by Vladimir Lenin","format=,%PAGE%\\n"))
	return listOfWorks(author)
end

return p