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('ALI','ALI') --this is disabled due to bug ArtistInsert('BAND-MAID','BAND-MAID') ArtistInsert('BABYMETAL','BABYMETAL') ArtistInsert('King Gnu','King Gnu') ArtistInsert('Linked Horizon','Linked Horizon') ArtistInsert('MAN WITH A MISSION','MAN WITH A MISSION') ArtistInsert('Mrs. GREEN APPLE','Mrs. GREEN APPLE') ArtistInsert('NEMOPHILA','NEMOPHILA') ArtistInsert('SPYAIR','SPYAIR') ArtistInsert('The GazettE','the GazettE') ArtistInsert('Unlucky Morpheus','Unlucky Morpheus') ArtistInsert('X JAPAN','X JAPAN') --ArtistInsert(,) end

function PopulateSoloist ArtistInsert('Akiyama Kiro','Akiyama Kiro') ArtistInsert('Hoshino Gen','Hoshino Gen') ArtistInsert('KOTO','KOTO') ArtistInsert('LiSA','LiSA') ArtistInsert('Shiina Hikari','Shiina Hikari') ArtistInsert('Yonezu Kenshi','Yonezu Kenshi') --ArtistInsert(,) end

function PopulateGroup ArtistInsert('Atarashii Gakkou no Leaders','Atarashii Gakkou no Leaders') ArtistInsert('CY8ER','CY8ER') ArtistInsert('Chelmico', 'chelmico') --this is disabled due to bug ArtistInsert('Dempagumi.inc','Dempagumi.inc') ArtistInsert('KAQRIYOTERROR','KAQRIYOTERROR') ArtistInsert('Little Glee Monster','Little Glee Monster') ArtistInsert('MIGMA SHELTER','MIGMA SHELTER') ArtistInsert('Wa-Suta','Wa-Suta') ArtistInsert('ZOC','ZOC') --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; margin:10px 0 10px 0;" width="100%" bgcolor="primarycolor" !colspan=1 bgcolor="#e15467" align="center" colspan="8"|titleplaceholder'''
 * align="center" bgcolor="#3c3c3c" width="160px"| 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(, ) --removes description = description:gsub('%(%)', '') --limiting maximum length of description if(string.len(description) > 290) then --cropping at 300 characters description = description:sub(1,290) --removing last word (probably cropped) and replacing with ... description = description:gsub('%s%S*$', '...') 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.Debug1 ArtistInsert('Dempagumi.inc','Dempagumi.inc') if(count > 0) then return ParsePage('Debug') end end

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