Switch to edit mode.
Name(s): edit_verb1: caller == this || raise(E_PERM)
2: player:isa($webber) || raise(E_PERM)
3: player:tell($eval.antistealth)
4: set_task_perms(player.user)
5: {get, object} = args
6: if (iobj && player.referer && $www:previous_object() != object && player.user != $no_one)
7: "We have an unknown form refering a command to us with a user's perms..."
8: $msg:mtell("www_error", "Warning! Previous page doesn't appear to be this one!")
9: player:tell("For security reasons the command will not be executed. Refering page: [", player.referer, "]")
10: iobj = {}
11: endif
12: suspend(0)
13: url = tostr("/", toint(object))
14: vnum = $code_utils:find_verb_named(object, get)
15: if (vnum == -1)
16: if ($www:parse_POST("create"))
17: "Verb doesn't exist, and we want to create it."
18: try
19: add_verb(object, {player.user.wizard ? $hacker | player.user, "roxd", get}, {"this", "none", "this"})
20: except (E_PERM)
21: player:tell("<B>Verb not created. This may be because you are over-quota.</B><BR>")
22: return
23: endtry
24: player:tell("<B>Verb created!</B><BR>")
25: vnum = length(verbs(object))
26: "Keep going, and show the edit page."
27: iobj = {}
28: else
29: "Verb doesn't exist, offer to create it."
30: player:tell("<B>", object:nn(), " doesn't define this verb.</B><BR>")
31: if (host = object:has_verb(get))
32: host = host[1]
33: player:tell("However, its ancestor <A HREF=\"/", toint(host), "\">", host.name, " (", host, ")</A> does. View/Edit <A HREF=\"/", toint(host), ":", get, "\">", host, ":", get, "</A><BR>")
34: endif
35: if ($perm_utils:controls(player.user, object) || (object.w && player.user != $no_one))
36: player:tell("<FORM METHOD='post' ACTION=\"", url, ":", get, "?edit\"><INPUT NAME='create' TYPE='hidden' VALUE='X'><INPUT TYPE='submit' VALUE='Create verb'></FORM><BR>")
37: endif
38: inherited = 0
39: for x in ({object, @object:ancestors()})
40: inherited = inherited + length(`verbs(x) ! E_PERM => {}')
41: endfor
42: return player:tell("See the list of <A HREF=\"", url, ":\">", `length(verbs(object)) ! E_PERM => "?"', " defined verbs</A> and <A HREF=\"", url, ";\">", inherited, " inherited verbs</A> on ", $su:nn(object), ".")
43: endif
44: endif
45: code = 0
46: v_args = 0
47: info = `verb_info(object, vnum) ! E_PERM'
48: if (info == E_PERM)
49: $msg:mtell("www_error", "You do not have permission to view this verb.")
50: return $www.exam:tell_verbs(object)
51: endif
52: hack = player.user.programmer && player.user != $no_one && (player.user:controls(info[1]) || index(info[2], "w"))
53: if ($www:parse_POST("delete") == "Delete verb")
54: "Unconfirmed request to delete verb (probably no JavaScript)."
55: player:tell("<B>Are you sure you want to delete this verb?</B><BR>")
56: player:tell("<FORM ACTION=\"", url, ":", get, "\" METHOD='post'><INPUT NAME='delete' TYPE='hidden' VALUE='Confirmed'><INPUT TYPE='submit' VALUE='Delete verb'></FORM><BR>")
57: return
58: elseif ($www:parse_POST("delete"))
59: "Delete the verb, then show the list of verbs."
60: if (`delete_verb(object, vnum) ! E_PERM' == E_PERM)
61: $msg:mtell("www_error", "You do not have permission to delete this verb.")
62: return $www.exam:tell_verbs(object)
63: else
64: player:tell("<B>", object, ":", $html_utils:literal_text(get), " has been deleted!</B><BR>")
65: return $www.exam:tell_verbs(object)
66: endif
67: elseif (iobj)
68: "Recompile the verb."
69: if ($www:parse_POST("create"))
70: $msg:mtell("www_error", "Verb already exists!")
71: elseif (this.sharing_violations && $www:parse_POST("hash") && this:hash(tostr(object, ":", get)) != $www:parse_POST("hash"))
72: $msg:mtell("www_error", "Sharing violation!")
73: player:tell("While you were in the editor, somebody/something changed this verb. You have two choices: you can either lose your changes or you can lose the other person's changes.<P>")
74: player:tell("<FORM ACTION=\"", url, ":", $su:subst(get, $www.desubst_single), "?edit\" METHOD=\"post\">")
75: player:tell($html_utils:input_hidden("hash", ""))
76: for x in (iobj)
77: if (x[1] != "hash")
78: player:tell($html_utils:input_hidden(@x))
79: endif
80: endfor
81: player:tell("It might be wise to see what <A HREF=\"", url, ":", $su:subst(get, $www.desubst_single), "\">the verb looks like now</A> and determine if you want to redo your changes on the new version, or come back here and <INPUT TYPE=\"submit\" VALUE=\"overwrite\"> the new version with your changes.</FORM>")
82: player:tell("<P>How did this happen?<UL><LI>Somebody else may be editing this verb at the same time as you.<LI>You may have two browsers open, both editing the same verb.<LI>You may have used the back button to return to an old editor.<LI>This verb might be self-modifying.</UL>")
83: return
84: elseif (!$set_utils:includes($list_utils:slice(iobj), {"hash", "verbnames", "code", "arg1", "arg2", "arg3"}))
85: $msg:mtell("www_error", "Invalid form elements.")
86: player:tell("Verb was not compiled due to an error in the web interface. Tell a wizard.<BR>")
87: else
88: name = $www:parse_POST("verbnames")
89: code = $www:parse_POST("code")
90: typeof(code) == $STR && (code = $string_utils:explode(code, "%0a"))
91: code = {@code}
92: v_args = {$www:parse_POST("arg1"), $www:parse_POST("arg2"), $www:parse_POST("arg3")}
93: mods = ($www:parse_POST("r") ? "r" | "") + ($www:parse_POST("w") ? "w" | "") + ($www:parse_POST("o") ? "o" | "") + ($www:parse_POST("x") ? "x" | "") + ($www:parse_POST("d") ? "d" | "")
94: if (player.user.wizard && $www:parse_POST("owner") && $www:parse_POST("owner") != $su:nn(info[1]))
95: owner = $su:match_nn_object($www:parse_POST("owner"), #-1, player.user)
96: valid(owner) || (owner = $su:match_player($www:parse_POST("owner"), player.user))
97: else
98: owner = info[1]
99: endif
100: old_info = info
101: info = {owner, mods, name}
102: result = `set_verb_info(object, vnum, info) ! E_PERM, E_INVARG'
103: if (result == E_PERM)
104: $msg:mtell("www_error", "You do not have permission to modify this verb.")
105: elseif (result == E_INVARG)
106: if (valid(owner))
107: $msg:mtell("www_error", "Error, verb not compiled.")
108: player:tell("The name of the verb is probably invalid.<BR>")
109: else
110: $msg:mtell("www_error", "Couldn't match new owner (" + $www:parse_POST("owner") + ").")
111: owner = $www:parse_POST("owner")
112: player:tell("Verb not changed.")
113: endif
114: else
115: "No problem setting the verb_info; try setting the code."
116: if (result = set_verb_code(object, vnum, code))
117: "Error in compile, reset the verb_info"
118: $msg:mtell("www_error", "Error during compile!")
119: player:tell("<PRE>")
120: player:tell(result)
121: line = toint(result[1][5..index(result[1], ":") - 1])
122: player:tell()
123: if (line > length(code))
124: player:tell("<I>Check for missing endif/endfor/endwhile/endtry/endtry statements.</I>")
125: else
126: for x in [max(1, line - 2)..min(line + 2, length(code))]
127: if (line == x)
128: player:tell("<I>", $html_utils:literal_text(code[x]), "</I>")
129: else
130: player:tell($html_utils:literal_text(code[x]))
131: endif
132: endfor
133: endif
134: player:tell("</PRE><HR>")
135: set_verb_info(object, vnum, old_info)
136: else
137: set_verb_args(object, vnum, v_args)
138: if (info[1] != owner)
139: player:tell("<B>Chowned verb from ", $su:nn(info[1]), " to ", $su:nn(owner), "!</B><BR>")
140: hack = player.user:controls(owner) || index(info[2], "w")
141: endif
142: if (info[3] != name)
143: player:tell("<B>Verb renamed from \"", info[3], "\" to \"", name, "\"!</B><P>")
144: endif
145: if (bad = $code_utils:bad_ref(object, vnum))
146: $msg:mtell("www_warning", "Warning: Invalid $reference detected: " + $su:english_list(bad))
147: endif
148: if (bad = $code_utils:bad_obj(object, vnum))
149: $msg:mtell("www_warning", "Warning: Invalid object number detected: " + $su:english_list(bad))
150: endif
151: if (bad = $code_utils:bad_var(object, vnum))
152: $msg:mtell("www_warning", "Warning: Undefined variables may be present: " + $su:english_list(bad))
153: endif
154: if (bad = $code_utils:bad_var_unused(object, vnum))
155: $msg:mtell("www_warning", "Warning: Unused variables may be present: " + $su:english_list(bad))
156: endif
157: if (length(code) >= 10 && !$help_utils:verb_documentation(object, vnum))
158: $msg:mtell("www_warning", "Warning: This verb has no documentation comments.")
159: endif
160: player:tell("<B>Compile successful!</B><P>")
161: code = verb_code(object, vnum)
162: endif
163: endif
164: info = {owner, mods, name}
165: endif
166: "Keep going, and show the edit page."
167: endif
168: current_info = `verb_info(object, vnum) ! E_PERM'
169: "Redirect to the full URL if we aren't there already."
170: webname = $su:subst(current_info[3], $www.desubst_single)
171: if ($su:subst(get, $www.desubst_single) != webname)
172: webname = webname + dobjstr
173: player:tell({"<SCRIPT LANGUAGE='JavaScript'>", "<!--", " // " + get + " is not the full name. Redirect.", tostr(" location = \"", $www.url, toint(object), index(player.user_agent, "Mozilla") && !index(player.user_agent, "MSIE") ? ":" | "%3A", webname, "\";"), "//-->", "</SCRIPT>"})
174: player:tell("Redirecting to <A HREF=\"", $www.url, toint(object), index(player.user_agent, "Mozilla") && !index(player.user_agent, "MSIE") ? ":" | "%3A", webname, "\">full name</A>...<P>")
175: return
176: endif
177: "----------------------------------------------------------------------"
178: "Show the edit form."
179: suspend(0)
180: code == 0 && (code = verb_code(object, vnum))
181: typeof(info[1]) == $OBJ && (info[1] = $su:nn(info[1]))
182: if ($www:parse_GET("isindex") == "edit" || ($www:parse_GET("isindex") != "view" && this:view_or_edit(object, vnum) == 1))
183: code = $html_utils:literal_text(code)
184: if (code && index(code[$], "Last modified by"))
185: lmb = strsub(code[$], """, "\"")[2..$ - 2]
186: code = listdelete(code, length(code))
187: else
188: lmb = ""
189: endif
190: player:tell("<P><I>Switch to <A HREF=\"/", toint(object), index(player.user_agent, "Mozilla") && !index(player.user_agent, "MSIE") ? ":" | "%3A", webname, "?view\">view mode</A>.</I></P>")
191: player:tell("<FORM ACTION=\"/", toint(object), index(player.user_agent, "Mozilla") && !index(player.user_agent, "MSIE") ? ":" | "%3A", webname, "?edit\" METHOD=post>")
192: player:tell("<INPUT NAME=hash TYPE=hidden VALUE=\"", this:hash(tostr(object, ":", current_info[3])), "\">")
193: player:tell("Verb name(s): <INPUT NAME=verbnames VALUE=\"", $html_utils:literal_text(info[3]), "\" SIZE=", max(20, length(info[3]) + 5), "><BR>")
194: code || (code = {""})
195: code[1] = tostr("<TEXTAREA NAME=code ROWS='", max(length(code), value_bytes(code) / abs(player.user:linelength())) + 5, "' COLS='", abs(player.user:linelength()) - 1, "' WRAP='virtual' STYLE='width: 100%'>", code[1])
196: code = {@code, "</TEXTAREA>"}
197: player:tell(code)
198: v_args == 0 && (v_args = verb_args(object, vnum))
199: lmb && player:tell("<BR><I>", lmb, "</I>")
200: player:tell("<BR>Verb arguments: ")
201: player:tell(@$html_utils:input_select("arg1", {"this", "none", "any"}, v_args[1]))
202: player:tell(@$html_utils:input_select("arg2", {"none", "any", @$code_utils.prepositions}, v_args[2]))
203: player:tell(@$html_utils:input_select("arg3", {"this", "none", "any"}, v_args[3]))
204: player:tell("<BR><INPUT NAME=r TYPE=checkbox", index(info[2], "r") ? " CHECKED>" | ">", " <B>R</B>eadable")
205: index(info[2], "w") && player:tell("<INPUT NAME=w TYPE=checkbox CHECKED> <B>W</B>riteable")
206: player:tell("<INPUT NAME=o TYPE=checkbox", index(info[2], "o") ? " CHECKED>" | ">", " <B>O</B>verridable")
207: player:tell("<INPUT NAME=x TYPE=checkbox", index(info[2], "x") ? " CHECKED>" | ">", " e<B>X</B>ecutable")
208: player:tell(index(info[2], "d") ? "<INPUT NAME=d TYPE=hidden VALUE=on>" | "<INPUT NAME=d TYPE=checkbox><B>D</B>ebug")
209: if (player.user.wizard)
210: player:tell("<BR>Verb owned by: <INPUT NAME=owner VALUE=\"", info[1], "\"><BR>")
211: else
212: player:tell("<BR>Verb owned by: <TT>", info[1], "</TT>")
213: endif
214: if (hack)
215: player:tell("<P><INPUT TYPE=submit VALUE='Save verb'> <INPUT TYPE=reset>")
216: else
217: player:tell("<P><IMG SRC='", $www.fileURL, "/2/8/stop.gif' ALIGN='left' HEIGHT=32 WIDTH=32 ALT='[Stop]'>You do not have permission to save changes to this verb.")
218: if (player.user == $no_one)
219: player:tell("This is because you are not logged in.")
220: elseif (!player.user:isa($prog))
221: player:tell("This is because you are not a programmer.")
222: elseif (!player.user.programmer)
223: player:tell("This may be because you are over-quota.")
224: endif
225: player:tell("If you have made changes you wish to keep, you can always copy and paste the code elsewhere.")
226: endif
227: player:tell("</FORM>")
228: player:tell("<SCRIPT LANGUAGE='JavaScript1.2' SRC='", $www.fileURL, "/8/4/expand.js'></SCRIPT>")
229: else
230: player:tell("<P><I>Switch to <A HREF=\"/", toint(object), index(player.user_agent, "Mozilla") && !index(player.user_agent, "MSIE") ? ":" | "%3A", webname, "?edit\">edit mode</A>.</I></P>")
231: player:tell("Name(s): <TT>", $html_utils:literal_text(info[3]), "</TT><BR>")
232: if (code)
233: "Add line numbers"
234: for x in [1..length(code)]
235: code[x] = tostr(x, ": ")[1..length(tostr(length(code))) + 2] + strsub(strsub(strsub(code[x], "&", "&"), "<", "<"), ">", ">")
236: "code[x] = tostr(x, \": \")[1..length(tostr(length(code))) + 2] + tostr(@$compile_utils:tokens2html($compile_utils:code2tokens(code[x])))"
237: $command_utils:suspend_if_needed()
238: endfor
239: code[1] = tostr("<PRE ID='code'>", code[1])
240: code[$] = code[$] + "</PRE>"
241: player:tell(code)
242: player:tell("<SCRIPT LANGUAGE='JavaScript1.2' SRC='", $www.fileURL, "/8/4/colourcode.js'></SCRIPT>")
243: player:tell("<SCRIPT LANGUAGE='JavaScript1.2'><!--")
244: player:tell("setTimeout(\"colourcode('code')\", 1);")
245: player:tell("--></SCRIPT>")
246: else
247: player:tell("<I>[Empty verb]</I>")
248: endif
249: v_args == 0 && (v_args = verb_args(object, vnum))
250: player:tell("<BR>Verb arguments: <TT>", $su:from_list(v_args, " "), "</TT>")
251: player:tell("<BR>Verb perms: <TT>", index(info[2], "r") ? "<B>R</B>eadable " | "", index(info[2], "w") ? "<B>W</B>riteable " | "", index(info[2], "o") ? "<B>O</B>verridable " | "", index(info[2], "x") ? "e<B>X</B>ecutable " | "", index(info[2], "d") ? "" | "NOT-<B>D</B>ebug", "</TT>")
252: player:tell("<BR>Verb owned by: <TT>", info[1], "</TT>")
253: endif
254: hack && player:tell("<HR><FORM ACTION=\"", url, ":", webname, "\" METHOD='post'><INPUT TYPE='submit' NAME='delete' VALUE='Delete verb' onClick=\"var ok=confirm('Are you sure you want to delete this verb?');if(ok)this.value='Confirmed';return ok;\"></FORM>")
255: "Last modified by whiz (#3135) on Wed Feb 27 23:34:28 2008 EST."