<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AWikiProjectBanner%2FContext</id>
	<title>Module:WikiProjectBanner/Context - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AWikiProjectBanner%2FContext"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:WikiProjectBanner/Context&amp;action=history"/>
	<updated>2026-05-17T07:48:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:WikiProjectBanner/Context&amp;diff=147658&amp;oldid=prev</id>
		<title>imported&gt;Mr. Stradivarius: add assessmentLink, isSmall and isDemo, and take the args as input</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:WikiProjectBanner/Context&amp;diff=147658&amp;oldid=prev"/>
		<updated>2014-09-11T12:33:44Z</updated>

		<summary type="html">&lt;p&gt;add assessmentLink, isSmall and isDemo, and take the args as input&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-------------------------------------------------------------------------------&lt;br /&gt;
--                               Context class                               --&lt;br /&gt;
-- This module contains the Context class used in Module:WikiProjectBanner.  --&lt;br /&gt;
-- It stores data about the title we are being called from, provides access  --&lt;br /&gt;
-- to the config and banner config modules, generates data commonly used by  --&lt;br /&gt;
-- subclasses (e.g. project name), and provides a place to store data        --&lt;br /&gt;
-- generated by subclasses that needs to be reused (e.g. Grade objects)      --&lt;br /&gt;
-------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
-- Load required modules&lt;br /&gt;
local mShared = require(&amp;#039;Module:WikiProjectBanner/shared&amp;#039;)&lt;br /&gt;
local libraryUtil = require(&amp;#039;libraryUtil&amp;#039;)&lt;br /&gt;
local checkType = libraryUtil.checkType&lt;br /&gt;
&lt;br /&gt;
-- Lazily load modules we don&amp;#039;t always need.&lt;br /&gt;
local yesno&lt;br /&gt;
&lt;br /&gt;
local Context = {}&lt;br /&gt;
&lt;br /&gt;
function Context.new(bannerName, args, cfg, bannerCfg)&lt;br /&gt;
	local obj = {}&lt;br /&gt;
&lt;br /&gt;
	-- Check the input set default values.&lt;br /&gt;
	checkType(&amp;#039;Context.new&amp;#039;, 1, project, &amp;#039;string&amp;#039;)&lt;br /&gt;
	checkType(&amp;#039;Context.new&amp;#039;, 2, args, &amp;#039;table&amp;#039;, true)&lt;br /&gt;
	checkType(&amp;#039;Context.new&amp;#039;, 3, cfg, &amp;#039;table&amp;#039;, true)&lt;br /&gt;
	checkType(&amp;#039;Context.new&amp;#039;, 4, bannerCfg, &amp;#039;table&amp;#039;, true)&lt;br /&gt;
	obj.bannerName = bannerName&lt;br /&gt;
	obj.args = args or {}&lt;br /&gt;
	obj.cfg = cfg or mw.loadData(&amp;#039;Module:WikiProjectBanner/config&amp;#039;)&lt;br /&gt;
	obj.bannerCfg = bannerCfg or mShared.maybeRequire(&lt;br /&gt;
		&amp;#039;Module:WikiProjectBanner/banners/&amp;#039; .. data.bannerName&lt;br /&gt;
	)&lt;br /&gt;
	if not obj.bannerCfg then&lt;br /&gt;
		error(&lt;br /&gt;
			&amp;#039;banner data page [[Module:WikiProjectBanner/banners/&amp;#039; ..&lt;br /&gt;
			bannerName ..&lt;br /&gt;
			&amp;#039;]] does not exist&amp;#039;,&lt;br /&gt;
			0&lt;br /&gt;
		)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Set properties that we will need every time or that are inexpensive.&lt;br /&gt;
	obj.currentTitle = mw.title.getCurrentTitle()&lt;br /&gt;
	obj.subjectTitle = obj.currentTitle.subjectPageTitle&lt;br /&gt;
&lt;br /&gt;
	-- Set up the metatable and define functions for properties to be&lt;br /&gt;
	-- generated on the fly. These functions are used for properties that are&lt;br /&gt;
	-- expensive to generate and that we might not need.&lt;br /&gt;
	local propertyFuncs = {}&lt;br /&gt;
	setmetatable(obj, {&lt;br /&gt;
		__index = function (t, key)&lt;br /&gt;
			local func = propertyFuncs[key]&lt;br /&gt;
			if func then&lt;br /&gt;
				local val = func()&lt;br /&gt;
				obj[key] = val&lt;br /&gt;
				return val&lt;br /&gt;
			else&lt;br /&gt;
				return Context[key]&lt;br /&gt;
			end			&lt;br /&gt;
		end&lt;br /&gt;
	})&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.pageType()&lt;br /&gt;
		return require(&amp;#039;Module:Pagetype&amp;#039;)._main{}&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.project()&lt;br /&gt;
		-- Gets the project name from the banner name.&lt;br /&gt;
		-- For example, for &amp;quot;WikiProject Tulips&amp;quot;, the project name would be&lt;br /&gt;
		-- &amp;quot;Tulips&amp;quot;.&lt;br /&gt;
		if obj.bannerCfg.project then&lt;br /&gt;
			return obj.bannerData.project&lt;br /&gt;
		else&lt;br /&gt;
			local pattern = obj.cfg.msg[&amp;#039;project-page-name-pattern&amp;#039;]&lt;br /&gt;
			return mw.ustring.match(obj.bannerName, pattern) or obj.bannerName&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.projectLink()&lt;br /&gt;
		-- The project page, e.g. &amp;quot;Wikipedia:WikiProject Tulips&amp;quot;.&lt;br /&gt;
		if obj.bannerCfg.projectLink then&lt;br /&gt;
			return obj.bannerCfg.projectLink&lt;br /&gt;
		else&lt;br /&gt;
			local msg = obj.cfg.msg[&amp;#039;project-link&amp;#039;]&lt;br /&gt;
			return mShared.substituteParams(msg, obj.project)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.projectName()&lt;br /&gt;
		-- The project name without a namespace prefix,&lt;br /&gt;
		-- e.g. &amp;quot;WikiProject Tulips&amp;quot;.&lt;br /&gt;
		if obj.bannerCfg.projectName then&lt;br /&gt;
			return obj.bannerCfg.projectName&lt;br /&gt;
		else&lt;br /&gt;
			local msg = obj.cfg.msg[&amp;#039;project-name&amp;#039;]&lt;br /&gt;
			return mShared.substituteParams(msg, obj.project)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.projectScope()&lt;br /&gt;
		-- A link to an article that encapsulates the project&amp;#039;s scope,&lt;br /&gt;
		-- e.g. &amp;quot;[[Tulips]]&amp;quot;. The link will have square brackets added if they&lt;br /&gt;
		-- are not already present.&lt;br /&gt;
		local scope = obj.bannerCfg.projectScope&lt;br /&gt;
		if scope and scope:find(&amp;#039;^%[%[&amp;#039;) then&lt;br /&gt;
			return scope&lt;br /&gt;
		elseif scope then&lt;br /&gt;
			return mShared.makeWikilink(scope)&lt;br /&gt;
		else&lt;br /&gt;
			return mShared.makeWikilink(obj.project)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.projectLinkTalk()&lt;br /&gt;
		-- A link to the project talk page, without square brackets, e.g.&lt;br /&gt;
		-- &amp;quot;Wikipedia talk:WikiProject Tulips&amp;quot;.&lt;br /&gt;
		return mw.title.new(obj.projectLink).talkPageTitle.prefixedText&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.assessmentLink()&lt;br /&gt;
		-- The page containing the project&amp;#039;s assessment scales.&lt;br /&gt;
		if obj.bannerCfg.assessmentLink ~= nil then&lt;br /&gt;
			-- Custom link or false for no link&lt;br /&gt;
			return bannerCfg.assessmentLink&lt;br /&gt;
		else&lt;br /&gt;
			local assessmentPage = obj.projectLink .. &amp;#039;/Assessment&amp;#039;&lt;br /&gt;
			local assessmentTitle = mw.title.new(assessmentPage)&lt;br /&gt;
			return assessmentTitle&lt;br /&gt;
				and assessmentTitle.exists&lt;br /&gt;
				and assessmentTitle.prefixedText&lt;br /&gt;
				or false&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	function propertyFuncs.isSmall()&lt;br /&gt;
		-- Whether we are outputting a small banner or not.&lt;br /&gt;
		yesno = yesno or require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
		return yesno(obj.args.small)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	function propertyFuncs.isDemo()&lt;br /&gt;
		-- Whether we are outputting a demo page.&lt;br /&gt;
		local currentPage = obj.currentTitle.prefixedText&lt;br /&gt;
		local template = mw.site.namespaces[10].name .. &amp;#039;:&amp;#039; .. obj.bannerName&lt;br /&gt;
		local sandboxSubpage = obj.cfg.msg[&amp;#039;sandbox-subpage&amp;#039;]&lt;br /&gt;
		return currentPage == template&lt;br /&gt;
			or currentPage == template .. &amp;#039;/&amp;#039; .. sandboxSubpage&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return obj&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return Context&lt;/div&gt;</summary>
		<author><name>imported&gt;Mr. Stradivarius</name></author>
	</entry>
</feed>