Module:User scripts table and Module:User scripts table/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
m It failed to parse the author for MediaWiki:Easy-brfa.js - added an empty string as default |
Guarapiranga (talk | contribs) 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 |
||
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 = '' |
||
local status = '' |
|||
local browsers = '' |
|||
excerpt = mw.text.truncate(excerpt |
|||
local skins = '' |
|||
⚫ | |||
local docText = mw.title.new(docTitle):getContent() or '' |
|||
--expand {{u}} at top level |
|||
⚫ | |||
⚫ | |||
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 '' |
|||
⚫ | |||
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 '' |
|||
⚫ | |||
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]|([^}]+)}}" |
|||
⚫ | |||
if user then |
|||
:gsub('^{{[Uu]|([^}]+)', '[[User:%1|%1]]') --expand {{u}} at top level |
|||
⚫ | |||
end |
|||
if bracketed:find('^{{') and bracketed:find('}}$') then |
|||
return '' |
|||
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('(.+) |
, 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 |
|||
.. '<!-- -->' -- 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 |
||
⚫ | |||
if not excerpt then excerpt = '' end |
|||
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( |
row:tag('td'):wikitext(skins) |
||
row:tag('td'):wikitext( |
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 |