Боты, Бюрократы, Боты Структурированных обсуждений, Администраторы интерфейса, Управляющие подписками push-уведомлений, Скрывающие, Администраторы
4361
правка
Mansur700 (обсуждение | вклад) Нет описания правки |
Adam (обсуждение | вклад) Нет описания правки |
||
Строка 13: | Строка 13: | ||
end | end | ||
local function makeInvokeFunc(funcName) | local function makeInvokeFunc(funcName, flags) | ||
return function (frame) | return function (frame) | ||
local args = copy(getArgs(frame, { | local args = copy(getArgs(frame, { | ||
Строка 19: | Строка 19: | ||
removeBlanks = false | removeBlanks = false | ||
})) | })) | ||
return p[funcName](args) | return p[funcName](args, flags) | ||
end | end | ||
end | end | ||
--предотвращает обработку вики-текста в отображении образца | |||
local function processText(str, nowiki) | |||
local res = str | |||
if nowiki then | |||
str = mw.text.unstripNoWiki(str) | |||
str = string.gsub(str, '%[', '[') | |||
str = string.gsub(str, '%]', ']') | |||
str = string.gsub(str, '<', '<') | |||
str = string.gsub(str, '>', '>') | |||
str = string.gsub(str, '{', '{') | |||
str = string.gsub(str, '|', '|') | |||
str = string.gsub(str, '}', '}') | |||
str = string.gsub(str, '\'', ''') | |||
str = string.gsub(str, '"', '"') | |||
str = string.gsub(str, '(://)', '<span>%1</span>') | |||
local | |||
if | |||
end | end | ||
return str | |||
return | |||
end | end | ||
function addParams(args, params) | local function addParams(args, params) | ||
local text, equals_pos, param, value = '', 0, '', '' | local text, equals_pos, param, value = '', 0, '', '' | ||
function addPipe() | local function addPipe() | ||
if params.spaced then | if params.spaced then | ||
text = text .. ' ' | text = text .. ' ' | ||
end | end | ||
text = text .. '<span' | text = text .. '<span class="' | ||
if not params.spaced then | |||
text = text .. ' ts-templateCallCode-pipe' | |||
end | |||
if not params.black then | if not params.black then | ||
text = text .. ' | text = text .. ' ts-templateCallCode-weak' | ||
end | end | ||
text = text .. '>|</span>' | |||
-- |, чтобы не трактовалось как разделитель ячеек в таблицах | |||
text = text .. '">|</span>' | |||
end | end | ||
local beforeParam = '<span class="ts-templateCallCode-param">' | |||
local afterParam = '</span>' | |||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
if type(k) == 'number' then -- Неименованные параметры | if type(k) == 'number' then -- Неименованные параметры | ||
equals_pos = v:find('=') | if k >= params.from then | ||
equals_pos = v:find('=') | |||
if equals_pos and v:find('{{=}}') == equals_pos - 2 then | |||
equals_pos = nil | |||
end | |||
if equals_pos then -- Содержащие «=» преобразуем в именованные | |||
param = v:sub(1, equals_pos - 1) | |||
value = v:sub(equals_pos + 1) | |||
addPipe() | |||
text = text .. beforeParam .. processText(param, params.nowiki) .. '=' .. processText(value, params.nowiki) .. afterParam | |||
else -- Истинно неименованные | |||
addPipe() | |||
local paramValue = processText(v, params.nowiki) | |||
if #paramValue ~= 0 then | |||
text = text .. beforeParam .. paramValue .. afterParam | |||
end | |||
end | |||
end | end | ||
elseif not k:find('^_') then -- Именованные параметры, исключая модификаторы внешнего вида | elseif not k:find('^_') then -- Именованные параметры, исключая модификаторы внешнего вида | ||
addPipe() | addPipe() | ||
text = text .. k .. '=' .. v | text = text .. beforeParam .. processText(k, params.nowiki) .. '=' .. processText(v, params.nowiki) .. afterParam | ||
end | end | ||
end | end | ||
Строка 262: | Строка 93: | ||
end | end | ||
function p._main(args, flags) | |||
function p. | |||
local name = args[1] | local name = args[1] | ||
table.remove(args, 1) | table.remove(args, 1) | ||
Строка 280: | Строка 109: | ||
local optpText | local optpText | ||
if name then | if not flags.withoutParams then | ||
if name then | |||
local spanOffset = mw.ustring.find(name, '<span') -- След использования шаблона optp | |||
if spanOffset then | |||
optpText = mw.ustring.sub(name, spanOffset) | |||
name = mw.ustring.sub(name, 1, spanOffset - 1) | |||
end | |||
end | end | ||
end | end | ||
Строка 290: | Строка 121: | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
local nobr | local nolink, subst, podst, global, nav, noRedirect, ucFirst, black, nobr | ||
local tag, style, comment, lang, sister, global, textInPlaceOfName, | |||
namePrefix, prefix, postfix, nowiki | |||
local spaced, from | |||
if flags.withoutParams then | |||
for i, v in ipairs(args) do | |||
if v == 'nl' or v == 'nolink' then | |||
noLink = true | |||
elseif v == 's' then | |||
subst = true | |||
elseif v == 'п' then | |||
podst = true | |||
elseif v == 'g' then | |||
global = true | |||
elseif v == 'nav' then | |||
nav = true | |||
elseif v == 'noredir' then | |||
noRedirect = true | |||
elseif v == 'u' then | |||
ucFirst = true | |||
elseif v == 'b' then | |||
black = true | |||
elseif v == 'nobr' then | |||
nobr = true | |||
end | |||
end | |||
tag = args.tag or 'span' | |||
style = args.style | |||
comment = args.comment | |||
lang = args.lang | |||
sister = args.sister | |||
textInPlaceOfName = args.text | |||
namePrefix = args.nameprefix | |||
prefix = args.prefix | |||
postfix = args.postfix | |||
nowiki = args.nowiki | |||
else | |||
noLink = yesno(args._nolink or args._nl, false) or not yesno(args._link, false) | |||
subst = yesno(args._s, false) | |||
podst = yesno(args['_п'], false) | |||
global = yesno(args._g, false) | |||
nav = yesno(args._nav, false) | |||
noRedirect = yesno(args._noredir, false) | |||
ucFirst = yesno(args._u, false) | |||
black = yesno(args._b, false) | |||
nobr = yesno(args._nobr, false) | |||
tag = args._tag or 'span' | |||
style = args._style | |||
comment = args._comment | |||
lang = args._lang | |||
sister = args._sister | |||
textInPlaceOfName = args._text | |||
namePrefix = args._nameprefix | |||
prefix = args._prefix | |||
postfix = args._postfix | |||
nowiki = args._nowiki | |||
spaced = yesno(args._spaced, false) | |||
from = (tonumber(args._from) or 2) - 1 | |||
end | |||
global = global or name and mw.ustring.sub(name, 1, 1) == ':' | |||
black = black or tag ~= 'span' | |||
if textInPlaceOfName == '' then | if textInPlaceOfName == '' then | ||
Строка 320: | Строка 200: | ||
if sister == '' then | if sister == '' then | ||
sister = nil | sister = nil | ||
end | |||
if namePrefix == '' then | |||
namePrefix = nil | |||
end | end | ||
Строка 332: | Строка 215: | ||
name = mw.ustring.sub(trimmedName, 7) | name = mw.ustring.sub(trimmedName, 7) | ||
end | end | ||
end | |||
if subst then | |||
namePrefix = 'subst:' | |||
elseif podst then | |||
namePrefix = 'подст:' | |||
end | end | ||
Строка 339: | Строка 228: | ||
local currentTitleRoot = currentTitle.rootText | local currentTitleRoot = currentTitle.rootText | ||
if not ucFirst and | if not ucFirst and | ||
((ru:uc(currentTitleRoot) ~= currentTitleRoot and | ( | ||
( | |||
ru:uc(currentTitleRoot) ~= currentTitleRoot and | |||
-- Книга:Литературное наследство, TranslateDate | |||
not mw.ustring.match(currentTitleRoot, '^[А-Яа-яA-Za-z]+:?[А-ЯA-Z]') | |||
) or | |||
#currentTitleRoot == 1 | #currentTitleRoot == 1 | ||
) | ) | ||
Строка 377: | Строка 268: | ||
local noLink = noLink or currentTitle == titleObject | local noLink = noLink or currentTitle == titleObject | ||
if not noLink then | if not noLink then | ||
if not noRedirect or ( | if not noRedirect or ( | ||
Строка 403: | Строка 289: | ||
local text = '' | local text = '' | ||
if tag then | if tag then | ||
text = text .. '<' .. tag .. ' class="templateCallCode' | text = text .. '<' .. tag .. ' class="ts-templateCallCode' | ||
if nobr then | if nobr then | ||
text = text .. ' nowrap' | text = text .. ' nowrap' | ||
Строка 414: | Строка 300: | ||
end | end | ||
if prefix then | if prefix then | ||
text = text .. prefix | text = text .. processText(prefix, nowiki) | ||
end | end | ||
text = text .. '<span class="' | |||
if not spaced then | |||
text = text .. ' ts-templateCallCode-opening' | |||
end | |||
if not black then | if not black then | ||
text = text .. ' | text = text .. ' ts-templateCallCode-weak' | ||
end | end | ||
if | text = text .. '">{{' | ||
text = text .. | if namePrefix then | ||
text = text .. namePrefix | |||
end | end | ||
text = text .. '</span>' | |||
if nav and currentTitle == titleObject then | if nav and currentTitle == titleObject then | ||
text = text .. '\'\'\'' | text = text .. '\'\'\'' | ||
end | end | ||
text = text .. '<span class="ts-templateCallCode-templateName" data-navboxnavigation-link="0">' | |||
local commentedLabel | local commentedLabel | ||
if comment then | if comment then | ||
-- https://phabricator.wikimedia.org/T200704 | -- https://phabricator.wikimedia.org/T200704 | ||
-- commentedLabel = mw.getCurrentFrame():expandTemplate({title = 'comment', args = {( | -- commentedLabel = mw.getCurrentFrame():expandTemplate({title = 'comment', args = {(textInPlaceOfName or name), comment}}) | ||
commentedLabel = '<span class="commentedText" title="' .. comment .. '" style="border-bottom: 1px dotted; cursor: help;">' .. | commentedLabel = '<span class="commentedText" title="' .. comment .. '" style="border-bottom: 1px dotted; cursor: help;">' .. | ||
(textInPlaceOfName or name) .. | (textInPlaceOfName or name) .. | ||
Строка 454: | Строка 342: | ||
text = text .. label | text = text .. label | ||
end | end | ||
text = text .. '</span>' | |||
if nav and currentTitle == titleObject then | if nav and currentTitle == titleObject then | ||
Строка 459: | Строка 349: | ||
end | end | ||
if optpText then | if not flags.withoutParams then | ||
if optpText then | |||
text = text .. optpText | |||
end | |||
text = text .. addParams(args, { | |||
spaced = spaced, | |||
black = black, | |||
nowiki = nowiki, | |||
from = from | |||
}) | |||
if spaced then | |||
text = text .. ' ' | |||
end | |||
end | end | ||
if not | text = text .. '<span class="' | ||
text = text .. ' | if not spaced then | ||
text = text .. ' ts-templateCallCode-closing' | |||
end | end | ||
if not black then | if not black then | ||
text = text .. ' | text = text .. ' ts-templateCallCode-weak' | ||
end | end | ||
text = text .. '">}}</span>' | |||
if postfix then | if postfix then | ||
text = text .. postfix | text = text .. processText(postfix, nowiki) | ||
end | end | ||
if tag then | if tag then | ||
Строка 487: | Строка 382: | ||
end | end | ||
return text | local ts = mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Модуль:Template call code/styles.css' } } | ||
return ts .. text | |||
end | end | ||
function p._onlyParams(args) | function p._onlyParams(args) | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
return addParams(args, { | |||
spaced = yesno(args._spaced, false), | spaced = yesno(args._spaced, false), | ||
black = true, | black = true, | ||
}) | nowiki = yesno(args._nowiki, false), | ||
from = 1 | |||
}) | |||
end | |||
p.withoutParams = makeInvokeFunc('_main', {withoutParams = true}) | |||
p.withParams = makeInvokeFunc('_main', {withoutParams = false}) | |||
p.onlyParams = makeInvokeFunc('_onlyParams') | |||
return p | return p |