Module:Yesno and Module:Message box/configuration: Difference between pages

From Frontierpedia, the Microsoft Agent encyclopedia
(Difference between pages)
en>Mr. Stradivarius
(tweak logic to make it work like the actual template - the documentation was slightly wrong)
 
en>Mr. Stradivarius
(allow the hidden arg to be blank, and allow tmbox to have an id attribute, per protected edit request by User:Technical 13)
 
Line 1: Line 1:
local p = {}
local ambox = {
types = {
speedy = {
class = 'ambox-speedy',
image = 'Ambox speedy deletion.png'
},
delete = {
class = 'ambox-delete',
image = 'Ambox deletion.png'
},
content = {
class = 'ambox-content',
image = 'Ambox content.png'
},
style = {
class = 'ambox-style',
image = 'Edit-clear.svg'
},
move = {
class = 'ambox-move',
image = 'Ambox move.png'
},
protection = {
class = 'ambox-protection',
image = 'Ambox protection.png'
},
notice = {
class = 'ambox-notice',
image = 'Ambox notice.png'
}
},
default                    = 'notice',
allowBlankParams            = {'talk', 'sect', 'date', 'issue', 'fix', 'subst', 'hidden'},
allowSmall                  = true,
smallParam                  = 'left',
smallClass                  = 'mbox-small-left',
substCheck                  = true,
classes                    = {'metadata', 'plainlinks', 'ambox'},
imageEmptyCell              = true,
imageCheckBlank            = true,
imageSmallSize              = '20x20px',
imageCellDiv                = true,
useCollapsibleTextFields    = true,
imageRightNone              = true,
sectionDefault              = 'article',
allowMainspaceCategories    = true,
templateCategory            = 'Article message templates',
        templateCategoryRequireName = true,
templateErrorCategory      = 'Article message templates with missing parameters',
templateErrorParamsToCheck  = {'issue', 'fix', 'subst'}
}


function p.yesno(frame)
local cmbox = {
types = {
speedy = {
class = 'cmbox-speedy',
image = 'Cmbox deletion.png'
},
delete = {
class = 'cmbox-delete',
image = 'Cmbox deletion.png'
},
content = {
class = 'cmbox-content',
image = 'Cmbox content.png'
},
style = {
class = 'cmbox-style',
image = 'Edit-clear.svg'
},
move = {
class = 'cmbox-move',
image = 'Cmbox move.png'
},
protection = {
class = 'cmbox-protection',
image = 'Cmbox protection.png'
},
notice = {
class = 'cmbox-notice',
image = 'Cmbox notice.png'
}
},
default              = 'notice',
showInvalidTypeError = true,
classes              = {'plainlinks', 'cmbox'},
imageEmptyCell      = true
}


    -- defaults
local fmbox = {
    local retvals = {
types = {
        yes  = "yes",
warning = {
        no    = "",
class = 'fmbox-warning',
        ["¬"] = ""
image = 'Cmbox deletion.png'
    }
},
editnotice = {
class = 'fmbox-editnotice',
image = 'Imbox notice.png'
},
system = {
class = 'fmbox-system',
image = 'Imbox notice.png'
}
},
default              = 'system',
showInvalidTypeError = true,
allowId                = true,
classes              = {'plainlinks', 'fmbox'},
imageEmptyCell      = false,
imageRightNone      = false
}


    -- Allow arguments to override defaults.
local imbox = {
    -- 'any' tracks the presence of any arguments at all.
types = {
    local args = frame.args
speedy = {
    local any = false
class = 'imbox-speedy',
    for k,v in pairs(args) do
image = 'Imbox speedy deletion.png'
        any = true
},
        retvals[k] = v
delete = {
    end
class = 'imbox-delete',
    -- If there are no arguments, try and get them from the parent frame.
image = 'Imbox deletion.png'
    if any == false then
},
        local pframe = frame:getParent()
content = {
        args = pframe.args
class = 'imbox-content',
        for k,v in pairs(args) do
image = 'Imbox content.png'
            any = true
},
            retvals[k] = v
style = {
        end
class = 'imbox-style',
     end   
image = 'Edit-clear.svg'
},
move = {
class = 'imbox-move',
image = 'Imbox move.png'
},
protection = {
class = 'imbox-protection',
image = 'Imbox protection.png'
},
license = {
class = 'imbox-license',
image = 'Imbox license.png'
},
featured = {
class = 'imbox-featured',
image = 'Imbox featured.png'
},
notice = {
class = 'imbox-notice',
image = 'Imbox notice.png'
}
},
default              = 'notice',
showInvalidTypeError = true,
classes              = {'imbox'},
usePlainlinksParam  = true,
imageEmptyCell      = true,
below                = true,
templateCategory     = 'File message boxes'
}


    val = args[1]
