<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AWP</id>
	<title>Module:WP - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AWP"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:WP&amp;action=history"/>
	<updated>2026-06-19T08:17:32Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:WP&amp;diff=479993&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:WP&amp;diff=479993&amp;oldid=prev"/>
		<updated>2021-07-16T07:56:44Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require('Module:No globals');&lt;br /&gt;
&lt;br /&gt;
local getArgs = require ('Module:Arguments').getArgs;&lt;br /&gt;
local mRedirect = require ('Module:Redirect')&lt;br /&gt;
	&lt;br /&gt;
local namespaces = {															-- includes namespace aliases - these are case insensitive&lt;br /&gt;
	['HELP'] = 'Help',															-- canonical namespaces&lt;br /&gt;
	['WIKIPEDIA'] = 'WP',&lt;br /&gt;
&lt;br /&gt;
	['PROJECT'] = 'Project',													-- namespace aliases&lt;br /&gt;
	['WP'] = 'WP',&lt;br /&gt;
	['H'] = 'Help',&lt;br /&gt;
	['MOS'] = 'MOS',&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E S C A P E _ L U A _ M A G I C _ C H A R S &amp;gt;----------------------------------&lt;br /&gt;
&lt;br /&gt;
Returns a string where all of lua's magic characters have been escaped.  This is important because functions like&lt;br /&gt;
string.gsub() treat their pattern and replace strings as patterns, not literal strings.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function escape_lua_magic_chars (argument)&lt;br /&gt;
	argument = argument:gsub(&amp;quot;%%&amp;quot;, &amp;quot;%%%%&amp;quot;);										-- replace % with %%&lt;br /&gt;
	argument = argument:gsub(&amp;quot;([%^%$%(%)%.%[%]%*%+%-%?])&amp;quot;, &amp;quot;%%%1&amp;quot;);				-- replace all other lua magic pattern characters&lt;br /&gt;
	return argument;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E R R &amp;gt;------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
returns formatted error message that is less strident than error() or standard MediaWiki error messages&lt;br /&gt;
&lt;br /&gt;
TODO: add link to template page for help text&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function err (error_msg)&lt;br /&gt;
	return '&amp;lt;span class=&amp;quot;error&amp;quot; style=&amp;quot;font-size:100%&amp;quot;&amp;gt;' .. error_msg .. ' ([[Template:WP|help]])&amp;lt;/span&amp;gt;';		-- tamer, less strident error messages&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; G E T _ C O N T E N T &amp;gt;--------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
get content from &amp;lt;title&amp;gt; page.  On error, use &amp;lt;label&amp;gt; in returned message to identify failing event in the process&lt;br /&gt;
&lt;br /&gt;
returns:&lt;br /&gt;
	&amp;lt;content&amp;gt;, nil – expected returns&lt;br /&gt;
	nil, msg – &amp;lt;title&amp;gt; not a valid title&lt;br /&gt;
	nil, msg – &amp;lt;title&amp;gt; does not exist&lt;br /&gt;
	nil, msg – &amp;lt;title&amp;gt; is empty&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function get_content (title, label)&lt;br /&gt;
	local content;&lt;br /&gt;
	local title_obj = mw.title.new (title);										-- get title object for &amp;lt;title&amp;gt;&lt;br /&gt;
	if not title_obj then														-- title object for non-existent valid &amp;lt;title&amp;gt; will have been created; nil else&lt;br /&gt;
		return nil, label .. ': invalid title: ' .. title;						-- return nil when &amp;lt;title&amp;gt; is malformed (not a valid title)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	content = title_obj:getContent();											-- get content &lt;br /&gt;
	if not content then&lt;br /&gt;
		return nil, label .. ': page does not exist: ' .. title;				-- return nil when &amp;lt;title&amp;gt; does not exist&lt;br /&gt;
	elseif '' == content then&lt;br /&gt;
		return nil, label .. ': page is empty: ' .. title;						-- return nil when &amp;lt;title&amp;gt; has no content&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return content;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[=[-------------------------&amp;lt; W I K I L I N K _ S T R I P &amp;gt;--------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Wikilink markup does not belong in an anchor id and can / does confuse the code that parses apart citation and&lt;br /&gt;
harvc templates so here we remove any wiki markup:&lt;br /&gt;
	[[link|label]] -&amp;gt; label&lt;br /&gt;
	[[link]] -&amp;gt; link&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
&lt;br /&gt;
local function wikilink_strip(text)&lt;br /&gt;
	for wikilink in text:gmatch('%[%b[]%]') do									-- get a wikilink&lt;br /&gt;
		text = text:gsub('%[%b[]%]', '__57r1P__', 1);							-- install a marker&lt;br /&gt;
		if wikilink:match ('^%[%[%s*[Ff]ile:') or wikilink:match ('^%[%[%s*[Ii]mage:') then	-- if this wikilink is an image&lt;br /&gt;
			wikilink = '[IMAGE]';												-- can't display it in a tooltip so use a word; TODO: parse out alt text or caption? worth the effort?&lt;br /&gt;
		elseif wikilink:match('%[%[.-|(.-)%]%]') then&lt;br /&gt;
			wikilink = wikilink:match('%[%[.-|(.-)%]%]');						-- extract label from complex [[link|label]] wikilink&lt;br /&gt;
		else&lt;br /&gt;
			wikilink = wikilink:match('%[%[(.-)%]%]');							-- extract link from simple [[link]] wikilinks&lt;br /&gt;
		end&lt;br /&gt;
		wikilink = escape_lua_magic_chars(wikilink);							-- in case there are lua magic characters in wikilink&lt;br /&gt;
		text = text:gsub('__57r1P__', wikilink, 1);								-- replace the marker with the appropriate text&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return text;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; T I T L E _ M A K E &amp;gt;----------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
makes a prefix for the tooltip from {{nutshell}} |title= parameter value, if present, pagename else&lt;br /&gt;
&lt;br /&gt;
Because we are evaluating the content of pagename, we set the frag_flag here when the pagename&lt;br /&gt;
has an anchor fragment (&amp;lt;namespace&amp;gt;:&amp;lt;pagename&amp;gt;#&amp;lt;anchor&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function title_make (title_param, pagename)&lt;br /&gt;
	local frag_flag;&lt;br /&gt;
	local c;&lt;br /&gt;
	local namespace;&lt;br /&gt;
	&lt;br /&gt;
	pagename, c = pagename:gsub ('#.*$', '');									-- remove section fragment if any&lt;br /&gt;
	if 0 &amp;lt; c then&lt;br /&gt;
		frag_flag = true;														-- when fragment removed, set the flag&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	namespace = pagename:match ('^%a+'):upper();								-- extract canonical namespace; convert to upper case for indexing&lt;br /&gt;
	pagename = pagename:gsub ('^%a+', namespaces[namespace]);					-- replace with abbreviation&lt;br /&gt;
&lt;br /&gt;
	if '' == title_param then&lt;br /&gt;
		title_param = '&amp;amp;quot;' .. pagename .. '&amp;amp;quot;';							-- use name of shortcut's target page when |title= missing or empty&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return title_param, frag_flag;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; T O O L T I P _ M A K E &amp;gt;------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
assemble the tooltip (title= attribute value)&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function tooltip_make (title_param, nutshell, frag_flag)&lt;br /&gt;
	return table.concat ({&lt;br /&gt;
		title_param,															-- the tooltip prefix (usually WP: article name)&lt;br /&gt;
		('' ~= nutshell and ' in a nutshell: ' or ''),							-- when there is nutshell text&lt;br /&gt;
		nutshell,&lt;br /&gt;
		(frag_flag and ' (subsection link)' or ''),								-- when WP: article name has a fragment&lt;br /&gt;
		});&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; N U T S H E L L _ T E X T _ G E T &amp;gt;--------------------------------------------&lt;br /&gt;
&lt;br /&gt;
gets text from {{nutshell}} (or redirect) template in shortcut's target page; frame included as argument here&lt;br /&gt;
so that this function has access to frame:preprocess()&lt;br /&gt;
&lt;br /&gt;
shortcut is shortcut name with a namespace prefix (WP:BOLD, MOS:MED, H:CS1, etc)&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function nutshell_text_get (shortcut, frame)&lt;br /&gt;
	local content;																-- content of shortcut page then content of target&lt;br /&gt;
	local target;																-- name of shortcut's redirect target&lt;br /&gt;
	local msg;																	-- error messages go here&lt;br /&gt;
	local c;																	-- general purpose var holds the tally of gsub() replacements made when needed&lt;br /&gt;
	local title_param;															-- {{nutshell}} |title= parameter contents and value used in tooltip rendering&lt;br /&gt;
	local frag_flag;															-- boolean set true when normalized page name has a fragment (WP:&amp;lt;page title&amp;gt;#&amp;lt;anchor name&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
	content, msg = get_content (shortcut, 'shortcut');							-- get content of shortcut redirect page&lt;br /&gt;
	if msg then&lt;br /&gt;
		return nil, msg;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	target = mRedirect.getTargetFromText (content);								-- get redirect &amp;lt;target title&amp;gt; (page name) from content of redirect page: (#Redirect [[&amp;lt;target title&amp;gt;]]) or nil&lt;br /&gt;
	if not target then&lt;br /&gt;
		return nil, 'shortcut: ' .. shortcut .. ' is not a redirect';&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	content, msg = get_content (target, 'target');								-- get content of redirect target&lt;br /&gt;
	if msg then&lt;br /&gt;
		return nil, msg;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local templatePatterns = {&lt;br /&gt;
		&amp;quot;{{%s*[Nn]utshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Pp]olicy in a nutshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Pp]olicy proposal in a nutshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Ii]n a nutshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Ii]nanutshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Gg]uideline in a nutshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Gg]uideline one liner%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Nn]aming convention in a nutshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Nn]utshell2%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Pp]roposal in a nutshell%s*|&amp;quot;,&lt;br /&gt;
		&amp;quot;{{%s*[Ee]ssay in a nutshell%s*|&amp;quot;&lt;br /&gt;
		}&lt;br /&gt;
	&lt;br /&gt;
	local nutshell&lt;br /&gt;
	for i, pattern in ipairs (templatePatterns) do&lt;br /&gt;
		local pos = mw.ustring.find (content, pattern)&lt;br /&gt;
		&lt;br /&gt;
		if pos then&lt;br /&gt;
			nutshell = mw.ustring.match (content, '%b{}', pos)&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if not nutshell then														-- nil when there is no recognized nutshell template&lt;br /&gt;
		title_param, frag_flag = title_make ('', target);&lt;br /&gt;
		return tooltip_make (title_param, '', frag_flag);						-- nutshell doesn't exist so empty string for concatenation&lt;br /&gt;
	end&lt;br /&gt;
																				-- begin template disassembly - order is important here - rare case where |title= holds a template&lt;br /&gt;
	nutshell = nutshell:gsub ('^{{[%w%s]*|', ''):gsub ('}}$', '');				-- remove opening {{ and template name then remove closing }}&lt;br /&gt;
&lt;br /&gt;
	for t in nutshell:gmatch('%b{}') do											-- get an embedded template&lt;br /&gt;
		nutshell = nutshell:gsub('%b{}', '__57r1P__', 1)						-- install a marker&lt;br /&gt;
		local replacement = frame:preprocess (t);								-- get the template's rendering&lt;br /&gt;
		replacement = escape_lua_magic_chars(replacement);						-- in case there are lua magic characters in replacement&lt;br /&gt;
		nutshell = nutshell:gsub('__57r1P__', replacement, 1)					-- replace the marker with the appropriate text&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	nutshell = wikilink_strip (nutshell);										-- remove wikilinks&lt;br /&gt;
	&lt;br /&gt;
	title_param = nutshell:match ('|%s*title%s*=%s*([^|]+)') or '';				-- get title text or an empty string&lt;br /&gt;
	title_param = mw.text.trim (title_param);									-- remove extraneous leading / trailing whitespace&lt;br /&gt;
&lt;br /&gt;
	title_param, frag_flag = title_make (title_param, target);					-- get content from {{nutshell}} |title= param if present, else concot a title&lt;br /&gt;
&lt;br /&gt;
	nutshell = nutshell:gsub ('|%s*title%s*=%s*[^|]*', '');						-- remove title parameter and value; TODO: these two can be made one?&lt;br /&gt;
	nutshell = nutshell:gsub ('|%s*shortcut%d*%s*[^|]*', '');					-- remove all shortcut parameters and their values&lt;br /&gt;
&lt;br /&gt;
	nutshell, c = nutshell:gsub ('%s*|%s*', ' *');								-- replace pipes and get a tally&lt;br /&gt;
	if 0 &amp;lt; c then&lt;br /&gt;
		nutshell = '*' .. nutshell;												-- if any pipes were replaced, prefix with a splat&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	nutshell = nutshell:gsub ('&amp;quot;', '&amp;amp;quot;'):gsub ('%b&amp;lt;&amp;gt;', '');					-- convert double quote characters to html entities then remove html-like tags&lt;br /&gt;
																				-- end template disassembly&lt;br /&gt;
	return tooltip_make (title_param, nutshell, frag_flag);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; M A I N &amp;gt;----------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
template entry point&lt;br /&gt;
&lt;br /&gt;
{{#invoke:Nutshell|main|&amp;lt;shortcut&amp;gt;}} where &amp;lt;shortcut&amp;gt; is shortcut name with or without namespace prefix; BOLD or WP:BOLD&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function main (frame)&lt;br /&gt;
	local args = getArgs (frame);												-- get a table of arguments&lt;br /&gt;
	local out = {};&lt;br /&gt;
	local shortcut = args[1];													-- TODO: error check this; no point in continuing without properly formed shortcut&lt;br /&gt;
&lt;br /&gt;
	if not shortcut or '' == shortcut then&lt;br /&gt;
		return err ('no shortcut name given');&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local namespace, rest = shortcut:match ('^(%a+)(:%w+)');&lt;br /&gt;
	if namespace then&lt;br /&gt;
		namespace = namespace:upper();&lt;br /&gt;
		if not namespaces[namespace] then&lt;br /&gt;
			return err ('namespace \'' .. namespace .. '\' not recognized in shortcut: ' .. shortcut);&lt;br /&gt;
		else&lt;br /&gt;
			shortcut = namespaces[namespace] .. rest;&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		shortcut = 'WP:' .. shortcut;											-- add WP: namespace&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local nutshell, error_msg = nutshell_text_get (shortcut, frame);			-- pass frame so that nutshell_text_get() has access to frame:preprocess()&lt;br /&gt;
	if error_msg then&lt;br /&gt;
		return err (error_msg);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	table.insert (out, '[[');													-- open wikilink&lt;br /&gt;
	table.insert (out, shortcut);												-- add shortcut&lt;br /&gt;
	if nutshell then&lt;br /&gt;
		table.insert (out, '|&amp;lt;span title=&amp;quot;');									-- pipe, then start the opening span&lt;br /&gt;
		table.insert (out, nutshell);											-- add nutshell text&lt;br /&gt;
		table.insert (out, '&amp;quot; class=&amp;quot;rt-commentedText&amp;quot; style=&amp;quot;border-bottom:1px dotted&amp;quot;&amp;gt;');	--finish the opening span&lt;br /&gt;
		table.insert (out, shortcut);											-- add shortcut&lt;br /&gt;
		table.insert (out, '&amp;lt;/span&amp;gt;');											-- close the span&lt;br /&gt;
	end&lt;br /&gt;
	table.insert (out, ']]');													-- close the wikilink&lt;br /&gt;
&lt;br /&gt;
	return table.concat (out);													-- concatenate and done&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T E D   F U N C T I O N S &amp;gt;------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	main = main,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>Zoran</name></author>
	</entry>
</feed>