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); } } @@ -162,6 +162,46 @@ class IDF_Views_Wiki } /** + * 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. */ public $update_precond = array('IDF_Precondition::accessWiki', 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}

+
+ + + + + +
  | {trans 'Cancel'} +
+
+ +

{$page.summary}

+ +{markdown $oldrev.content, $request} + +{/block} +{block context} +{assign $submitter = $page.get_submitter()} +

{trans 'Created:'} {$page.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}

+{if $rev.creation_dtime != $page.creation_dtime}

{assign $submitter = $rev.get_submitter()} +{trans 'Updated:'} {$rev.creation_dtime|dateago}
{blocktrans}by {$submitter}{/blocktrans}

{/if} +{if $tags.count()} +

+{trans 'Labels:'}
+{foreach $tags as $tag} +{$tag.class}:{$tag.name}
+{/foreach} +

{/if} +{if $revs.count() > 0} +

{trans 'Old Revisions'}

+ +{/if} +{/block} diff --git a/src/IDF/templates/idf/wiki/view.html b/src/IDF/templates/idf/wiki/view.html index 4d457eb..838eaa2 100644 --- a/src/IDF/templates/idf/wiki/view.html +++ b/src/IDF/templates/idf/wiki/view.html @@ -18,6 +18,9 @@ by {$submitter}.{/blocktrans}

{markdown $rev.content, $request} {else} {markdown $oldrev.content, $request} +{if $isOwner or $isAdmin}{aurl 'url', 'IDF_Views_Wiki::deleteRev', array($project.shortname, $oldrev.id)} +

{trans 'Trash'} {trans 'Delete this revision'}

+{/if} {/if} {/block} diff --git a/www/media/idf/css/style.css b/www/media/idf/css/style.css index 2335c09..444066e 100644 --- a/www/media/idf/css/style.css +++ b/www/media/idf/css/style.css @@ -598,3 +598,12 @@ div.old-rev { -moz-border-radius: 5px; -webkit-border-radius: 5px; } + +.delp { + float: right; + position: relative; +} + +.delp a { + color: #a00; +}