diff --git a/src/IDF/Form/WikiDelete.php b/src/IDF/Form/WikiDelete.php new file mode 100644 index 0000000..e40d14e --- /dev/null +++ b/src/IDF/Form/WikiDelete.php @@ -0,0 +1,64 @@ +page = $extra['page']; + $this->fields['confirm'] = new Pluf_Form_Field_Boolean( + array('required' => true, + 'label' => __('Yes, I understand that the page and all its revisions will be deleted.'), + 'initial' => '', + )); + } + + /** + * Check the confirmation. + */ + public function clean_confirm() + { + if (!$this->cleaned_data['confirm']) { + throw new Pluf_Form_Invalid(__('You need to confirm the deletion.')); + } + return $this->cleaned_data['confirm']; + } + + + function save($commit=true) + { + if (!$this->isValid()) { + throw new Exception(__('Cannot save the model from an invalid form.')); + } + $this->page->delete(); + return true; + } +} diff --git a/src/IDF/Views/Wiki.php b/src/IDF/Views/Wiki.php index c421ee1..3e3374b 100644 --- a/src/IDF/Views/Wiki.php +++ b/src/IDF/Views/Wiki.php @@ -346,6 +346,46 @@ class IDF_Views_Wiki $request); } + /** + * Delete a Wiki page. + */ + public $delete_precond = array('IDF_Precondition::accessDownloads', + 'IDF_Precondition::projectMemberOrOwner'); + public function delete($request, $match) + { + $prj = $request->project; + $page = Pluf_Shortcuts_GetObjectOr404('IDF_WikiPage', $match[2]); + $prj->inOr404($page); + $params = array('page' => $page); + if ($request->method == 'POST') { + $form = new IDF_Form_WikiDelete($request->POST, $params); + if ($form->isValid()) { + $form->save(); + $request->user->setMessage(__('The documentation page has been deleted.')); + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::index', + array($prj->shortname)); + return new Pluf_HTTP_Response_Redirect($url); + } + } else { + $form = new IDF_Form_WikiDelete(null, $params); + } + $title = sprintf(__('Delete Page %s'), $page->title); + $revision = $page->get_current_revision(); + $false = Pluf_DB_BooleanToDb(false, $page->getDbConnection()); + $revs = $page->get_revisions_list(array('order' => 'creation_dtime DESC', + 'filter' => 'is_head='.$false)); + return Pluf_Shortcuts_RenderToResponse('idf/wiki/deletepage.html', + array( + 'page_title' => $title, + 'page' => $page, + 'form' => $form, + 'rev' => $revision, + 'revs' => $revs, + 'tags' => $page->get_tags_list(), + ), + $request); + } + /** * Get the wiki tags. * diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 15b8935..495db53 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -224,6 +224,11 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/delrev/(\d+)/$#', 'model' => 'IDF_Views_Wiki', 'method' => 'deleteRev'); +$ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/delete/(\d+)/$#', + 'base' => $base, + 'model' => 'IDF_Views_Wiki', + 'method' => 'delete'); + $ctl[] = array('regex' => '#^/p/([\-\w]+)/page/(.*)/$#', 'base' => $base, 'model' => 'IDF_Views_Wiki', diff --git a/src/IDF/templates/idf/wiki/deletepage.html b/src/IDF/templates/idf/wiki/deletepage.html new file mode 100644 index 0000000..57c99e6 --- /dev/null +++ b/src/IDF/templates/idf/wiki/deletepage.html @@ -0,0 +1,42 @@ +{extends "idf/wiki/base.html"} +{block docclass}yui-t3{assign $inView=true}{/block} +{block body} + +
{blocktrans}If you delete this documentation page, it will be removed from the database with all the associated revisions and you will not be able to recover it.{/blocktrans}
+ + +{$page.summary}
+ +{markdown $rev.content, $request} + +{/block} +{block context} +{assign $submitter = $page.get_submitter()} +{trans 'Created:'} {$page.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}
{assign $submitter = $rev.get_submitter()}
+{trans 'Updated:'} {$rev.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}
+{trans 'Labels:'}
+{foreach $tags as $tag}
+{$tag.class}:{$tag.name}
+{/foreach}
+
{trans 'Old Revisions'}
+