Module:SiteList: Difference between revisions

From Porn Base Central
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
 
(75 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}

local sites = {
website1 = {
label = 'Website 1',
aliases = {'website1', 'website1.com', 'website1com'},
url = 'https://website1.com/',
updatesUrl = 'https://website1.com/updates/',
modelsUrl = 'https://website1.com/models/',
category = 'Website 1 models',
network = 'Network1 Network',
},
website2 = {
label = 'Website 2',
aliases = {'website2', 'website2.com', 'website2com'},
url = 'https://website2.com/',
updatesUrl = 'https://website2.com/scene/',
modelsUrl = 'https://website2.com/people/',
category = 'Website 2 models',
network = 'Network2 Network',
},
website3 = {
label = 'Website 3',
aliases = {'website3', 'website3.com', 'website3com'},
url = 'https://website3.com/',
updatesUrl = 'https://website3.com/videos/',
modelsUrl = 'https://website3.com/performers/',
category = 'Website 3 models',
network = 'Network3 Network',
},
website4 = {
label = 'Website 4',
aliases = {'website4', 'website4.com', 'website4com'},
url = 'https://website4.com/',
updatesUrl = 'https://website4.com/videos/',
modelsUrl = 'https://website4.com/performers/',
category = 'Website 4 models',
network = '',
},
}