local ombox = {
types = {
speedy = {
class = 'ombox-speedy',
image = 'Imbox speedy deletion.png'
},
delete = {
class = 'ombox-delete',
image = 'Imbox deletion.png'
},
content = {
class = 'ombox-content',
image = 'Imbox content.png'
},
style = {
class = 'ombox-style',
image = 'Edit-clear.svg'
},
move = {
class = 'ombox-move',
image = 'Imbox move.png'
},
protection = {
class = 'ombox-protection',
image = 'Imbox protection.png'
},
notice = {
class = 'ombox-notice',
image = 'Imbox notice.png'
}
},
default              = 'notice',
showInvalidTypeError = true,
classes              = {'plainlinks', 'ombox'},
allowSmall          = true,
imageEmptyCell      = true,
imageRightNone      = true
}


    -- First deal with the case if val is nil, then deal with other cases.
local tmbox = {
    if val == nil then
types = {
        return retvals['¬']
speedy = {
     end
class = 'tmbox-speedy',
image = 'Imbox speedy deletion.png'
},
delete = {
class = 'tmbox-delete',
image = 'Imbox deletion.png'
},
content = {
class = 'tmbox-content',
image = 'Imbox content.png'
},
style = {
class = 'tmbox-style',
image = 'Edit-clear.svg '
},
move = {
class = 'tmbox-move',
image = 'Imbox move.png'
},
protection = {
class = 'tmbox-protection',
image = 'Imbox protection.png'
},
notice = {
class = 'tmbox-notice',
image = 'Imbox notice.png'
}
},
default              = 'notice',
showInvalidTypeError = true,
classes              = {'plainlinks', 'tmbox'},
allowId              = true,
allowSmall          = true,
imageRightNone      = true,
imageEmptyCell      = true,
imageEmptyCellStyle  = true,
templateCategory     = 'Talk message boxes'
}


    val = val:lower()          -- Coerce to blank if nil; make lowercase.
return {
    val = val:match'^%s*(.*%S)' or ''  -- Trim whitespace.
ambox = ambox,
 
cmbox = cmbox,
    if val == '' then
fmbox = fmbox,
        return retvals['blank'] or retvals['no']
imbox = imbox,
    elseif val == 'n' or val == 'no'  or val == '0' then
ombox = ombox,
        return retvals['no']
tmbox = tmbox
    elseif val == 'y' or val == 'yes' or val == '1' or retvals['def'] == nil then
}
        return retvals['yes']
    else
        return retvals['def']
    end
end
 
return p

Revision as of 01:07, 27 January 2014

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

local ambox = {
	types = {
		speedy = {
			class = 'ambox-speedy',
			image = 'Ambox speedy deletion.png'
		},
		delete = {
			class = 'ambox-delete',
			image = 'Ambox deletion.png'
		},
		content = {
			class = 'ambox-content',
			image = 'Ambox content.png'
		},
		style = {
			class = 'ambox-style',
			image = 'Edit-clear.svg'
		},
		move = {
			class = 'ambox-move',
			image = 'Ambox move.png'
		},
		protection = {
			class = 'ambox-protection',
			image = 'Ambox protection.png'
		},
		notice = {
			class = 'ambox-notice',
			image = 'Ambox notice.png'
		}
	},
	default                     = 'notice',
	allowBlankParams            = {'talk', 'sect', 'date', 'issue', 'fix', 'subst', 'hidden'},
	allowSmall                  = true,
	smallParam                  = 'left',
	smallClass                  = 'mbox-small-left',
	substCheck                  = true,
	classes                     = {'metadata', 'plainlinks', 'ambox'},
	imageEmptyCell              = true,
	imageCheckBlank             = true,
	imageSmallSize              = '20x20px',
	imageCellDiv                = true,
	useCollapsibleTextFields    = true,
	imageRightNone              = true,
	sectionDefault              = 'article',
	allowMainspaceCategories    = true,
	templateCategory            = 'Article message templates',
        templateCategoryRequireName = true,
	templateErrorCategory       = 'Article message templates with missing parameters',
	templateErrorParamsToCheck  = {'issue', 'fix', 'subst'}
}

