Jump to content

Module:User scripts table and Module:User scripts table/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
m It failed to parse the author for MediaWiki:Easy-brfa.js - added an empty string as default
 
No edit summary
 
Line 4: Line 4:
return s:gsub('([%^%$%(%)%%%.%[%]%*%+%-])', '%%%1')
return s:gsub('([%^%$%(%)%%%.%[%]%*%+%-])', '%%%1')
:gsub('%a', function(letter) return '['..letter:upper()..letter:lower()..']' end)
:gsub('%a', function(letter) return '['..letter:upper()..letter:lower()..']' end)
end

local function getParam(content, template, parameter)
if content == nil then return ''
else return content:gsub('%b{}',
function(templated)
return templated:gsub('^{{%s*'..template..'%s*(|.-})}$',
function(parameters)
return parameters:gsub('|%s*'..allcases(parameter)..'%s*=%s*([^|}]+)', '%1')
end)
end)
end
end
end


Line 13: Line 25:
local rows = mw.html.create()
local rows = mw.html.create()
local count = 0
local count = 0
for script, total, active in source:gmatch('\n| %[%[([^%]]+)%]%] -\n| (%d+) -\n| (%d+)') do
for scriptTitle, total, active in source:gmatch('\n| %[%[([^%]]+)%]%] -\n| (%d+) -\n| (%d+)') do
count = count + 1
count = count + 1
if count > rowOffset then
if count > rowOffset then
local redirectTarget = mw.title.new(script).redirectTarget
local redirectTarget = mw.title.new(scriptTitle).redirectTarget
if redirectTarget then script = redirectTarget.prefixedText end
if redirectTarget then local scriptTitle = redirectTarget.prefixedText end
local jsContent = mw.title.new(script):getContent() or ''
local scriptText = mw.title.new(scriptTitle):getContent()
-- don't include scripts that have been blanked or redirected as non-functional
-- don't include scripts that have been blanked or redirected as non-functional
if not jsContent:find("mw.log.warn( 'You installed the userscript", 1, true) then
if not scriptText:find("mw.log.warn( 'You installed the userscript", 1, true) then
data[script] = { total = total, active = active }
data[scriptTitle] = { total = total, active = active }
local desc = script:match('(.-)%.[CJcj][Ss][Ss]?$')
local docTitle = scriptTitle:match('(.-)%.[CJcj][Ss][Ss]?$')
local redirectTarget = mw.title.new(desc).redirectTarget
local redirectTarget = mw.title.new(docTitle).redirectTarget
if redirectTarget then desc = redirectTarget.prefixedText end
if redirectTarget then local docTitle = redirectTarget.prefixedText end
local name = desc:match('([^/:]-)$')
local name = docTitle:match('([^/:]-)$')
local author = script:match('User:([^%/]+)')
local author = scriptTitle:match('User:([^%/]+)')
local excerpt = mw.title.new(desc):getContent() or ''
local desc = ''
if excerpt ~= '' then
local status = ''
local browsers = ''
excerpt = mw.text.truncate(excerpt
local skins = ''
--keep descriptions from template params
local docText = mw.title.new(docTitle):getContent() or ''
--expand {{u}} at top level
if docText ~= '' then
--remove other templates
name = getParam(docText, '[Ii]nfobox user script', 'name') or getParam(docText, '[Ii]nfobox wikipedia user script', 'name') or docTitle:match('([^/:]-)$')
:gsub("%b{}", function(bracketed)
author = getParam(docText, '[Ii]nfobox user script', 'author') or getParam(docText, '[Ii]nfobox wikipedia user script', 'author') or script:match('User:([^%/]+)')
local desc_first, desc_rest = bracketed:match('|%s*[Dd][Ee][Ss][Cc][^=]+=%s*([^|])([^|]+)|')
status = getParam(docText, '[Ii]nfobox user script', 'status') or getParam(docText, '[Ii]nfobox wikipedia user script', 'status') or ''
if desc_first then
browsers = getParam(docText, '[Ii]nfobox user script', 'browsers') or getParam(docText, '[Ii]nfobox wikipedia user script', 'browsers') or ''
return desc_first:upper() .. desc_rest
skins = getParam(docText, '[Ii]nfobox user script', 'skins') or getParam(docText, '[Ii]nfobox wikipedia user script', 'skins') or ''
end
desc = getParam(docText, '[Ii]nfobox user script', 'desc') or getParam(docText, '[Ii]nfobox wikipedia user script', 'desc') or mw.text.truncate(docText
local user = bracketed:find "^{{[Uu]|([^}]+)}}"
--keep descriptions from template params
if user then
return '[[User:' .. user .. '|' .. user .. ']]'
:gsub('^{{[Uu]|([^}]+)', '[[User:%1|%1]]') --expand {{u}} at top level
:gsub("%b{}", '') --remove other templates
end
if bracketed:find('^{{') and bracketed:find('}}$') then
return ''
end
end)
--strip out images, files, media, categories
--strip out images, files, media, categories
:gsub('%b[]',
:gsub('%b[]',
Line 78: Line 86:
:gsub('(%s)%s+', '%1') --strip redundant spaces
:gsub('(%s)%s+', '%1') --strip redundant spaces
:gsub(allcases(name)..'(%s)', "'''"..name.."'''%1")
:gsub(allcases(name)..'(%s)', "'''"..name.."'''%1")
, 600, ''):gsub('(.+)\n', '%1') -- truncate at end of last paragraph before 600 chars
, 600, ''):gsub('^(.+%.).+$', '%1') --truncate at end of last sentence before 600 chars
..' '..'[['..desc..'|→]]'
.. '<!-- -->'
desc = mw.text.trim(desc):gsub('^(.+)%.$', '%1')..'.' --trim and add last period, if missing
.. '<!-- -->' -- add an empty HTML comment so that if the excerpt ends with an unclosed comment (such as [[User:Steel359/Protection js]]), it doesn't break things
.. ' [[' .. docTitle .. '|→]]' --add arrow link to full doc
end
end
local row = rows:tag('tr'):attr('id', scriptTitle):attr('style','vertical-align:top')
if not excerpt then excerpt = '' end
if docText == '' then link = scriptTitle else link = docTitle end
local row = rows:tag('tr'):attr('id', script):attr('style','vertical-align:top')
row:tag('td'):wikitext(string.format('\'\'\'[[%s|%s]]\'\'\'<span id="%s" class=scriptInstallerLink></span>', script, name, script))
row:tag('td'):wikitext(string.format('\'\'\'[[%s|%s]]\'\'\'<span id="%s" class=scriptInstallerLink></span>\n<p>%s</p>', link, name, scriptTitle, desc))
row:tag('td'):wikitext(author and string.format('[[User:%s|%s]]', author, author) or '')
row:tag('td'):wikitext(string.format('[[User:%s|%s]]', author, author))
row:tag('td'):wikitext(frame:callParserFunction('#time', 'j M Y', frame:callParserFunction('REVISIONTIMESTAMP', script))):addClass('nowrap'):attr('style','text-align:right')
row:tag('td'):wikitext(frame:callParserFunction('#time', 'j M Y', frame:callParserFunction('REVISIONTIMESTAMP', scriptTitle))):addClass('nowrap'):attr('style','text-align:right')
row:tag('td'):wikitext(excerpt)
row:tag('td'):wikitext(status)
row:tag('td'):wikitext(data[script].active):attr('style','text-align:right')
row:tag('td'):wikitext(skins)
row:tag('td'):wikitext(data[script].total):attr('style','text-align:right')
row:tag('td'):wikitext(browsers)
row:tag('td'):wikitext(data[scriptTitle].active):attr('style','text-align:right')
row:tag('td'):wikitext(data[scriptTitle].total):attr('style','text-align:right')
rows:wikitext('\n')
rows:wikitext('\n')
end
end