Module:Universe: Difference between revisions
From PC Gaming Shelter
No edit summary |
No edit summary |
||
| Line 17: | Line 17: | ||
local displayTitle = frame:preprocess(string.format('{{DISPLAYTITLE:%s|noreplace, noerror}}', title)) | local displayTitle = frame:preprocess(string.format('{{DISPLAYTITLE:%s|noreplace, noerror}}', title)) | ||
return displayTitle | return displayTitle | ||
end | |||
local function escapePattern(value) | |||
return value:gsub('([^%w])', '%%%1') | |||
end | |||
local function removeGameFromLabels(results, game) | |||
local gamePattern = escapePattern(game) | |||
for index, link in ipairs(results) do | |||
results[index] = link:gsub( | |||
'|' .. gamePattern .. '%s+', | |||
'|' | |||
) | |||
end | |||
return results | |||
end | end | ||
local function getSubpages(page) | local function getSubpages(page) | ||
local subpages = mw.smw.ask({ | local subpages = mw.smw.ask({ | ||
'[[ | '[[Has parent page::' .. page .. ']][[Modification date::+]]' | ||
}) or {} | }) or {} | ||
return | |||
local subpageTable = {} | |||
for _, subpage in ipairs(subpages) do | |||
local link = subpage[1] | |||
if link then | |||
table.insert(subpageTable, link) | |||
end | |||
end | |||
removeGameFromLabels(subpageTable, page) | |||
if #subpageTable == 0 then | |||
return '' | |||
end | |||
local html = mw.html.create() | |||
local universe = html:tag('div'):attr('id', 'universeMenu'):wikitext(' | ' .. table.concat(subpageTable, ' | ')) | |||
return html | |||
end | end | ||
| Line 110: | Line 148: | ||
function p.test() | function p.test() | ||
local page = 'Half-Life' | local page = 'Half-Life' | ||
return getSubpages(page) | |||
return | |||
end | end | ||
return p | return p | ||
Revision as of 10:31, 31 July 2026
Documentation for this module may be created at Module:Universe/doc
local utils = require( 'Module:Utils' )
local p = {}
local function getCurrentGame()
local title = mw.title.getCurrentTitle()
local game = title.rootText
local resource = title.subpageText
local data = {
['game'] = game,
['resource'] = resource,
}
return data
end
local function setDisplayTitle(frame, title)
local displayTitle = frame:preprocess(string.format('{{DISPLAYTITLE:%s|noreplace, noerror}}', title))
return displayTitle
end
local function escapePattern(value)
return value:gsub('([^%w])', '%%%1')
end
local function removeGameFromLabels(results, game)
local gamePattern = escapePattern(game)
for index, link in ipairs(results) do
results[index] = link:gsub(
'|' .. gamePattern .. '%s+',
'|'
)
end
return results
end
local function getSubpages(page)
local subpages = mw.smw.ask({
'[[Has parent page::' .. page .. ']][[Modification date::+]]'
}) or {}
local subpageTable = {}
for _, subpage in ipairs(subpages) do
local link = subpage[1]
if link then
table.insert(subpageTable, link)
end
end
removeGameFromLabels(subpageTable, page)
if #subpageTable == 0 then
return ''
end
local html = mw.html.create()
local universe = html:tag('div'):attr('id', 'universeMenu'):wikitext(' | ' .. table.concat(subpageTable, ' | '))
return html
end
function p.Mods(frame)
local data = getCurrentGame()
local game = data.game
local resource = data.resource
mw.smw.set({
['Has parent page'] = game
})
local query = {
'[[Category:Mods||Maps||Skins||Utilities]][[Related game::' .. game .. ']]'
}
local content = mw.smw.ask(query)
local forminput = frame:callParserFunction({ name = '#forminput', '', args = {
'form=Mod',
'query string=Mod[Related game]=' .. game,
'button text=Create or Edit Mod',
'autofocus=no'
}})
setDisplayTitle(frame, string.format('%s %s', game, resource))
return forminput
end
function p.Players(frame)
local data = getCurrentGame()
local game = data.game
local resource = data.resource
mw.smw.set({
['Has parent page'] = game
})
local query = {
'[[Category:Players]][[Plays game::' .. game .. ']]'
}
local content = mw.smw.ask(query)
local forminput = frame:callParserFunction({ name = '#forminput', '', args = {
'form=Player',
'query string=Player[Plays game]=' .. game,
'button text=Create or Edit Player Entry',
'autocomplete on category=Players',
'autofocus=no'
}})
setDisplayTitle(frame, string.format('%s %s', game, resource))
return forminput
end
function p.Clans(frame)
local data = getCurrentGame()
local game = data.game
local resource = data.resource
mw.smw.set({
['Has parent page'] = game
})
local query = {
'[[Category:Communities]][[Related game::' .. game .. ']]'
}
local content = mw.smw.ask(query)
local forminput = frame:callParserFunction({ name = '#forminput', '', args = {
'form=Community',
'query string=Community[Related game]=' .. game,
'button text=Create or Edit Community Entry',
'autocomplete on category=Communities',
'autofocus=no'
}})
setDisplayTitle(frame, string.format('%s %s', game, resource))
return forminput
end
function p.test()
local page = 'Half-Life'
return getSubpages(page)
end
return p
