Module:RandomArticle

local p = {}

L = {} N = {} I = {} D = {} count = 0

function ArtistInsert(link, name, image, desc) table.insert(L, link) table.insert(N, name) table.insert(I, image) table.insert(D, desc) count = count + 1 end

--====================== DATA INSERT: Syntax: ArtistInsert("link","name", "image", [=[description]=]) ======================== --if name is the same as link, you can leave it blank --if image is blank, it will be picked automatically from the article --if description is blank, it will be picked automatically from the article --if name or link includes a double quote, it needs to be written as \" so the quote is not interpreted as the end of the name. --for the sake of maintenance, please add entries in alphabetical order

function PopulateBand ArtistInsert("Accént","","",[=[]=]) ArtistInsert("ALI","","",[=[]=]) ArtistInsert("BABYMETAL","","",[=[]=]) ArtistInsert("BRATS","","",[=[]=]) ArtistInsert("BRIDEAR","","",[=[]=]) ArtistInsert("HANABIE.","","",[=[]=]) ArtistInsert("King Gnu","","",[=[]=]) ArtistInsert("Linked Horizon","","",[=[]=]) ArtistInsert("LOVEBITES","","",[=[]=]) ArtistInsert("MAN WITH A MISSION","","",[=[]=]) ArtistInsert("Mary's Blood","","",[=[]=]) ArtistInsert("Mrs. GREEN APPLE","","",[=[]=]) ArtistInsert("MUTANT MONSTER","","",[=[]=]) ArtistInsert("NEMOPHILA","","",[=[]=]) ArtistInsert("Otoboke Beaver","","",[=[]=]) ArtistInsert("SEKAI NO OWARI","","",[=[]=]) ArtistInsert("SPYAIR","","",[=[]=]) ArtistInsert("Shinsei Kamattechan","","",[=[]=]) ArtistInsert("The GazettE","","",[=[]=]) ArtistInsert("TRiDENT.","","",[=[]=]) ArtistInsert("Unlucky Morpheus","","",[=[]=]) ArtistInsert("X JAPAN","","",[=[]=]) end

function PopulateSoloist ArtistInsert("Akiyama Kiro","","",[=[]=]) ArtistInsert("Horiuchi Marina","","",[=[]=]) ArtistInsert("Hoshino Gen","","",[=[]=]) ArtistInsert("Ito Mio","","",[=[]=]) ArtistInsert("Juuyondaime Toire no Hanako-san","","",[=[]=]) ArtistInsert("Kanou Emiri","","",[=[]=]) ArtistInsert("KOTO","","",[=[]=]) ArtistInsert("LiSA","","",[=[]=]) ArtistInsert("Nono Aimi","","",[=[]=]) ArtistInsert("Sakurai Yune","","",[=[]=]) ArtistInsert("Shiina Hikari","","",[=[]=]) ArtistInsert("Yoneko","","",[=[]=]) ArtistInsert("Yonezu Kenshi","","",[=[]=]) ArtistInsert("Yunomi","","",[=[]=]) end

