--
p =
p.getUsers = function (text, sort, unique) sort = sort or false; unique = unique or false; local user_table = ; local search_re, link; -- Note, mw.ustring.gmatch is relatively slow. Should switch to -- string once the string.gmatch bug is resolved. if not sort then search_re = '%[%[User:([^/]-)[|%]#]'; for ind, name in string.gmatch(text, search_re) do link = table.concat; table.insert(user_table,); end search_re = '%[%[User talk:([^/]-)[|%]#]'; for ind, name in string.gmatch(text, search_re) do if string.match(name, '^%d-%.%d-%.%d-%.%d-$') or string.match(name, '^[%dA-F]-:[%dA-F]-:[%dA-F]-:[%dA-F]-:[%dA-F]-:[%dA-F]$') then link = table.concat; table.insert(user_table,); else link = table.concat; table.insert(user_table,); end end table.sort(user_table, p._comp1); else search_re = '%[%[User:([^/]-)[|%]#]'; for name in string.gmatch(text, search_re) do link = table.concat; table.insert(user_table,); end search_re = '%[%[User talk:([^/]-)[|%]#]'; for name in string.gmatch(text, search_re) do if string.match(name, '^%d-%.%d-%.%d-%.%d-$') or string.match(name, '^[%dA-F]-:[%dA-F]-:[%dA-F]-:[%dA-F]-:[%dA-F]-:[%dA-F]$') then link = table.concat; table.insert(user_table,); else link = table.concat; table.insert(user_table,); end end local comp = function(a, b) return a[2] < b[2]; end table.sort(user_table, comp); end if unique then user_table = p._makeUniqueTable(user_table, 2, sort); end
local name_table = ; local last; for _, v in ipairs(user_table) do if v[2] ~= last then table.insert(name_table,); end last = v[2]; end
return name_table;end
p.getSections =function(text, header_level) local head_item = '^' .. string.rep('=', header_level) .. '[^=]'; local head_filter = table.concat; local pos, last_pos, total_len; local new_table = ; local line_group = ; local headings = ; local header_delink; for line in string.gmatch(text, "\n([^\n]*)") do if string.match(line, head_item) then table.insert(new_table, table.concat(line_group, "\n")); header_delink = mw.ustring.match(line, head_filter); header_delink = string.match(header_delink, "%|(.*)%]%]") or header_delink; --strip piped links table.insert(headings, header_delink); line_group = ; else table.insert(line_group, line); end end table.insert(new_table, table.concat(line_group)); return new_table, headings;end
p.getTimestamps = function (text) local time_table = ; local lang = mw.getContentLanguage; local val; -- 01:02, 28 February 2013 (UTC) for ts in string.gmatch(text, '%d%d:%d%d, %d%d? %w- %d%d%d%d %(UTC%)') do val = tonumber(lang:formatDate('U', ts)); table.insert(time_table,); end return time_table;end
p.formatSectionLink =function(root, text) local frame = mw.getCurrentFrame; local link = text; link = string.gsub(link, '%b<>', ); link = string.gsub(link, '%[%[', ''); link = string.gsub(link, '%]%]', ); return table.concat; end
p.formatDateDiff = function(date_diff) if date_diff < 60*60 then return tonumber(math.floor(date_diff/6)/10) .. ' minutes'; elseif date_diff < 60*60*24 then return tonumber(math.floor(date_diff/(6*60))/10) .. ' hours'; else return tonumber(math.floor(date_diff/(6*60*24))/10) .. ' days'; endend
p.getExcerpt = function(text, length) length = length or 200; text = '\n' .. text .. '\n'; text = string.gsub(text, '\n=+[^=]-=+', '\n'); --headings text = string.gsub(text, '%[%[File:[^%]]*%]%]', ); --files text = string.gsub(text, '%[%[Image:[^%]]*%]%]', ); --images text = mw.ustring.match(text, '%s*(%S.*%S)%s*'); --trim text = string.gsub(text, '|', "|"); --table text = string.gsub(text, '%b<>', ""); --tags text = string.gsub(text, '