Module:DefinitionCategory

local p = {}

local priv = {}

--Private functions function priv.isNull( arg ) return ( arg == nil or arg == "" ) end

function priv.defPage( def, cat ) local defPage if priv.isNull( def ) then defPage = "Definition:" .. cat elseif ( string.match( def, ":" ) == nil ) then defPage = "Definition:" .. def else defPage = def end return defPage end

function priv.defDisp( def, disp, cat ) local defDisp if not priv.isNull( disp ) then defDisp = disp elseif not priv.isNull( def ) then defDisp = string.gsub( def, "^[^:]*:", "") else defDisp = cat end return defDisp end

function priv.defCat( cat, sortkey ) return "" end

function priv.initVars( frame ) local vars = {} local fullTitle = mw.title.getCurrentTitle.text vars.category  = string.gsub( fullTitle, '^[^/]*/', "" ) vars.tpl_args  = frame:getParent.args --Support passing nocat/notrans at the invoke level as well (for DefinitionCategoryNocat/Notrans) vars.tpl_args.nocat  = vars.tpl_args.nocat or frame.args.nocat vars.tpl_args.notrans = vars.tpl_args.notrans or frame.args.notrans return vars end

--Public functions (that is, main entry points) function p.main( frame ) local vars = priv.initVars( frame ) local tpl_args = vars.tpl_args local category = vars.category --[=[ defPage: Definition page link. def contains a ":"  " " def contains no ":" "Definition: " Default:            "Definition: " ]=] local defPage = priv.defPage( tpl_args.def, category ) --[=[ defDisp: Display part of definition page link disp exists: def exists:  part of after ":", if any Default: ]=] local defDisp = priv.defDisp( tpl_args.def, tpl_args.disp, category ) --[=[ defLinkWikitext: Display of definition page link ]=] local defLinkWikitext = "" .. defDisp .. "" --[=[ contextText: Display of context addendum "in the context of ..." contextdisp exists: " " context exists:    " " Default:           No addendum ]=] local contextText if priv.isNull( tpl_args.context ) then contextText = "" else contextText = " in the context of "   if priv.isNull( tpl_args.contextdisp ) then      contextText = contextText .. tpl_args.context .. "" else contextText = contextText .. tpl_args.contextdisp .. "]]"   end end --[=[ resultCatText: Display of link to associated results category nocat exists: No display Default: ]=] local resultCatText = "" if priv.isNull( tpl_args.nocat ) then resultCatText = frame:expandTemplate{ title = 'ProofsLink', args = { category } } end --[=[ transcludeText: Transclusion, if applicable, of the page linked to with  notrans exists: No display Default: ]=] local transcludeText = "" if priv.isNull( tpl_args.notrans ) then --Lua pcall construct to present graceful message when the to-be-transcluded page does not exist local exists, val = pcall( frame.expandTemplate, frame, { title = defPage } ) if exists then transcludeText = "\n" .. val else transcludeText = "\nTransclusion of " .. defPage .. " failed." end end --[=[ categoriesText: Adding the categories passed as numbered parameters See priv.defCat ]=] local categoriesText = "" local i = 1 while not priv.isNull( tpl_args[i] ) do   categoriesText = categoriesText .. priv.defCat( tpl_args[i], category ) i = i + 1 end if i == 1 then categoriesText = "" end local result = mw.html.create result :wikitext( 'This category contains definitions related to ' ) :wikitext( defLinkWikitext ) :wikitext( contextText ) :wikitext( '. ' ) :wikitext( resultCatText ) :wikitext( '\n' ) :wikitext( transcludeText ) :wikitext( categoriesText ) return result end

return p