Module:ParsePage

--

This module is a collection of functions to assist in extracting information

from full Wikipedia pages.

It is not intended to be a full parser, or anything like that, merely a simple

system for grabbing a few relevant details. These functions are not intended

to be called directly from templates, but rather these functions would be

included and referenced in other Lua modules that examine page text.

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( {, name, } );

table.insert( user_table, {ind, name, link} );

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( {, name, } );

table.insert( user_table, {ind, name, link} );

else

link = table.concat( {, name, } );

table.insert( user_table, {ind, name, link} );

end

end

table.sort( usertable, p.comp1 );

else

search_re = '%%User:(^/-)%#';

for name in string.gmatch( text, search_re ) do

link = table.concat( {, name, } );

table.insert( user_table, {0, name, link} );

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( {, name, } );

table.insert( user_table, {0, name, link} );

else

link = table.concat( {, name, } );

table.insert( user_table, {0, name, link} );

end

end

local comp = function( a, b )

return a2 ', );

link = string.gsub( link, '%%', );

link = string.gsub( link, '%%', );

return table.concat( { .. link .. } );

end

p.formatDateDiff =

function( date_diff )

if date_diff ', "" ); --tags

text = string.gsub( text, '{', "{" ); --tags

text = string.gsub( text, '{', "}" ); --tags

if mw.ustring.len( text ) < length then

return text;

else

return mw.ustring.sub( text, 1, length ) ..

mw.ustring.match( text, '%S*', length+1 ) .. '...';

end

end

function p._compKey( a, b, key )

return akey < bkey;

end

function p._comp1( a, b )

return p._compKey( a, b, 1 );

end

function p._makeUniqueTable( t, key, sort )

sort = sort or false;

local comp;

if key then

comp = function( a, b )

return p._compKey( a, b, key );

end

else

comp = nil;

end

if sort then

if comp then

table.sort( t, comp );

else

table.sort( t );

end

local new_table, last;

new_table = ;

last =

for k, v in ipairs( t ) do

if key then

if vkey ~= last then

table.insert( new_table, v );

last = vkey;

end

else

if v ~= last then

table.insert( new_table, v );

last = v;

end

end

end

return new_table;

else

local simple_table = ;

local new_table = ;

for _, item in ipairs( t ) do

if key then

if not simple_tableitemkey then

table.insert( new_table, item )

end

simple_tableitemkey = true;

else

if not simple_tableitem then

table.insert( new_table, item )

end

simple_tableitem = true;

end

end

return new_table;

end

end

return p;