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