Module:PageNews: Difference between revisions

From TwogPedia
(Created page with "local pageNews = {} function pageNews.main(frame) end return pageNews")
 
mNo edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
local cargo = mw.ext.cargo
local News = require('Module:NewsItem')
local pageNews = {}
local pageNews = {}


function pageNews.main(frame)
function pageNews.main(frame)
local currentTitle = string.gsub(mw.title.getCurrentTitle().text, ' ', '_')
local empty = true
-- Check if there are any interviews for this page
local tables = 'News'
local fields = '_pageName, category, game, date, content, targets, author'
local cargoArgs = {
where = 'content LIKE "%[[' .. currentTitle .. '|%" OR content LIKE "%[[' .. currentTitle .. ']]%" OR targets HOLDS "' .. currentTitle .. '"',
orderBy = 'date DESC'
}
local results = cargo.query(tables, fields, cargoArgs)
local container = mw.html.create():node(mw.html.create('h2'):wikitext('News'))
if #results > 0 then
empty = false
local ul = mw.html.create('ul')
for r = 1, #results do
ul:node(mw.html.create('li'):node(News.main(pageNews.object(results[r]))))
end
container:node(ul)
end
if empty then
return '<span class="d-none"></span>'
else
return container
end
end
function pageNews.object(result)
local object = {
date = result.date,
_pageName  = result._pageName,
category = result.category,
game = result.game,
content = result.content,
author = result.author
}
return object
end
end


return pageNews
return pageNews

Latest revision as of 08:01, 30 April 2024

Documentation for this module may be created at Module:PageNews/doc

local cargo = mw.ext.cargo
local News = require('Module:NewsItem')

local pageNews = {}

function pageNews.main(frame)
	local currentTitle = string.gsub(mw.title.getCurrentTitle().text, ' ', '_')
	local empty = true
	-- Check if there are any interviews for this page
	local tables = 'News'
	local fields = '_pageName, category, game, date, content, targets, author'
	local cargoArgs = {
		where = 'content LIKE "%[[' .. currentTitle .. '|%" OR content LIKE "%[[' .. currentTitle .. ']]%" OR targets HOLDS "' .. currentTitle .. '"',
		orderBy = 'date DESC'
	}
	
	local results = cargo.query(tables, fields, cargoArgs)

	local container = mw.html.create():node(mw.html.create('h2'):wikitext('News'))
	if #results > 0 then
		empty = false
		local ul = mw.html.create('ul')
		
		for r = 1, #results do
			ul:node(mw.html.create('li'):node(News.main(pageNews.object(results[r]))))
		end

		container:node(ul)
	end
	
	if empty then
		return '<span class="d-none"></span>'
	else
		return container
	end
	
end

function pageNews.object(result) 
	local object = {
		date = result.date,
		_pageName  = result._pageName,
		category = result.category,
		game = result.game,
		content = result.content,
		author = result.author
	}
	
	return object
end

return pageNews