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