local cmbox = {
	types = {
		speedy = {
			class = 'cmbox-speedy',
			image = 'Cmbox deletion.png'
		},
		delete = {
			class = 'cmbox-delete',
			image = 'Cmbox deletion.png'
		},
		content = {
			class = 'cmbox-content',
			image = 'Cmbox content.png'
		},
		style = {
			class = 'cmbox-style',
			image = 'Edit-clear.svg'
		},
		move = {
			class = 'cmbox-move',
			image = 'Cmbox move.png'
		},
		protection = {
			class = 'cmbox-protection',
			image = 'Cmbox protection.png'
		},
		notice = {
			class = 'cmbox-notice',
			image = 'Cmbox notice.png'
		}
	},
	default              = 'notice',
	showInvalidTypeError = true,
	classes              = {'plainlinks', 'cmbox'},
	imageEmptyCell       = true
}

local fmbox = {
	types = {
		warning = {
			class = 'fmbox-warning',
			image = 'Cmbox deletion.png'
		},
		editnotice = {
			class = 'fmbox-editnotice',
			image = 'Imbox notice.png'
		},
		system = {
			class = 'fmbox-system',
			image = 'Imbox notice.png'
		}
	},
	default              = 'system',
	showInvalidTypeError = true,
	allowId                = true,
	classes              = {'plainlinks', 'fmbox'},
	imageEmptyCell       = false,
	imageRightNone       = false
}

local imbox = {
	types = {
		speedy = {
			class = 'imbox-speedy',
			image = 'Imbox speedy deletion.png'
		},
		delete = {
			class = 'imbox-delete',
			image = 'Imbox deletion.png'
		},
		content = {
			class = 'imbox-content',
			image = 'Imbox content.png'
		},
		style = {
			class = 'imbox-style',
			image = 'Edit-clear.svg'
		},
		move = {
			class = 'imbox-move',
			image = 'Imbox move.png'
		},
		protection = {
			class = 'imbox-protection',
			image = 'Imbox protection.png'
		},
		license = {
			class = 'imbox-license',
			image = 'Imbox license.png'
		},
		featured = {
			class = 'imbox-featured',
			image = 'Imbox featured.png'
		},
		notice = {
			class = 'imbox-notice',
			image = 'Imbox notice.png'
		}
	},
	default              = 'notice',
	showInvalidTypeError = true,
	classes              = {'imbox'},
	usePlainlinksParam   = true,
	imageEmptyCell       = true,
	below                = true,
	templateCategory     = 'File message boxes'
}

local ombox = {
	types = {
		speedy = {
			class = 'ombox-speedy',
			image = 'Imbox speedy deletion.png'
		},
		delete = {
			class = 'ombox-delete',
			image = 'Imbox deletion.png'
		},
		content = {
			class = 'ombox-content',
			image = 'Imbox content.png'
		},
		style = {
			class = 'ombox-style',
			image = 'Edit-clear.svg'
		},
		move = {
			class = 'ombox-move',
			image = 'Imbox move.png'
		},
		protection = {
			class = 'ombox-protection',
			image = 'Imbox protection.png'
		},
		notice = {
			class = 'ombox-notice',
			image = 'Imbox notice.png'
		}
	},
	default              = 'notice',
	showInvalidTypeError = true,
	classes              = {'plainlinks', 'ombox'},
	allowSmall           = true,
	imageEmptyCell       = true,
	imageRightNone       = true
}

local tmbox = {
	types = {
		speedy = {
			class = 'tmbox-speedy',
			image = 'Imbox speedy deletion.png'
		},
		delete = {
			class = 'tmbox-delete',
			image = 'Imbox deletion.png'
		},
		content = {
			class = 'tmbox-content',
			image = 'Imbox content.png'
		},
		style = {
			class = 'tmbox-style',
			image = 'Edit-clear.svg '
		},
		move = {
			class = 'tmbox-move',
			image = 'Imbox move.png'
		},
		protection = {
			class = 'tmbox-protection',
			image = 'Imbox protection.png'
		},
		notice = {
			class = 'tmbox-notice',
			image = 'Imbox notice.png'
		}
	},
	default              = 'notice',
	showInvalidTypeError = true,
	classes              = {'plainlinks', 'tmbox'},
	allowId              = true,
	allowSmall           = true,
	imageRightNone       = true,
	imageEmptyCell       = true,
	imageEmptyCellStyle  = true,
	templateCategory     = 'Talk message boxes'
}

return {
	ambox = ambox,
	cmbox = cmbox,
	fmbox = fmbox,
	imbox = imbox,
	ombox = ombox,
	tmbox = tmbox
}