FANDOM


local navigation = {}
----------------------------
-- Libraries of functions --
----------------------------
-- stands for High Frequency
local HF = require('Module:HF')
-- Parses invocation and template parameters, trims whitespace, and removes blanks.
local getArgs = require('Dev:Arguments').getArgs
-- Generates lists
local L = require('Dev:List')
_G.page_title = mw.title.getCurrentTitle().text
 
_G.t = getArgs(frame, { trim = true, removeBlanks = true, parentOnly = true })
_G.kr_release = (t['kr_sets'] or t['ko_sets']) and true
_G.ae_release = t['ae_sets'] and true
_G.tc_release = t['tc_sets'] and true
_G.na_release = t['na_sets'] and true
_G.eu_release = t['eu_sets'] and true
_G.de_release = t['de_sets'] and true
_G.it_release = t['it_sets'] and true
_G.pt_release = t['pt_sets'] and true
_G.sp_release = t['sp_sets'] and true
_G.ocg_jp = (t['jp_sets'] or t['ja_sets']) and true
_G.ocg = (ocg_jp or kr_release or ae_release or tc_release) and true
_G.tcg_en = (t['en_sets'] or na_release or eu_release or t['au_sets']) and true
_G.tcg_fr = (t['fr_sets'] or t['fc_sets']) and true
_G.tcg = (tcg_en or tcg_fr or de_release or it_release or pt_release or sp_release) and true
_G.ocg_tcg = (ocg or tcg) and true
 
_G.non_game = (t['type'] and (t['type']:lower() == 'illustration card' or t['type']:lower() == 'strategy card' or t['type']:lower() == 'tip card' or t['type']:lower() == 'faq card' or t['type']:lower() == 'non-game card' or t['type']:lower() == 'character card'))
 
---------------------------------------------------------
-- Internal functions (used in this and other Modules) --
---------------------------------------------------------
function navigation.related(args)
    -- Template parameters, passed from .
    local t = args
    local list = {
        _relatedpagelink( 'Card Rulings', t['cardgame'] or t['name'] or nil, 'Rulings' ),
        _relatedpagelink( 'Card Errata', t['cardgame'] or t['name'] or nil, 'Errata' ),
        _relatedpagelink( 'Card Tips', t['cardgame'] or t['name'] or nil, 'Tips' ),
        _relatedpagelink( 'Card Appearances', t['cardgame'] or t['name'] or nil, 'Appearances' ),
        _relatedpagelink( 'Card Trivia', t['cardgame'] or t['name'] or nil, 'Trivia' ),
        _relatedpagelink( 'Card Lores', t['cardgame'] or t['name'] or nil, 'Lores' ),
        _relatedpagelink( 'Card Artworks', t['cardgame'] or t['name'] or nil, 'Artworks' ),
        _relatedpagelink( 'Card Names', t['cardgame'] or t['name'] or nil, 'Names' ),
    }
    local hlist = L.makeList( 'horizontal' , list )
    return tostring(hlist)
end
 
function navigation.relatedTabView(args)
    -- Template parameters, passed from .
    local t = args
    local list = {
        _relatedtabpage( 'Card Rulings', t['cardgame'] or t['name'] or nil, 'Rulings' )..'',
        _relatedtabpage( 'Card Errata', t['cardgame'] or t['name'] or nil, 'Errata' ),
        _relatedtabpage( 'Card Tips', t['cardgame'] or t['name'] or nil, 'Tips' ),
        _relatedtabpage( 'Card Appearances', t['cardgame'] or t['name'] or nil, 'Appearances' ),
        _relatedtabpage( 'Card Trivia', t['cardgame'] or t['name'] or nil, 'Trivia' ),
        _relatedtabpage( 'Card Lores', t['cardgame'] or t['name'] or nil, 'Lores' ),
        _relatedtabpage( 'Card Artworks', t['cardgame'] or t['name'] or nil, 'Artworks' ),
        _relatedtabpage( 'Card Names', t['cardgame'] or t['name'] or nil, 'Names' ),
    }
    return table.concat( list, '\n')
end
 
function navigation.external(args)
    local o = {}
    local categories = {}
    if (args['yugioh_site'] or args['yugioh_site_raw'] or args['appears_in_dm'] or args['appears_in_cm'] or args['appears_in_gx'] or args['appears_in_5d'] or args['appears_in_zx'] or args['appears_in_av'] or args['appears_in_vr']) and not ( args['yugioh_site'] and args['yugioh_site']:lower() == 'none' ) then
        for _,list_item in ipairs( _yugioh_site(args) ) do
            table.insert( o, list_item )
        end
    end
    if ocg_tcg --and not ( non_game or token_counter or args['cardgame'] or (args['image'] and args['image']:match('-BD-JP-')) ) 
        then
 
        table.insert( o, _yugioh_card_db(args) )
    end