function PopulateGroup ArtistInsert("&Ch!ll","","",[=[]=]) ArtistInsert("@onefive","","",[=[]=]) ArtistInsert("A.B.C-Z","","",[=[]=]) ArtistInsert("Aiiro Asterism","","",[=[]=]) ArtistInsert("alliance","","",[=[]=]) ArtistInsert("Amaterasu","","",[=[]=]) ArtistInsert("Angel Sisters","","",[=[]=]) ArtistInsert("Angel♡Heart","","",[=[]=]) ArtistInsert("Aqua Note","","",[=[]=]) ArtistInsert("Atarashii Gakkou no Leaders","","",[=[]=]) ArtistInsert("Boku wa Mada Shinanai","","",[=[]=]) ArtistInsert("BROKEN BY THE SCREAM","","",[=[]=]) ArtistInsert("COLORLESS","","",[=[]=]) ArtistInsert("CY8ER","","",[=[]=]) ArtistInsert("Chelmico","","",[=[]=]) ArtistInsert("Chouonpa","","",[=[]=]) ArtistInsert("chuLa","","",[=[]=]) ArtistInsert("Ciào Smiles","","",[=[]=]) ArtistInsert("Dempagumi.inc","","",[=[]=]) ArtistInsert("DokidokiDreamCampus+","","",[=[]=]) ArtistInsert("DoublePeace","","",[=[]=]) ArtistInsert("HARP STAR","","",[=[]=]) ArtistInsert("HEROINES","","",[=[]=]) ArtistInsert("Hamu!STAR","","",[=[]=]) ArtistInsert("Hey! Say! JUMP","","",[=[]=]) ArtistInsert("Higeki no Heroine Syndrome","","",[=[]=]) ArtistInsert("Ichizen!","","",[=[]=]) ArtistInsert("iLiFE!","","",[=[]=]) ArtistInsert("Item wa Teru Teru Nomi!","","",[=[]=]) ArtistInsert("KAQRIYOTERROR","","",[=[]=]) ArtistInsert("KAT-TUN","","",[=[]=]) ArtistInsert("KATA☆CHU","","",[=[]=]) ArtistInsert("KUWAGATA☆KIDS","","",[=[]=]) ArtistInsert("Konyanko","","",[=[]=]) ArtistInsert("Lil na Valley","","",[=[]=]) ArtistInsert("Little Glee Monster","","",[=[]=]) ArtistInsert("L★ROCK BAB","","",[=[]=]) ArtistInsert("L・I・E・P","","",[=[]=]) ArtistInsert("M!LK","","",[=[]=]) ArtistInsert("MAG!C☆PRINCE","","",[=[]=]) ArtistInsert("MELON BATAKE A GO GO","","",[=[]=]) ArtistInsert("MERUCHU","","",[=[]=]) ArtistInsert("MIGMA SHELTER","","",[=[]=]) ArtistInsert("Marble Angel","","",[=[]=]) ArtistInsert("NECRONOMIDOL","","",[=[]=]) ArtistInsert("NiceToMeetYou","","",[=[]=]) ArtistInsert("Nue","","",[=[]=]) ArtistInsert("OHMIKAMI","","",[=[]=]) ArtistInsert("One Chance Yeah Hoi!","","",[=[]=]) ArtistInsert("OnePixcel","","",[=[]=]) ArtistInsert("Onyanko Club","","",[=[]=]) ArtistInsert("PATI PATI CANDY...☆","","",[=[]=]) ArtistInsert("PiXMiX","","",[=[]=]) ArtistInsert("Policy Nante Gongo Doudan!","","",[=[]=]) ArtistInsert("Ponkotsu Konpo","","",[=[]=]) ArtistInsert("Pu Lathessa","","",[=[]=]) ArtistInsert("RABBIT HUTCH","","",[=[]=]) ArtistInsert("Rabi Rin","","",[=[]=]) ArtistInsert("reaction","","",[=[]=]) ArtistInsert("Runup!!","","",[=[]=]) ArtistInsert("Sakura Gakuin","","",[=[]=]) ArtistInsert("Sexy Zone","","",[=[]=]) ArtistInsert("Suneeds","","",[=[]=]) ArtistInsert("TENRIN","","",[=[]=]) ArtistInsert("TOKYO GIRLS&#39 STYLE","","",[=[]=]) ArtistInsert("Twinkle","","",[=[]=]) ArtistInsert("ULTRA BUZZ","","",[=[]=]) ArtistInsert("YURiMental","","",[=[]=]) ArtistInsert("Yurutto Kakumeidan","","",[=[]=]) ArtistInsert("ZOC","","",[=[]=]) 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 ParseImage(content) image = nil extensions = {'jpg', 'png', 'jpeg', 'webp', 'gif', 'svg'} --pattern 1 --get image from the infobox field "image" as 	for i = 1, #extensions do		if(image == nil) then imgpattern = 'image%s*=%s*%[%[File:(.-%.' .. extensions[i] .. ')' image = string.match(content, imgpattern) end end --pattern 2 --if it fails, get it from the infobox field "image" as imgpath.ext for i = 1, #extensions do		if(image == nil) then imgpattern = 'image%s*=%s*(.-%.' .. extensions[i] .. ')' image = string.match(content, imgpattern) end end --pattern 3 --if it fails, get it from anywhere else as [[File:imgpath.ext]] for i = 1, #extensions do		if(image == nil) then imgpattern = '%[%[File:(.-%.' .. extensions[i] .. ')' image = string.match(content, imgpattern) end end --pattern 4 --if it fails, try to get it from anywhere else as imgpath.ext for i = 1, #extensions do		if(image == nil) then imgpattern = '.-%.' .. extensions[i] .. ')'			image = string.match(content, imgpattern)		end	end	return image end

function ParseDescription(content, name) --picking description from page --replace PAGENAME template with predefined actual name desc = 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*'''.*" desc = string.match(desc, descPattern) --if no description with this pattern is found, it will be just the name of the page if(desc == nil) then desc = "'''" .. name .. "'''" end --removes references desc = desc:gsub('.- ', '') --removes files desc = desc:gsub('%', '') --removes everything starting from the first section desc = desc:gsub('==+.*==+.*', '') --removes multiple linebreaks desc = desc:gsub('\n\n+', '\n') --removes any template in the text desc = desc:gsub(, ) --removes desc = desc:gsub('%(%)', '') --limiting maximum length of description if(string.len(desc) > 290) then --cropping at 290 characters desc = desc:sub(1,290) --removing last word (probably cropped) and replacing with ... desc = desc:gsub('%s%S*$', '...') end return desc end

function ParsePage(title) math.randomseed(os.time) index = math.random(count) link = L[index] name = N[index] image = I[index] desc = D[index] local page = mw.title.new(link) local content = page:getContent --if no name is given, it is the same as link if(name == '') then name = link end --if no image is given, get it from the article content if(image == '') then image = ParseImage(content) end --if no description is given, get it from the article content if(desc == '') then desc = ParseDescription(content, name) end return BuildOutput(title, link, name, image, desc) end

function BuildOutput(title, link, name, image, desc) size = '220px' primarycolor = '#e15467' backgroundcolor = '#ffffff' pattern = pattern:gsub('primarycolor', primarycolor) pattern = pattern:gsub('backgroundcolor', backgroundcolor) pattern = pattern:gsub('titleplaceholder', title) pattern = pattern:gsub('linkplaceholder', link) pattern = pattern:gsub('nameplaceholder', name) pattern = pattern:gsub('fileplaceholder', image) pattern = pattern:gsub('sizeplaceholder', size) pattern = pattern:gsub('descplaceholder', desc) 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("BAND-MAID","","",[=[]=]) ArtistInsert("Wa-Suta","","",[=[]=]) return ParsePage("Debug") end

function p.Debug2 ArtistInsert("SPACE PIRATES class ZERO","","",[=[]=]) return ParsePage("Debug") end return p