5,076
edits
No edit summary |
No edit summary |
||
(18 intermediate revisions by the same user not shown) | |||
Line 39: | Line 39: | ||
Constructs a standard format reference using the given parameters, with the | Constructs a standard format reference using the given parameters, with the | ||
provided content. Content table supports unlimited numeric arguments, in | provided content. Content table supports unlimited numeric arguments, in | ||
addition to | addition to Subheading, Detail, Quote, Quotee and Suffix arguments. | ||
@param frame - object - The current parser frame | @param frame - object - The current parser frame | ||
Line 56: | Line 56: | ||
Generates the text content of a standard format reference from the provided | Generates the text content of a standard format reference from the provided | ||
arguments. Content table supports unlimited numeric arguments, in | arguments. Content table supports unlimited numeric arguments, in | ||
addition to | addition to subheading, detail, quote, quotee and suffix arguments. | ||
@param content - table - The content of the reference | @param content - table - The content of the reference | ||
Line 64: | Line 64: | ||
function makeRefText( content ) | function makeRefText( content ) | ||
local text = "''" .. tostring( content[ 1 ] or '' ) .. "''" | local text = "''" .. tostring( content[ 1 ] or '' ) .. "''" | ||
if not utils.empty( content. | if not utils.empty( content.subheading ) then | ||
text = text .. ': ' .. tostring( content.subheading ) | text = text .. ': ' .. tostring( content.subheading ) | ||
end | end | ||
Line 79: | Line 79: | ||
end | end | ||
if not utils.empty( content.quote ) then | if not utils.empty( content.quote ) then | ||
text = text .. ' ' .. tostring( content.quote ) | text = text .. " ''\"" .. tostring( content.quote ) .. "\"''" | ||
if not utils.empty( content.quotee ) then | if not utils.empty( content.quotee ) then | ||
text = text .. ' - ' .. | text = text .. ' - ' | ||
text = text .. uniqueLinkIfExists( content.quotee, content.quoteetext, 'ref' ) | |||
end | end | ||
end | end | ||
Line 135: | Line 136: | ||
return frame:extensionTag( 'references', '', args ) | return frame:extensionTag( 'references', '', args ) | ||
end | |||
function uniqueLink( page, text, category ) | |||
local frame = mw.getCurrentFrame() | |||
if utils.empty( text ) then | |||
text = page | |||
end | |||
return frame:callParserFunction( '#uniquelink', page, text, category ) | |||
end | |||
function uniqueLinkIfExists( page, text, category ) | |||
local frame = mw.getCurrentFrame() | |||
if utils.empty( text ) then | |||
text = page | |||
end | |||
return frame:callParserFunction( '#uniquelinkifexists', page, text, category ) | |||
end | |||
function acronym( category, acronym, target, default ) | |||
local frame = mw.getCurrentFrame() | |||
if utils.empty( default ) then | |||
default = acronym | |||
end | |||
return frame:callParserFunction( '#acronym', category, acronym, target, default ) | |||
end | end | ||
Line 186: | Line 217: | ||
[ 'valid' ] = { 'id', 'subheading', 3, 4, 5, 6, 7, 'detail', 'quote', | [ 'valid' ] = { 'id', 'subheading', 3, 4, 5, 6, 7, 'detail', 'quote', | ||
'quotee', 'quoteelinktext', 'suffix' }, | 'quotee', 'quoteelinktext', 'suffix' }, | ||
[ 'aliases' ] = { [ 1 ] = 'heading | [ 'aliases' ] = { [ 1 ] = 'heading' } | ||
} ) | |||
}) | |||
local content = { | local content = { | ||
args.heading, args[2], args[3], args[4], args[5], args[6], args[7], | args.heading, args[2], args[3], args[4], args[5], args[6], args[7], | ||
Line 211: | Line 241: | ||
[ 'required' ] = { 'game' }, | [ 'required' ] = { 'game' }, | ||
[ 'recommended' ] = { 'what' }, | [ 'recommended' ] = { 'what' }, | ||
[ 'valid' ] = { 'id', 'part', 'detail', 'quote', | [ 'valid' ] = { 'whattext', 'id', 'part', 'parttext', 'detail', 'quote', | ||
'quotee', ' | 'quotee', 'quoteetext', 'suffix' }, | ||
[ 'aliases' ] = { [ 1 ] = 'game', [ 2 ] = 'what', [ 'expansion' ] = 'part', [ 'dlc' ] = 'part' }, | [ 'deprecated' ] = { 'gamelinktext', 'whatlinktext', 'partlinktext', | ||
[ ' | 'quoteelinktext' }, | ||
}) | [ 'aliases' ] = { [ 1 ] = 'game', [ 'gamelink' ] = 'game', | ||
[ 2 ] = 'what', [ 'whatlink' ] = 'what', [ 3 ] = 'whattext', | |||
[ 'whatlinktext' ] = 'whattext', [ 'partlink' ] = 'part', | |||
[ 'expansion' ] = 'part', | |||
[ 'dlc' ] = 'part', [ 'edition' ] = 'part', [ 'partlink' ] = 'part', | |||
[ 'expansionlink' ] = 'part', [ 'dlclink' ] = 'part', | |||
[ 'editionlink' ] = 'part', | |||
[ 'partlinktext' ] = 'parttext', [ 'expansiontext' ] = 'parttext', | |||
[ 'dlctext' ] = 'parttext', [ 'editiontext' ] = 'parttext', | |||
[ 'quoteelinktext' ] = 'quoteetext' } | |||
} ) | |||
local game = uniqueLinkIfExists( | |||
acronym( 'game', args.game, 'page', args.game ), | |||
args.gameLinkText or acronym( 'game', args.game, 'title', args.game ), | |||
'ref' | |||
) | |||
local part | |||
if not utils.empty( args.part ) then | |||
part = uniqueLinkIfExists( | |||
args.part, | |||
args.parttext or args.part, | |||
'ref' | |||
) | |||
end | |||
local what | |||
if not utils.empty( args.what ) then | |||
what = uniqueLinkIfExists( | |||
args.what, | |||
args.whattext or args.what, | |||
'ref' | |||
) | |||
end | |||
local content = { | |||
game, what, | |||
[ 'subheading' ] = part or args.part, | |||
[ 'detail' ] = args.detail, | |||
[ 'quote' ] = args.quote, | |||
[ 'quotee' ] = args.quotee, | |||
[ 'quoteetext' ] = args.quoteetext or args.quotee, | |||
[ 'suffix' ] = args.suffix | |||
} | |||
return out .. makeStandardRef( frame, args.id, nil, content) | |||
end | |||
--[[[ | |||
Invocation entry point for Template:Ref/File. | |||
@param frame - object - The current parser frame | |||
@return wikitext - the constructed reference | |||
]] | |||
function ref.file( frame ) | |||
local args, out = arguments.preprocess( frame, { | |||
[ 'required' ] = { 'game', 'file' }, | |||
[ 'valid' ] = { 'gametext', 'excerpt', 'id', 'part', 'parttext', | |||
'detail', 'quote', 'quotee', 'quoteetext', 'suffix' }, | |||
[ 'deprecated' ] = { 'gamelinktext' }, | |||
[ 'aliases' ] = { [ 1 ] = 'game', [ 'gamelink' ] = 'game', | |||
[ 2 ] = 'file', [ 3 ] = 'excerpt', | |||
[ 'gamelinktext' ] = 'gametext', [ 'partlink' ] = 'part', | |||
[ 'expansion' ] = 'part', | |||
[ 'dlc' ] = 'part', [ 'edition' ] = 'part', [ 'partlink' ] = 'part', | |||
[ 'expansionlink' ] = 'part', [ 'dlclink' ] = 'part', | |||
[ 'editionlink' ] = 'part', | |||
[ 'partlinktext' ] = 'parttext', [ 'expansiontext' ] = 'parttext', | |||
[ 'dlctext' ] = 'parttext', [ 'editiontext' ] = 'parttext', | |||
[ 'quoteelinktext' ] = 'quoteetext' } | |||
} ) | |||
local game = uniqueLinkIfExists( | |||
acronym( 'game', args.game, 'page', args.game ), | |||
args.gameLinkText or acronym( 'game', args.game, 'title', args.game ), | |||
'ref' | |||
) | |||
local part | |||
if not utils.empty( args.part ) then | |||
part = uniqueLinkIfExists( | |||
args.part, | |||
args.parttext or args.part, | |||
'ref' | |||
) | |||
end | |||
local file = args.file or 'unspecified file' | |||
file = 'game file <code>' .. file .. '</code>' | |||
local excerpt = args.excerpt | |||
if not utils.empty( excerpt ) then | |||
excerpt = 'excerpt <code>' .. excerpt .. '</code>' | |||
end | |||
local content = { | local content = { | ||
game, file, excerpt, | |||
[ 'subheading' ] = args.part, | [ 'subheading' ] = part or args.part, | ||
[ 'detail' ] = args.detail, | [ 'detail' ] = args.detail, | ||
[ 'quote' ] = args.quote, | [ 'quote' ] = args.quote, | ||
[ 'quotee' ] = args.quotee, | [ 'quotee' ] = args.quotee, | ||
[ 'quoteetext' ] = args.quoteetext or args.quotee, | |||
[ 'suffix' ] = args.suffix | [ 'suffix' ] = args.suffix | ||
} | } |