Module:SMW

From devsummit
Revision as of 08:37, 27 November 2017 by Ccicalese (talk | contribs) (Created page with "-- Module:SMW local p = {} -- Return results function p.ask(frame) if not mw.smw then return "mw.smw module not found" end if frame.args[1] == nil then...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:SMW/doc

-- Module:SMW
local p = {}

-- Return results
function p.ask(frame)

    if not mw.smw then
        return "mw.smw module not found"
    end

    if frame.args[1] == nil then
        return "no parameter found"
    end

    local queryResult = mw.smw.getQueryResult( frame.args )

    if queryResult == nil then
        return "(no values)"
    end

    if type( queryResult ) == "table" then
        local myResult = ""
        for k,v in pairs( queryResult.results ) do
            if  v.fulltext and v.fullurl then
                myResult = myResult .. k .. " | " .. v.fulltext .. " " .. v.fullurl .. " | " .. "<br/>"
            else
                myResult = myResult .. k .. " | no page title for result set available (you probably specified ''mainlabel=-')"
            end
        end
        return myResult
    end

    return queryResult
end

return p