Модуль:Football box: различия между версиями

1400 байт добавлено ,  2 года назад
нет описания правки
(Новая страница: «-- Модуль для шаблона Шаблон:Footballbox local fbxb = require("Module:Football box/base") local p = {} local lang = nil local delink = require('Module:Delink')._delink local templatestyles = 'Football box/styles.css' local tracking, preview local function checkarg(k,v) fbxb.checkarg(k, v, 'Страницы, использующие шаблон footballbox с неизвестными параметрами', tracking, preview)...»)
 
Нет описания правки
Метка: отменено
Строка 1: Строка 1:
-- Модуль для шаблона [[Шаблон:Footballbox]]
-- This module de-links most wikitext.
local fbxb = require("Module:Football box/base")


require('Module:No globals')
local yesno = require('Module:Yesno')


local p = {}
local p = {}
local lang = nil
local delink = require('Module:Delink')._delink
local templatestyles = 'Football box/styles.css'


local tracking, preview
local getArgs


local function checkarg(k,v)
local function delinkReversePipeTrick(s)
fbxb.checkarg(k, v, 'Страницы, использующие шаблон footballbox с неизвестными параметрами', tracking, preview)
    if s:match("^%[%[|.*[|\n]") then -- Check for newlines or multiple pipes.
        return s
    else
        return s:match("%[%[|(.*)%]%]")
    end
end
end


local function timestamp(d, t)
local function delinkPipeTrick(s)
if d then
    local linkarea, display = "", ""
lang = lang or mw.language.getContentLanguage() -- lazy initialize
    -- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].
local success, timestamp = pcall(lang.formatDate, lang, 'c', delink({d .. ' ' .. (t or '')}))
   
if success then
    -- First, remove the text before the first colon, if any.
return timestamp
    if s:match(":") then
else
        s = s:match("%[%[.-:(.*)|%]%]")
return nil
    -- If there are no colons, grab all of the text apart from the square brackets and the pipe.
end
    else
end
        s = s:match("%[%[(.*)|%]%]")
return nil
    end
   
    -- Next up, brackets and commas.
    if s:match("%(.-%)$") then -- Brackets trump commas.
        s = s:match("(.-) ?%(.-%)$")
    elseif s:match(",") then -- If there are no brackets, display only the text before the first comma.
        s = s:match("(.-),.*$")
    end
    return s
end
end


local function getid(s)
local function delinkWikilink(s)
s = fbxb.trim(s or '')
    local result = s
if fbxb.isnotempty(s) then
    -- Deal with the reverse pipe trick.
return s
    if result:match("%[%[|") then
end
        return delinkReversePipeTrick(result)
