Module:PageNews: Difference between revisions

From TwogPedia
No edit summary
mNo edit summary
 
(11 intermediate revisions by the same user not shown)
Line 5: Line 5:


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


local container = mw.html.create():node(mw.html.create('h2'):wikitext('News'))
if #results > 0 then
if #results > 0 then
-- container:node(mw.html.create('h2'):addClass('mw-collapsible'):wikitext('Interviews'))
returnString = returnString .. tostring(mw.html.create('h2'):addClass('mw-collapsible'):wikitext('Interviews'))
empty = false
empty = false
local ul = mw.html.create('ul')
local ul = mw.html.create('ul')
-- local interviews = mw.html.create('div'):node(ul)
local interviews = mw.html.create('ul')
for r = 1, #results do
for r = 1, #results do
ul:node(mw.html.create('li'):node(News.main(pageNews.object(results[r]))))
ul:node(mw.html.create('li'):node(News.main(pageNews.object(results[r]))))
end
end
mw.log('itnervisdsdad')
 
mw.log(ul)
container:node(ul)
mw.logObject(ul)
returnString = returnString .. tostring(ul)
-- container:node(interviews)
end
end
Line 40: Line 32:
return '<span class="d-none"></span>'
return '<span class="d-none"></span>'
else
else
mw.log('stringggggg')
return container
mw.log(returnString)
-- return container
return returnString
end
end
Line 49: Line 38:


function pageNews.object(result)  
function pageNews.object(result)  
local object = {}
local object = {
object.date = result.date
date = result.date,
object.lang = result.lang
_pageName = result._pageName,
object.url = result.url
category = result.category,
object.author = result.author
game = result.game,
object.source = result.source
content = result.content,
object.event = result.event
author = result.author
object.trans_lang = result.trans_lang
}
object.translator = result.translator
object.event  = result.event
return object
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