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') ArtistInsert('ALI','ALI') ArtistInsert('NEMOPHILA','NEMOPHILA') ArtistInsert('SPYAIR','SPYAIR') --ArtistInsert(,) end

function PopulateSoloist ArtistInsert('LiSA','LiSA') ArtistInsert('Shiina Hikari','Shiina Hikari') --ArtistInsert(,) 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') ArtistInsert('Dempagumi.inc','Dempagumi.inc') --ArtistInsert(,) 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="backgroundcolor" | fileplaceholder
 * align="left" valign="top" bgcolor="backgroundcolor" style="padding:1px 20px 1px 20px;"|
 * 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" as 	image = string.match(content, 'image%s*=%s*%[%[File:(.-%.%a%a%a?%a)') if(image == nil) then --if it fails, get it from the infobox field "image" as imgpath image = string.match(content, 'image%s*=%s*(.-%.%a%a%a?%a)') end if(image == nil) then --if it fails, get it from anywhere else as [[File:imgpath]] image = string.match(content, '%[%[File:(.-%.%a%a%a?%a)') end if(image == nil) then --if it fails, try to get it from anywhere else as imgpath image = string.match(content, '.-%.%a%a%a?%a') end --replace PAGENAME template with predefined actual name description = 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(description, 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 section description = description:gsub('==+.*==+.*', '') --removes multiple linebreaks description = description:gsub('\n\n+', '\n') --removes any template in the text description = description:gsub(, ) --limiting maximum length of description if(string.len(description) > 300) then --cropping at 300 characters description = description:sub(1,300) --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 = '220px' 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

function p.Debug ArtistInsert('BAND-MAID','BAND-MAID') if(count > 0) then return ParsePage('Debug') end end return p