return nil
    end
   
    result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
    result = mw.text.decode(result, true) -- decode HTML entities.
   
    -- Check for bad titles. To do this we need to find the
    -- title area of the link, i.e. the part before any pipes.
    local titlearea
    if result:match("|") then -- Find if we're dealing with a piped link.
        titlearea = result:match("^%[%[(.-)|.*%]%]")
    else
        titlearea = result:match("^%[%[(.-)%]%]")
    end
    -- Check for bad characters.
    if mw.ustring.match(titlearea, "[%[%]<>{}%%%c\n]") then
        return s
    end
   
    -- Check for categories, interwikis, and files.
    local colonprefix = result:match("%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.
    local ns = mw.site.namespaces[colonprefix] -- see if this is a known namespace
    if mw.language.isKnownLanguageTag(colonprefix)
    or ( ns and ( ns.canonicalName == "File" or ns.canonicalName == "Category" ) ) then
        return ""
    end
   
    -- Remove the colon if the link is using the [[Help:Colon trick]].
    if result:match("%[%[:") then
        result = "[[" .. result:match("%[%[:(.*%]%])")
    end
   
    -- Deal with links using the [[Help:Pipe trick]].
    if mw.ustring.match(result, "^%[%[[^|]*|%]%]") then
        return delinkPipeTrick(result)
    end
   
    -- Find the display area of the wikilink
    if result:match("|") then -- Find if we're dealing with a piped link.
        result = result:match("^%[%[.-|(.+)%]%]")
        -- Remove new lines from the display of multiline piped links,
        -- where the pipe is before the first new line.
        result = result:gsub("\n", "")
    else
        result = result:match("^%[%[(.-)%]%]")
    end
 
    return result
end
end


function p.main(frame)
local function delinkURL(s)
local args = require('Module:Arguments').getArgs(frame)
    -- Assume we have already delinked internal wikilinks, and that
local id = getid(args['id'])
    -- we have been passed some text between two square brackets [foo].
local d = timestamp(args['date'], args['time'])
   
local block
    -- If the text contains a line break it is not formatted as a URL, regardless of other content.
    if s:match("\n") then
        return s
    end
   
    -- Check if the text has a valid URL prefix and at least one valid URL character.
    local valid_url_prefixes = {"//", "http://", "https://", "ftp://", "gopher://", "mailto:", "news:", "irc://"}
    local url_prefix
    for i,v in ipairs(valid_url_prefixes) do
        if mw.ustring.match(s, '^%[' .. v ..'[^"%s].*%]' ) then
            url_prefix = v
            break
        end
    end
   
    -- Get display text
    if not url_prefix then
        return s
    end
    s = s:match("^%[" .. url_prefix .. "(.*)%]") -- Grab all of the text after the URL prefix and before the final square bracket.
    s = s:match('^.-(["<> ].*)') or "" -- Grab all of the text after the first URL separator character ("<> ).
    s = mw.ustring.match(s, "^%s*(%S.*)$") or "" -- If the separating character was a space, trim it off.
   
    local s_decoded = mw.text.decode(s, true)
    if mw.ustring.match(s_decoded, "%c") then
        return s
    else   
        return s_decoded
    end
end


tracking, preview = {}, {}
local function delinkLinkClass(s, pattern, delinkFunction)
fbxb.process_rus_params(args)
    if not type(s) == "string" then
for k, v in pairs(args) do
        error("Attempt to de-link non-string input.", 2)
if v ~= '' then
    end
checkarg(k,v)
    if not ( type(pattern) == "string" and mw.ustring.sub(pattern, 1, 1) == "^" ) then
end
        error('Invalid pattern detected. Patterns must begin with "^".', 2)
end
    end
    -- Iterate over the text string, and replace any matched text. using the
    -- delink function. We need to iterate character by character rather
    -- than just use gsub, otherwise nested links aren't detected properly.
    local result = ""
    while s ~= '' do
        -- Replace text using one iteration of gsub.
        s = mw.ustring.gsub(s, pattern, delinkFunction, 1)
        -- Append the left-most character to the result string.
        result = result .. mw.ustring.sub(s, 1, 1)
        s = mw.ustring.sub(s, 2, -1)
    end
    return result
end


local score = '–:–'
function p._delink(args)
if args['score1'] or args['score2'] then
    local text = args[1] or ""
score = (args['score1'] or '0') .. ':' .. (args['score2'] or '0')
    if yesno(args.markers) == true then
elseif fbxb.isnotempty(args['score']) then
        text = mw.text.killMarkers(text) -- [[Help:Strip markers]]
score = args['score']
    end
end
    if yesno(args.refs) == true then
if args['aet'] then
        -- Remove any [[Help:Strip markers]] representing ref tags. In most situations
score = score .. ' (' .. fbxb.labels.aet .. ')'
        -- this is not a good idea - only use it if you know what you are doing!
end
        text = mw.ustring.gsub(text, "UNIQ%w*%-ref%-%d*%-QINU", "")
if args['scorenote'] then
    end
score = score .. '<br>' .. args['scorenote']
    if not (yesno(args.wikilinks) == false) then
end
        text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink) -- De-link wikilinks.
 
    end
-- Start box
    if not (yesno(args.urls) == false) then
local root =  
        text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.
mw.html.create('div')
    end
:addClass('footballbox')
    if not (yesno(args.comments) == false) then
:css('width', args['size'])
        text = text:gsub("<!%-%-.-%-%->", "") -- Remove html comments.
:css('background-color', args['bg'])
    end
:attr('id', id)
    if not (yesno(args.whitespace) == false) then
root:newline()
        -- Replace single new lines with a single space, but leave double new lines
        -- and new lines only containing spaces or tabs before a second new line.
if args['event'] then
        text = mw.ustring.gsub(text, "([^\n \t][ \t]*)\n([ \t]*[^\n \t])", "%1 %2")
root:tag('div')
        text = text:gsub("[ \t]+", " ") -- Remove extra tabs and spaces.
:addClass('ftitle')
    end
:wikitext(args['event'])
    return text
end
end
 
-- Start left block
block = root:tag('div')
:addClass('mobile-float-reset')
:addClass('fleft')
local timetag = block:tag('time')
:attr('itemprop', d and 'startDate' or nil)
:attr('datetime', d)
timetag:tag('div')
:addClass('mobile-float-reset')
:addClass('fdate')
:wikitext(args['date'])
if args['time'] then
timetag:tag('div')
:addClass('mobile-float-reset')
:addClass('ftime')
:wikitext(args['time'])
end
if args['round'] then
block:tag('div')
:addClass('mobile-float-reset')
:addClass('frnd')
:wikitext(args['round'])
end
-- End block
 
-- Start table
local rtable = root:tag('table')
:addClass('fevent')
local row = rtable:tag('tr')
row:newline()
row:tag('th')
:addClass('fhome')
:tag('span')
:wikitext(args['team1'])
row:tag('th')
:addClass('fscore')
:wikitext(score)
row:tag('th')
:addClass('faway')
:tag('span')
:wikitext(args['team2'])
 
row = rtable:tag('tr')
:addClass('fgoals')
:newline()
row:tag('td')
:addClass('fhgoal')
:wikitext(fbxb.fmtlist(args['goals1']))
row:newline()
row:tag('td')
:wikitext(fbxb.makelink(args['report'] or '', '(отчёт)'))
row:newline()
row:tag('td')
:addClass('fagoal')
:wikitext(fbxb.fmtlist(args['goals2']))
row:newline()
 
if args['penaltyscore'] then
rtable
:tag('tr')
:tag('th')
:attr('colspan', 3)
:wikitext(fbxb.labels.penalties)
row = rtable:tag('tr')
:addClass('fgoals')
row:newline()
row:tag('td')
:addClass('fhgoal')
:wikitext(fbxb.fmtlist(args['penalties1']))
row:newline()
row:tag('th')
:wikitext(args['penaltyscore'])
row:newline()
row:tag('td')
:addClass('fagoal')
:wikitext(fbxb.fmtlist(args['penalties2']))
row:newline()
end
-- End table
 
-- Start right block
block = root:tag('div')
:addClass('mobile-float-reset')
:addClass('fright')
 
if args['stadium'] then
local sdiv = block:tag('div')
if args['location'] then
sdiv:tag('span')
:wikitext(args['stadium'])
sdiv:wikitext(', ')
sdiv:tag('span')
:wikitext(args['location'])
else
sdiv:tag('span')
:wikitext(args['stadium'])
end
end
 
if args['attendance'] then
block:tag('div'):wikitext(fbxb.labels.attendance ..' ' .. args['attendance'])
end
if args['referee'] then
block:tag('div'):wikitext(fbxb.labels.referee .. ' ' .. args['referee'])
end
 
local squads = {}
 
if fbxb.isnotempty(args['squad1']) then
table.insert(squads, fbxb.bold(fbxb.check_team_pattern(args['team1'])) .. ": " .. args['squad1'])
end
if fbxb.isnotempty(args['squad2']) then
table.insert(squads, fbxb.bold(fbxb.check_team_pattern(args['team2'])) .. ": " .. args['squad2'])
end
 
if #squads > 0 then
local squad_table = root:tag('table')
:css('float', 'left')  
:css('width', '100%')
:css('table-layout', 'fixed')
:css('text-align', 'left')
:css('vertical-align', 'bottom')
:css('font-size', '85%')
squad_table:tag('tr'):tag('td')
:wikitext(table.concat(squads, '<br>'))
end


local trackstr = (#tracking > 0) and table.concat(tracking, '') or ''
function p.delink(frame)
if #preview > 0 and frame:preprocess( "{{REVISIONID}}" ) == "" then
    if not getArgs then
trackstr = tostring(mw.html.create('div')
    getArgs = require('Module:Arguments').getArgs
:addClass('hatnote')
    end
:css('color','red')
    return p._delink(getArgs(frame, {wrappers = 'Template:Delink'}))
:tag('strong'):wikitext('Внимание:'):done()
:wikitext('Неизвестные параметры: ' .. table.concat(preview, '; ')))
end
return frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles} } .. tostring(root) .. trackstr
end
end


return p
return p