Module:UserLinks/shared: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(create module for shared functions between this page and the extras page) |
(use non-breaking spaces in display values) |
||
Line 41: | Line 41: | ||
function p.makeWikilink(page, display) |
function p.makeWikilink(page, display) |
||
if display then |
if display then |
||
display = display:gsub(' ', ' ') |
|||
return string.format('[[%s|%s]]', page, display) |
return string.format('[[%s|%s]]', page, display) |
||
else |
else |
||
Line 52: | Line 53: | ||
url = tostring(url) |
url = tostring(url) |
||
if display then |
if display then |
||
display = display:gsub(' ', ' ') |
|||
return string.format('[%s %s]', url, display) |
return string.format('[%s %s]', url, display) |
||
else |
else |
Revision as of 10:39, April 1, 2014
This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This Lua module is used in system messages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
This module stores functions that are shared between Module:UserLinks and Module:UserLinks/extra.
-- This module stores functions that are shared between [[Module:UserLinks]]
-- and [[Module:UserLinks/extra]].
local p = {}
function p.raiseError(message, section, level)
if section then
message = message .. '|' .. section
end
if not level or level == 0 then
level = 0
else
level = level + 1
end
error(message, level)
end
function p.makeWikitextError(encodedMessage, demo)
local message, section = mw.ustring.match(encodedMessage, '^(.-)|(.*)$')
message = message or encodedMessage
if section then
section = ' ([[Template:User-multi#' .. section .. '|help]])'
else
section = ''
end
local category
if not demo then
category = '[[Category:UserLinks transclusions with errors]]'
mCategoryHandler = require('Module:Category handler')
category = mCategoryHandler.main{
all = category -- Categorise all namespaces, but not blacklisted pages.
}
end
category = category or ''
return string.format(
'<strong class="error">[[Template:User-multi|User-multi]] error: %s%s.</strong>%s',
message, section, category
)
end
function p.makeWikilink(page, display)
if display then
display = display:gsub(' ', ' ')
return string.format('[[%s|%s]]', page, display)
else
return string.format('[[%s]]', page)
end
end
function p.makeUrlLink(page, query, display)
query = query or {}
local url = mw.uri.fullUrl(page, query)
url = tostring(url)
if display then
display = display:gsub(' ', ' ')
return string.format('[%s %s]', url, display)
else
return string.format('[%s]', url)
end
end
return p