Jump to content

Module:Archives

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Izno (talk | contribs) at 21:16, 15 August 2021 (ok, is search_box done?). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
p = {}

-- simple helper for simple cases
local function var_or_default(var, default)
	if var and var ~= '' then
		return var
	else
		return default
	end
end

local function talk_other(demospace, talk)
	if demospace and demospace ~= '' then return demospace end
	
	if mw.title.getCurrentTitle().isTalkPage then return talk end
	
	return nil -- just return nil rather than 'other' since we have no need
end

local function image(builder)
	
end

local function archive_list(builder)
	
end

local function make_title(builder)


end

local function search_box(frame, is_banner, root, search)

	if search.search and search.search == 'no' then return nil end
	
	local prefix = ''
	if search.prefix and search.prefix ~= '' then
		prefix = search.prefix
	-- this double-check elseif may move out to code-proper
	elseif root and root ~= '' then
		search.prefix = root
	else
		search.prefix = mw.title.getCurrentTitle().prefixedText .. '/'
	end
	
	-- break
	local sbreak
	if search.sbreak and (search.sbreak == 'yes' or search.sbreak == 'no') then
		sbreak = search.sbreak
	end
	-- set sbreak's default
	if not sbreak then
		if is_banner then
			sbreak = 'no'
		else
			sbreak = 'yes'
		end
	end
	
	-- width
	local width = ''
	if not is_banner then
		width = var_or_default(search.width, '22')
	end
	
	-- label
	local label = var_or_default(search.label, 'Search archives')
	
	local inputbox_options = {
		['bgcolor'] = 'transparent',
		['type'] = 'fulltext',
		['prefix'] = prefix,
		['break'] = sbreak,
		['width'] = width,
		['searchbuttonlabel'] = label
	}
	
	local inputbox_content = ''
	for k, v in pairs(inputbox_options) do
		inputbox_content = inputbox_content .. '\n' .. k .. '=' .. v
	end
		
	local inputbox = frame:extensionTag{
		name = 'inputbox',
		content = inputbox_content
	}	

	local div = mw.html.create('div')
	div
		:addClass('archives-search')
		:wikitext(inputbox)
	
	return div
end
--[[
pass the frame down for a minute because we do a lot of work with a frame

]]
function p._main(args, frame)
	local frame = frame -- data continuity
	local list = args.list
	local list1 = args[1]
	local auto = args.auto
	local root = args.root
	local box_width = args['box-width']
	local image = args.image
	local image_alt = args.alt
	local image_link = args.link
	local image_size = args['image-size']
	local collapsed = args.collapsed
	local collapsible = args.collapsible
	local title = args.title
	local archive_list = args.archivelist
	

	local is_banner = false
	if (args.banner and args.banner == 'yes') or (args.large and args.large == 'yes') then
		is_banner = true
	end
	
	local demospace
	if args.demospace and args.demospace ~= '' then
		demospace = args.demospace
	end
	
	local archives = mw.html.create()
	archives
		:tag('div')
			:addClass('archives plainlinks')
			-- banner is roughly mbox, small is roughly mbox-small
			:addClass(is_banner and 'archives-banner' or 'archives-small')
			-- archives-talk has same-ish styles as tmbox tmbox-notice
			-- base styles are same-ish as ombox ombox-notice
			:addClass(talk_other(demospace, 'archives-talk'))
			
			:node(search_box(frame, is_banner, root, {
				search = args.search,
				prefix = args.prefix,
				width = args['search-width'],
				sbreak = args['search-break'],
				label = args['search-button-label']
			}))

	return tostring(archives)
	
end

function p.main(frame)
	return p._main(require('Module:Arguments').getArgs(frame), frame)
end

return p