[cvs-annodex] commit (/annodex): cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi
cmmlwiki/trunk/cmmlwiki/handler.py
cmmlwiki/trunk/cmmlwiki/redirect.py
conrad
nobody at lists.annodex.net
Tue Jan 10 18:27:37 EST 2006
Update of /annodex (new revision 1771)
Modified files:
cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi
cmmlwiki/trunk/cmmlwiki/handler.py
cmmlwiki/trunk/cmmlwiki/redirect.py
Log Message:
add UI for renaming items:
- adds Special:RenameItem, accessible from the CMML Overview for any item
- checks for redirection loops, updates redirection chains to the most
recent target, and breaks loops
Modified: cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi
===================================================================
--- cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi 2006-01-10 06:06:57 UTC (rev 1770)
+++ cmmlwiki/trunk/cgi-bin/cmmlwiki.cgi 2006-01-10 07:27:37 UTC (rev 1771)
@@ -41,7 +41,7 @@
else:
handler.error ("Invalid procedure %s" % (proc))
-def handle_special (handler, command):
+def handle_special (handler, command, path_bits):
if (command == "ListAllItems"):
handler.list_all_items ()
elif (command == "ListOverview"):
@@ -52,6 +52,12 @@
handler.list_media ()
elif (command == "ListImages"):
handler.list_images ()
+ elif (command == "RenameItem"):
+ try:
+ iname = path_bits[1]
+ handler.rename_item (iname)
+ except:
+ handler.error ('Invalid request %s' % (command))
else:
handler.error ('Invalid request %s' % (command))
@@ -94,6 +100,8 @@
handler.update_field ('a_href')
elif (action == "delete_clip"):
handler.delete_clip ()
+ elif (action == "rename_item"):
+ handler.do_rename_item ()
else:
handler.error("Invalid action %s" % (action))
@@ -124,7 +132,7 @@
except KeyError:
action = "toc"
- if (not redirect (wikiname)):
+ if (not redirect (wikiname, ext)):
handler = Handler (wikiname, form)
wikibits = split (wikiname, ':')
@@ -132,7 +140,7 @@
if (wikibits[0] == 'API'):
handle_api (handler, wikibits[1], path_bits)
elif (wikibits[0] == 'Special'):
- handle_special (handler, wikibits[1])
+ handle_special (handler, wikibits[1], path_bits)
else:
handle_iname (handler, ext, action)
Modified: cmmlwiki/trunk/cmmlwiki/handler.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/handler.py 2006-01-10 06:06:57 UTC (rev 1770)
+++ cmmlwiki/trunk/cmmlwiki/handler.py 2006-01-10 07:27:37 UTC (rev 1771)
@@ -26,6 +26,7 @@
from cmmlwiki.environment import Environment
from cmmlwiki.html import html_head, html_foot, listpanel_head, listpanel_foot
from cmmlwiki.time import time2npt, parseTimestamp
+from cmmlwiki.redirect import redirect_add
from cmmlwiki.utils import content_type, content_type_html, location, http_404, xmlescape, edit_base, iname2edit, iname2view
class Handler (object):
@@ -269,6 +270,51 @@
html_foot ()
+ def rename_item (self, oldname):
+ content_type_html ()
+
+ html_head ("Rename Item")
+
+ print """
+<p>
+Using the form below will rename an item. The old name will become an
+HTTP redirect to the new name, for both editing and playback. Links
+to the old name will not be changed. Double redirects and redirect loops
+will be checked for and automatically removed; chains of redirection
+will be automatically updated to use the most recent target. This means
+that you can rename an item back to where it was just renamed from if you
+make a mistake.
+</p>
+<p>
+<b>WARNING!</b> This can be a drastic and unexpected change for a popular
+item; please be sure you understand the consequences of this before
+proceeding.
+</p>
+
+<form method="post" action="%s">
+ <input type="hidden" name="action" value="rename_item"/>
+<table>
+<tr><td>Rename item:</td><td><b>%s</b></td></tr>
+<tr><td>To new name:</td><td><input name="newname" value="%s"/>
+</td></tr>
+<tr><td> </td><td><input type="submit" value="Rename Item"/></td></tr>
+</table>
+</form>
+""" % (iname2edit(oldname), oldname, oldname)
+
+ html_foot()
+
+ def do_rename_item (self):
+ try:
+ newname = self.form['newname'].value
+ except KeyError:
+ # Fail
+ pass
+
+ redirect_add (self.iname, newname)
+
+ location (iname2edit (newname))
+
def edit(self):
content_type_html ()
@@ -303,9 +349,10 @@
actions = """
[<a href="%s">Play</a>]
+[<a href="%s/Special:RenameItem/%s">Rename</a>]
[<a href="%s?action=delete_item">Delete</a>]
[<a href="%s?action=edit">Insert clip</a>]
-""" % (iname2view(self.iname), iname2edit(self.iname), iname2edit(self.iname))
+""" % (iname2view(self.iname), edit_base, self.iname, iname2edit(self.iname), iname2edit(self.iname))
cmmlwiki.browse.item_summary (self.inspector, self.ixi, actions, editable=True)
#listpanel_head()
Modified: cmmlwiki/trunk/cmmlwiki/redirect.py
===================================================================
--- cmmlwiki/trunk/cmmlwiki/redirect.py 2006-01-10 06:06:57 UTC (rev 1770)
+++ cmmlwiki/trunk/cmmlwiki/redirect.py 2006-01-10 07:27:37 UTC (rev 1771)
@@ -13,11 +13,13 @@
# Author: Conrad Parker <conrad at annodex.net>
import os
+import sqlite
from cmmlwiki.database import inspect
+from cmmlwiki.environment import Environment
from cmmlwiki.utils import location
-def redirect (wikiname):
+def redirect (wikiname, ext):
def wiki_redirect (oldname, newname):
server_name = os.getenv ('SERVER_NAME')
server_port = os.getenv ('SERVER_PORT')
@@ -38,7 +40,7 @@
if (query_string != ''):
query_string = '?' + query_string
- new_location = method + server_name + server_port + script_name + '/' + newname + query_string
+ new_location = method + server_name + server_port + script_name + '/' + newname + ext + query_string
location(new_location)
# Begin
@@ -58,3 +60,30 @@
return True
except:
return False
+
+def redirect_add (oldname, newname):
+
+ env = Environment()
+ db = env.db_filename()
+ con = sqlite.connect(db, encoding='utf-8', autocommit=1)
+ cur = con.cursor()
+
+ sql = """INSERT INTO rename
+ VALUES ("%s","%s")""" % (oldname, newname)
+ cur.execute (sql)
+
+ # Update existing redirects to oldname to redirect to newname
+ sql = """UPDATE rename
+ SET newname="%s"
+ WHERE newname="%s" """ % (newname, oldname)
+ cur.execute (sql)
+
+ # Delete any idempotent renames (remove loops)
+ sql = """DELETE FROM rename
+ WHERE oldname=newname"""
+ cur.execute (sql)
+
+ sql = """UPDATE items
+ SET name="%s"
+ WHERE name="%s" """ % (newname, oldname)
+ cur.execute (sql)
--
conrad
More information about the cvs-annodex
mailing list