Jump to content

Editing Module:Life Guide

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 4: Line 4:
local getTemplateArgs = require('Module:Parser').getTemplateArgs
local getTemplateArgs = require('Module:Parser').getTemplateArgs


-- [[Template:Life Guide]]
-- [[Template:Tutorial]]
function p.LifeGuide(frame, args)
function p.Tutorial(frame, args)
if args == nil then
if args == nil then
args = require('Module:Arguments').getArgs(frame, { parentFirst = true })
args = require('Module:Arguments').getArgs(frame, { parentFirst = true })
end
end
local title = mw.title.getCurrentTitle()
local standalone = not args.table and title.rootText == 'Life Guide'
local html = mw.html.create()
local html = mw.html.create()
if args[1] and type(args[1]) == 'string' then
if args[1] and type(args[1]) == 'string' then
for page in lib.gsplit(args[1], ';', { removeEmpty = true }) do
for page in lib.gsplit(args[1], ';', { removeEmpty = true }) do
local lifeguideArgs = getTemplateArgs('Life Guide/' .. page, { only = 'Life Guide' })
local tutorialArgs = getTemplateArgs('Tutorial/' .. page, { only = 'Tutorial' })
if lib.isEmpty(lifeguideArgs) then
if lib.isEmpty(tutorialArgs) then
html:tag('strong'):addClass('error'):wikitext('The page [[Life Guide/', page, ']] is not a valid lifeguide.')
html:tag('strong'):addClass('error'):wikitext('The page [[Tutorial/', page, ']] is not a valid tutorial.')
else
else
html
html
:tag('div')
:tag('div'):addClass('tutorial')
:addClass('lifeguide')
:addClass(standalone and 'lifeguide-standalone' or '')
:tag('dl')
:tag('dl')
:tag('dt'):wikitext(lifeguideArgs.title or page)
:tag('dt'):wikitext(tutorialArgs.title or page)
:tag('dd'):node(p._LifeGuideFormat(lifeguideArgs))
:tag('dd'):node(p._TutorialFormat(tutorialArgs))
end
end
end
end
else
else
html
html
:tag('div')
:tag('div'):addClass('tutorial')
:addClass('lifeguide')
:node(p._TutorialFormat(args))
:addClass(standalone and 'lifeguide-standalone' or '')
:node(p._LifeGuideFormat(args))
end
end
return frame:preprocess(tostring(html))
return frame:preprocess(tostring(html))
end
end


function p._LifeGuideFormat(args)
function p._TutorialFormat(args)
local out = mw.html.create('')
local out = mw.html.create('')
local title = mw.title.getCurrentTitle()
local title = mw.title.getCurrentTitle()
if args.about then
if args.about then
args.about = lib.split(args.about, ';')
args.about = lib.split(args.about, ';')
if title.rootText == 'Life Guide' then
if title.rootText == 'Tutorial' then
out:tag('i'):wikitext(require('Module:Hatnote').main(args.about))
out:tag('i'):wikitext(require('Module:Hatnote').main(args.about))
end
end
Line 50: Line 43:
local size = args.size or '200px'
local size = args.size or '200px'
if (title.rootText == 'Life Guide') then
if (title.rootText == 'Tutorial') then
size = '400px'
size = '400px'
end
end
Line 60: Line 53:
local text = args['text' .. tostring(I)]
local text = args['text' .. tostring(I)]
if (image or text) then
if (image or text) then
local row = out:tag('div'):addClass('lifeguide-detail')
local row = out:tag('div'):addClass('tutorial-detail')
row:wikitext('[[File:', (image or 'Empty.png'), '|', size, ']]')
row:wikitext('[[File:', (image or 'Empty.png'), '|', size, ']]')
row:tag('div'):wikitext((text or '<wbr>'))
row:tag('div'):wikitext((text or '<wbr>'))
Line 72: Line 65:
-- add categories if correct page
-- add categories if correct page
local subpage = args.title or title.subpageText
local subpage = args.title or title.subpageText
if (not args['table'] and title.baseText == 'Life Guide' and (subpage ~= nil and not lib.inArray({ 'Elements', 'Enemies', 'System', 'Adventure', 'Event', 'Quest', 'Uncategorized' }, subpage))) then
if (not args['table'] and title.baseText == 'Tutorial' and (subpage ~= nil and not lib.inArray({ 'Elements', 'Enemies', 'System', 'Adventure', 'Event', 'Quest', 'Uncategorized' }, subpage))) then
local cat = mw.html.create()
local cat = mw.html.create()
cat:wikitext('[[Category:Life Guides|', subpage, ']]')
cat:wikitext('[[Category:Tutorials|', subpage, ']]')
if args['sort'] then
if args['sort'] then
cat:wikitext('[[Category:Life Guide|', string.format('%05d', args['sort']), ']]')
cat:wikitext('[[Category:Tutorial|', string.format('%05d', args['sort']), ']]')
else
else
cat:wikitext('[[Category:Life Guide]]')
cat:wikitext('[[Category:Tutorial]]')
end
end
if lib.inArray({ 'Elements', 'Enemies', 'System', 'Adventure' }, args['type']) then
if lib.inArray({ 'Elements', 'Enemies', 'System', 'Adventure' }, args['type']) then
cat:wikitext('[[Category:', args['type'], ' Life Guides|', subpage, ']]')
cat:wikitext('[[Category:', args['type'], ' Tutorials|', subpage, ']]')
if not args['sort'] then
if not args['sort'] then
cat:wikitext('[[Category:Life Guide Missing Sort]]')
cat:wikitext('[[Category:Tutorial Missing Sort]]')
end
end
elseif args['type'] == 'Event' or args['type'] == 'Quest' then
elseif args['type'] == 'Event' or args['type'] == 'Quest' then
cat:wikitext('[[Category:', args['type'], ' Life Guides|', subpage, ']]')
cat:wikitext('[[Category:', args['type'], ' Tutorials|', subpage, ']]')
else
else
cat:wikitext('[[Category:Uncategorized Life Guides|', subpage, ']]')
cat:wikitext('[[Category:Uncategorized Tutorials|', subpage, ']]')
end
end
if args.about then
if args.about then
for _, v in pairs(args.about) do
for _, v in pairs(args.about) do
cat:wikitext('[[Category:', v, ' Life Guides]]')
cat:wikitext('[[Category:', v, ' Tutorials]]')
end
end
end
end
Line 103: Line 96:
while (args['image' .. tostring(I)] and exists) do
while (args['image' .. tostring(I)] and exists) do
if not checkExists('File:' .. args['image' .. tostring(I)]) then
if not checkExists('File:' .. args['image' .. tostring(I)]) then
cat:wikitext('[[Category:Life Guide Missing Image]]')
cat:wikitext('[[Category:Tutorial Missing Image]]')
exists = false;
exists = false;
end
end
Line 116: Line 109:
end
end


