Module:RDIndex
This module is responsible for making the Lua-based archive pages for the Refdesk at WP:Reference desk/Archives/Lua.
Usage
For all the recent archives like WP:Reference desk/Archives/Lua/Science/January 2013, it extracts the month, year, and desk from the title string if they are not otherwise specified. (The exact order doesn't matter; it does a text search) Therefore, these pages contain simply:
{{#invoke:RDIndex|month}}
However, conventional parameter-based settings are available to override the defaults thus obtained - however, these haven't been tested much and may need debugging.
Parameters
- cat = a specific category (as provided by the Template:Rdcat pseudo-template) can be specified here, in which case only the pages from that category will be indexed. Or it can be set to "no" and this column is omitted.
- input = a text for the "main" function (not "month") to process
- desk = (Science, Humanities, etc.)
- label = (an arbitrary replacement for the desk to be shown in the table, if provided)
- date = (the date to be shown, if not obtained from the page name)
- arcpage = (the page where the original discussion is archived)
The Rdcat pseudo-template
Template:Rdcat doesn't do anything, because the text is read in by the module without template substitution - this module simply looks for {{Rdcat|xxx|xxx}} and processes it on its own. The first parameter sets a category for display in the table; the second is reserved for a subcategory system within a system.
Categories are things like "biology", "chemistry", "astronomy", "physics", "engineering" under Science. The subcategories would be more specific topics, perhaps evolution, DNA, protein, taxonomy, virology, etc. under Biology. To make the categories and subcategories work it is well-nigh essential to recruit people interested in sorting the questions, and for them to do so pretty consistently.
local p={} -- ultimate planned purpose is to create table rows of Refdesk questions, type, date, answerer including wikilinks in collaboration with a big template
function p.main(frame)
local args=frame.args
local parent=frame:getParent()
local pargs=parent.args
local input=pargs.input or args.input or "ERROR"
local label=pargs.label or args.label or "unlabelled"
local date=pargs.date or args.date or "undated"
local arcpage=pargs.arcpage or args.arcpage or nil
local cat=pargs.cat or args.arcpage or "yes"
if cat=="no" then cat = nil end
local output="no section headings found"
local cursor, next_cursor, questioner, users, user_table, last_user;
local input_length = mw.ustring.len( input );
local breakpoints = {};
local cut, item
for cut, item in mw.ustring.gmatch( input, "\n()==+(.-)==+%s+" ) do
table.insert( breakpoints, cut );
table.insert( breakpoints, item );
end
index = 1;
output = '';
repeat
cursor = tonumber( breakpoints[index] );
title = breakpoints[index + 1];
if cursor == nil then
break;
end
next_cursor = tonumber( breakpoints[index+2] ) or input_length;
text = mw.ustring.sub(input,cursor,next_cursor-1)
tt = mw.ustring.match(title,"[=%s]+(.-)[=%s]+$")
if tt then
title=tt
else
tt = mw.ustring.match(title,"UNIQ.-QINU.(.+)")
if tt then
title=tt
end
end
local tcat=""
if cat then tcat = (mw.ustring.match(text,"<!%-%-=cat (.+)=%-%->") or "") end
text = mw.ustring.gsub(text, "%[%[Special:Contributions/", "[[User:")
questioner = mw.ustring.gsub(mw.ustring.match(text,"%[%[User:(.-)[|%]]") or "","_"," ")
user_table = {}
for tt in mw.ustring.gmatch(text,"%[%[User:(.-)[|%]]" ) do
tt = mw.ustring.gsub(tt,"_"," ")
table.insert( user_table, tt );
end
table.sort( user_table );
last_user = ''
users = '';
for index, tt in pairs( user_table ) do
if tt ~= last_user and tt ~= questioner then
users = table.concat( {users, "[[User:", tt, "|", tt, "]]", " "} );
end
last_user = tt;
end
users = "[[User:" .. questioner .. "|" .. questioner .. "]]" .. " " .. users
title = mw.ustring.gsub( title, '%[%[.-|(.-)%]%]', '%1' );
title = mw.ustring.gsub( title, '%[', '' );
title = mw.ustring.gsub( title, '%]', '' );
title = mw.ustring.gsub( title, '%b<>', '' );
if arcpage then
title= table.concat( {"[[", arcpage, "#", (title or ""), "|", title, "]]"} );
else
title= title or ""
end
output = table.concat( {output, "\n|-\n|", title, "\n|", next_cursor-cursor, "\n|", label, "\n|", tcat, "\n|", date, "\n|", users} ); -- debug ; many more goodies should be placed here!
index = index + 2;
until next_cursor == input_length
return output
end
return p