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

Module:Library work multi-author: Difference between revisions

From ProleWiki, the proletarian encyclopedia
Forte (talk | contribs)
Created page with "local p = {} function p.main(frame) local args = frame:getParent().args local items = {} for _, value in pairs(args) do if value ~= '' then -- ignores empty arguments table.insert(items, value) end end local count = #items if count == 0 then return "" -- returns nothing if empty elseif count == 1 then return items[1] -- just return the string input if alone elseif count ==..."
 
Forte (talk | contribs)
now with automatica wikilinking
Line 1: Line 1:
local p = {}
local p = {}
local function formatList(items)
    local count = #items
    if count == 0 then
        return "" -- returns nothing if empty
    elseif count == 1 then
        return items[1] -- just return the string input if alone
    elseif count == 2 then
        return items[1] .. " and " .. items[2] -- returns "string1, string2, ... and last_string"
    else
        local last = table.remove(items)
        return table.concat(items, ", ") .. " and " .. last
    end
end


function p.main(frame)
function p.main(frame)
Line 6: Line 20:
      
      
     for _, value in pairs(args) do
     for _, value in pairs(args) do
         if value ~= '' then -- ignores empty arguments
         if value ~= '' then
             table.insert(items, value)
             table.insert(items, value)
         end
         end
     end
     end
      
      
     local count = #items
    return formatList(items)
end
 
function p.link(frame)
     local args = frame:getParent().args
    local items = {}
      
      
     if count == 0 then
     for _, value in pairs(args) do
        return "" -- returns nothing if empty
        if value ~= '' then
    elseif count == 1 then
            local title = mw.title.new(value) -- creates object for page
        return items[1] -- just return the string input if alone
            if title and title.exists then -- checks if page exists
    elseif count == 2 then
                table.insert(items, "[[" .. value .. "]]") -- adds to the item table with wikilink format
        return items[1] .. " and " .. items[2] -- returns "string1, string2, ... and last_string"
            else
    else
                table.insert(items, value) -- page doesn't exist, adds to the item table without the wikilink format
        local last = table.remove(items)
            end
         return table.concat(items, ", ") .. " and " .. last
         end
     end
     end
   
    return formatList(items)
end
end


return p
return p

Revision as of 02:49, 16 October 2025

local p = {}

local function formatList(items)
    local count = #items
    if count == 0 then
        return ""			-- returns nothing if empty
    elseif count == 1 then
        return items[1]		-- just return the string input if alone
    elseif count == 2 then
        return items[1] .. " and " .. items[2]		-- returns "string1, string2, ... and last_string"
    else
        local last = table.remove(items)
        return table.concat(items, ", ") .. " and " .. last
    end
end

function p.main(frame)
    local args = frame:getParent().args
    local items = {}
    
    for _, value in pairs(args) do
        if value ~= '' then
            table.insert(items, value)
        end
    end
    
    return formatList(items)
end

function p.link(frame)
    local args = frame:getParent().args
    local items = {}
    
    for _, value in pairs(args) do
        if value ~= '' then
            local title = mw.title.new(value)		-- creates object for page
            if title and title.exists then			-- checks if page exists
                table.insert(items, "[[" .. value .. "]]")	-- adds to the item table with wikilink format
            else
                table.insert(items, value)				-- page doesn't exist, adds to the item table without the wikilink format
            end
        end
    end
    
    return formatList(items)
end

return p