Emperor's Domination Wiki
No edit summary
No edit summary
Line 124: Line 124:
 
 
   
if not m.isempty(output)
+
if not m.empty(output)
then output = '<h2>Links</h2>'..table.concat(output)
+
then output = m.header('Links', 2)..table.concat(output)
 
else output = ''
 
else output = ''
 
end
 
end

Revision as of 04:39, 31 July 2020

Documentation for this module may be created at Module:Links/doc

local p = {}
local m = require("Module:Main")


function p.lua_link_part(s_cat, s_text, s_needed, s_type)
    local i
    local output = ''

    s_type = s_type or 'pages'
    i = m.pages_in_category(s_cat, s_type)
    if i > 0
        then
            output = '<li> '..m.category_link(s_cat, i..' '..s_text)
            if not m.empty(s_needed) and not m.exists({'Category:'..s_cat})
                then output = output..m.add_category(s_needed)
            end
    end
    return output
end


--------------------------------------------------------------------------------------------------
function p.lua_links(s_page, s_type)
    local appearances = m.pages_in_category(s_page..'/Appearances', 'pages')
    local mentions = m.pages_in_category(s_page..'/Mentions', 'pages')
    local items = 'Item(s) used by '..s_page
    local techniques = 'Technique(s) used by '..s_page
    local events = 'Event(s) in which '..s_page..' participated'
    local output = {}
    
    ------ Appearances and Mentions ------
    if appearances > 0
        then
            table.insert( output, '<li> '..m.category_link(s_page..'/Appearances', appearances + mentions..' Appearance(s) of '..s_page) )

            if not m.exists({'Category:'..s_page..'/Appearances'})
                then table.insert(output, m.add_category('Appearances Category Needed') )
            end
            if mentions > 0 and not m.exists({'Category:'..s_page..'/Mentions'})
                then table.insert(output, m.add_category('Mentions Category Needed') )
            end
        elseif mentions > 0
            then 
                table.insert( output, '<li> '..m.category_link(s_page..'/Mentions', mentions..' Mention(s) of '..s_page) )

                if not m.exists({'Category:'..s_page..'/Mentions'})
                    then table.insert(output, m.add_category('Mentions Category Needed') )
                end
    end
    
    table.insert( output, p.lua_link_part(s_page..'/Images', 'Image(s) of '..s_page, 'Images Category Needed', 'files') )
    table.insert( output, p.lua_link_part(s_page..'/Quotes', 'Quote(s) of '..s_page, 'Quotes Category Needed') )
    ------ character ------
    --if s_type == 'character'
    --    then
    ------ location ------
    if s_type == 'location'
        then
            table.insert( output, p.lua_link_part(s_page..'/Characters', 'Character(s) from '..s_page, 'Characters Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Nations', 'Nation(s) from '..s_page, 'Locations Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Sects', 'Sect(s) from '..s_page, 'Locations Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Places', 'Place(s) from '..s_page, 'Locations Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Races', 'Race(s) from '..s_page, 'Race Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Tribes', 'Tribe(s) from  '..s_page, 'Tribe Category Needed') )
    ------ tribe ------
    elseif s_type == 'tribe'
        then
            table.insert( output, p.lua_link_part(s_page, 'Representative(s) of '..s_page, 'Tribe Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Places', 'Place(s) from '..s_page, 'Locations Category Needed') )
    ------ race ------
    elseif s_type == 'race'
        then
            table.insert( output, p.lua_link_part(s_page, 'Representative(s) of '..s_page, 'Race Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Lineages', 'Lineage(s) of '..s_page, 'Locations Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Tribes', 'Tribe(s) of '..s_page, 'Tribe Category Needed') )
    ------ era ------
    elseif s_type == 'era'
        then
            table.insert( output, p.lua_link_part(s_page..'/Races', 'Race(s) from '..s_page, 'Race Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Characters', 'Character(s) from '..s_page, 'Characters Category Needed') )
            table.insert( output, p.lua_link_part(s_page..'/Locations', 'Location(s) from '..s_page, 'Locations Category Needed') )
            items = 'Item(s) from '..s_page
            techniques = 'Technique(s) from '..s_page
            events = 'Event(s) during '..s_page
    ------ cultivation type (physique, fate palace, etc.) ------
    elseif s_type == 'cultivation type'
        then
            table.insert( output, p.lua_link_part(s_page, 'Character(s) with '..s_page, 'Cultivators Category Needed') )

    ------ level (cultivation, alchemy, etc.) ------
    elseif s_type == 'level'
        then
            table.insert( output, p.lua_link_part(s_page, 'Character(s) at the '..s_page..' level', 'Cultivators Category Needed') )
    
    ------ techniques by type ------
    elseif s_type == 'techniques by type'
        then
            table.insert( output, p.lua_link_part(string.gsub(s_page,'Merit Laws','Techniques'), s_page, 'Techniques Category Needed') )
--[[    
    ------ items by type ------
    if s_type == 'items by type'
        then
            table.insert( output, p.lua_link_part(s_page, s_page, 'Items Category Needed') )
    end

    ------ techniques ------
    if s_type == 'techniques'
        then
            table.insert( output, p.lua_link_part(s_page, s_page, 'Techniques Category Needed') )
    end
--]]    
    ------ else ------
    else 
        table.insert( output, p.lua_link_part(s_page, s_page, 'Category Needed') )
    end

    table.insert( output, p.lua_link_part(s_page..'/Items', items, 'Items Category Needed') )
    table.insert( output, p.lua_link_part(s_page..'/Techniques', techniques, 'Techniques Category Needed') )
    table.insert( output, p.lua_link_part(s_page..'/Events', events, 'Events Category Needed') )
    table.insert( output, p.lua_link_part('Events in '..s_page, 'Event(s) that occurred in '..s_page, 'Events Category Needed') )
    table.insert( output, p.lua_link_part('Killed by '..s_page, 'character(s) killed by '..s_page, 'Killed by Category Needed') )
    table.insert( output, p.lua_link_part('Locations destroyed by '..s_page, 'location(s) destroyed by '..s_page, 'Destroyed by Category Needed') )
    table.insert( output, p.lua_link_part('Items destroyed by '..s_page, 'item(s) destroyed by '..s_page, 'Destroyed by Category Needed') )
    

    if not m.empty(output)
        then output = m.header('Links', 2)..table.concat(output)
        else output = ''
    end
    
    return output
end

function p.links(frame)
    local s1 = frame.args[1]
    local s2 = frame.args[2]
    if s2 ~= nil and s2 ~= ''
        then s2 = string.lower(s2)
        else s2 =''
    end
    
    return p.lua_links(s1, s2)
end

return p