Module:RandomArticle

local p = {}

L = {} N = {} count = 0

function ArtistInsert(Link, Name) table.insert(L, Link) table.insert(N, Name) count = count + 1 end

--======================== DATA INSERT: Syntax: ArtistInsert('Link','Name') ========================

function PopulateBand ArtistInsert('X JAPAN','X JAPAN') ArtistInsert('The GazettE','the GazettE') ArtistInsert('King Gnu','King Gnu') ArtistInsert('Mrs. GREEN APPLE','Mrs. GREEN APPLE') ArtistInsert('MAN WITH A MISSION','MAN WITH A MISSION') ArtistInsert('Unlucky Morpheus','Unlucky Morpheus') ArtistInsert('BAND-MAID','BAND-MAID') ArtistInsert('BABYMETAL','BABYMETAL') end

function PopulateSoloist ArtistInsert('LiSA','LiSA') end

function PopulateGroup ArtistInsert('CY8ER','CY8ER') ArtistInsert('Little Glee Monster','Little Glee Monster') ArtistInsert('ZOC','ZOC') ArtistInsert('MIGMA SHELTER','MIGMA SHELTER') ArtistInsert('Atarashii Gakkou no Leaders','Atarashii Gakkou no Leaders') end

function PopulateArtist PopulateBand PopulateGroup PopulateSoloist end

--================================================ Module functions ================================================

--Pattern from Template:FAid pattern = [==[{|style="height:20px" cellpadding="2" style="float:left; border: 2px solid primarycolor "width="100%" bgcolor="primarycolor" !colspan=1 bgcolor="#e15467" align="center" colspan="8"| titleplaceholder
 * align="center" bgcolor="primarycolor" width="160px" | fileplaceholder
 * align="left" valign="top" bgcolor="backgroundcolor"|
 * descplaceholder
 * ...Read more about nameplaceholder
 * ...Read more about nameplaceholder


 * }]==]

function ParsePage(title) math.randomseed(os.time) index = math.random(count) link = L[index] name = N[index] local page = mw.title.new(link) local content = page:getContent --get image from the infobox field "image" image = string.match(content, 'image%s*=%s*(.-%.%a%a%a?%a)') if(image == nil) then --if it fails, get it from a file include image = string.match(content, '%[%[File:(.-%.%a%a%a?%a)') end if(image == nil) then --if it fails, try to get it from anything followed by a 3/4 letter file extension image = string.match(content, '.-%.%a%a%a?%a') end --replace PAGENAME template with predefined actual name content = content:gsub('', name) --getting description, starting from the first paragraph of the page, --where the name of it is mentioned between   descPattern = "'''%s*" .. name .. "%s*'''*.*" description = string.match(content, descPattern) if(description == nil) then --if no description with this pattern is found, it will be just the name of the page description = "'''" .. name .. "'''"	end --removes references description = description:gsub('.* ', '') --removes files description = description:gsub('%[%[File:.*%]%]', '') --removes everything starting from the first double linebreak description = description:gsub('\n\n.*', '') --limiting maximum length of description if(string.len(description) > 350) then description = description:sub(1,350) --removing last word (probably cropped) and replacing with ... description = description:gsub('%s%a*$', '...') end return BuildFAid(title, link, name, image, description) end

function BuildFAid(title, link, name, image, description) size = '250px' primarycolor = '#e15467' backgroundcolor = '#ffffff' pattern = pattern:gsub('primarycolor', primarycolor) pattern = pattern:gsub('backgroundcolor', backgroundcolor) pattern = pattern:gsub('titleplaceholder', title) pattern = pattern:gsub('fileplaceholder', image) pattern = pattern:gsub('sizeplaceholder', size) pattern = pattern:gsub('linkplaceholder', L[index]) pattern = pattern:gsub('descplaceholder', description) pattern = pattern:gsub('nameplaceholder', N[index]) return pattern end

function p.GetBand PopulateBand if(count > 0) then return ParsePage('Featured Band') end end

function p.GetGroup PopulateGroup if(count > 0) then return ParsePage('Featured Group') end end

function p.GetSoloist PopulateSoloist if(count > 0) then return ParsePage('Featured Soloist') end end

function p.GetArtist PopulateArtist if(count > 0) then return ParsePage('Featured Artist') end end return p