diff --git a/src/IDF/Form/WikiResourceDelete.php b/src/IDF/Form/WikiResourceDelete.php new file mode 100644 index 0000000..2eef1dd --- /dev/null +++ b/src/IDF/Form/WikiResourceDelete.php @@ -0,0 +1,64 @@ +resource = $extra['resource']; + $this->fields['confirm'] = new Pluf_Form_Field_Boolean( + array('required' => true, + 'label' => __('Yes, I understand that the resource 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->resource->delete(); + return true; + } +} diff --git a/src/IDF/Views/Wiki.php b/src/IDF/Views/Wiki.php index dc51c12..f7888c3 100644 --- a/src/IDF/Views/Wiki.php +++ b/src/IDF/Views/Wiki.php @@ -570,6 +570,45 @@ class IDF_Views_Wiki } /** + * Delete a Wiki resource. + */ + public $deleteResource_precond = array('IDF_Precondition::accessWiki', + 'IDF_Precondition::projectMemberOrOwner'); + public function deleteResource($request, $match) + { + $prj = $request->project; + $resource = Pluf_Shortcuts_GetObjectOr404('IDF_Wiki_Resource', $match[2]); + $prj->inOr404($resource); + $params = array('resource' => $resource); + if ($request->method == 'POST') { + $form = new IDF_Form_WikiResourceDelete($request->POST, $params); + if ($form->isValid()) { + $form->save(); + $request->user->setMessage(__('The documentation resource has been deleted.')); + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::listResources', + array($prj->shortname)); + return new Pluf_HTTP_Response_Redirect($url); + } + } else { + $form = new IDF_Form_WikiResourceDelete(null, $params); + } + $title = sprintf(__('Delete Resource %s'), $resource->title); + $revision = $resource->get_current_revision(); + $false = Pluf_DB_BooleanToDb(false, $resource->getDbConnection()); + $revs = $resource->get_revisions_list(array('order' => 'creation_dtime DESC', + 'filter' => 'is_head='.$false)); + return Pluf_Shortcuts_RenderToResponse('idf/wiki/deleteResource.html', + array( + 'page_title' => $title, + 'resource' => $resource, + 'form' => $form, + 'rev' => $revision, + 'revs' => $revs, + ), + $request); + } + + /** * Get the wiki tags. * * @param IDF_Project diff --git a/src/IDF/Wiki/ResourceRevision.php b/src/IDF/Wiki/ResourceRevision.php index cdf7bce..0ec8fc0 100644 --- a/src/IDF/Wiki/ResourceRevision.php +++ b/src/IDF/Wiki/ResourceRevision.php @@ -123,8 +123,7 @@ class IDF_Wiki_ResourceRevision extends Pluf_Model function preDelete() { - // if we kill off a head revision, ensure that we either mark a previous - // revision as head or kill off the resource record as well + // if we kill off a head revision, ensure that we either mark a previous revision as head if ($this->is_head) { $sql = new Pluf_SQL('wikiresource=%s and id!=%s', array($this->wikiresource, $this->id)); $revs = Pluf::factory('IDF_Wiki_ResourceRevision')->getList(array('filter'=>$sql->gen(), 'order'=>'id DESC')); @@ -132,8 +131,6 @@ class IDF_Wiki_ResourceRevision extends Pluf_Model $previous = $revs[0]; $previous->is_head = true; $previous->update(); - } else { - $this->get_wikiresource()->delete(); } } diff --git a/src/IDF/templates/idf/wiki/deleteResource.html b/src/IDF/templates/idf/wiki/deleteResource.html new file mode 100644 index 0000000..c229190 --- /dev/null +++ b/src/IDF/templates/idf/wiki/deleteResource.html @@ -0,0 +1,47 @@ +{extends "idf/wiki/base.html"} +{block docclass}yui-t3{assign $inResourceView=true}{/block} +{block body} + +
{blocktrans}If you delete this documentation resource, it will be removed from the database with all the associated revisions +and you will not be able to recover it. Any documentation pages that reference this resource, +will no longer be able to render it, but won't be deleted.{/blocktrans}
+ + +{$resource.summary}
+ +{assign $preview = $rev.renderRaw()} +{if $preview == ''} + {assign $preview = __('Unable to render preview for this MIME type.')} +{/if} +{$preview|unsafe}
+ +{trans 'Created:'} {$resource.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}
{assign $submitter = $rev.get_submitter()}
+{trans 'Updated:'} {$rev.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}
{trans 'Old Revisions'}
+