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("Amiliyah","","",[=[]=]) ArtistInsert("BABYMETAL","","",[=[]=]) ArtistInsert("BAND-MAID","","",[=[]=]) ArtistInsert("BAND-MAIKO","","",[=[]=]) ArtistInsert("BRATS","","",[=[]=]) ArtistInsert("BRIDEAR","","",[=[]=]) ArtistInsert("Dorodoro","","",[=[]=]) ArtistInsert("Fear, and Loathing in Las Vegas","","",[=[]=]) ArtistInsert("Galneryus","","",[=[]=]) ArtistInsert("HANABIE.","","",[=[]=]) ArtistInsert("Jupiter","","",[=[]=]) ArtistInsert("King Gnu","","",[=[]=]) ArtistInsert("Linked Horizon","","",[=[]=]) ArtistInsert("LOVEBITES","","",[=[]=]) ArtistInsert("MAN WITH A MISSION","","",[=[]=]) ArtistInsert("Mary's Blood","","",[=[]=]) ArtistInsert("MAXIMUM THE HORMONE","","",[=[]=]) 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("Wagakki Band","","",[=[]=]) ArtistInsert("X JAPAN","","",[=[]=]) ArtistInsert("Yosei Teikoku","","",[=[]=]) ArtistInsert("Ziyoou-Vachi","","",[=[]=]) end

function PopulateSoloist ArtistInsert("Akiyama Kiro","","",[=[]=]) ArtistInsert("Aoi Eir","","",[=[]=]) ArtistInsert("DAOKO","","",[=[]=]) ArtistInsert("GARUDA","","",[=[]=]) ArtistInsert("Haru Nemuri","","",[=[]=]) ArtistInsert("Horiuchi Marina","","",[=[]=]) ArtistInsert("Hoshino Gen","","",[=[]=]) ArtistInsert("Ito Mio","","",[=[]=]) ArtistInsert("Iwai Yukiko","","",[=[]=]) ArtistInsert("Juuyondaime Toire no Hanako-san","","",[=[]=]) ArtistInsert("Kanou Emiri","","",[=[]=]) ArtistInsert("KOTO","","",[=[]=]) ArtistInsert("KOTOKO","","",[=[]=]) ArtistInsert("LiSA","","",[=[]=]) ArtistInsert("Nono Aimi","","",[=[]=]) ArtistInsert("Okinawa Electric Girl Saya","","",[=[]=]) ArtistInsert("Rie a.k.a. Suzaku","","",[=[]=]) ArtistInsert("Sakurai Yune","","",[=[]=]) ArtistInsert("Sawano Hiroyuki","","",[=[]=]) ArtistInsert("Shiina Hikari","","",[=[]=]) ArtistInsert("Tatsumi Rika (1965)","Tatsumi Rika","",[=[]=]) ArtistInsert("Yajima Mai","","",[=[]=]) ArtistInsert("Yamazaki Mayumi","","",[=[]=]) ArtistInsert("Yoneko","","",[=[]=]) ArtistInsert("Yonezu Kenshi","","",[=[]=]) ArtistInsert("Yunomi","","",[=[]=]) ArtistInsert("ZAQ","","",[=[]=]) end

