No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
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 = ' | local tables = 'Test' | ||
local fields = ' | local fields = '_pageName, category, game, date, content, targets, author' | ||
local cargoArgs = { | local cargoArgs = { | ||
where = 'targets HOLDS "' .. currentTitle .. ' | where = 'content LIKE "%[[' .. currentTitle .. '%" OR targets HOLDS "' .. currentTitle .. '"', | ||
orderBy = 'date' | orderBy = 'date' | ||
} | } | ||
local results = cargo.query(tables, fields, cargoArgs) | local results = cargo.query(tables, fields, cargoArgs) | ||
mw.logObject(results) | |||
local container = mw.html.create() | local container = mw.html.create():node(mw.html.create('h2'):wikitext('News')) | ||
if #results > 0 then | if #results > 0 then | ||
empty = false | empty = false | ||
local ul = mw.html.create('ul') | local ul = mw.html.create('ul') | ||
Line 39: | Line 38: | ||
function pageNews.object(result) | function pageNews.object(result) | ||
local object = { | local object = { | ||
date = result.date, | |||
_pageName = result._pageName, | |||
category = result.category, | |||
game = result.game, | |||
content = result.content, | |||
author = result.author | |||
} | |||
return object | return object | ||
end | end | ||
return pageNews | return pageNews |
Revision as of 20:48, 4 May 2023
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 local empty = true -- Check if there are any interviews for this page local tables = 'Test' local fields = '_pageName, category, game, date, content, targets, author' local cargoArgs = { where = 'content LIKE "%[[' .. currentTitle .. '%" OR targets HOLDS "' .. currentTitle .. '"', orderBy = 'date' } local results = cargo.query(tables, fields, cargoArgs) mw.logObject(results) 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