Module:Feature page

--[[ Displays content from randomly featured live article from a list or lua table (e.g. Module:Top/data) Syntax :

--]] local p ={} local utility = require("Dev:Utility") function p.main(frame) local tArgs = utility.getArgs(frame) local extTable if tArgs and type(tArgs)=="table" then extTable = mw.clone(tArgs) if tArgs["#table"] then extTable = require(tArgs["#table"]) end math.randomseed(os.time) math.random local iRand = math.random(#extTable) if not extTable[iRand] or extTable[iRand]=="" then return end local pagename = extTable[iRand] local titleFeatured = mw.title.new(pagename) -- Follow redirect once if titleFeatured and titleFeatured.exists then if titleFeatured.isRedirect then local pageContents = mw.clone(titleFeatured:getContent) pageContents = pageContents:match("%[%[(.-)%]%]") titleFeatured = mw.title.new(pageContents) end --Sanitize content and display if titleFeatured and titleFeatured.exists then pageContents = mw.clone(titleFeatured:getContent) if not (tArgs["#notable"] and tArgs["#notables"]=="1") then pageContents = pageContents:gsub("%{%s*%|.-%|%s*%}","") end pageContents = string.gsub(pageContents,"%<%s*ref.-%>.-%<%/%s*ref%s*>","") pageContents = string.gsub(pageContents,"%<%s*ref.-%/%>","") pageContents = pageContents:gsub("%[%[File%:.-%]%]","") pageContents = pageContents:gsub("%=%=.-%=%=.*","") if not (tArgs["#notemplate"] and tArgs["#notemplate"]=="1") then pageContents = pageContents:gsub("%{%{.-%}%}","") end pageContents = mw.text.truncate(pageContents,300) pageContents = mw.text.trim(pageContents) return frame:preprocess(pageContents .. "(more)") end end end return "Nothing to display..." end return p