Added the deletion of old revisions of the wiki pages.

This commit is contained in:
Loic d'Anterroches 2008-11-23 12:33:11 +01:00
parent 048e2ba783
commit 7c1ad62cdb
5 changed files with 105 additions and 1 deletions

View File

@ -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.
*/

View File

@ -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,

View File

@ -0,0 +1,46 @@
{extends "idf/wiki/base.html"}
{block extraheader}{if $oldrev}<meta name="ROBOTS" content="NOINDEX" />{/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)}
<div class="old-rev">
<p>{blocktrans}You are looking at an old revision (<em>{$oldrev.summary}</em>) of the page
<a href="{$url}">{$page.title}</a>. This revision was created
by {$submitter}.{/blocktrans}</p>
</div>
<p>{blocktrans}If you delete this old revision, it will be removed from the database and <strong>you will not be able to recover it</strong>.{/blocktrans}</p>
<form method="post" action=".">
<table class="form" summary="">
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="{trans 'Delete Revision'}" name="submit" /> | <a href="{url 'IDF_Views_Wiki::view', array($project.shortname, $page.title)}">{trans 'Cancel'}</a>
</td>
</tr>
</table>
</form>
<p class="desc">{$page.summary}</p>
{markdown $oldrev.content, $request}
{/block}
{block context}
{assign $submitter = $page.get_submitter()}
<p><strong>{trans 'Created:'}</strong> <span class="nobrk">{$page.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>
{if $rev.creation_dtime != $page.creation_dtime}<p>{assign $submitter = $rev.get_submitter()}
<strong>{trans 'Updated:'}</strong> <span class="nobrk">{$rev.creation_dtime|dateago}</span><br /><span class="nobrk">{blocktrans}by {$submitter}{/blocktrans}</span></p>{/if}
{if $tags.count()}
<p>
<strong>{trans 'Labels:'}</strong><br />
{foreach $tags as $tag}
<span class="label"><strong>{$tag.class}:</strong>{$tag.name}</span><br />
{/foreach}
</p>{/if}
{if $revs.count() > 0}
<p><strong>{trans 'Old Revisions'}</strong></p>
<ul>{foreach $revs as $old}
<li><a href="{url 'IDF_Views_Wiki::view', array($project.shortname, $page.title), array('rev'=>$old.id)}">{$old.summary}</a></li>
{/foreach}</ul>
{/if}
{/block}

View File

@ -18,6 +18,9 @@ by {$submitter}.{/blocktrans}</p>
{markdown $rev.content, $request}
{else}
{markdown $oldrev.content, $request}
{if $isOwner or $isAdmin}{aurl 'url', 'IDF_Views_Wiki::deleteRev', array($project.shortname, $oldrev.id)}
<p class="delp"><a href="{$url}" title="{trans 'Delete this revision'}"><img src="{media '/idf/img/trash.png'}" style="vertical-align: text-bottom;" alt="{trans 'Trash'}" /></a> <a href="{$url}">{trans 'Delete this revision'}</a></p>
{/if}
{/if}
{/block}

View File

@ -598,3 +598,12 @@ div.old-rev {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.delp {
float: right;
position: relative;
}
.delp a {
color: #a00;
}