-- [[Template:Life Guides by Category Table]]
-- [[Template:Tutorials by Category Table]]
function p.Table(frame)
function p.Table(frame)
local args = require('Module:Arguments').getArgs(frame, { parentFirst = true })
local args = require('Module:Arguments').getArgs(frame, { parentFirst = true })
local result = mw.html.create('div'):addClass('lifeguide-table')
local result = mw.html.create('div'):addClass('tutorial-table')
local title = mw.title.getCurrentTitle().text
local title = mw.title.getCurrentTitle().text
if lib.isEmpty(args.pages) then
if lib.isEmpty(args.pages) then
result:tag('span'):wikitext('No [[Life Guide]]s ', (args[1] and 'that match the category selection' or 'are in ' .. title), '.')
result:tag('span'):wikitext('No [[Tutorial]]s ', (args[1] and 'that match the category selection' or 'are in ' .. title), '.')
else
else
local resultTable = mw.html.create('table'):addClass('article-table')
local resultTable = mw.html.create('table'):addClass('article-table')
local count = 0
local count = 0
for lifeguidePage in lib.gsplit(args.pages, ';;;', { noTrim = true, removeEmpty = true }) do
for tutorialPage in lib.gsplit(args.pages, ';;;', { noTrim = true, removeEmpty = true }) do
local lifeguideArgs = getTemplateArgs(lifeguidePage, { only = 'Life Guide' })
local tutorialArgs = getTemplateArgs(tutorialPage, { only = 'Tutorial' })
for key, value in pairs(lifeguideArgs) do
for key, value in pairs(tutorialArgs) do
if value == '' then lifeguideArgs[key] = nil end
if value == '' then tutorialArgs[key] = nil end
end
end
lifeguideArgs.PAGENAME = lifeguidePage
tutorialArgs.PAGENAME = tutorialPage
resultTable:node(p._TableRow(frame, lifeguideArgs))
resultTable:node(p._TableRow(frame, tutorialArgs))
count = count + 1
count = count + 1
end
end
local header = result:tag('div'):addClass('lifeguide-header')
local header = result:tag('div'):addClass('tutorial-header')
if lib.isNotEmpty(args.header) then
if lib.isNotEmpty(args.header) then
header:wikitext(tostring(tostring(args.header):gsub('%%PAGES%%', count)))
header:wikitext(tostring(tostring(args.header):gsub('%%PAGES%%', count)))
Line 147: Line 140:
count,
count,
"'''",
"'''",
' [[Life Guide]]',
' [[Tutorial]]',
(count == 1 and ' ' or 's '),
(count == 1 and ' ' or 's '),
(args[1] and ('that match' .. (count == 1 and 'es' or '') .. ' the category selection:') or ' are in ' .. title)
(args[1] and ('that match' .. (count == 1 and 'es' or '') .. ' the category selection:') or ' are in ' .. title)
Line 173: Line 166:
local row = out:tag('tr'):tag('td')
local row = out:tag('tr'):tag('td')
args['table'] = true
args['table'] = true
row:node(p.LifeGuide(frame, args))
row:node(p.Tutorial(frame, args))
end
end
return out
return out
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Petit Planet Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template
Below are commonly used wikitext from MediaWiki:Edittools. Click on any to insert them in the edit box.
File Pages==Summary====Licensing=={{Fairuse}}{{File|}}
Dynamic Page List¦²«»²{¦}²«»«/»«!----»
Array in DPL¹^2{}^2^2{¹}^2
Parser Functions{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}
Markup{{}}|[][[]][[Category:]]#REDIRECT [[]] [[Category:Redirect Pages]]<code></code><includeonly></includeonly><noinclude></noinclude><nowiki></nowiki><!----><br>§
Notices{{Stub|}}{{Stub Dialogue}}{{Upcoming}}{{Under Construction}}{{Placeholder|}}
Magic Words{{!}}{{formatnum:}}{{lc:}}{{uc:}}{{PAGENAME}}{{FULLPAGENAME}}{{ROOTPAGENAME}}{{BASEPAGENAME}}{{SUBPAGENAME}}{{DISPLAYTITLE:|noreplace}}__TOC____NOTOC____EXPECTUNUSEDCATEGORY____HIDDENCAT__
HTML Entities&mdash;&nbsp;&comma;&shy;