Module:SMW: Difference between revisions

From devsummit
No edit summary
No edit summary
Line 3: Line 3:


-- Return results
-- Return results
function p.ask(frame)
function p.sessionTable(frame)


    if not mw.smw then
     local queryResult = mw.smw.getQueryResult( "[[Category:Sessions]]" )
        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
     if queryResult == nil then
Line 19: Line 11:
     end
     end


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


     return queryResult
     return myResult
end
end


return p
return p

Revision as of 08:44, 27 November 2017

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

-- Module:SMW
local p = {}

-- Return results
function p.sessionTable(frame)

    local queryResult = mw.smw.getQueryResult( "[[Category:Sessions]]" )

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

    if type( queryResult ) ~= "table" then
        return "(invalid query result)"
    end
    
    local myResult = ""
    for k,v in pairs( queryResult.results ) do
        myResult = myResult .. "[[" .. v.fulltext .. "]]" .. "<br/>"
    end

    return myResult
end

return p