Jump to content

Module:Message box

From HopperWiki

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

local getArgs = require('Module:Arguments').getArgs -- for processing arguments



local p = {}


function p.incomplete(frame)
	local get_args = require('Module:Arguments').getArgs
	local args = get_args(frame)
	local item = args.item or "page"
	local width = args.width or '50%'
	local reason = args.reason or ''
	local image = args.image or "Mediawiki_exclamation_black.png"

	-- Normalize reason to title case
	local flavor = reason:lower():gsub("^(%l)", string.upper)
	if flavor == '' then
		flavor = 'Default'
	end

	-- Build transclusion string with item passed in
	local subpage_title = 'Incomplete/' .. flavor
	local message = string.format('{{%s|item=%s}}', subpage_title, item)

	local success, rendered_message = pcall(function()
		return frame:preprocess(message)
	end)

	if not success then
		rendered_message = "'''This " .. item .. " is incomplete.''' If you have relevant information, please contribute or [[Hopperwiki:About#Who manages HopperWiki?|contact an administrator]]."
	end

	-- Styling lives in MediaWiki:Common.css (.hw-notice / .hw-notice--warning),
	-- themed via the --hw-notice-warning-* tokens so it stays legible in dark mode.
	local container = mw.html.create('div')
		:addClass('hw-notice hw-notice--warning')
		:css{ ['width'] = width }

	container:tag('div')
		:addClass('hw-notice__icon')
		:wikitext(string.format("[[File:%s|frameless|none|50px|alt=Placeholder image]]", image))

	container:tag('div')
		:addClass('hw-notice__body')
		:wikitext(rendered_message)

	return tostring(container)
end





















-- Friendly "this page is built from data and needs a human write-up" box ({{Awaiting write-up}}).
-- article_type= picks the wording from a subpage (Template:Awaiting write-up/<Type>), so each kind of
-- article can say how people can help with THAT kind of content; unknown/missing types fall back to Default.
function p.awaiting_write_up(frame)
	local args = getArgs(frame)
	local item = args.item or "page"
	local width = args.width or '50%'

	local flavor = (args.article_type or ''):lower():gsub("^(%l)", string.upper)
	if flavor == '' then
		flavor = 'Default'
	end

	local subpage = mw.title.new('Template:Awaiting write-up/' .. flavor)
	if not (subpage and subpage.exists) then
		flavor = 'Default'
	end

	local default_images = { Species = "Species icon.png" }
	local image = args.image or default_images[flavor] or "Mediawiki_exclamation_black.png"

	local message = string.format('{{Awaiting write-up/%s|item=%s}}', flavor, item)
	local success, rendered_message = pcall(function()
		return frame:preprocess(message)
	end)

	if not success then
		rendered_message = "'''This " .. item .. " is awaiting a write-up.''' If you have relevant expertise, please contribute or [[Hopperwiki:About#Who manages HopperWiki?|contact an administrator]]."
	end

	-- Styling lives in MediaWiki:Common.css (.hw-notice / .hw-notice--help), themed via the --hw-notice-help-* tokens.
	local container = mw.html.create('div')
		:addClass('hw-notice hw-notice--help')
		:css{ ['width'] = width }

	-- icon_size= overrides the default; the help box runs bigger than Incomplete's so the species icon is legible
	local icon_size = args.icon_size or "70px"
	container:tag('div')
		:addClass('hw-notice__icon')
		:wikitext(string.format("[[File:%s|frameless|none|%s|alt=]]", image, icon_size))

	container:tag('div')
		:addClass('hw-notice__body')
		:wikitext(rendered_message)

	return tostring(container)
end





-- function to create a general message box
function p.message(frame)
    local args = getArgs(frame)
    local width = args.width or '50%'
    local message = args.message
    local image = args.image or "Mediawiki_exclamation_black.png" -- placeholder for default image

    -- Styling lives in MediaWiki:Common.css (.hw-notice / .hw-notice--warning),
    -- themed via the --hw-notice-warning-* tokens so it stays legible in dark mode.
    local container = mw.html.create('div')
        :addClass('hw-notice hw-notice--warning')
        :css{ ['width'] = width }

    container:tag('div')
        :addClass('hw-notice__icon')
        :wikitext(string.format("[[File:%s|frameless|none|50px|alt=Placeholder image]]", image))

    container:tag('div')
        :addClass('hw-notice__body')
        :wikitext(message)

    return tostring(container)
end



























--[[ This function leaves a breadcrumb trail with a person's real name that can be placed onto a user page 
For a given user page inquiries cargo and obtains the real name for that person to provide on the user page with an info box--]]
function p.get_person_for_user(frame)
	local args = getArgs(frame)
    local item = args.item or "page"
    local width = args.width or '50%'
    local reason = args.reason
    local admin_link = "Hopperwiki:About#Who manages HopperWiki?"
    local image = args.image or "Mediawiki_exclamation_black.png" -- placeholder for default image

    -- Styling lives in MediaWiki:Common.css (.hw-notice / .hw-notice--warning),
    -- themed via the --hw-notice-warning-* tokens so it stays legible in dark mode.
    local container = mw.html.create('div')
        :addClass('hw-notice hw-notice--warning')
        :css{ ['width'] = width }

    container:tag('div')
        :addClass('hw-notice__icon')
        :wikitext(string.format("[[File:%s|frameless|none|50px|alt=Placeholder image]]", image))

    local contentContainer = container:tag('div')
        :addClass('hw-notice__body')

    if args.reason == "references" or args.reason == "reference" then
        contentContainer:wikitext(string.format(
            "'''This %s needs supporting references!''' If you have expertise or materials on this topic that you are willing to contribute, [[Hopperwiki:About#Who manages HopperWiki?|please get in touch with an administrator]].",
            item
        ))
    elseif args.reason == "photos" or args.reason == "photo" then
        contentContainer:wikitext(string.format(
            "'''This %s needs additional photos!''' If you have any relevant photos to contribute, [[Hopperwiki:About#Who manages HopperWiki?|please get in touch with an administrator]].",
            item
        ))
    elseif not args.reason then
        contentContainer:wikitext(string.format(
            "'''This %s is incomplete and lacking information and resources!''' If you have any to contribute, [[Hopperwiki:About#Who manages HopperWiki?|please get in touch with an administrator]].",
            item
        ))    
    end
    

    return tostring(container)
end





return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.