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('Shinsei Kamattechan','Shinsei Kamattechan') ArtistInsert('SEKAI NO OWARI','SEKAI NO OWARI') ArtistInsert('BRATS','BRATS') ArtistInsert('Accént','Accént') --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('Sakurai Yune','Sakurai Yune') ArtistInsert('Nono Aimi','Nono Aimi') ArtistInsert('Ito Mio','Ito Mio') ArtistInsert('Horiuchi Marina','Horiuchi Marina') --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('Sakura Gakuin','Sakura Gakuin') ArtistInsert('Ciào Smiles','Ciào Smiles') ArtistInsert('PiXMiX','PiXMiX') ArtistInsert('OnePixcel','OnePixcel') ArtistInsert('TOKYO GIRLS&#39 STYLE','TOKYO GIRLS&#39 STYLE') ArtistInsert('MERUCHU','MERUCHU') ArtistInsert('RABBIT HUTCH','RABBIT HUTCH') ArtistInsert('Hamu!STAR','Hamu!STAR') ArtistInsert('Marble Angel','Marble Angel') ArtistInsert('DoublePeace','DoublePeace') ArtistInsert('KUWAGATA☆KIDS','KUWAGATA☆KIDSRabi Rin') ArtistInsert('Rabi Rin','Rabi Rin') ArtistInsert('Angel Sisters','Angel Sisters') ArtistInsert('Angel♡Heart','Angel♡Heart') ArtistInsert('L★ROCK BAB','L★ROCK BAB') ArtistInsert('Twinkle','Twinkle') ArtistInsert('Aqua Note','Aqua Note') ArtistInsert('M!LK','M!LK') ArtistInsert('chuLa','chuLa') ArtistInsert('KATA☆CHU','KATA☆CHU') ArtistInsert('Item wa Teru Teru Nomi!','Item wa Teru Teru Nomi!') ArtistInsert('@onefive','@onefive') ArtistInsert('Hey! Say! JUMP','Hey! Say! JUMP') ArtistInsert('A.B.C-Z','A.B.C-Z') ArtistInsert('Sexy Zone','Sexy Zone') ArtistInsert('KAT-TUN','KAT-TUN') ArtistInsert('Boku wa Mada Shinanai','Boku wa Mada Shinanai') ArtistInsert('Higeki no Heroine Syndrome','Higeki no Heroine Syndrome') ArtistInsert('Nue','Nue') ArtistInsert('Ponkotsu Konpo','Ponkotsu Konpo') ArtistInsert('TENRIN','TENRIN') ArtistInsert('iLiFE!','iLiFE!') ArtistInsert('HEROINES','HEROINES') ArtistInsert('YURiMental','YURiMental') ArtistInsert('&Ch!ll','&Ch!ll') ArtistInsert('HARP STAR','HARP STAR') ArtistInsert('Aiiro Asterism','Aiiro Asterism') ArtistInsert('PATI PATI CANDY...☆','PATI PATI CANDY...☆') ArtistInsert('L・I・E・P','L・I・E・P') ArtistInsert('Ichizen!','Ichizen!') ArtistInsert('MAG!C☆PRINCE','MAG!C☆PRINCE') ArtistInsert('SPACE PIRATES class ZERO','SPACE PIRATES class ZERO') ArtistInsert('Pu Lathessa','Pu Lathessa') ArtistInsert('Lil na Valley','Lil na Valley') ArtistInsert('COLORLESS','COLORLESS') ArtistInsert('Suneeds','Suneeds') ArtistInsert('Yurutto Kakumeidan','Yurutto Kakumeidan') ArtistInsert('Policy Nante Gongo Doudan!','Policy Nante Gongo Doudan!') ArtistInsert('Konyanko','Konyanko') ArtistInsert('Chouonpa','Chouonpa') ArtistInsert('alliance','alliance') ArtistInsert('NiceToMeetYou','NiceToMeetYou') ArtistInsert('Runup!!','Runup!!') ArtistInsert('Amaterasu','Amaterasu') ArtistInsert('One Chance Yeah Hoi!','One Chance Yeah Hoi!') ArtistInsert('ULTRA BUZZ','ULTRA BUZZ') ArtistInsert('OHMIKAMI','OHMIKAMI') ArtistInsert('reaction','reaction') ArtistInsert('DokidokiDreamCampus+','DokidokiDreamCampus+') ArtistInsert('Onyanko Club','Onyanko Club') --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