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('X JAPAN','X JAPAN') --ArtistInsert('The GazettE','The GazettE') --ArtistInsert('King Gnu','King Gnu') --ArtistInsert('Mrs. GREEN APPLE','Mrs. GREEN APPLE') --ArtistInsert('MAN WITH A MISSION','MAN WITH A MISSION') --ArtistInsert(,) end

function PopulateSoloist --ArtistInsert('LiSA','LiSA') end

function PopulateGroup ArtistInsert('CY8ER','CY8ER') --ArtistInsert('Little Glee Monster','Little Glee Monster') --ArtistInsert('ZOC','ZOC') ArtistInsert('MIGMA SHELTER','MIGMA SHELTER') end

function PopulateArtist PopulateBand PopulateGroup PopulateSoloist end

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

--Pattern from Template:FAid pattern = [==[{|style=%"height:20px" cellpadding="2" style="float:right; border: 1px solid gray" width="100%" !colspan=1 bgcolor="primarycolor" align="center" colspan="8"| titleplaceholder
 * align="center" bgcolor="primarycolor" width="160px" | fileplaceholder
 * align="left" valign="top" bgcolor="backgroundcolor"|
 * 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" image = string.match(content, 'image%s*=%s*(.-%.%a%a%a?%a)') if(image == nil) then --if it fails, get it from a file include image = string.match(content, '%[%[File:(.-%.%a%a%a?%a)') end if(image == nil) then --if it fails, try to get it from anything followed by a 3/4 letter file extension image = string.match(content, '.-%.%a%a%a?%a') end --replace PAGENAME template with predefined actual name description = content:gsub('', name) --removes infoboxes description = description:gsub(, ) description = description:gsub(, ) --removes references --description = description:gsub('.* ', '') --removes files --description = description:gsub('%[%[File:.*%]%]', '') --removes Concept section marker to include concept content in the description if available --description = description:gsub('==%s*Concept%s*==', name) --removes everything starting from the first section --description = description:gsub('==+.*==+.*', '') --limiting maximum length of description if(string.len(description) > 350) then description = description:sub(1,350) --removing last word (probably cropped) and replacing with ... description = description:gsub('%s%a*$', '...') end return BuildFAid(title, link, name, image, description) end

function BuildFAid(title, link, name, image, description) size = '250px' 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 return p