More languages
More actions
m (Comp function) |
(Adding actual comparator function now and sorting tables before presenting them) |
||
Line 9: | Line 9: | ||
end | end | ||
local function | local function removeApostrophes(str) | ||
return str:gsub("[\"'%`]", "") | |||
end | |||
local | |||
local function compareStrings(a,b) | |||
local stringA = removeApostrophes(a):lower() | |||
local stringB = removeApostrophes(b):lower() | |||
return stringA < stringB | |||
end | end | ||
Line 38: | Line 34: | ||
linkTable[i] = "Library:" .. v | linkTable[i] = "Library:" .. v | ||
end | end | ||
table.sort(linkTable,compareStrings) | |||
table.sort(titleTable,compareStrings) | |||
return {links=linkTable,titles=titleTable} | return {links=linkTable,titles=titleTable} | ||
end | end |
Revision as of 12:43, 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 removeApostrophes(str)
return str:gsub("[\"'%`]", "")
end
local function compareStrings(a,b)
local stringA = removeApostrophes(a):lower()
local stringB = removeApostrophes(b):lower()
return stringA < stringB
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
table.sort(linkTable,compareStrings)
table.sort(titleTable,compareStrings)
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