(Created page with "local pageNews = {} function pageNews.main(frame) end return pageNews") |
No edit summary |
||
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 = mw.title.getCurrentTitle().text | |||
-- Check if there are any interviews for this page | |||
local tables = 'News' | |||
local fields = 'date, title, type, author, lang, source, trans_lang, translator, event, note, targets' | |||
local cargoArgs = { | |||
where = 'targets HOLDS "' .. currentTitle .. '" AND type="interview"', | |||
orderBy = 'date' | |||
} | |||
local results = cargo.query(tables, fields, cargoArgs) | |||
local container = mw.html.create('div') | |||
if #results > 0 then | |||
local ul = mw.html.create('ul') | |||
local interviews = mw.html.create('div'):node(mw.html.create('h2'):wikitext('Interviews')):node(ul) | |||
for r = 1, #results do | |||
ul:node(mw.html.create('li'):node(News.main(pageNews.object(results[r])))) | |||
end | |||
container:node(interviews) | |||
end | |||
-- mw.logObject(results) | |||
return container | |||
end | |||
function pageNews.object(result) | |||
local object = {} | |||
object.date = result.date | |||
object.lang = result.lang | |||
object.url = result.url | |||
object.author = result.author | |||
object.source = result.source | |||
object.event = result.event | |||
object.trans_lang = result.trans_lang | |||
object.translator = result.translator | |||
object.event = result.event | |||
return object | |||
end | end | ||
return pageNews | return pageNews |
Revision as of 17:05, 10 October 2022
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 = mw.title.getCurrentTitle().text
-- Check if there are any interviews for this page
local tables = 'News'
local fields = 'date, title, type, author, lang, source, trans_lang, translator, event, note, targets'
local cargoArgs = {
where = 'targets HOLDS "' .. currentTitle .. '" AND type="interview"',
orderBy = 'date'
}
local results = cargo.query(tables, fields, cargoArgs)
local container = mw.html.create('div')
if #results > 0 then
local ul = mw.html.create('ul')
local interviews = mw.html.create('div'):node(mw.html.create('h2'):wikitext('Interviews')):node(ul)
for r = 1, #results do
ul:node(mw.html.create('li'):node(News.main(pageNews.object(results[r]))))
end
container:node(interviews)
end
-- mw.logObject(results)
return container
end
function pageNews.object(result)
local object = {}
object.date = result.date
object.lang = result.lang
object.url = result.url
object.author = result.author
object.source = result.source
object.event = result.event
object.trans_lang = result.trans_lang
object.translator = result.translator
object.event = result.event
return object
end
return pageNews