Module:RandomArticle

local p = {}

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

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

--====================== DATA INSERT: Syntax: DataInsert("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 DataInsert("Accént","","",[=[]=]) DataInsert("ALI","","",[=[]=]) DataInsert("Amiliyah","","",[=[]=]) DataInsert("BABYMETAL","","",[=[]=]) DataInsert("BAND-MAID","","",[=[]=]) DataInsert("BAND-MAIKO","","",[=[]=]) DataInsert("BRATS","","",[=[]=]) DataInsert("BRIDEAR","","",[=[]=]) DataInsert("Dorodoro","","",[=[]=]) DataInsert("FATE GEAR","","",[=[]=]) DataInsert("Fear, and Loathing in Las Vegas","","",[=[]=]) DataInsert("Fuyu no Doubutsuen","","",[=[]=]) DataInsert("Galneryus","","",[=[]=]) DataInsert("HANABIE.","","",[=[]=]) DataInsert("Jupiter","","",[=[]=]) DataInsert("King Gnu","","",[=[]=]) DataInsert("Linked Horizon","","",[=[]=]) DataInsert("LOVEBITES","","",[=[]=]) DataInsert("MAN WITH A MISSION","","",[=[]=]) DataInsert("Mary's Blood","","",[=[]=]) DataInsert("MAXIMUM THE HORMONE","","",[=[]=]) DataInsert("Mrs. GREEN APPLE","","",[=[]=]) DataInsert("MUTANT MONSTER","","",[=[]=]) DataInsert("NEMOPHILA","","",[=[]=]) DataInsert("Otoboke Beaver","","",[=[]=]) DataInsert("SEKAI NO OWARI","","",[=[]=]) DataInsert("SPYAIR","","",[=[]=]) DataInsert("Shinsei Kamattechan","","",[=[]=]) DataInsert("the GazettE","","",[=[]=]) DataInsert("TRiDENT","","",[=[]=]) DataInsert("Unlucky Morpheus","","",[=[]=]) DataInsert("Wagakki Band","","",[=[]=]) DataInsert("X JAPAN","","",[=[]=]) DataInsert("Yosei Teikoku","","",[=[]=]) DataInsert("Ziyoou-Vachi","","",[=[]=]) end

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

function PopulateGroup DataInsert("&Ch!ll","","",[=[]=]) DataInsert("@onefive","","",[=[]=]) DataInsert("8bitBRAIN","","",[=[]=]) DataInsert("A.B.C-Z","","",[=[]=]) DataInsert("Aiiro Asterism","","",[=[]=]) DataInsert("alliance","","",[=[]=]) DataInsert("Amaterasu","","",[=[]=]) DataInsert("Angel Sisters","","",[=[]=]) DataInsert("Angel♡Heart","","",[=[]=]) DataInsert("Anthurium","","",[=[]=]) DataInsert("Aqua Note","","",[=[]=]) DataInsert("Atarashii Gakkou no Leaders","","",[=[]=]) DataInsert("Boku wa Mada Shinanai","","",[=[]=]) DataInsert("BROKEN BY THE SCREAM","","",[=[]=]) DataInsert("COLORLESS","","",[=[]=]) DataInsert("CY8ER","","",[=[]=]) DataInsert("chelmico","","",[=[]=]) DataInsert("Chouonpa","","",[=[]=]) DataInsert("chuLa","","",[=[]=]) DataInsert("Ciào Smiles","","",[=[]=]) DataInsert("Dempagumi.inc","","",[=[]=]) DataInsert("DESURABBITS","","",[=[]=]) DataInsert("DokidokiDreamCampus+","","",[=[]=]) DataInsert("DoublePeace","","",[=[]=]) DataInsert("Gekizyou Refrain","","",[=[]=]) DataInsert("HARP STAR","","",[=[]=]) DataInsert("HEROINES","","",[=[]=]) DataInsert("Hamu!STAR","","",[=[]=]) DataInsert("Hey! Say! JUMP","","",[=[]=]) DataInsert("Higeki no Heroine Syndrome","","",[=[]=]) DataInsert("Hikicomoteikoku","","",[=[]=]) DataInsert("Ichizen!","","",[=[]=]) DataInsert("iLiFE!","","",[=[]=]) DataInsert("INUWASI","","",[=[]=]) DataInsert("Item wa Teru Teru Nomi!","","",[=[]=]) DataInsert("JAM Project","","",[=[]=]) DataInsert("KAQRIYOTERROR","","",[=[]=]) DataInsert("Kamikaze Sensation","","",[=[]=]) DataInsert("KAT-TUN","","",[=[]=]) DataInsert("KATA☆CHU","","",[=[]=]) DataInsert("KUWAGATA☆KIDS","","",[=[]=]) DataInsert("Konyanko","","",[=[]=]) DataInsert("Lil na Valley","","",[=[]=]) DataInsert("Little Glee Monster","","",[=[]=]) DataInsert("L★ROCK BAB","","",[=[]=]) DataInsert("L・I・E・P","","",[=[]=]) DataInsert("M!LK","","",[=[]=]) DataInsert("MAG!C☆PRINCE","","",[=[]=]) DataInsert("MANACLE","","",[=[]=]) DataInsert("MELON BATAKE A GO GO","","",[=[]=]) DataInsert("MERUCHU","","",[=[]=]) DataInsert("MERRY BAD END","","",[=[]=]) DataInsert("MIGMA SHELTER","","",[=[]=]) DataInsert("Minna no Kodomo-chan","","",[=[]=]) DataInsert("miscast","","",[=[]=]) DataInsert("Marble Angel","","",[=[]=]) DataInsert("NECRONOMIDOL","","",[=[]=]) DataInsert("NEO JAPONISM","","",[=[]=]) DataInsert("NiceToMeetYou","","",[=[]=]) DataInsert("Nue","","",[=[]=]) DataInsert("OHMIKAMI","","",[=[]=]) DataInsert("One Chance Yeah Hoi!","","",[=[]=]) DataInsert("OnePixcel","","",[=[]=]) DataInsert("Onyanko Club","","",[=[]=]) DataInsert("PassCode","","",[=[]=]) DataInsert("PATI PATI CANDY...☆","","",[=[]=]) DataInsert("PIGGS","","",[=[]=]) DataInsert("PiXMiX","","",[=[]=]) DataInsert("Policy Nante Gongo Doudan!","","",[=[]=]) DataInsert("Ponkotsu Konpo","","",[=[]=]) DataInsert("Pu Lathessa","","",[=[]=]) DataInsert("RABBIT HUTCH","","",[=[]=]) DataInsert("Rabi Rin","","",[=[]=]) DataInsert("reaction","","",[=[]=]) DataInsert("Runup!!","","",[=[]=]) DataInsert("Sakura Gakuin","","",[=[]=]) DataInsert("Satanic Punish","","",[=[]=]) DataInsert("Seireki13ya","","",[=[]=]) DataInsert("Sexy Zone","","",[=[]=]) DataInsert("Smewthie","","",[=[]=]) DataInsert("SPACE PIRATES class ZERO","","",[=[]=]) DataInsert("SPARK SPEAKER","","",[=[]=]) DataInsert("STARMARIE","","",[=[]=]) DataInsert("Suneeds","","",[=[]=]) DataInsert("TENRIN","","",[=[]=]) DataInsert("THE BANANA MONKEYS","","",[=[]=]) DataInsert("TOKYO GIRLS' STYLE","","",[=[]=]) DataInsert("Twinkle","","",[=[]=]) DataInsert("ULTRA BUZZ","","",[=[]=]) DataInsert("Underbeasty","","",[=[]=]) DataInsert("Wagamama Rakia","","",[=[]=]) DataInsert("Wa-Suta","","",[=[]=]) DataInsert("WONDER SNAKE","","",[=[]=]) DataInsert("XTEEN","","",[=[]=]) DataInsert("Yandoll","","",[=[]=]) DataInsert("YORUWA KOREKARA","","",[=[]=]) DataInsert("YURiMental","","",[=[]=]) DataInsert("Yurutto Kakumeidan","","",[=[]=]) DataInsert("Zenbu Kimi no Sei da","","",[=[]=]) DataInsert("Zsasz","","",[=[]=]) DataInsert("ZOC","","",[=[]=]) DataInsert("ZOMBIE POWDER","","",[=[]=]) end

function PopulateArtist PopulateBand PopulateGroup PopulateSoloist end

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

--Original pattern from Template:F_aid pattern = [==[{|style="float:left; border:2px solid primarycolor; margin:2px 0 10px 0;" width="100%" bgcolor="primarycolor" !bgcolor="#e15467" align="center" colspan="8"|titleplaceholder''' descplaceholder
 * align="center" bgcolor="#3c3c3c" width="160px"| fileplaceholder
 * align="left" valign="top" bgcolor="backgroundcolor" style="padding:5px 20px 0px 20px;"|
 * align="left" valign="top" bgcolor="backgroundcolor" style="padding:5px 20px 0px 20px;"|
 * ...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(n_items) 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) imgsize = '220px' primarycolor = '#e15467' backgroundcolor = '#ffffff' if(image == nil) then --if no image was found, displays "No Image" text in its place pattern = pattern:gsub('%', ' No Image ') else pattern = pattern:gsub('fileplaceholder', image) pattern = pattern:gsub('imgsizeplaceholder', imgsize) 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(n_items > 0) then return ParsePage("Featured Band") end end

function p.GetGroup PopulateGroup if(n_items > 0) then return ParsePage("Featured Group") end end

function p.GetSoloist PopulateSoloist if(n_items > 0) then return ParsePage("Featured Soloist") end end

function p.GetArtist PopulateArtist if(n_items > 0) then return ParsePage("Featured Artist") end end return p