FANDOM


-- <nowiki>
local p = {}
local isValid = require("Dev:Scriptlist/validate")
 
--% Makes a [[Help:DynamicPageList|DPL]] query that:
---
--- # Gets all pages in [[:Category:JavaScript]]
--- # Limits those to pages in the main namespace
--- # Looks for [[Template:Infobox JavaScript]] and:
--- #* If found, passes it to [[User:DarthKitty/surrogate]]
--- #* If missing, uses [[User:DarthKitty/surrogate.default]]
---
--- @TODO: replace [[Template:Infobox Javascript/sandbox]] with
--- [[Template:Infobox JavaScript]].
---
--- @TODO: replace [[User:DarthKitty/surrogate]] with something more relevant,
--- like [[Template:Infobox JavaScript/dpl]].
--: (string) The results of the DPL query.
function p.fetch()
    local query = [[{{#dpl:
    | category = JavaScript
    | namespace =
    | include = {Infobox JavaScript/sandbox¦User:DarthKitty/surrogate}
    | format = ,,,
    | allowcachedresults = true
    }}]]
 
    mw.incrementExpensiveFunctionCount()
 
    return mw.getCurrentFrame():preprocess(query)
end
 
--% Transforms XML into a [[Help:Lua|Lua]] table, according a certain pattern.
--@ xml (string) The XML data to be parsed.
--: (table) A sequence of tables, each containing basic information about a
--- given script.
function p.parse(xml)
    local scripts = {}
    local xmlPattern = [[
<scriptdata>
    <pagename>(.-)</pagename>
    <name>(.-)</name>
    <description>(.-)</description>
    <categories>(.-)</categories>
    <scope>(.-)</scope>
    <skins>(.-)</skins>
    <updated>(.-)</updated>
    <authors>(.-)</authors>
    <languages>(.-)</languages>
</scriptdata>]]
 
    for pagename, name, description, categories, scope, skins, updated, authors,
        languages
    in xml:gmatch(xmlPattern) do
        local script = {
            pagename = pagename,
            name = name,
            description = description,
            categories = categories,
            scope = scope,
            skins = skins,
            updated = updated,
            authors = authors,
            languages = languages
        }
 
        -- call the appropriate `isValid` method for each piece of data
        for dataType, validator in pairs(isValid) do
            if script[dataType] and not validator(script[dataType]) then
                script.invalid = true
            end
        end
 
        table.insert(scripts, script)
    end
 
    return scripts
end
 
--% Builds a list of all scripts on the wiki using [[Help:HTML|HTML]].
---
--- @TODO: create a header for each category, and sort scripts accordingly.
--@ frame (table) The
--- [[Lua reference manual/Scribunto libraries#Frame object|frame object]].
--: (string) A formatted list of all scripts.
function p.build(frame)
    local dplResults = p.fetch()
    local scripts = p.parse(dplResults)
    local list = mw.html.create("ul")
 
    for _, script in pairs(scripts) do
        if not script.invalid then
            list:tag("li")
                :wikitext("[[" .. script.pagename .. "]] — " .. script.description)
                :done()
        end
    end
 
    return tostring(list) 
end
 
return p
-- </nowiki>

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.