1<?php 2if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); 3if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 4require_once(DOKU_PLUGIN.'admin.php'); 5require_once(DOKU_INC.'inc/changelog.php'); 6 7/** 8 * All DokuWiki plugins to extend the admin function 9 * need to inherit from this class 10 */ 11class admin_plugin_revert extends DokuWiki_Admin_Plugin { 12 var $cmd; 13 14 /** 15 * Constructor 16 */ 17 function admin_plugin_revert(){ 18 $this->setupLocale(); 19 } 20 21 /** 22 * return some info 23 */ 24 function getInfo(){ 25 return array( 26 'author' => 'Andreas Gohr', 27 'email' => 'andi@splitbrain.org', 28 'date' => '2005-11-10', 29 'name' => 'Revert Manager', 30 'desc' => 'Allows you to mass revert recent edits', 31 'url' => 'http://wiki.splitbrain.org/plugin:revert', 32 ); 33 } 34 35 /** 36 * return sort order for position in admin menu 37 */ 38 function getMenuSort() { 39 return 40; 40 } 41 42 /** 43 * handle user request 44 */ 45 function handle() { 46 } 47 48 /** 49 * output appropriate html 50 */ 51 function html() { 52 53 echo $this->plugin_locale_xhtml('intro'); 54 55 $this->_searchform(); 56 57 if(is_array($_REQUEST['revert'])){ 58 $this->_revert($_REQUEST['revert']); 59 }elseif(isset($_REQUEST['filter'])){ 60 $this->_list($_REQUEST['filter']); 61 } 62 } 63 64 /** 65 * Display the form for searching spam pages 66 */ 67 function _searchform(){ 68 global $lang; 69 echo '<form action="" method="post">'; 70 echo '<label>'.$this->getLang('filter').': </label>'; 71 echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />'; 72 echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />'; 73 echo ' <span>'.$this->getLang('note').'</span>'; 74 echo '</form><br /><br />'; 75 } 76 77 /** 78 * Start the reversion process 79 */ 80 function _revert($revert){ 81 global $conf; 82 83 echo '<hr /><br />'; 84 echo '<p>'.$this->getLang('revstart').'</p>'; 85 86 echo '<ul>'; 87 foreach($revert as $id){ 88 global $REV; 89 $old = getRevisions($id, 0, 1); 90 $REV = $old[0]; 91 if($REV){ 92 saveWikiText($id,rawWiki($id,$REV),'old revision restored',false); 93 printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV); 94 }else{ 95 saveWikiText($id,'','',false); 96 printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id,$REV); 97 } 98 @set_time_limit(10); 99 flush(); 100 } 101 echo '</ul>'; 102 103 echo '<p>'.$this->getLang('revstop').'</p>'; 104 } 105 106 /** 107 * List recent edits matching the given filter 108 */ 109 function _list($filter){ 110 global $conf; 111 echo '<hr /><br />'; 112 echo '<form action="" method="post">'; 113 echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />'; 114 115 $recents = getRecents(0,800); 116 echo '<ul>'; 117 118 119 $cnt = 0; 120 foreach($recents as $recent){ 121 if($filter){ 122 if(strpos(rawWiki($recent['id']),$filter) === false) continue; 123 } 124 125 $cnt++; 126 $date = date($conf['dformat'],$recent['date']); 127 128 echo ($recent['type']==='e') ? '<li class="minor">' : '<li>'; 129 echo '<div class="li">'; 130 echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />'; 131 echo '<label for="revert__'.$cnt.'">'.$date.'</label> '; 132 133 echo '<a href="'.wl($recent['id'],"do=diff").'">'; 134 $p = array(); 135 $p['src'] = DOKU_BASE.'lib/images/diff.png'; 136 $p['width'] = 15; 137 $p['height'] = 11; 138 $p['title'] = $lang['diff']; 139 $p['alt'] = $lang['diff']; 140 $att = buildAttributes($p); 141 echo "<img $att />"; 142 echo '</a> '; 143 144 echo '<a href="'.wl($recent['id'],"do=revisions").'">'; 145 $p = array(); 146 $p['src'] = DOKU_BASE.'lib/images/history.png'; 147 $p['width'] = 12; 148 $p['height'] = 14; 149 $p['title'] = $lang['btn_revs']; 150 $p['alt'] = $lang['btn_revs']; 151 $att = buildAttributes($p); 152 echo "<img $att />"; 153 echo '</a> '; 154 155 echo html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']); 156 echo ' – '.htmlspecialchars($recent['sum']); 157 158 echo ' <span class="user">'; 159 echo $recent['user'].' '.$recent['ip']; 160 echo '</span>'; 161 162 echo '</div>'; 163 echo '</li>'; 164 165 @set_time_limit(10); 166 flush(); 167 } 168 echo '</ul>'; 169 170 echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" />'; 171 172 echo '</form>'; 173 } 174 175} 176//Setup VIM: ex: et ts=4 enc=utf-8 : 177