--    if tcg_en 
    --and (not non_game) and (not args['cardgame']) 
--        then
        table.insert( o, _yugioh_prices(args) )
--    end
--    if ocg_tcg
    --and (not non_game) 
--    then
        for _,list_item in ipairs( _ygo_card_de(args) ) do
            table.insert( o, list_item )
        end
--    end
    return tostring( L.makeList('horizontal', o) )..table.concat( categories )
end
 
function navigation.yugioh_card_db (args)
    local db_id = args['database_id']
    local has_db_id = (ocg_jp or tcg_en or tcg_fr or de_release or it_release or sp_release) and true
    local categories = {}
    if db_id == nil and has_db_id 
        then
        table.insert( categories, '<includeonly>'..HF.Category('Card pages needing a Yugioh-Card database ID')..'</includeonly>' )
    elseif db_id == nil then
        -- No parameter, doesn't need one.
    elseif type(db_id) == 'string' and db_id:lower() == 'none' then
        table.insert( categories, HF.Category('Card pages without a Yugioh-Card database ID') )
    elseif type(db_id) ~= 'number' then
        table.insert( categories, HF.Category('Pages with an invalid Yugioh-Card database ID') )
    else
        local YCCD_list = {
            _dblink( ocg_jp, db_id, args['ja_database_id'], 'ja', 'Japanese', 'Japanese'),
            ocg_jp 
                and '('..
                    HF.ExternalLink(
                        'http://www.db.yugioh-card.com/yugiohdb/faq_search.action?ope=4&cid='..db_id..'&request_locale=ja',
                        'Japanese rulings')
                    ..')',
            _dblink( tcg_en, db_id, args['en_database_id'], 'en', 'English', 'English'),
            _dblink( tcg_fr, db_id, args['fr_database_id'], 'fr', 'French', 'French'),
            _dblink( de_release, db_id, args['de_database_id'], 'de', 'German', 'German'),
            _dblink( it_release, db_id, args['it_database_id'], 'it', 'Italian', 'Italian'),
            _dblink( sp_release, db_id, args['es_database_id'], 'es', 'Spanish', 'Spanish')
        }
        mw.smw.set{ 'Database ID='..db_id }
--        return 
--            'DBID: '..db_id..'<hr/>'..
--            tostring(L.makelist( 'bulleted' , YCCD_list ))..
--            table.concat(categories)
        return 'Test'
    end
 
end
 
function navigation.specialized_pages (args)
    local query = mw.smw.ask{ 
('[[Main card page::%s]]'):format( 'Dragon Piper' ),
'?#-=page',
'?Medium',
'sort=Medium',
'order=ascending' } or nil
    -- for each result is a record, and the first property should be the bare page name, the second the type
    if assert(query, 'No results found') then
        local o = {}
        for _,item in ipairs( query ) do
            table.insert(o, ('%s|%s'):format(item['page'], (item['Medium'][1] or item['Medium'])) )
        end
        return table.concat(o, '\n')
    else
        return ''
    end
end
 
------------------------------------------------
-- Local functions (only used in this Module) --
------------------------------------------------
function _relatedpagelink( namespace, value, label, section, itype )
    local pagename = HF.NP()
    local link
    local ask = mw.smw.ask{ ('[[%s %s for::%s]]'):format(namespace, (itype or 'page'), pagename), link='none' } and mw.smw.ask{ ('[[%s %s for::%s]]'):format(namespace, (itype or 'page'), pagename), link='none' }[1][1] or nil
    if value then
        link = namespace..':'..value
    elseif not pagename:match('=') and ask then
        link = ask
    else
        link = namespace..':'..pagename
    end
    if section then link = link .. '#' .. section end
    return HF.Link( link, label or namespace or '' )
end
 
function _relatedtabpage( namespace, value, label, section, itype )
    local pagename = HF.NP()
    local link
    local ask = mw.smw.ask{ ('[[%s %s for::%s]]'):format(namespace, (itype or 'page'), pagename), link='none' } and mw.smw.ask{ ('[[%s %s for::%s]]'):format(namespace, (itype or 'page'), pagename), link='none' }[1][1] or nil
    if value then
        link = namespace..':'..value
    elseif not pagename:match('=') and ask then
        link = ask
    else
        link = namespace..':'..pagename
    end
    if section then link = link .. '#' .. section end
    return link..'|'..( label or namespace or '' )
end
 
