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