function p.site(frame)
function p.site(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'})
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'})
local site = getSite(args.site)
local site, error = getSite(args.site)


if site then
if error then
return string.format('|-\n| colspan="4" style="text-align:center;vertical-align:middle;color:red;font-weight:bold;" | %s \n| style="width: 0px; padding: 0px; border: none;" |\n', error)
local url = site.url
if args.sceneid then
elseif site then
local url = site.url
url = site.updatesUrl .. args.sceneid .. '.html'
local isArchived = site.archived and (site.archived == 'yes' or site.archived == 'y')
elseif args.id then
local archiveNotice = isArchived and " <small>(''Website archived'')</small>" or ''
url = site.modelsUrl .. args.id .. '.html'
end
if isArchived and site.archiveURL and site.archiveURL ~= '' then
url = site.archiveURL
local alias = args.alias or mw.title.getCurrentTitle().text
elseif isArchived then
local notes = args.notes and '<small><span style="font-size: 0.875em;">' .. args.notes .. '</span></small>' or '<small><span>N/A</span></small><!-- comment -->'
url = ''
else
local categoryLink = site.network and site.network ~= '' and string.format(' <small>([[:Category:%s|%s]])</small>', site.network, site.network) or '<small><span>N/A</span></small>'
if url ~= '' then
if args.sceneid and site.sceneUrl ~= '' then
url = site.sceneUrl .. args.sceneid .. site.suffix
elseif args.id and site.modelUrl ~= '' then
url = site.modelUrl .. args.id .. site.suffix
end
end
end


local alias = args.alias or '<div style="font-size: 1em;">' .. mw.title.getCurrentTitle().text .. '</div>'
local notes = args.notes and '<div style="font-size: 1em;">' .. args.notes .. '</div>' or '<div style="font-size: 1em;">N/A</div>'
local categoryLink = site.network and site.network ~= '' and string.format(" <small>([[:Category:%s|'''%s''']])</small>", site.network, site.network) or ''
local siteType = site.sitetype or args[1]
local style
local style

if args[1] == 'Studio' then
if siteType == nil or siteType == '' then
style = 'background-color:#DADADA;text-align:center;color:black'
siteType = 'Invalid type'
style = 'background-color:#E7E7E7;text-align:center;color:red;font-weight:bold'
elseif siteType:lower() == 'studio' then
style = 'background-color:#DADADA;text-align:center;color:black;font-weight:bold'
else
else
style = 'background-color:#E7E7E7;text-align:center;color:black'
style = 'background-color:#E7E7E7;text-align:center;color:black;font-weight:bold'
end
end


local linkOrLabel
local result = string.format(
if url ~= '' then
'|-\n| style="%s" | <span>%s</span>\n| style="text-align:center;vertical-align:middle;" | <span>%s</span>\n| style="text-align:center;vertical-align:middle;" | <span>%s</span>\n| style="text-align:center;vertical-align:middle;" | %s<div style="display: none;">Hidden content</div>\n',
if site.idtonum and (site.idtonum == 'yes' or site.idtonum == 'y') and args.id then
style,
linkOrLabel = string.format('[%s %s #%s]%s', url, site.label, args.id, archiveNotice)
args[1] == 'Studio' and 'Studio' or 'Website',
else
string.format('[%s %s] <small>([[:Category:%s|%s]])</small>', url, site.label, site.category, site.category),
linkOrLabel = string.format('[%s %s]%s', url, site.label, archiveNotice)
alias,
notes
end
else
)
linkOrLabel = site.label .. archiveNotice
end


if site.list and site.list ~= '' then
local ns = mw.title.getCurrentTitle().namespace
linkOrLabel = linkOrLabel .. string.format(' ([[%s|LIST]])', site.list)
if ns == 0 then
result = result .. '[[Category:' .. site.category .. ']]'
result = result .. '[[Category:Articles in the mainspace using Template:SiteList]]'
elseif ns == 2 then
result = result .. '[[Category:Articles in the userspace using Template:SiteList]]'
elseif ns == 118 then
result = result .. '[[Category:Drafts using Template:SiteList]]'
end
end

local result = string.format(
'|-\n| style="%s" | %s\n| style="text-align:center;vertical-align:middle;" | %s%s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="width: 0px; padding: 0px; border: none;" |\n',
style,
siteType and siteType:gsub("^%l", string.upper) or 'Website',
linkOrLabel,
categoryLink,
alias,
notes
)

local ns = mw.title.getCurrentTitle().namespace
if ns == 0 then
if type(site.category) == "table" then
for _, cat in pairs(site.category) do
if cat ~= '' then
result = result .. '[[Category:' .. cat .. ']]'
end
end
elseif site.category ~= '' then
result = result .. '[[Category:' .. site.category .. ']]'
end
result = result .. '[[Category:Articles in the mainspace using Template:SiteList]]'
elseif ns == 2 then
result = result .. '[[Category:Articles in the userspace using Template:SiteList]]'
elseif ns == 118 then
result = result .. '[[Category:Drafts using Template:SiteList]]'
end


return result
return result
else
else
return string.format('|-\n| colspan="4" style="text-align:center;vertical-align:middle;color:red;font-weight:bold;" | Error: invalid site parameter: %s. See [[PBC:SiteList|PBC:SiteList for documentation]] \n| style="width: 0px; padding: 0px; border: none;" |\n', args.site)
return mw.text.nowiki('{{SiteList}}') .. ' Error: invalid site parameter'
end
end
end
end
Line 99: Line 100:


function getSite(name)
function getSite(name)
local firstLetter = name:sub(1, 1):upper()
for _, site in pairs(sites) do
local success, siteDictModule = pcall(require, 'Module:SiteDict/' .. firstLetter)
if site.label:lower() == name:lower() or table.contains(site.aliases, name:lower()) then

return site
if success then
local matchedSites = {}
for _, site in pairs(siteDictModule.sites) do
if site.label:lower() == name:lower() or table.contains(site.aliases, name:lower()) then
table.insert(matchedSites, site)
end
end
end

if #matchedSites > 1 then
return nil, 'Error: Duplicate sites found in module. Please check the module for errors.'
elseif #matchedSites == 1 then
return matchedSites[1]
end
else
mw.log('Could not load module: ' .. 'Module:SiteDict/' .. firstLetter)
end
end

return nil
return nil
end
end

Latest revision as of 12:03, 23 July 2023

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

local p = {}

function p.site(frame)
    local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'})
    local site, error = getSite(args.site)

    if error then
        return string.format('|-\n| colspan="4" style="text-align:center;vertical-align:middle;color:red;font-weight:bold;" | %s \n| style="width: 0px; padding: 0px; border: none;" |\n', error)
    elseif site then
        local url = site.url
        local isArchived = site.archived and (site.archived == 'yes' or site.archived == 'y')
        local archiveNotice = isArchived and " <small>(''Website archived'')</small>" or ''
        
        if isArchived and site.archiveURL and site.archiveURL ~= '' then
            url = site.archiveURL
        elseif isArchived then
            url = ''
        else
            if url ~= '' then
                if args.sceneid and site.sceneUrl ~= '' then
                    url = site.sceneUrl .. args.sceneid .. site.suffix
                elseif args.id and site.modelUrl ~= '' then
                    url = site.modelUrl .. args.id .. site.suffix
                end
            end
        end

        local alias = args.alias or '<div style="font-size: 1em;">' .. mw.title.getCurrentTitle().text .. '</div>'
        local notes = args.notes and '<div style="font-size: 1em;">' .. args.notes .. '</div>' or '<div style="font-size: 1em;">N/A</div>'
        local categoryLink = site.network and site.network ~= '' and string.format(" <small>([[:Category:%s|'''%s''']])</small>", site.network, site.network) or ''
        local siteType = site.sitetype or args[1]
        local style

        if siteType == nil or siteType == '' then
            siteType = 'Invalid type'
            style = 'background-color:#E7E7E7;text-align:center;color:red;font-weight:bold'
        elseif siteType:lower() == 'studio' then
            style = 'background-color:#DADADA;text-align:center;color:black;font-weight:bold'
        else
            style = 'background-color:#E7E7E7;text-align:center;color:black;font-weight:bold'
        end

        local linkOrLabel
        if url ~= '' then
            if site.idtonum and (site.idtonum == 'yes' or site.idtonum == 'y') and args.id then
                linkOrLabel = string.format('[%s %s #%s]%s', url, site.label, args.id, archiveNotice)
            else
                linkOrLabel = string.format('[%s %s]%s', url, site.label, archiveNotice)
            end
        else
            linkOrLabel = site.label .. archiveNotice
        end

        if site.list and site.list ~= '' then
            linkOrLabel = linkOrLabel .. string.format(' ([[%s|LIST]])', site.list)
        end

        local result = string.format(
            '|-\n| style="%s" | %s\n| style="text-align:center;vertical-align:middle;" | %s%s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="width: 0px; padding: 0px; border: none;" |\n',
            style,
            siteType and siteType:gsub("^%l", string.upper) or 'Website',
            linkOrLabel,
            categoryLink,
            alias,
            notes
        )

		local ns = mw.title.getCurrentTitle().namespace
		if ns == 0 then
		    if type(site.category) == "table" then
		        for _, cat in pairs(site.category) do
		            if cat ~= '' then
		                result = result .. '[[Category:' .. cat .. ']]'
		            end
		        end
		    elseif site.category ~= '' then
		        result = result .. '[[Category:' .. site.category .. ']]'
		    end
		    result = result .. '[[Category:Articles in the mainspace using Template:SiteList]]'
		elseif ns == 2 then
		    result = result .. '[[Category:Articles in the userspace using Template:SiteList]]'
		elseif ns == 118 then
		    result = result .. '[[Category:Drafts using Template:SiteList]]'
		end

        return result
    else
        return string.format('|-\n| colspan="4" style="text-align:center;vertical-align:middle;color:red;font-weight:bold;" | Error: invalid site parameter: %s. See [[PBC:SiteList|PBC:SiteList for documentation]] \n| style="width: 0px; padding: 0px; border: none;" |\n', args.site)
    end
end

function table.contains(table, element)
  for _, value in pairs(table) do
    if value == element then
      return true
    end
  end
  return false
end

function getSite(name)
    local firstLetter = name:sub(1, 1):upper()
    local success, siteDictModule = pcall(require, 'Module:SiteDict/' .. firstLetter)

    if success then
        local matchedSites = {}
        for _, site in pairs(siteDictModule.sites) do
            if site.label:lower() == name:lower() or table.contains(site.aliases, name:lower()) then
                table.insert(matchedSites, site)
            end
        end

        if #matchedSites > 1 then
            return nil, 'Error: Duplicate sites found in module. Please check the module for errors.'
        elseif #matchedSites == 1 then
            return matchedSites[1]
        end
    else
        mw.log('Could not load module: ' .. 'Module:SiteDict/' .. firstLetter)
    end

    return nil
end

return p