function PopulateGroup ArtistInsert("&Ch!ll","","",[=[]=]) ArtistInsert("@onefive","","",[=[]=]) ArtistInsert("8bitBRAIN","","",[=[]=]) ArtistInsert("A.B.C-Z","","",[=[]=]) ArtistInsert("Aiiro Asterism","","",[=[]=]) ArtistInsert("alliance","","",[=[]=]) ArtistInsert("Amaterasu","","",[=[]=]) ArtistInsert("Angel Sisters","","",[=[]=]) ArtistInsert("Angel♡Heart","","",[=[]=]) ArtistInsert("Anthurium","","",[=[]=]) 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("DESURABBITS","","",[=[]=]) ArtistInsert("DokidokiDreamCampus+","","",[=[]=]) ArtistInsert("DoublePeace","","",[=[]=]) ArtistInsert("Gekizyou Refrain","","",[=[]=]) ArtistInsert("HARP STAR","","",[=[]=]) ArtistInsert("HEROINES","","",[=[]=]) ArtistInsert("Hamu!STAR","","",[=[]=]) ArtistInsert("Hey! Say! JUMP","","",[=[]=]) ArtistInsert("Higeki no Heroine Syndrome","","",[=[]=]) ArtistInsert("Hikicomoteikoku","","",[=[]=]) ArtistInsert("Ichizen!","","",[=[]=]) ArtistInsert("iLiFE!","","",[=[]=]) ArtistInsert("INUWASI","","",[=[]=]) ArtistInsert("Item wa Teru Teru Nomi!","","",[=[]=]) ArtistInsert("JAM Project","","",[=[]=]) ArtistInsert("KAQRIYOTERROR","","",[=[]=]) ArtistInsert("Kamikaze Sensation","","",[=[]=]) 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("MERRY BAD END","","",[=[]=]) ArtistInsert("MIGMA SHELTER","","",[=[]=]) ArtistInsert("Minna no Kodomo-chan","","",[=[]=]) ArtistInsert("miscast","","",[=[]=]) ArtistInsert("Marble Angel","","",[=[]=]) ArtistInsert("NECRONOMIDOL","","",[=[]=]) ArtistInsert("NEO JAPONISM","","",[=[]=]) ArtistInsert("NiceToMeetYou","","",[=[]=]) ArtistInsert("Nue","","",[=[]=]) ArtistInsert("OHMIKAMI","","",[=[]=]) ArtistInsert("One Chance Yeah Hoi!","","",[=[]=]) ArtistInsert("OnePixcel","","",[=[]=]) ArtistInsert("Onyanko Club","","",[=[]=]) ArtistInsert("PassCode","","",[=[]=]) 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("Satanic Punish","","",[=[]=]) ArtistInsert("Sexy Zone","","",[=[]=]) ArtistInsert("Smewthie","","",[=[]=]) ArtistInsert("SPACE PIRATES class ZERO","","",[=[]=]) ArtistInsert("SPARK SPEAKER","","",[=[]=]) ArtistInsert("Suneeds","","",[=[]=]) ArtistInsert("TENRIN","","",[=[]=]) ArtistInsert("THE BANANA MONKEYS","","",[=[]=]) ArtistInsert("TOKYO GIRLS&#39 STYLE","","",[=[]=]) ArtistInsert("Twinkle","","",[=[]=]) ArtistInsert("ULTRA BUZZ","","",[=[]=]) ArtistInsert("Wagamama Rakia","","",[=[]=]) ArtistInsert("Wa-Suta","","",[=[]=]) ArtistInsert("WONDER SNAKE","","",[=[]=]) ArtistInsert("XTEEN","","",[=[]=]) ArtistInsert("Yandoll","","",[=[]=]) ArtistInsert("YORUWA KOREKARA","","",[=[]=]) ArtistInsert("YURiMental","","",[=[]=]) ArtistInsert("Yurutto Kakumeidan","","",[=[]=]) ArtistInsert("Zenbu Kimi no Sei da","","",[=[]=]) ArtistInsert("Zsasz","","",[=[]=]) ArtistInsert("ZOC","","",[=[]=]) ArtistInsert("ZOMBIE POWDER","","",[=[]=]) end

function PopulateArtist PopulateBand PopulateGroup PopulateSoloist end

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

--Original 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 --searching for images using different patterns until one of them (or none) finds an image --note: [gjpsw][einpv][befg][gp]? is intended to capture the extensions jpg, png, jpeg, webp, gif and svg --pattern 1 --search for image in the infobox field "image" as 	if(image == nil) then imgpattern = 'image%s*=%s*%[%[File:(.-%.[gjpsw][einpv][befg][gp]?)' image = string.match(content, imgpattern) end --pattern 2 --search for image in the infobox field "image" as image.ext if(image == nil) then imgpattern = 'image%s*=%s*(.-%.[gjpsw][einpv][befg][gp]?)' image = string.match(content, imgpattern) end --pattern 3 --search for image anywhere else as [[File:image.ext]] if(image == nil) then imgpattern = '%[%[File:(.-%.[gjpsw][einpv][befg][gp]?)' image = string.match(content, imgpattern) end --pattern 4 --search for image inside a gallery as image.ext if(image == nil) then imgpattern = , )		--removes Concept section marker to include its content in the description, if available		desc = desc:gsub('==+%s*Concept%s*==+', )		--removes everything below (and including) the first section marker		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	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, try to get it from the article if(image == '') then if(content == nil) then image = nil else --if article exists, get it from the article content image = ParseImage(content) end end --if no description is given, try to get it from the article if(desc == '') then if(content == nil) then desc = nil else --if article exists, get it from the article content desc = ParseDescription(content, name) end end return BuildOutput(title, link, name, image, desc) end

function BuildOutput(title, link, name, image, desc) size = '220px' primarycolor = '#e15467' backgroundcolor = '#ffffff' if(image == nil) then --if no image was found, return "No Image" pattern = pattern:gsub('%', ' No Image ') else pattern = pattern:gsub('fileplaceholder', image) pattern = pattern:gsub('sizeplaceholder', size) end if(desc == nil) then --if no description was found, page don't exist. Return error message. errormessage = 'No article found with PAGENAME ' .. link .. '. If you see this message, please contact an admin so it can be fixed.' pattern = pattern:gsub('descplaceholder', errormessage) else pattern = pattern:gsub('descplaceholder', desc) end 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) 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