diff --git a/src/IDF/Views/Wiki.php b/src/IDF/Views/Wiki.php index 4d0333e..7b87bb2 100644 --- a/src/IDF/Views/Wiki.php +++ b/src/IDF/Views/Wiki.php @@ -139,7 +139,7 @@ class IDF_Views_Wiki if (isset($request->GET['rev']) and preg_match('/^[0-9]+$/', $request->GET['rev'])) { $oldrev = Pluf_Shortcuts_GetObjectOr404('IDF_WikiRevision', $request->GET['rev']); - if ($oldrev->wikipage != $page->id) { + if ($oldrev->wikipage != $page->id or $oldrev->is_head == true) { throw new Pluf_HTTP_Error404($request); } } @@ -161,6 +161,46 @@ class IDF_Views_Wiki $request); } + /** + * Remove a revision of a page. + */ + public $deleteRev_precond = array('IDF_Precondition::accessWiki', + 'IDF_Precondition::projectMemberOrOwner'); + public function deleteRev($request, $match) + { + $prj = $request->project; + $oldrev = Pluf_Shortcuts_GetObjectOr404('IDF_WikiRevision', $match[2]); + $page = $oldrev->get_wikipage(); + $prj->inOr404($page); + if ($oldrev->is_head == true) { + throw new Pluf_HTTP_Error404($request); + } + if ($request->method == 'POST') { + $oldrev->delete(); + $request->user->setMessage(__('The old revision has been deleted.')); + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', + array($prj->shortname, $page->title)); + return new Pluf_HTTP_Response_Redirect($url); + } + + $title = sprintf(__('Delete Old Revision of %s'), $page->title); + $revision = $page->get_current_revision(); + $db = $page->getDbConnection(); + $false = Pluf_DB_BooleanToDb(false, $db); + $revs = $page->get_revisions_list(array('order' => 'creation_dtime DESC', + 'filter' => 'is_head='.$false)); + return Pluf_Shortcuts_RenderToResponse('idf/wiki/delete.html', + array( + 'page_title' => $title, + 'page' => $page, + 'oldrev' => $oldrev, + 'rev' => $revision, + 'revs' => $revs, + 'tags' => $page->get_tags_list(), + ), + $request); + } + /** * View a documentation page. */ diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index f59584d..bf91384 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -215,6 +215,12 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/update/(.*)/$#', 'model' => 'IDF_Views_Wiki', 'method' => 'update'); +$ctl[] = array('regex' => '#^/p/([\-\w]+)/doc/delrev/(\d+)/$#', + 'base' => $base, + 'priority' => 4, + 'model' => 'IDF_Views_Wiki', + 'method' => 'deleteRev'); + $ctl[] = array('regex' => '#^/p/([\-\w]+)/page/(.*)/$#', 'base' => $base, 'priority' => 4, diff --git a/src/IDF/templates/idf/wiki/delete.html b/src/IDF/templates/idf/wiki/delete.html new file mode 100644 index 0000000..813f088 --- /dev/null +++ b/src/IDF/templates/idf/wiki/delete.html @@ -0,0 +1,46 @@ +{extends "idf/wiki/base.html"} +{block extraheader}{if $oldrev}{/if}{/block} +{block docclass}yui-t3{assign $inView=true}{/block} +{block body} + +{assign $submitter = $oldrev.get_submitter()}{aurl 'url', 'IDF_Views_Wiki::view', array($project.shortname, $page.title)} +
{blocktrans}You are looking at an old revision ({$oldrev.summary}) of the page +{$page.title}. This revision was created +by {$submitter}.{/blocktrans}
+{blocktrans}If you delete this old revision, it will be removed from the database and you will not be able to recover it.{/blocktrans}
+ + +{$page.summary}
+ +{markdown $oldrev.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'}
+