summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/actions.php53
-rw-r--r--inc/lang/en/lang.php1
-rw-r--r--inc/template.php15
-rw-r--r--lib/tpl/default/main.php1
4 files changed, 68 insertions, 2 deletions
diff --git a/inc/actions.php b/inc/actions.php
index 27aa37515..d61781629 100644
--- a/inc/actions.php
+++ b/inc/actions.php
@@ -79,6 +79,15 @@ function act_dispatch(){
}
}
+ //revert
+ if($ACT == 'revert'){
+ if(checkSecurityToken()){
+ $ACT = act_revert($ACT);
+ }else{
+ $ACT = 'show';
+ }
+ }
+
//save
if($ACT == 'save'){
if(checkSecurityToken()){
@@ -185,7 +194,7 @@ function act_clean($act){
//disable all acl related commands if ACL is disabled
if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin',
- 'subscribe','unsubscribe','profile',
+ 'subscribe','unsubscribe','profile','revert',
'resendpwd','subscribens','unsubscribens',))){
msg('Command unavailable: '.htmlspecialchars($act),-1);
return 'show';
@@ -193,7 +202,7 @@ function act_clean($act){
if(!in_array($act,array('login','logout','register','save','cancel','edit','draft',
'preview','search','show','check','index','revisions',
- 'diff','recent','backlink','admin','subscribe',
+ 'diff','recent','backlink','admin','subscribe','revert',
'unsubscribe','profile','resendpwd','recover','wordblock',
'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) {
msg('Command unknown: '.htmlspecialchars($act),-1);
@@ -225,6 +234,9 @@ function act_permcheck($act){
}
}elseif(in_array($act,array('login','search','recent','profile'))){
$permneed = AUTH_NONE;
+ }elseif($act == 'revert'){
+ $permneed = AUTH_ADMIN;
+ if($INFO['ismanager']) $permneed = AUTH_EDIT;
}elseif($act == 'register'){
$permneed = AUTH_NONE;
}elseif($act == 'resendpwd'){
@@ -320,6 +332,43 @@ function act_save($act){
}
/**
+ * Revert to a certain revision
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function act_revert($act){
+ global $ID;
+ global $REV;
+ global $lang;
+
+ // when no revision is given, delete current one
+ // FIXME this feature is not exposed in the GUI currently
+ $text = '';
+ $sum = $lang['deleted'];
+ if($REV){
+ $text = rawWiki($ID,$REV);
+ if(!$text) return 'show'; //something went wrong
+ $sum = $lang['restored'];
+ }
+
+ // spam check
+ if(checkwordblock($Text))
+ return 'wordblock';
+
+ saveWikiText($ID,$text,$sum,false);
+ msg($sum,1);
+
+ //delete any draft
+ act_draftdel($act);
+ session_write_close();
+
+ // when done, show current page
+ $_SERVER['REQUEST_METHOD'] = 'post'; //should force a redirect
+ $REV = '';
+ return 'show';
+}
+
+/**
* Do a redirect after receiving post data
*
* Tries to add the section id as hash mark after section editing
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php
index 4b3251f89..04ec3170e 100644
--- a/inc/lang/en/lang.php
+++ b/inc/lang/en/lang.php
@@ -49,6 +49,7 @@ $lang['btn_resendpwd'] = 'Send new password';
$lang['btn_draft'] = 'Edit draft';
$lang['btn_recover'] = 'Recover draft';
$lang['btn_draftdel'] = 'Delete draft';
+$lang['btn_revert'] = 'Restore';
$lang['loggedinas'] = 'Logged in as';
$lang['user'] = 'Username';
diff --git a/inc/template.php b/inc/template.php
index ea35f4526..e1b253f96 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -528,6 +528,11 @@ function tpl_button($type,$return=false){
$out .= html_btn('admin',$ID,'',array('do' => 'admin'));
}
break;
+ case 'revert':
+ if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
+ $out .= html_btn('revert',$ID,'',array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken()));
+ }
+ break;
case 'subscribe':
case 'subscription':
if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
@@ -692,6 +697,13 @@ function tpl_actionlink($type,$pre='',$suf='',$inner='',$return=false){
'class="action admin" rel="nofollow"',1);
}
break;
+ case 'revert':
+ if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
+ $out .= tpl_link(wl($ID,array('do' => 'revert', 'rev' => $REV, 'sectok' => getSecurityToken())),
+ $pre.(($inner)?$inner:$lang['btn_revert']).$suf,
+ 'class="action revert" rel="nofollow"',1);
+ }
+ break;
case 'subscribe':
case 'subscription':
if($conf['useacl'] && $auth && $ACT == 'show' && $conf['subscribers'] == 1){
@@ -1279,6 +1291,9 @@ function tpl_actiondropdown($empty='',$button='&gt;'){
}
echo '<option value="revisions">'.$lang['btn_revs'].'</option>';
+ if($INFO['ismanager'] && $REV && $INFO['writable'] && actionOK('revert')){
+ echo '<option value="revert">'.$lang['btn_revert'].'</option>';
+ }
echo '<option value="backlink">'.$lang['btn_backlink'].'</option>';
echo '</optgroup>';
diff --git a/lib/tpl/default/main.php b/lib/tpl/default/main.php
index 35f6b2299..67c3a00ba 100644
--- a/lib/tpl/default/main.php
+++ b/lib/tpl/default/main.php
@@ -113,6 +113,7 @@ if (!defined('DOKU_INC')) die();
<div class="bar-left" id="bar__bottomleft">
<?php tpl_button('edit')?>
<?php tpl_button('history')?>
+ <?php tpl_button('revert')?>
</div>
<div class="bar-right" id="bar__bottomright">
<?php tpl_button('subscribe')?>