require "proto" require "ustring" require "upath" local create = Object:clone() --uwiki.action HEAD~ Create;; --uwiki.action --uwiki.action The `create` action provides the user a form for creating new, not yet existing content. --uwiki.action It uses the `form/create.html` as template for this. --uwiki.action function create:invoke(session, request, response) assert(session:acl_check(session.sys.."action/upload", "action"), "EACCESS:May not call upload") assert(session:acl_check(session.path, "upload"), "EACCESS:May not create content") assert(not upath.exists("." .. session.path), "EEXIST:File exists already") local amend = session:acl_check(session.path, "amend") local acls, aclpath -- check if one 'may' create an acl on upload, get the existing acl then if session:metaacl_check(session.path, "upload", "acl", "new") then acls, aclpath = session:acl_get(session.path) end -- enumerate valid types local types = {} for name in lfs.dir("." .. session.sys .. "type") do -- TODO select the default type for tree if #name <= 32 and (name:find("^%l[%d%l_]*$")) and session:acl_check(session.sys.."type/"..name, "type") then types[#types+1] = name end end ustring.file_interpolate( uwiki_conf.prefix .. uwiki_conf.docroot .. session.sys .. "form/create.html", { --action.create PARA login;; --action.create Name of the logged user logged in, needed when no cookie is set and password auth is passed around. --action.create login = session.user.login:sanitize('name'), --action.create PARA pass;; --action.create Password passed around when password auth is used. --action.create pass = session.user.pass, --action.create HEAD~ Substituted Variables;; --action.create --action.create PARA cgi;; --action.create Points to the path used to invoke the uwiki cgi. --action.create cgi = uwiki_conf.cgi, --action.create PARA path;; --action.create The path/file to be created. --action.create path = session.path:sanitize('apath'), --action.create PARA aclbegin;; --action.create Substituted to a html comment beginning when the user might not create new acls. (TODO hide this via css) --action.create aclbegin = aclpath and '' or '', --action.create PARA aclorigin;; --action.create Path of the acl used to seed the defaults. --action.create aclorigin = aclpath or '', --action.create PARA acls;; --action.create group:role pairs from the existing acl as default. --action.create acls = (function () if aclpath then local str = "" for _,row in ipairs(acls) do str = str .. row.group .. ":" .. row.role .. "\n" end return str else return "EACCESS" end end)(), --action.create PARA types;; --action.create create a list of type options for selecting the type --action.create types = (function () local str = "" for _,row in ipairs(types) do str = str .. "\n" end return str end )() --action.create --action.create }, function (str) response:write(str) end ) session:done() return response:finish() end return create -- Local Variables: -- mode: lua -- lua-indent-level: 4 -- indent-tabs-mode: nil -- End: