Module:Featured: Difference between revisions
From PC Gaming Shelter
No edit summary |
No edit summary Tag: Reverted |
||
| Line 63: | Line 63: | ||
function p.video(frame) | function p.video(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local mediatype = value(args, 'mediatype', '') | |||
local | local header = value(args, 'header', '') | ||
local | local title = value(args, 'title', '') | ||
local | local tagline = value(args, 'tagline', '') | ||
local | local id = value(args, 'id', '') | ||
local image = value(args, 'image', '') | |||
local | local alt = value(args, 'alt', 'Featured video') | ||
local | local attribution = value(args, 'attribution', '') | ||
local | local description = value(args, 'description', '') | ||
local | local category = value(args, 'category', '') | ||
local | local game = value(args, 'game', '') | ||
local | local video = frame:callParserFunction('#tag', { | ||
local | |||
local video = frame:callParserFunction('#tag', { | |||
'embedvideo', | 'embedvideo', | ||
service = 'youtube', | service = 'youtube', | ||
autoResize = '1', | autoResize = '1', | ||
title = title, | title = title, | ||
id | |||
}) | }) | ||
setFeaturedProperties({ | setFeaturedProperties({ | ||
['Featured date'] = featuredDate(), | ['Featured date'] = featuredDate(), | ||
['Has featured media type'] = | ['Has featured media type'] = mediatype, | ||
['Has | ['Has video id'] = id, | ||
['Has | ['Has card header'] = header, | ||
['Has featured title'] = title, | |||
['Has featured title'] = | ['Has featured tagline'] = tagline, | ||
['Has featured tagline'] = | |||
['Has featured description'] = description, | ['Has featured description'] = description, | ||
['Has featured category'] = category, | ['Has featured category'] = category, | ||
['Has | ['Has featured media'] = image, | ||
['Has alt text'] = | ['Has attribution'] = attribution, | ||
['Related game'] = | ['Has alt text'] = alt, | ||
['Related game'] = game | |||
}) | }) | ||
| Line 121: | Line 119: | ||
function p.image(frame) | function p.image(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local mediatype = value(args, 'mediatype', '') | |||
local header = value(args | local header = value(args, 'header', '') | ||
local | local title = value(args, 'title', '') | ||
local | local tagline = value(args, 'tagline', '') | ||
local | local id = value(args, 'id', '') | ||
local | local image = value(args, 'image', '') | ||
local | local alt = value(args, 'alt', 'Featured image') | ||
local | local attribution = value(args, 'attribution', '') | ||
local | local description = value(args, 'description', '') | ||
local category = value(args, | local category = value(args, 'category', '') | ||
local game = value(args, 'game', '') | |||
local image = frame:preprocess( | local image = frame:preprocess( | ||
'[[File:{{PAGENAME:' .. | '[[File:{{PAGENAME:' .. image .. '}}|' .. altText .. ']]' | ||
) | ) | ||
setFeaturedProperties({ | setFeaturedProperties({ | ||
['Featured date'] = featuredDate( | ['Featured date'] = featuredDate(), | ||
['Has featured media type'] = | ['Has featured media type'] = mediatype, | ||
['Has | ['Has video id'] = id, | ||
['Has | ['Has card header'] = header, | ||
['Has featured title'] = | ['Has featured title'] = title, | ||
['Has featured tagline'] = | ['Has featured tagline'] = tagline, | ||
['Has featured description'] = description, | ['Has featured description'] = description, | ||
['Has featured category'] = category, | ['Has featured category'] = category, | ||
['Has | ['Has featured media'] = image, | ||
['Has alt text'] = | ['Has attribution'] = attribution, | ||
['Related game'] = | ['Has alt text'] = alt, | ||
['Related game'] = game | |||
}) | }) | ||
Revision as of 10:23, 7 June 2026
Documentation for this module may be created at Module:Featured/doc
local p = {}
local function getArgs(frame)
return frame:getParent().args or {}
end
local function value(args, names, default)
for _, name in ipairs(names) do
local candidate = args[name]
if candidate ~= nil then
candidate = mw.text.trim(candidate)
if candidate ~= '' then
return candidate
end
end
end
return default
end
local function setFeaturedProperties(data)
local properties = {}
for property, propertyValue in pairs(data) do
if propertyValue ~= nil and propertyValue ~= '' then
properties[property] = propertyValue
end
end
mw.smw.set(properties)
end
local function youtubeId(content)
if not content:find('://', 1, true) then
return content
end
return content:match('[?&]v=([^&]+)')
or content:match('youtu%.be/([^?&/]+)')
or content:match('youtube%.com/embed/([^?&/]+)')
or ''
end
local function featuredDate()
local title = mw.title.getCurrentTitle()
local year, month = title.prefixedText:match('^Featured:(%d%d%d%d)/(%d%d)/')
if year == nil then
return ''
end
local monthNumber = tonumber(month)
if monthNumber < 1 or monthNumber > 12 then
return ''
end
return mw.language.getContentLanguage():formatDate(
'F Y',
year .. month .. '01000000'
)
end
function p.video(frame)
local args = getArgs(frame)
local mediatype = value(args, 'mediatype', '')
local header = value(args, 'header', '')
local title = value(args, 'title', '')
local tagline = value(args, 'tagline', '')
local id = value(args, 'id', '')
local image = value(args, 'image', '')
local alt = value(args, 'alt', 'Featured video')
local attribution = value(args, 'attribution', '')
local description = value(args, 'description', '')
local category = value(args, 'category', '')
local game = value(args, 'game', '')
local video = frame:callParserFunction('#tag', {
'embedvideo',
service = 'youtube',
autoResize = '1',
title = title,
id
})
setFeaturedProperties({
['Featured date'] = featuredDate(),
['Has featured media type'] = mediatype,
['Has video id'] = id,
['Has card header'] = header,
['Has featured title'] = title,
['Has featured tagline'] = tagline,
['Has featured description'] = description,
['Has featured category'] = category,
['Has featured media'] = image,
['Has attribution'] = attribution,
['Has alt text'] = alt,
['Related game'] = game
})
local displayDescription = description
if displayDescription ~= '' then
displayDescription = '\n' .. displayDescription
end
local html = mw.html.create()
html:tag('div'):addClass('card bg-dark thumbwall mb-3')
:tag('div'):addClass('card-header order-0'):wikitext(header):done()
:tag('div'):addClass('card-img'):wikitext(video):done()
:tag('div'):addClass('card-body bg-dark flex-column')
:tag('div'):addClass('card-title mb-0'):wikitext(title):done()
:tag('div'):addClass('card-tagline lead'):wikitext(tagline):done()
:tag('div'):addClass('card-text'):wikitext(displayDescription):done()
:done()
:done()
return html
end
function p.image(frame)
local args = getArgs(frame)
local mediatype = value(args, 'mediatype', '')
local header = value(args, 'header', '')
local title = value(args, 'title', '')
local tagline = value(args, 'tagline', '')
local id = value(args, 'id', '')
local image = value(args, 'image', '')
local alt = value(args, 'alt', 'Featured image')
local attribution = value(args, 'attribution', '')
local description = value(args, 'description', '')
local category = value(args, 'category', '')
local game = value(args, 'game', '')
local image = frame:preprocess(
'[[File:{{PAGENAME:' .. image .. '}}|' .. altText .. ']]'
)
setFeaturedProperties({
['Featured date'] = featuredDate(),
['Has featured media type'] = mediatype,
['Has video id'] = id,
['Has card header'] = header,
['Has featured title'] = title,
['Has featured tagline'] = tagline,
['Has featured description'] = description,
['Has featured category'] = category,
['Has featured media'] = image,
['Has attribution'] = attribution,
['Has alt text'] = alt,
['Related game'] = game
})
local displayDescription = description
if displayDescription ~= '' then
displayDescription = '\n' .. displayDescription
end
local html = mw.html.create()
html:tag('div'):addClass('card bg-dark thumbwall mb-3')
:tag('div'):addClass('card-header order-0'):wikitext(header):done()
:tag('div'):addClass('card-img'):wikitext(image):done()
:tag('div'):addClass('card-body bg-dark flex-column')
:tag('div'):addClass('card-title lead'):wikitext(title):done()
:tag('div'):addClass('card-text'):wikitext(displayDescription):done()
:done()
:done()
return html
end
return p
