[PATCH] Add delete action

Add delete action on (with confirmation) similar to edit action and update
documentation to match.

Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
---
 src/wiki.c     |   37 ++++++++++++++++++++++++++++++++++---
 src/wikitext.h |   14 ++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)

Index: didiwiki/src/wiki.c
===================================================================
--- didiwiki.orig/src/wiki.c
+++ didiwiki/src/wiki.c
@@ -619,6 +619,21 @@
 }
 
 void
+wiki_show_delete_confirm_page(HttpResponse *res, char *page)
+{
+  wiki_show_header(res, "Delete Page", FALSE);
+
+  http_response_printf(res, DELETEFORM, page, page);
+
+  wiki_show_footer(res);
+
+  http_response_send(res);
+
+  exit(0);
+
+}
+
+void
 wiki_show_create_page(HttpResponse *res)
 {
   wiki_show_header(res, "Create New Page", FALSE);
@@ -850,8 +865,8 @@
 		       "<body>\n", page_title
 		       );
 
-  http_response_printf(res, PAGEHEADER, page_title, 
-		       (want_edit) ? " ( <a href='?edit' title='Edit this wiki page contents. [alt-j]' accesskey='j'>Edit</a> ) " : "" );     
+  http_response_printf(res, PAGEHEADER, page_title,
+		       (want_edit) ? EDITHEADER : "" );
 }
 
 void
@@ -1059,7 +1074,23 @@
 		  wikitext = file_read(page);
 	  }
 
-	  if (!strcmp(command, "edit") || !strcmp(command, "create"))
+	  if (!strcmp(command, "delete"))
+	  {
+		  if (http_request_param_get(req, "confirm"))
+		  {
+			  unlink(page);
+			  wiki_redirect(res, "/");
+		  }
+		  else if (http_request_param_get(req, "cancel"))
+		  {
+			  wiki_redirect(res, page);
+		  }
+		  else
+		  {
+			  wiki_show_delete_confirm_page(res, page);
+		  }
+	  }
+	  else if (!strcmp(command, "edit") || !strcmp(command, "create"))
 	  {
 		  char *newtext = http_request_param_get(req, "wikitext");
 
Index: didiwiki/src/wikitext.h
===================================================================
--- didiwiki.orig/src/wikitext.h
+++ didiwiki/src/wikitext.h
@@ -17,6 +17,11 @@
 #ifndef _HAVE_WIKI_TEXT_HEADER
 #define _HAVE_WIKI_TEXT_HEADER
 
+#define EDITHEADER                                                       \
+                                                                         \
+" ( <a href='?edit' title='Edit this wiki page contents. [alt-j]'"       \
+" accesskey='j'>Edit</a> | "                                             \
+"<a href='?delete' title='Delete page. [alt-d]' accesskey='d'>Delete</a>) "
 
 #define PAGEHEADER                                                       \
                                                                          \
@@ -73,6 +78,14 @@
 "<div id=\"header\"><strong>Preview:</strong></div>\n"
 
 
+#define DELETEFORM                                                       \
+                                                                         \
+"<form method=POST action='%s?delete' name='deleteform'>\n"              \
+"Are you really sure you want to delete the page <strong>%s</strong>?\n" \
+"<p><input type='submit' name='confirm' Value='OK'>\n"                   \
+"<input type='submit' name='cancel' value='Cancel'></form>"
+
+
 #define HOMETEXT ""                                                      \
                                                                          \
 "==Welcome to !DidiWiki\n"                                               \
@@ -91,6 +104,7 @@
 "=Quick Guide \n"                                                    \
 "Top toolbar usage\n"                                                    \
 "* [?edit Edit] Allows you to edit pages ( see below for rules )\n"       \
+"* [?delete Delete] Allows you to delete pages\n"                        \
 "* [WikiHome Home] Takes you to the wiki front page\n"                \
 "* [Changes Changes] Lists the pages changed by date\n"                  \
 "* [Create New] Creates a new wiki page by title\n"                      \
