Module:BioboxSharing
Documentation for this module may be created at Module:BioboxSharing/doc
local p = {}
local sitesModule = require('Module:BioboxSharing/sites')
local sites = sitesModule.sites
local siteOrder = sitesModule.siteOrder
local PBD = require('Module:PBD')
local PBDIB = require('Module:PornBaseDataIB')
local function isEmpty(value)
return value == nil or value == ''
end
local function formatField(state, label, value, fieldName, rowIndex, category)
if isEmpty(value) then
return ''
end
local rowStyle = state:getRowStyle(rowIndex)
local categoryCode = ''
if category and mw.title.getCurrentTitle().namespace == 0 then
categoryCode = string.format('[[%s]]', category)
end
return string.format('|-\n! style="%s %s" | \'\'\'%s\'\'\'\n| style="%s text-align:left; max-width: 100px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | %s%s',
rowStyle,
state.STYLES.LABEL,
label,
rowStyle,
value,
categoryCode)
end
function collectParametersWithSuffixes(args, paramBase, maxCount)
local values = {}
maxCount = tonumber(maxCount) or 4
for i = 1, maxCount do
local suffix = i > 1 and i or ""
local paramName = paramBase .. suffix
if not isEmpty(args[paramName]) then
table.insert(values, args[paramName])
end
end
return values
end
function p.formatSite(state, args, siteConfig, rowIndex)
local section = {}
local values = {}
if siteConfig.paramBase then
values = collectParametersWithSuffixes(
args,
siteConfig.paramBase,
siteConfig.maxCount
)
end
if #values == 0 and args.qid then
local entity = mw.wikibase.getEntity(args.qid)
if siteConfig.pbdProps then
for _, pbdProp in ipairs(siteConfig.pbdProps) do
if entity and entity.claims and entity.claims[pbdProp] then
for _, statement in ipairs(entity.claims[pbdProp]) do
if statement.mainsnak.snaktype == "value" and
statement.mainsnak.datavalue then
local id
if statement.mainsnak.datavalue.type == "string" then
id = statement.mainsnak.datavalue.value
elseif statement.mainsnak.datavalue.type == "wikibase-entityid" then
id = statement.mainsnak.datavalue.value.id
end
if id then
table.insert(values, {id = id, pbdProp = pbdProp})
end
end
end
end
end
end
end
if #values > 0 then
local displayValues = {}
for _, entry in ipairs(values) do
local id, pbdProp
if type(entry) == "table" then
id = entry.id
pbdProp = entry.pbdProp
else
id = entry
end
local urlFormat = siteConfig.urlFormat
local url = urlFormat:format(id)
if siteConfig.suffix then
url = url .. siteConfig.suffix
end
local displayValue = string.format('[%s %s]', url, id)
table.insert(displayValues, displayValue)
end
local combinedDisplay = table.concat(displayValues, '<br>')
local label
if siteConfig.labelFunc then
label = siteConfig.labelFunc()
else
local frame = mw.getCurrentFrame()
label = frame:expandTemplate{ title = 'abbr', args = { siteConfig.abbr, siteConfig.label } }
end
section[#section + 1] = formatField(state, label, combinedDisplay, siteConfig.name, rowIndex, siteConfig.category)
rowIndex = rowIndex + 1
end
return section, rowIndex
end
function p.formatFapHouse(state, args, rowIndex)
local section = {}
local faphouse_model = sites.faphouse_model
local faphouse_pornstar = sites.faphouse_pornstar
local model_values = {}
local pornstar_values = {}
if faphouse_model.paramBase then
model_values = collectParametersWithSuffixes(
args,
faphouse_model.paramBase,
faphouse_model.maxCount
)
end
if faphouse_pornstar.paramBase then
pornstar_values = collectParametersWithSuffixes(
args,
faphouse_pornstar.paramBase,
faphouse_pornstar.maxCount
)
end
if #model_values == 0 and #pornstar_values == 0 and args.qid then
local entity = mw.wikibase.getEntity(args.qid)
if faphouse_model.pbdProps and entity and entity.claims then
for _, pbdProp in ipairs(faphouse_model.pbdProps) do
if entity.claims[pbdProp] then
for _, statement in ipairs(entity.claims[pbdProp]) do
if statement.mainsnak.snaktype == "value" and
statement.mainsnak.datavalue then
local id
if statement.mainsnak.datavalue.type == "string" then
id = statement.mainsnak.datavalue.value
elseif statement.mainsnak.datavalue.type == "wikibase-entityid" then
id = statement.mainsnak.datavalue.value.id
end
if id then
table.insert(model_values, {id = id, pbdProp = pbdProp, type = "model"})
end
end
end
end
end
end
if faphouse_pornstar.pbdProps and entity and entity.claims then
for _, pbdProp in ipairs(faphouse_pornstar.pbdProps) do
if entity.claims[pbdProp] then
for _, statement in ipairs(entity.claims[pbdProp]) do
if statement.mainsnak.snaktype == "value" and
statement.mainsnak.datavalue then
local id
if statement.mainsnak.datavalue.type == "string" then
id = statement.mainsnak.datavalue.value
elseif statement.mainsnak.datavalue.type == "wikibase-entityid" then
id = statement.mainsnak.datavalue.value.id
end
if id then
table.insert(pornstar_values, {id = id, pbdProp = pbdProp, type = "pornstar"})
end
end
end
end
end
end
end
if #model_values > 0 or #pornstar_values > 0 then
local displayValues = {}
for _, entry in ipairs(model_values) do
local id, pbdProp, entryType
if type(entry) == "table" then
id = entry.id
pbdProp = entry.pbdProp
entryType = entry.type
else
id = entry
entryType = "model"
end
local urlFormat = faphouse_model.urlFormat
local url = urlFormat:format(id)
if faphouse_model.suffix then
url = url .. faphouse_model.suffix
end
local displayValue = string.format('[%s %s]', url, id)
table.insert(displayValues, displayValue)
end
for _, entry in ipairs(pornstar_values) do
local id, pbdProp, entryType
if type(entry) == "table" then
id = entry.id
pbdProp = entry.pbdProp
entryType = entry.type
else
id = entry
entryType = "pornstar"
end
local urlFormat = faphouse_pornstar.urlFormat
local url = urlFormat:format(id)
if faphouse_pornstar.suffix then
url = url .. faphouse_pornstar.suffix
end
local displayValue = string.format('[%s %s]', url, id)
table.insert(displayValues, displayValue)
end
local combinedDisplay = table.concat(displayValues, '<br>')
local label
local frame = mw.getCurrentFrame()
label = frame:expandTemplate{ title = 'abbr', args = { faphouse_model.abbr, faphouse_model.label } }
section[#section + 1] = formatField(state, label, combinedDisplay, "faphouse", rowIndex, faphouse_model.category)
rowIndex = rowIndex + 1
end
return section, rowIndex
end
function p.formatSharingSection(state, args, rowIndex)
local section = {}
local sharingSections = {}
local hasAny = false
local faphouseSection, newRowIndex = p.formatFapHouse(state, args, rowIndex)
if #faphouseSection > 0 then
hasAny = true
for _, line in ipairs(faphouseSection) do
sharingSections[#sharingSections + 1] = line
end
rowIndex = newRowIndex
end
for _, siteName in ipairs(siteOrder) do
if siteName ~= "faphouse_model" and siteName ~= "faphouse_pornstar" then
local config = sites[siteName]
if config then
local siteSection, newRowIndex = p.formatSite(state, args, config, rowIndex)
if #siteSection > 0 then
hasAny = true
for _, line in ipairs(siteSection) do
sharingSections[#sharingSections + 1] = line
end
rowIndex = newRowIndex
end
end
end
end
if hasAny then
section[#section + 1] = string.format('|-\n! colspan="2" %s | \'\'\'Porn sharing\'\'\'', state.STYLES.SECTION_HEADER)
for _, line in ipairs(sharingSections) do
section[#section + 1] = line
end
end
return section, rowIndex
end
return p