@verb #84:"edit_file" this none this rxdo #789
@program #84:"edit_file" this none this
caller == this || raise(E_PERM)
player:isa($webber) || raise(E_PERM)
player:tell($eval.antistealth)
set_task_perms(player.user)
{name, object} = args
if (iobj && player.referer && $www:previous_object() != object && player.user != $no_one)
"We have an unknown form refering a command to us with a user's perms..."
$msg:mtell("www_error", "Warning! Previous page doesn't appear to be this one!")
player:tell("For security reasons the command will not be executed. Refering page: [", player.referer, "]")
iobj = {}
endif
suspend(0)
image_types = {".gif", ".jpg", ".jpeg", ".png"}
url = tostr("/", toint(object))
oldname = name
access = `object:fileaccess(name) ! "E_FILE" => E_INVARG'
if (access == "" && !$perm_utils:controls(player.user, object))
$msg:mtell("www_error", "You do not have permission to view this file.")
return $www.exam:tell_files(object)
elseif (access == E_INVARG)
if ($www:parse_POST("create"))
"File doesn't exist, and we want to create it."
object:filewrite(name, {})
player:tell("File created!
")
"Keep going, and show the edit page."
iobj = {}
else
"File doesn't exist, offer to create it."
player:tell("", object:nn(), " doesn't have this file.
")
if ($perm_utils:controls(player.user, object))
player:tell("
")
endif
return player:tell("See the list of existing files on ", $su:nn(object), ".")
endif
elseif ($www:parse_POST("delete") == "Delete file")
"Unconfirmed request to delete file (probably no JavaScript)."
player:tell("Are you sure you want to delete this file?
")
player:tell("
")
return
elseif ($www:parse_POST("delete"))
"Delete the file, then show the list of files."
if (`object:filedelete(name) ! E_PERM' == E_PERM)
$msg:mtell("www_error", "You do not have permission to delete this file.")
else
player:tell("", object, "!", $html_utils:literal_text(name), " has been deleted!
")
return $www.exam:tell_files(object)
endif
elseif ($www:parse_POST("copy") == "Copy file...")
"Request to move file with no target (probably no JavaScript)."
player:tell("Where do you want to copy this file to?
eg. #123 or !filename or #123!filename
")
player:tell("
")
return
elseif ($www:parse_POST("move") == "Move file...")
"Request to move file with no target (probably no JavaScript)."
player:tell("Where do you want to move this file to?
eg. #123 or !filename or #123!filename
")
player:tell("
")
return
elseif ($www:parse_POST("copy") || $www:parse_POST("move"))
mode = $www:parse_POST("copy") ? "copy" | "move"
player:tell("")
result = player.user:("_" + mode + ($www:parse_POST("force") ? "!" | "") + "_file")(object, name, $www:parse_POST(mode))
player:tell("")
if (result == E_NACC)
"Aready exists. Force?"
player:tell("
")
"Links to target would be nice, but that info isn't available."
elseif (result)
"Success"
{destobj, destname, desttype} = result
if (destobj == object && desttype == "file")
$www.exam:tell_files(object)
else
player:tell("
| ")
$www.exam:tell_files(object)
player:tell(" | ")
$www.exam:("tell_" + desttype + "s")(destobj)
player:tell(" |
")
endif
else
"Failure"
player:tell("", $su:capitalise(mode), " failed.")
$www.exam:tell_files(object)
endif
return
elseif (iobj)
"Save the file."
if ($www:parse_POST("create"))
$msg:mtell("www_error", "File already exists!")
elseif (this.sharing_violations && $www:parse_POST("hash") && this:hash(tostr(object, "!", name)) != $www:parse_POST("hash"))
$msg:mtell("www_error", "Sharing violation!")
player:tell("While you were in the editor, somebody/something changed this file. You have two choices: you can either lose your changes or you can lose the other person's changes.")
player:tell("