Modulo:Bozza: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
passo arg e arg2 |
riorganizzo codice |
||
Riga 3:
local p = {}
local getArgs = require('Module:Arguments').getArgs
local function checkForCategories(str)
local catpattern = "[Cc][Aa][Tt][Ee][Gg][Oo][Rr][YyIi][Aa]?"
for colonprefix in str:gmatch('%[%[ *(' .. catpattern .. ') *: *[^%s][^\n]-%]%]') do
local ns = mw.site.namespaces[colonprefix]
if ns and ns.canonicalName == 'Category' then
return '[[Categoria:Bozze con categorie da disabilitare]]'
end
end
end
local function createRow(text1, text2)
return mw.html.create('div')
:addClass('bozza-history-row')
:tag('div')
:wikitext(text1)
:done()
:tag('div')
:wikitext(text2)
:done()
:done()
end
local function pairsByTimestamp(t)
local a = {}
local i = 0
local comp = function (ts1, ts2)
return ts1 > ts2
end
for ts in pairs(t) do
table.insert(a, ts)
end
table.sort(a, comp)
local iter = function ()
i = i + 1
if not a[i] then
return
else
return a[i], t[a[i]]
end
end
return iter
end
local function removeFalsePositives(str)
return str
:gsub('<!%-%-.-%-%->', '')
:gsub('<nowiki>.-</nowiki>', '')
:gsub('%f[%{]%{%f[^%{]', '\r')
:gsub('%{%{ *[Cc]ategorie *bozza *%|.-%}%}', '')
end
local function replace(str, pattern, replace)
Line 14 ⟶ 71:
for tmp in text:gmatch('%{(%b{})%}') do
local
stored_submissions, tmp = getSubmissions(stored_submissions, tmp)
new_text = replace(new_text,
if tmp:find('^%{ *[Rr]ichiesta *revisione *bozza *[%|%}]') then
Line 22 ⟶ 79:
new_text = replace(new_text, submission, '')
tmp = tmp:gsub('%{%b{}%}', '{{')
submission = submission:gsub('\r', '{')
local ts = tmp:match('%| *ts *= *(%d%d%d%d%d%d%d%d%d%d%d%d%d%d) *[%|%}]')
Line 35 ⟶ 93:
return stored_submissions, new_text
end
function p.main(frame)
local current_title = mw.title.getCurrentTitle()
local text = current_title:getContent()
if current_title.namespace == 0 then
return '[[Categoria:Rimuovere template Bozza]]'
elseif not text then
return
else
text = removeFalsePositives(text)
end
local args = getArgs(frame, { parentOnly = true })
Line 93 ⟶ 123:
if next(submissions.old) then
local i = 0
local styles = frame:extensionTag{
name = 'templatestyles',
args = { src = 'Modulo:Bozza/styles.css' }
}
local header = createRow('Data richiesta', 'Esito revisione')
:addClass('nomobile bozza-history-header')
local collapsed_submissions = mw.html.create('div')
:addClass('nomobile mw-collapsible mw-collapsed')
:attr('data-expandtext', 'mostra richieste precedenti')
:attr('data-collapsetext', 'nascondi richieste precedenti')
history_table = mw.html.create('div')
:addClass('bozza-history')
:
for ts, a in pairsByTimestamp(submissions.old) do
Line 120 ⟶ 146:
if i == 2 then
history_table:node(collapsed_submissions)
end
for _, submission in ipairs(a) do
submission = submission:gsub('%}%}$', '|mostra esito=x}}')
local root = i > 1 and collapsed_submissions or history_table
local row = createRow(jFY, frame:preprocess(submission))
end
end
Line 148 ⟶ 161:
end
return frame:expandTemplate{ title = 'Template:Bozza/avviso', args = {
state,
arg = args.arg or args.arg1,
arg2 = args.arg2,
['cronologia revisioni'] = history_table
} } .. (current_title.namespace == 118 and checkForCategories(text) or '')
end
|