https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AUserLinks%2Fshared%2Fsandbox
Module:UserLinks/shared/sandbox - Revision history
2025-06-06T07:20:01Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.4
https://en.wikipedia.org/w/index.php?title=Module:UserLinks/shared/sandbox&diff=1132815273&oldid=prev
Trialpears: sandbox
2023-01-10T18:52:05Z
<p>sandbox</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 18:52, 10 January 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 3:</td>
<td colspan="2" class="diff-lineno">Line 3:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- Load data and define often-used variables</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>-- Load data and define often-used variables</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>local cfg = mw.loadData('Module:UserLinks/config')</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>local cfg = mw.loadData('Module:UserLinks/config<ins style="font-weight: bold; text-decoration: none;">/sandbox</ins>')</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local namespaces = mw.site.namespaces</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local namespaces = mw.site.namespaces</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
</table>
Trialpears
https://en.wikipedia.org/w/index.php?title=Module:UserLinks/shared/sandbox&diff=888037132&oldid=prev
Pppery: Create sandbox version of Module:UserLinks/shared
2019-03-16T14:12:34Z
<p>Create sandbox version of <a href="/wiki/Module:UserLinks/shared" title="Module:UserLinks/shared">Module:UserLinks/shared</a></p>
<p><b>New page</b></p><div>-- This module stores functions that are shared between [[Module:UserLinks]]<br />
-- and [[Module:UserLinks/extra]].<br />
<br />
-- Load data and define often-used variables<br />
local cfg = mw.loadData('Module:UserLinks/config')<br />
local namespaces = mw.site.namespaces<br />
<br />
-- Lazily initialise modules that we may or may not need<br />
local mCategoryHandler<br />
<br />
-- Define namespaces for which links need to be escaped with the colon trick.<br />
-- See [[w:en:Help:Colon trick]].<br />
local colonNamespaces = {<br />
[6] = true, -- File<br />
[14] = true, -- Category<br />
}<br />
<br />
local p = {}<br />
<br />
function p.maybeLoadModule(s)<br />
-- Attempts to load the module s. If it succeeds, returns the module;<br />
-- otherwise, returns false.<br />
local success, mdl = pcall(require, s)<br />
if success then<br />
return mdl<br />
else<br />
return false<br />
end<br />
end<br />
<br />
function p.raiseError(message, section, level)<br />
-- Raises an error using the Lua error function. The error message is<br />
-- designed to be caught with pcall and then passed to p.makeWikitextError.<br />
-- The section, if specified, is the section name on a help page that gives<br />
-- help to users about that particular error.<br />
if section then<br />
message = message .. '|' .. section<br />
end<br />
if not level or level == 0 then<br />
level = 0<br />
else<br />
level = level + 1<br />
end<br />
error(message, level)<br />
end<br />
<br />
local localBlacklist = {<br />
'/[sS]andbox$', -- Don't categorise sandboxes<br />
'/[tT]est ?cases$', -- Don't categorise test case pages<br />
}<br />
<br />
local function currentTitleMatchesLocalBlacklist()<br />
-- Return true if the current title matches any of the patterns in the<br />
-- local blacklist table. Otherwise return false.<br />
local title = mw.title.getCurrentTitle().prefixedText<br />
for i, pattern in ipairs(localBlacklist) do<br />
if title:find(pattern) then<br />
return true<br />
end<br />
end<br />
return false<br />
end<br />
<br />
function p.makeWikitextError(encodedMessage, demo)<br />
local errorMessage, section = mw.ustring.match(encodedMessage, '^(.-)|(.*)$')<br />
errorMessage = errorMessage or encodedMessage<br />
<br />
-- If not a demo, get the error category link and pass it through<br />
-- [[Module:Category handler]]'s blacklist.<br />
local category<br />
if not demo then<br />
category = string.format(<br />
'[[%s:%s]]',<br />
namespaces[14].name,<br />
p.message('error-config-category')<br />
)<br />
mCategoryHandler = p.maybeLoadModule('Module:Category handler')<br />
if mCategoryHandler then<br />
-- Categorise all namespaces, but not blacklisted pages.<br />
category = mCategoryHandler.main{all = category}<br />
end<br />
if category and currentTitleMatchesLocalBlacklist() then<br />
category = nil<br />
end<br />
end<br />
category = category or ''<br />
<br />
-- Format the error message and the section link.<br />
local formattedError<br />
if section then<br />
formattedError = p.message(<br />
'error-config-message-help',<br />
errorMessage,<br />
section<br />
)<br />
else<br />
formattedError = p.message(<br />
'error-config-message-nohelp',<br />
errorMessage<br />
)<br />
end<br />
<br />
-- Return the error message and the category inside html error tags.<br />
return string.format(<br />
'<strong class="error">%s</strong>%s',<br />
formattedError,<br />
category<br />
)<br />
end<br />
<br />
local function formatPage(interwiki, namespace, page)<br />
-- Formats an interwiki, a namespace and a page into a wikilink-ready<br />
-- string. The interwiki and namespace are optional. If a namespace is<br />
-- specified, it should be a valid key to mw.site.namespaces. The page<br />
-- parameter is required.<br />
local ret = {}<br />
interwiki = interwiki or ''<br />
if interwiki ~= '' or colonNamespaces[namespace] then<br />
ret[#ret + 1] = ':'<br />
end<br />
ret[#ret + 1] = interwiki<br />
if interwiki ~= '' then<br />
ret[#ret + 1] = ':'<br />
end<br />
if namespace then<br />
local nsTable = namespaces[namespace]<br />
if not nsTable then<br />
error('"' .. tostring(namespace) .. '" is not a valid namespace key', 2)<br />
end<br />
ret[#ret + 1] = nsTable.name<br />
if namespace ~= 0 then<br />
ret[#ret + 1] = ':'<br />
end<br />
end<br />
ret[#ret + 1] = page<br />
return table.concat(ret)<br />
end<br />
<br />
local function formatDisplay(s)<br />
-- Replaces spaces in a string with "&nbsp;" to make sure they don't wrap.<br />
-- Don't replace anything if we are substing, as we generally don't want<br />
-- to use "&nbsp;" in that case.<br />
if mw.isSubsting() then<br />
return s<br />
else<br />
return s:gsub(' ', '&nbsp;')<br />
end<br />
end<br />
<br />
function p.makeWikilink(interwiki, namespace, page, display)<br />
-- Creates a wikilink. The interwiki, namespace and display parameters are<br />
-- optional. If a namespace parameter is specified it must be a valid key<br />
-- to mw.site.namespaces.<br />
local formattedPage = formatPage(interwiki, namespace, page)<br />
if display then<br />
display = formatDisplay(display)<br />
return string.format('[[%s|%s]]', formattedPage, display)<br />
else<br />
return string.format('[[%s]]', formattedPage)<br />
end<br />
end<br />
<br />
local function formatUrlLink(url, display)<br />
-- Formats a URL link with an optional display parameter.<br />
if display then<br />
display = formatDisplay(display)<br />
return string.format('[%s %s]', url, display)<br />
else<br />
return string.format('[%s]', url)<br />
end<br />
end<br />
<br />
function p.makeUrlLink(s, display)<br />
-- Makes a URL link with an optional display parameter. The first input<br />
-- may be any valid input to mw.uri.new.<br />
local url = mw.uri.new(s)<br />
url = tostring(url)<br />
return formatUrlLink(url, display)<br />
end<br />
<br />
function p.makeFullUrlLink(interwiki, namespace, page, query, display)<br />
-- Makes a link to the full URL of a page. The interwiki, namespace, query<br />
-- and display parameters are optional. If a namespace parameter is<br />
-- specified it must be a valid key to mw.site.namespaces. The query<br />
-- parameter can be a string or a table as specified in the mw.uri library.<br />
local formattedPage = formatPage(interwiki, namespace, page)<br />
local url = mw.uri.fullUrl(formattedPage, query)<br />
url = tostring(url)<br />
return formatUrlLink(url, display)<br />
end<br />
<br />
function p.message(key, ...)<br />
-- Returns the message with the given key from [[Module:UserLinks/config]].<br />
-- Extra parameters are substituted in the message for keys $1, $2, $3, etc.<br />
local msg = cfg[key]<br />
if not msg then<br />
p.raiseError(<br />
'No message found with key "' .. tostring(key) .. '"',<br />
'No message found',<br />
2<br />
)<br />
end<br />
local noArgs = select('#', ...)<br />
if noArgs < 1 then<br />
return msg<br />
else<br />
local msg = mw.message.newRawMessage(msg, ...)<br />
return msg:plain()<br />
end<br />
end<br />
<br />
return p</div>
Pppery