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("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","","",[=[]=]) end

function PopulateSoloist ArtistInsert("Akiyama Kiro","","",[=[]=]) ArtistInsert("DAOKO","","",[=[]=]) ArtistInsert("GARUDA","","",[=[]=]) 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("Sawano Hiroyuki","","",[=[]=]) 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("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("Item wa Teru Teru Nomi!","","",[=[]=]) ArtistInsert("JAM Project","","",[=[]=]) 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("SPACE PIRATES class ZERO","","",[=[]=]) ArtistInsert("Suneeds","","",[=[]=]) ArtistInsert("TENRIN","","",[=[]=]) ArtistInsert("TOKYO GIRLS&#39 STYLE","","",[=[]=]) ArtistInsert("Twinkle","","",[=[]=]) ArtistInsert("ULTRA BUZZ","","",[=[]=]) ArtistInsert("Yandoll","","",[=[]=]) ArtistInsert("YURiMental","","",[=[]=]) ArtistInsert("Yurutto Kakumeidan","","",[=[]=]) ArtistInsert("XTEEN","","",[=[]=]) 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 --note: [jpwgs][pneiv][gbf]?[gp] captures 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:(.-%.[jpwgs][pneiv][gbf]?[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*(.-%.[jpwgs][pneiv][gbf]?[gp])' image = string.match(content, imgpattern) end --pattern 3 --search for image anywhere else as [[File:image.ext]] if(image == nil) then imgpattern = '%[%[File:(.-%.[jpwgs][pneiv][gbf]?[gp])' image = string.match(content, imgpattern) end --pattern 4 --search for image inside a gallery as image.ext if(image == nil) then imgpattern = '%s*(.-%.[jpwgs][pneiv][gbf]?[gp])' image = string.match(content, imgpattern) end return image end

function ParseDescription(content, name) --getting description from page --replace PAGENAME template with name desc = content:gsub('', name) --escaping characters from the name that might be interpreted as pattern matching symbols namePattern = name:gsub('%%', '%%%') namePattern = namePattern:gsub('%-', '%%-') namePattern = namePattern:gsub('%+', '%%+') namePattern = namePattern:gsub('%.', '%%.') namePattern = namePattern:gsub('%(', '%%(') namePattern = namePattern:gsub('%)', '%%)') namePattern = namePattern:gsub('%$', '%%$') namePattern = namePattern:gsub('%^', '%%^') namePattern = namePattern:gsub('%?', '%%?') namePattern = namePattern:gsub('%[', '%%[') namePattern = namePattern:gsub('%]', '%%]') --getting description, starting from the first paragraph of the page, --where the name of it is mentioned between   descPattern = "'''%s*" .. namePattern .. "%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 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 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