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

нет описания правки
Нет описания правки
Метка: отменено
Нет описания правки
 
Строка 1: Строка 1:
-- This module de-links most wikitext.
-- Модуль для шаблона [[Шаблон:Footballbox]]
local fbxb = require("Module:Football box/base")


require('Module:No globals')


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


local p = {}
local tracking, preview


local getArgs
local function checkarg(k,v)
fbxb.checkarg(k, v, 'Страницы, использующие шаблон footballbox с неизвестными параметрами', tracking, preview)
end


local function delinkReversePipeTrick(s)
local function timestamp(d, t)
    if s:match("^%[%[|.*[|\n]") then -- Check for newlines or multiple pipes.
if d then
        return s
lang = lang or mw.language.getContentLanguage() -- lazy initialize
    else
local success, timestamp = pcall(lang.formatDate, lang, 'c', delink({d .. ' ' .. (t or '')}))
        return s:match("%[%[|(.*)%]%]")
if success then
    end
return timestamp
else
return nil
end
end
return nil
end
end


local function delinkPipeTrick(s)
local function getid(s)
    local linkarea, display = "", ""
s = fbxb.trim(s or '')
    -- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].
if fbxb.isnotempty(s) then
   
return s
    -- First, remove the text before the first colon, if any.
end
    if s:match(":") then
return nil
        s = s:match("%[%[.-:(.*)|%]%]")
    -- If there are no colons, grab all of the text apart from the square brackets and the pipe.
    else
        s = s:match("%[%[(.*)|%]%]")
    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 delinkWikilink(s)
function p.main(frame)
    local result = s
local args = require('Module:Arguments').getArgs(frame)
    -- Deal with the reverse pipe trick.
local id = getid(args['id'])
    if result:match("%[%[|") then
local d = timestamp(args['date'], args['time'])
        return delinkReversePipeTrick(result)
local block
    end
 
   
tracking, preview = {}, {}
    result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
fbxb.process_rus_params(args)
    result = mw.text.decode(result, true) -- decode HTML entities.
for k, v in pairs(args) do
   
if v ~= '' then
    -- Check for bad titles. To do this we need to find the
checkarg(k,v)
    -- title area of the link, i.e. the part before any pipes.
end
    local titlearea
end
    if result:match("|") then -- Find if we're dealing with a piped link.
 
        titlearea = result:match("^%[%[(.-)|.*%]%]")
local score = '–:–'
    else
if args['score1'] or args['score2'] then
        titlearea = result:match("^%[%[(.-)%]%]")
score = (args['score1'] or '0') .. ':' .. (args['score2'] or '0')
    end
elseif fbxb.isnotempty(args['score']) then
    -- Check for bad characters.
score = args['score']
    if mw.ustring.match(titlearea, "[%[%]<>{}%%%c\n]") then
end
        return s
if args['aet'] then
    end
score = score .. ' (' .. fbxb.labels.aet .. ')'
   
end
    -- Check for categories, interwikis, and files.
if args['scorenote'] then
    local colonprefix = result:match("%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.
score = score .. '<br>' .. args['scorenote']
    local ns = mw.site.namespaces[colonprefix] -- see if this is a known namespace
end
    if mw.language.isKnownLanguageTag(colonprefix)
 
    or ( ns and ( ns.canonicalName == "File" or ns.canonicalName == "Category" ) ) then
-- Start box
        return ""
local root =  
    end
mw.html.create('div')
   
:addClass('footballbox')
    -- Remove the colon if the link is using the [[Help:Colon trick]].
:css('width', args['size'])
    if result:match("%[%[:") then
:css('background-color', args['bg'])
        result = "[[" .. result:match("%[%[:(.*%]%])")
:attr('id', id)
    end
root:newline()
   
    -- Deal with links using the [[Help:Pipe trick]].
if args['event'] then
    if mw.ustring.match(result, "^%[%[[^|]*|%]%]") then
root:tag('div')
        return delinkPipeTrick(result)
:addClass('ftitle')
    end
:wikitext(args['event'])
   
end
    -- Find the display area of the wikilink
 
    if result:match("|") then -- Find if we're dealing with a piped link.
-- Start left block
        result = result:match("^%[%[.-|(.+)%]%]")
block = root:tag('div')
        -- Remove new lines from the display of multiline piped links,
:addClass('mobile-float-reset')
        -- where the pipe is before the first new line.
:addClass('fleft')
        result = result:gsub("\n", "")
    else
local timetag = block:tag('time')
        result = result:match("^%[%[(.-)%]%]")
:attr('itemprop', d and 'startDate' or nil)
    end
: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


    return result
if args['attendance'] then
end
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 function delinkURL(s)
local squads = {}
    -- Assume we have already delinked internal wikilinks, and that
    -- we have been passed some text between two square brackets [foo].
   
    -- 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


local function delinkLinkClass(s, pattern, delinkFunction)
if fbxb.isnotempty(args['squad1']) then
    if not type(s) == "string" then
table.insert(squads, fbxb.bold(fbxb.check_team_pattern(args['team1'])) .. ": " .. args['squad1'])
        error("Attempt to de-link non-string input.", 2)
end
    end
if fbxb.isnotempty(args['squad2']) then
    if not ( type(pattern) == "string" and mw.ustring.sub(pattern, 1, 1) == "^" ) then
table.insert(squads, fbxb.bold(fbxb.check_team_pattern(args['team2'])) .. ": " .. args['squad2'])
        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


function p._delink(args)
if #squads > 0 then
    local text = args[1] or ""
local squad_table = root:tag('table')
    if yesno(args.markers) == true then
:css('float', 'left')  
        text = mw.text.killMarkers(text) -- [[Help:Strip markers]]
:css('width', '100%')  
    end
:css('table-layout', 'fixed')  
    if yesno(args.refs) == true then
:css('text-align', 'left')
        -- Remove any [[Help:Strip markers]] representing ref tags. In most situations
:css('vertical-align', 'bottom')
        -- this is not a good idea - only use it if you know what you are doing!
:css('font-size', '85%')
        text = mw.ustring.gsub(text, "UNIQ%w*%-ref%-%d*%-QINU", "")
squad_table:tag('tr'):tag('td')
    end
:wikitext(table.concat(squads, '<br>'))
    if not (yesno(args.wikilinks) == false) then
end
        text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink) -- De-link wikilinks.
    end
    if not (yesno(args.urls) == false) then
        text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.
    end
    if not (yesno(args.comments) == false) then
        text = text:gsub("<!%-%-.-%-%->", "") -- Remove html comments.
    end
    if not (yesno(args.whitespace) == false) then
        -- 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.
        text = mw.ustring.gsub(text, "([^\n \t][ \t]*)\n([ \t]*[^\n \t])", "%1 %2")
        text = text:gsub("[ \t]+", " ") -- Remove extra tabs and spaces.
    end
    return text
end


function p.delink(frame)
local trackstr = (#tracking > 0) and table.concat(tracking, '') or ''
    if not getArgs then
if #preview > 0 and frame:preprocess( "{{REVISIONID}}" ) == "" then
    getArgs = require('Module:Arguments').getArgs
trackstr = tostring(mw.html.create('div')
    end
:addClass('hatnote')
    return p._delink(getArgs(frame, {wrappers = 'Template:Delink'}))
:css('color','red')
: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