More languages
More actions
(Testing error messages) |
m (Added more robust method for processing titles of works) |
||
(5 intermediate revisions by the same user not shown) | |||
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 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=,%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 | |||
list = string.gsub(list,"Library:","") | |||
list = string.gsub(list,author .. "/","") | |||
return list | |||
end | |||
function p.cite(frame) | function p.cite(frame) | ||
-- Parent frame to get parameters from template calls instead of from {{#invoke: ... | -- Parent frame to get parameters from template calls instead of from {{#invoke: ... | ||
local parentFrame = frame:getParent() | local parentFrame = frame:getParent() | ||
local link = | -- get arguments from "args" table pre-defined by MediaWiki/Scribunto | ||
local author = | 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 | end | ||
return p |
Latest revision as of 02:15, 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=,%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
list = string.gsub(list,"Library:","")
list = string.gsub(list,author .. "/","")
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