Fandom

Old School RuneScape Wiki

Module:ExchangeData

15,965pages on
this wiki
Add New Page
Discuss0

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.

-- <pre>
-- Implements {{ExcgData}}
--
-- Original from http://runescape.wikia.com/wiki/Module:ExchangeData
 
local p = {}
 
-- required modules
local excg = require( 'Module:Exchange' )
 
--
-- @param args {table}
-- @param baseExcgPage {boolean} Shouldn't be used by any method here,
--                               only used by [[Module:ExchangeDefault]]
--
function p._main( args, baseExcgPage )
    -- prefer args[1] but that'll break on exchange /data pages due to the data being the first positional arg
    -- @todo change the order of these when data is removed fom there
    local item = args.name or args[1]
    local data = {}
    local div2, div3, div4, _data
 
    if not item then
        error( '"name" argument is not specified', 0 )
    end
 
    item = mw.text.trim( item )
 
    if args.size ~= 'data' then
        div2 = mw.html.create( 'div' )
            :addClass( 'GEChartBox' )
 
        if args.moreItems then
            div2
                :tag( 'div' )
                    :addClass( 'addGEChartItems' )
                    :css( 'display', 'none' )
                    :wikitext( args.moreItems )
                    :done()
        end
 
        -- some extra formatting for non exchange pages
        if not baseExcgPage then
            local div3 = div2
                :tag( 'div' )
                    :addClass( 'GEdatachart' )
                    :css( {
                        border = '1px solid #666',
                        ['padding-left'] = '1px'
                    } )
 
            if args.size == 'small' then
                div3
                    :addClass( 'smallChart' )
                    :css( {
                        margin = '5px',
                        float = 'left',
                        width = '258px',
                        height = '200px'
                    } )
            else
                div3
                    :css( {
                        margin = '5px 0 25px 0',
                        ['min-width'] = '600px',
                        height = '500px'
                    } )
            end
 
            div2 = div3
                :tag( 'div' )
                    :css( {
                        ['text-align'] = 'center',
                        ['font-size'] = '11px',
                        color = '#666'
                    } )
                    :wikitext( 'Loading...' )
                    :done()
                :done()
        end
    end
 
    -- for [[GEMW/C]]
    if mw.ustring.lower( item ) == 'blank' then
        local lang = mw.language.getContentLanguage()
        data = lang:formatDate( 'U' ) .. ':0'
    else
        -- make sure first letter is upper case
        item = mw.text.split( item, '' )
        item[1] = mw.ustring.upper( item[1] )
        item = table.concat( item, '' )
 
        -- mw.loadData doesn't return a proper table
        -- so we need to map it to a proper table
        local _data = mw.loadData( 'Module:Exchange/' .. item .. '/Data' )
 
        for k, v in pairs( _data ) do
            mw.log( k, v )
            data[k] = v
        end
 
        data = table.concat( data, '|' )
    end
 
    div4 = mw.html.create( 'div' )
        :addClass( 'GEdataprices' )
        :attr( 'data-item', item )
        :attr( 'data-data', data )
        :css( 'display', 'none' )
 
    if item and mw.ustring.match( item, 'Index' ) == nil and mw.ustring.lower( item ) ~= 'blank' then
        div4
            :attr( {
                ['data-value'] = tostring( excg._value( item ) ),
                ['data-limit'] = tostring( excg._limit( item ) )
            } )
    end
 
    if args.size == 'data' then
        div2 = div4
    else
        div2:node( div4:done() )
    end
 
    return tostring( div2 )
end
 
--
-- {{GEChart}}
--
function p.chart( frame )
    local args = frame:getParent().args
    local items = args[1] or args.items
 
    if items == nil then
        return
    end
 
    items = mw.text.trim( items )
    items = mw.text.split( items, ',' )
 
    if mw.text.trim( items[1] ) == '' then
        return args['else'] or ''
    end
 
    local div = mw.html.create( 'div' )
        :addClass( 'GEChartBox' )
        :tag( 'div' )
            :addClass( 'GEChartItems' )
            :css( 'display', 'none' )
            :wikitext( table.concat( items, ',', 2 ) )
            :done()
 
    local div2 = mw.html.create( 'div' )
        :addClass( 'GEdatachart' )
        :css( 'border', '1px solid #666' )
 
    if args.size == 'small' then
        div2
            :addClass( 'smallChart' )
            :css( {
                margin = '5px',
                float = 'left',
                width = '258px',
                height = '200px'
            } )
    else
        div2
            :css( {
                margin = '5px 0 25px 0',
                height = '500px',
                ['min-width'] = '600px'
            } )
    end
 
    div2
        :tag( 'div' )
            :css( {
                ['text-align'] = 'center',
                ['font-size'] = '11px',
                color = '#666'
            } )
            :wikitext( 'Loading...' )
            :done()
        :done()
 
    div
        :node( div2 )
 
    div
        :wikitext( p._main{items[1], size='data'} )
        :done()
 
    return tostring( div )
end
 
--
-- {{GEData}}
--
-- A stripped down version of ExcgData
-- Intended for more general usage and avoiding stuff specific to Exchange /Data pages
--
function p.data( frame )
    local args = frame:getParent().args
    return p._main( args )
end
 
--
-- {{ExcgData}}
--
function p.main( frame )
    local args = frame:getParent().args
    -- get title parts, as the exchange ns doesn't actually have subpages enabled
    local title = mw.title.getCurrentTitle()
    local parts = mw.text.split( title.text, '/' )
    local ns, base, sub = title.nsText, parts[1], parts[2]
 
    -- it'll throw an error later if this isn't supplied
    -- so default to an empty string for now
    local item = args.name or args[1] or ''
 
    local div1, cats = '', ''
 
    -- fake "back to main page" link
    if sub == 'Data' and ns == 'Exchange' then
        div1 = mw.html.create( 'div' )
            :attr( 'id', 'contentSub' )
            :css( {
                ['line-height'] = '0.8em',
                margin = '-0.75em 0 1.5em 1em'
            } )
            :tag( 'span' )
                :addClass( 'subpages' )
                :wikitext( '&lt; [[' .. ns .. ':' .. base .. ']]' )
                :done()
            :done()
        div1 = tostring( div1 )
    end
 
    -- categories
    if sub == 'Data' then
        if ns == 'Exchange' then
            cats = cats .. '[[Category:GEMW data|' .. item .. ']]'
        elseif mw.ustring.match( item, 'Index' ) ~= nil then
            cats = cats .. '[[Category:GEMW data|*]]'
        end
 
        if ns == 'Exchange' and item ~= base then
            cats = cats .. '[[Category:Exchange names that needs checking]]'
        end
    end
 
    return div1 .. p._main( args ) .. cats
end
 
return p

Also on Fandom

Random Wiki