Module:User scripts table
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
This module reads the table in WP:User scripts/Most imported scripts and produces the one in WP:User scripts/Ranking.
Usage
The module can be called either directly through {{#invoke:User scripts table|main}} or via its associated template {{User scripts table}}.
local p = {}
local function allcases(s)
return s:gsub('([%^%$%(%)%%%.%[%]%*%+%-])', '%%%1')
:gsub('%a', function(letter) return '['..letter:upper()..letter:lower()..']' end)
end
function p.main(frame)
local rowsToGet = tonumber(frame.args[1]) or 200 -- use this to determine number of rows to get (default 200)
local rowOffset = tonumber(frame.args[2]) or 0 -- use this offset to allow multiple calls to build larger table
local source = mw.title.new('Wikipedia:User scripts/Most imported scripts'):getContent()
local data = {}
local rows = mw.html.create()
local count = 0
for script, total, active in source:gmatch('\n| %[%[([^%]]+)%]%] -\n| (%d+) -\n| (%d+)') do
count = count + 1
if count > rowOffset then
local redirectTarget = mw.title.new(script).redirectTarget
if redirectTarget then script = redirectTarget.prefixedText end
local jsContent = mw.title.new(script):getContent() or ''
-- 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
data[script] = { total = total, active = active }
local desc = script:match('(.-)%.[CJcj][Ss][Ss]?$')
local redirectTarget = mw.title.new(desc).redirectTarget
if redirectTarget then desc = redirectTarget.prefixedText end
local name = desc:match('([^/:]-)$')
local author = script:match('User:([^%/]+)')
local excerpt = mw.title.new(desc):getContent() or ''
if excerpt ~= '' then
excerpt = mw.text.truncate(excerpt
--keep descriptions from template params
--expand {{u}} at top level
--remove other templates
:gsub("%b{}", function(bracketed)
local desc_first, desc_rest = bracketed:match('|%s*[Dd][Ee][Ss][Cc][^=]+=%s*([^|])([^|]+)|')
if desc_first then
return desc_first:upper() .. desc_rest
end
local user = bracketed:find "^{{[Uu]|([^}]+)}}"
if user then
return '[[User:' .. user .. '|' .. user .. ']]'
end
if bracketed:find('^{{') and bracketed:find('}}$') then
return ''
end
end)
--strip out images, files, media, categories
:gsub('%b[]',
function(bracketed)
return bracketed:gsub('^%[%[%s*(%a+):.-%]%]$',
function(link_prefix)
link_prefix = link_prefix:lower()
if link_prefix == "image" or link_prefix == "file"
or link_prefix == "media" or link_prefix == "category" then
return ""
end -- otherwise leave it alone
end)
end)
--remove spans while keeping text inside
--strip out remaining tags and the text inside
:gsub('<(%a+)[^>]+>(.-)</%1>', function(tag, contents)
if tag:lower() == "span" then
return contents
else
return ""
end
end)
:gsub('%b<>', '') --remove any other tag markup
:gsub('__[^_]+__', '') --remove __ markups
:gsub('^=+[^=]+=+', ''):gsub('\n=+[^=]+=+', '') --remove section titles
:gsub("''+", "") --strip out bold and italic markup
:gsub(' ', ' ') --replace nbsp spaces with regular spaces
:gsub('^[:;%s]+', ''):gsub('\n[:;%s]+', '\n') --strip indents, leading
:gsub('{|.-\n|}', '') --remove tables
:gsub('\n|[^\n]*\n', '') --remove table fragments
:gsub('%s+\n', '\n') --and trailing spaces
:gsub('(%s)%s+', '%1') --strip redundant spaces
:gsub(allcases(name)..'(%s)', "'''"..name.."'''%1")
, 600, ''):gsub('(.+)\n', '%1') -- truncate at end of last paragraph before 600 chars
..' '..'[['..desc..'|→]]'
.. '<!-- -->' -- 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
end
if not excerpt then excerpt = '' 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(author and string.format('[[User:%s|%s]]', author, author) or '')
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(excerpt)
row:tag('td'):wikitext(data[script].active):attr('style','text-align:right')
row:tag('td'):wikitext(data[script].total):attr('style','text-align:right')
rows:wikitext('\n')
end
end
if count >= rowsToGet + rowOffset then break end
end
return rows
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.