Module:MainPage

Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:MainPage/doc. Changes can be proposed in the talk page.
Function list
L 7 — p.random_article

require("strict");
local cargo = mw.ext.cargo

local p = {}

-- Generates a random article each day, for use in the featured box
function p.random_article(args)
	local tables

	math.randomseed(os.date("%Y%m%d"))
	local seed = math.random(1, 3)
	if (seed == 1) then
		tables = 'Rides'
	elseif (seed == 2) then
		tables = 'Roller_Coasters'
	else
		tables = 'Amusement_Parks'
	end

	local fields = string.format('%s._pageTitle=_pageTitle, %s.Name=Name, %s.Image=Image', tables, tables, tables)
	local tableargs = {
    	where = tables .. '.Image IS NOT NULL AND (_pageData._categories HOLDS NOT LIKE "%logo%" OR _pageData._pageName NOT LIKE "%logo%")',
        limit = 1,
        orderBy = 'RAND(CURDATE())',
        join = string.format('%s.Image=_pageData._pageName', tables)
    }

    local featured = cargo.query( tables .. ',_pageData', fields, tableargs )[1]

    return mw.html.create('div')
	    :attr('id', 'home-featured')
	    :addClass('home-card home-card--button home-card--col2 home-card--row3')
	    :tag('div')
	     	:addClass('home-card__background')
	     	:wikitext('[[' .. featured.Image .. '|link=' .. featured._pageTitle .. ']]')
	     	:done()
     	:tag('div')
     		:addClass('home-card__foreground')
     		:tag('div')
     			:addClass('home-card__label')
     			:wikitext('Featured')
     			:done()
 			:tag('div')
 				:addClass('home-card__header')
 				:wikitext(featured.Name)
 				:done()
			:done()
		:done()
end

return p