Modulo:DTSem: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
(First working version of RecurringListFromCategory)
(Generic ASK function)
Riga 139: Riga 139:
--return mw.text.nowiki(CategoryText) .. #Pages
--return mw.text.nowiki(CategoryText) .. #Pages
return table.concat(Results, string.char(10))
return table.concat(Results, string.char(10))
end
-- 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.ask( frame.args )
    if queryResult == nil then
        return "(no values)"
    end
    if type( queryResult ) == "table" then
        local myResult = ""
        for num, row in pairs( queryResult ) do
            myResult = myResult .. '* This is result #' .. num .. '\n'
            for property, data in pairs( row ) do
                local dataOutput = data
                if type( data ) == 'table' then
                    dataOutput = mw.text.listToText( data, ', ', ' and ')
                end
                myResult = myResult .. '** ' .. property .. ': ' .. dataOutput .. '\n'
            end
        end
        return myResult
    end
    return queryResult
end
end
return p
return p