[PATCH] Add delete action Add delete action on (with confirmation) similar to edit action and update documentation to match. Signed-off-by: Peter Korsgaard --- 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 @@ "\n", page_title ); - http_response_printf(res, PAGEHEADER, page_title, - (want_edit) ? " ( Edit ) " : "" ); + 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 \ + \ +" ( Edit | " \ +"Delete) " #define PAGEHEADER \ \ @@ -73,6 +78,14 @@ "
Preview:
\n" +#define DELETEFORM \ + \ +"
\n" \ +"Are you really sure you want to delete the page %s?\n" \ +"

\n" \ +"

" + + #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" \