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 (Testing dpl)
m (List without namespaces)
Line 3: Line 3:
function is_lib_work(s)
function is_lib_work(s)
return mw.getCurrentFrame():callParserFunction('#ifexist',"Library:" .. s,true) == "1"
return mw.getCurrentFrame():callParserFunction('#ifexist',"Library:" .. s,true) == "1"
end
local function checkset(var)
local rtn = ""
if not (var == nil or var == '') then
rtn = var
return rtn
end
end
end


function listOfWorks(author)  
function listOfWorks(author)  
local list = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","titleregexp=" ..author .. "/[^/]+$","format=,%PAGE%\\n")
local newMethod = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","titleregexp=" .. author .. "/[^/]+$","format=,%PAGE%\\n")
if list == "" then
local catMethod = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","category=Library works by " .. author ,"format=,%PAGE%\\n")
list = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","category=Library works by " .. author ,"format=,%PAGE%\\n")
local list = ""
-- Picks whatever method of recovering pages has the higher count, usually categories
if string.len(newMethod) > string.len(catMethod) then
list = string.gsub(newMethod,"Library:" .. author,"")
else
list = string.gsub(catMethod,"Library:","")
end
end
return list
return list
Line 17: Line 30:
local parentFrame = frame:getParent()
local parentFrame = frame:getParent()
-- get arguments from "args" table pre-defined by MediaWiki/Scribunto
-- get arguments from "args" table pre-defined by MediaWiki/Scribunto
local link = parentFrame.args.link
local link = checkset(parentFrame.args.link)
local author = parentFrame.args.author
local author = checkset(parentFrame.args.author)
-- error("error message") to send error messages
-- 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","titleregexp=Vladimir Lenin/[^/]+$","format=,%PAGE%\\n"))

Revision as of 02:02, 7 October 2024

local p = {}

function is_lib_work(s)
	return mw.getCurrentFrame():callParserFunction('#ifexist',"Library:" .. s,true) == "1"
end

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

function listOfWorks(author) 
	local newMethod = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","titleregexp=" .. author .. "/[^/]+$","format=,%PAGE%\\n")
	local catMethod = mw.getCurrentFrame():callParserFunction("#dpl","namespace=Library","category=Library works by " .. author ,"format=,%PAGE%\\n")
	local list = ""
	-- Picks whatever method of recovering pages has the higher count, usually categories
	if string.len(newMethod) > string.len(catMethod) then
		list = string.gsub(newMethod,"Library:" .. author,"")
		else
			list = string.gsub(catMethod,"Library:","")
	end
	return list
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