function _dblink( release, db_id, f_db_id, locale, Language, label)
    local link_label = label or locale
    if release and f_db_id then
        return HF.Category('Card pages with a suppressed ' .. Language .. ' Yugioh-Card database ID')
    elseif release and db_id then
        local URI = mw.uri.new{
            protocol = 'http',
            host = 'www.db.yugioh-card.com',
            path = '/yugiohdb/card_search.action',
            query = { ['ope'] = '2', ['cid'] = db_id, ['request_locale'] = locale  }
        }
        mw.smw.set{ Language..' database ID='..db_id }
        return HF.ExternalLink( URI, locale )
    else
        return nil
    end
end
 
function _yugioh_site(args)
    return {
            HF.ExternalLink( 'http://www.yugioh.com/cards/'..(args['yugioh_site_raw'] or (args['yugioh_site'] or args['name'] or page_title):gsub("%'",''):gsub(',',''):gsub('&',''):gsub('!',''):gsub('%.',''):gsub('%"',''):gsub(':',''):gsub('/',''):gsub('#',''):gsub('%s+', '-'):lower()), 'yugioh.com' ),
            args['yugioh_site'] and ('("%s")'):format(args['yugioh_site'])..HF.Category('Pages with an overwritten yugioh.com link'),
            args['yugioh_site_raw'] and ('<span class="sysop-show">(<code>%s</code>)</span>'):format(args['yugioh_site_raw'])..HF.Category('Pages with an overwritten yugioh.com link')
        }
end
 
function _yugioh_card_db(args)
    local db_id = args['database_id']
    local has_db_id = (ocg_jp or tcg_en or tcg_fr or de_release or it_release or sp_release) and true
    if db_id == nil and has_db_id 
        then
        table.insert( categories, '<includeonly>'..HF.Category('Card pages needing a Yugioh-Card database ID')..'</includeonly>' )
    elseif db_id:lower() == 'none' then
        table.insert( categories, HF.Category('Card pages without a Yugioh-Card database ID') )
    elseif type(db_id) ~= 'number' then
        table.insert( categories, HF.Category('Pages with an invalid Yugioh-Card database ID') )
    else
        local YCCD_list = {
            _dblink( ocg_jp, db_id, args['ja_database_id'], 'ja', 'Japanese'),
            ocg_jp 
                and '('..
                    HF.ExternalLink(
                        'http://www.db.yugioh-card.com/yugiohdb/faq_search.action?ope=4&cid='..db_id..'&request_locale=ja',
                        'rulings')
                    ..')',
            _dblink( tcg_en, db_id, args['en_database_id'], 'en', 'English'),
            _dblink( tcg_fr, db_id, args['fr_database_id'], 'fr', 'French'),
            _dblink( de_release, db_id, args['de_database_id'], 'de', 'German'),
            _dblink( it_release, db_id, args['it_database_id'], 'it', 'Italian'),
            _dblink( sp_release, db_id, args['es_database_id'], 'es', 'Spanish')
        }
        mw.smw.set{ 'Database ID='..db_id }
        return 
            'Yugioh-Card card database: '..db_id..' ('..
            tostring(L.makelist( 'horizontal' , YCCD_list ))
            ..')'
    end
end
 
function _yugioh_prices(args)
    local link = HF.ExternalLink(tostring(mw.uri.new{
            protocol = 'http',
            host = 'yugiohprices.com',
            path = '/card_price',
            query = { 
                ['name'] = mw.uri.encode( 
                    args['yugiohprices'] 
                    or (args['name'] and args['name']:gsub('#','') or HF.NP() ))
            }
            }), 'YugiohPrices')
    return link..(
        (args['yugiohprices'] and args['yugiohprices']:lower() == 'none' )
        and HF.Category() or ''
        )
end
 
function _ygo_card_de(args)
    local english = HF.ExternalLink( tostring(mw.uri.new{
        protocol = 'http',
        host = 'en.ygo-card.de',
        path = '/result_links.php',
        query = { 
            ['htm_name'] = mw.uri.encode( args['ygocard'] or ( args['name'] or page_title )),
            ['suche'] = 'true'
        }
    }), 'YGO-Card.de' )..' (English)'..(args['ygocard'] and HF.Category('Card pages with overridden YGO-Card.de English links') or '')
    local german = args['de_name']
        and HF.ExternalLink( tostring(mw.uri.new{
            protocol = 'http',
            host = 'de.ygo-card.de',
            path = '/result_links.php',
            query = { 
                ['htm_name'] = mw.uri.encode( args['ygocard-de'] or args['de_name'] or '' ),
                ['suche'] = 'true'
            }
            }), 'YGO-Card.de' )..' (German)'..(args['ygocard'] and HF.Category('Card pages with overridden YGO-Card.de German links') or '')
    return {
        english,
        german,
    }
end
 
function _counters()
end
 
function _tokens()
end
 
-------------------------------------------------
-- Output (send it back to whatever called it) --
-------------------------------------------------
return navigation

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.