Module:User scripts table and Module:User scripts table/sandbox: Difference between pages
(Difference between pages)
imported>Qwerfjkl m It failed to parse the author for MediaWiki:Easy-brfa.js - added an empty string as default |
imported>Guarapiranga 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 | 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( | local redirectTarget = mw.title.new(scriptTitle).redirectTarget | ||
if redirectTarget then | if redirectTarget then local scriptTitle = redirectTarget.prefixedText end | ||
local | 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 | if not scriptText:find("mw.log.warn( 'You installed the userscript", 1, true) then | ||
data[ | data[scriptTitle] = { total = total, active = active } | ||
local | local docTitle = scriptTitle:match('(.-)%.[CJcj][Ss][Ss]?$') | ||
local redirectTarget = mw.title.new( | local redirectTarget = mw.title.new(docTitle).redirectTarget | ||
if redirectTarget then | if redirectTarget then local docTitle = redirectTarget.prefixedText end | ||
local name = | local name = docTitle:match('([^/:]-)$') | ||
local author = | local author = scriptTitle:match('User:([^%/]+)') | ||
local | local desc = '' | ||
if | local status = '' | ||
local browsers = '' | |||
local skins = '' | |||
local docText = mw.title.new(docTitle):getContent() or '' | |||
if docText ~= '' then | |||
name = getParam(docText, '[Ii]nfobox user script', 'name') or getParam(docText, '[Ii]nfobox wikipedia user script', 'name') or docTitle:match('([^/:]-)$') | |||
author = getParam(docText, '[Ii]nfobox user script', 'author') or getParam(docText, '[Ii]nfobox wikipedia user script', 'author') or script:match('User:([^%/]+)') | |||
status = getParam(docText, '[Ii]nfobox user script', 'status') or getParam(docText, '[Ii]nfobox wikipedia user script', 'status') or '' | |||
browsers = getParam(docText, '[Ii]nfobox user script', 'browsers') or getParam(docText, '[Ii]nfobox wikipedia user script', 'browsers') or '' | |||
skins = getParam(docText, '[Ii]nfobox user script', 'skins') or getParam(docText, '[Ii]nfobox wikipedia user script', 'skins') or '' | |||
desc = getParam(docText, '[Ii]nfobox user script', 'desc') or getParam(docText, '[Ii]nfobox wikipedia user script', 'desc') or mw.text.truncate(docText | |||
--keep descriptions from template params | |||
:gsub('^{{[Uu]|([^}]+)', '[[User:%1|%1]]') --expand {{u}} at top level | |||
:gsub("%b{}", '') --remove other templates | |||
--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('(.+) | , 600, ''):gsub('^(.+%.).+$', '%1') --truncate at end of last sentence before 600 chars | ||
..' '..' | .. '<!-- -->' | ||
desc = mw.text.trim(desc):gsub('^(.+)%.$', '%1')..'.' --trim and add last period, if missing | |||
.. ' [[' .. docTitle .. '|→]]' --add arrow link to full doc | |||
end | end | ||
local row = rows:tag('tr'):attr('id', scriptTitle):attr('style','vertical-align:top') | |||
local row = rows:tag('tr'):attr('id', | if docText == '' then link = scriptTitle else link = docTitle end | ||
row:tag('td'):wikitext(string.format('\'\'\'[[%s|%s]]\'\'\'<span id="%s" class=scriptInstallerLink></span>', | 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( | row:tag('td'):wikitext(string.format('[[User:%s|%s]]', author, author)) | ||
row:tag('td'):wikitext(frame:callParserFunction('#time', 'j M Y', frame:callParserFunction('REVISIONTIMESTAMP', | 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( | row:tag('td'):wikitext(status) | ||
row:tag('td'):wikitext(data[ | row:tag('td'):wikitext(skins) | ||
row:tag('td'):wikitext(data[ | 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 | ||