1168f9feeSAndreas Gohr<?php 2*1687f569SGuy Brand// must be run within Dokuwiki 3*1687f569SGuy Brandif(!defined('DOKU_INC')) die(); 4*1687f569SGuy Brand 5168f9feeSAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 6168f9feeSAndreas Gohrrequire_once(DOKU_PLUGIN.'admin.php'); 7168f9feeSAndreas Gohrrequire_once(DOKU_INC.'inc/changelog.php'); 8168f9feeSAndreas Gohr 9168f9feeSAndreas Gohr/** 10168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function 11168f9feeSAndreas Gohr * need to inherit from this class 12168f9feeSAndreas Gohr */ 13168f9feeSAndreas Gohrclass admin_plugin_revert extends DokuWiki_Admin_Plugin { 14168f9feeSAndreas Gohr var $cmd; 1590f99567SAndreas Gohr // some vars which might need tuning later 1690f99567SAndreas Gohr var $max_lines = 800; // lines to read from changelog 1790f99567SAndreas Gohr var $max_revs = 20; // numer of old revisions to check 1890f99567SAndreas Gohr 19168f9feeSAndreas Gohr 20168f9feeSAndreas Gohr /** 21168f9feeSAndreas Gohr * Constructor 22168f9feeSAndreas Gohr */ 23168f9feeSAndreas Gohr function admin_plugin_revert(){ 24168f9feeSAndreas Gohr $this->setupLocale(); 25168f9feeSAndreas Gohr } 26168f9feeSAndreas Gohr 27168f9feeSAndreas Gohr /** 28168f9feeSAndreas Gohr * return some info 29168f9feeSAndreas Gohr */ 30168f9feeSAndreas Gohr function getInfo(){ 31168f9feeSAndreas Gohr return array( 32168f9feeSAndreas Gohr 'author' => 'Andreas Gohr', 33168f9feeSAndreas Gohr 'email' => 'andi@splitbrain.org', 3490f99567SAndreas Gohr 'date' => '2007-04-22', 35168f9feeSAndreas Gohr 'name' => 'Revert Manager', 36168f9feeSAndreas Gohr 'desc' => 'Allows you to mass revert recent edits', 37168f9feeSAndreas Gohr 'url' => 'http://wiki.splitbrain.org/plugin:revert', 38168f9feeSAndreas Gohr ); 39168f9feeSAndreas Gohr } 40168f9feeSAndreas Gohr 41168f9feeSAndreas Gohr /** 42f8cc712eSAndreas Gohr * access for managers 43f8cc712eSAndreas Gohr */ 44f8cc712eSAndreas Gohr function forAdminOnly(){ 45f8cc712eSAndreas Gohr return false; 46f8cc712eSAndreas Gohr } 47f8cc712eSAndreas Gohr 48f8cc712eSAndreas Gohr /** 49168f9feeSAndreas Gohr * return sort order for position in admin menu 50168f9feeSAndreas Gohr */ 51168f9feeSAndreas Gohr function getMenuSort() { 52168f9feeSAndreas Gohr return 40; 53168f9feeSAndreas Gohr } 54168f9feeSAndreas Gohr 55168f9feeSAndreas Gohr /** 56168f9feeSAndreas Gohr * handle user request 57168f9feeSAndreas Gohr */ 58168f9feeSAndreas Gohr function handle() { 59168f9feeSAndreas Gohr } 60168f9feeSAndreas Gohr 61168f9feeSAndreas Gohr /** 62168f9feeSAndreas Gohr * output appropriate html 63168f9feeSAndreas Gohr */ 64168f9feeSAndreas Gohr function html() { 65168f9feeSAndreas Gohr 66122b469fSAndreas Gohr echo $this->plugin_locale_xhtml('intro'); 67168f9feeSAndreas Gohr 68122b469fSAndreas Gohr $this->_searchform(); 69168f9feeSAndreas Gohr 70122b469fSAndreas Gohr if(is_array($_REQUEST['revert'])){ 7190f99567SAndreas Gohr $this->_revert($_REQUEST['revert'],$_REQUEST['filter']); 72122b469fSAndreas Gohr }elseif(isset($_REQUEST['filter'])){ 73168f9feeSAndreas Gohr $this->_list($_REQUEST['filter']); 74168f9feeSAndreas Gohr } 75122b469fSAndreas Gohr } 76168f9feeSAndreas Gohr 77122b469fSAndreas Gohr /** 78122b469fSAndreas Gohr * Display the form for searching spam pages 79122b469fSAndreas Gohr */ 80122b469fSAndreas Gohr function _searchform(){ 81122b469fSAndreas Gohr global $lang; 82122b469fSAndreas Gohr echo '<form action="" method="post">'; 83122b469fSAndreas Gohr echo '<label>'.$this->getLang('filter').': </label>'; 84122b469fSAndreas Gohr echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />'; 85122b469fSAndreas Gohr echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />'; 8690f99567SAndreas Gohr echo ' <span>'.$this->getLang('note1').'</span>'; 87122b469fSAndreas Gohr echo '</form><br /><br />'; 88122b469fSAndreas Gohr } 89122b469fSAndreas Gohr 90122b469fSAndreas Gohr /** 91122b469fSAndreas Gohr * Start the reversion process 92122b469fSAndreas Gohr */ 9390f99567SAndreas Gohr function _revert($revert,$filter){ 94168f9feeSAndreas Gohr global $conf; 95122b469fSAndreas Gohr 96122b469fSAndreas Gohr echo '<hr /><br />'; 97122b469fSAndreas Gohr echo '<p>'.$this->getLang('revstart').'</p>'; 98122b469fSAndreas Gohr 99122b469fSAndreas Gohr echo '<ul>'; 100168f9feeSAndreas Gohr foreach($revert as $id){ 101168f9feeSAndreas Gohr global $REV; 10290f99567SAndreas Gohr 10390f99567SAndreas Gohr // find the last non-spammy revision 10490f99567SAndreas Gohr $data = ''; 10590f99567SAndreas Gohr $old = getRevisions($id, 0, $this->max_revs); 10690f99567SAndreas Gohr if(count($old)){ 10790f99567SAndreas Gohr foreach($old as $REV){ 10890f99567SAndreas Gohr $data = rawWiki($id,$REV); 10990f99567SAndreas Gohr if(strpos($data,$filter) === false) break; 11090f99567SAndreas Gohr } 11190f99567SAndreas Gohr } 11290f99567SAndreas Gohr 11390f99567SAndreas Gohr if($data){ 11490f99567SAndreas Gohr saveWikiText($id,$data,'old revision restored',false); 115122b469fSAndreas Gohr printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV); 116168f9feeSAndreas Gohr }else{ 117168f9feeSAndreas Gohr saveWikiText($id,'','',false); 11890f99567SAndreas Gohr printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id); 119168f9feeSAndreas Gohr } 120168f9feeSAndreas Gohr @set_time_limit(10); 121168f9feeSAndreas Gohr flush(); 122168f9feeSAndreas Gohr } 123122b469fSAndreas Gohr echo '</ul>'; 124122b469fSAndreas Gohr 125122b469fSAndreas Gohr echo '<p>'.$this->getLang('revstop').'</p>'; 126168f9feeSAndreas Gohr } 127168f9feeSAndreas Gohr 128122b469fSAndreas Gohr /** 129122b469fSAndreas Gohr * List recent edits matching the given filter 130122b469fSAndreas Gohr */ 131168f9feeSAndreas Gohr function _list($filter){ 132168f9feeSAndreas Gohr global $conf; 133122b469fSAndreas Gohr echo '<hr /><br />'; 134122b469fSAndreas Gohr echo '<form action="" method="post">'; 135122b469fSAndreas Gohr echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />'; 136168f9feeSAndreas Gohr 13790f99567SAndreas Gohr $recents = getRecents(0,$this->max_lines); 138122b469fSAndreas Gohr echo '<ul>'; 139168f9feeSAndreas Gohr 140122b469fSAndreas Gohr 141122b469fSAndreas Gohr $cnt = 0; 142168f9feeSAndreas Gohr foreach($recents as $recent){ 143168f9feeSAndreas Gohr if($filter){ 144168f9feeSAndreas Gohr if(strpos(rawWiki($recent['id']),$filter) === false) continue; 145168f9feeSAndreas Gohr } 146168f9feeSAndreas Gohr 147122b469fSAndreas Gohr $cnt++; 148168f9feeSAndreas Gohr $date = date($conf['dformat'],$recent['date']); 149168f9feeSAndreas Gohr 150ebf1501fSBen Coburn echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>'; 151122b469fSAndreas Gohr echo '<div class="li">'; 152122b469fSAndreas Gohr echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />'; 153122b469fSAndreas Gohr echo '<label for="revert__'.$cnt.'">'.$date.'</label> '; 154168f9feeSAndreas Gohr 155122b469fSAndreas Gohr echo '<a href="'.wl($recent['id'],"do=diff").'">'; 156168f9feeSAndreas Gohr $p = array(); 157168f9feeSAndreas Gohr $p['src'] = DOKU_BASE.'lib/images/diff.png'; 158168f9feeSAndreas Gohr $p['width'] = 15; 159168f9feeSAndreas Gohr $p['height'] = 11; 160168f9feeSAndreas Gohr $p['title'] = $lang['diff']; 161168f9feeSAndreas Gohr $p['alt'] = $lang['diff']; 162168f9feeSAndreas Gohr $att = buildAttributes($p); 163122b469fSAndreas Gohr echo "<img $att />"; 164122b469fSAndreas Gohr echo '</a> '; 165168f9feeSAndreas Gohr 166122b469fSAndreas Gohr echo '<a href="'.wl($recent['id'],"do=revisions").'">'; 167168f9feeSAndreas Gohr $p = array(); 168168f9feeSAndreas Gohr $p['src'] = DOKU_BASE.'lib/images/history.png'; 169168f9feeSAndreas Gohr $p['width'] = 12; 170168f9feeSAndreas Gohr $p['height'] = 14; 171168f9feeSAndreas Gohr $p['title'] = $lang['btn_revs']; 172168f9feeSAndreas Gohr $p['alt'] = $lang['btn_revs']; 173168f9feeSAndreas Gohr $att = buildAttributes($p); 174122b469fSAndreas Gohr echo "<img $att />"; 175122b469fSAndreas Gohr echo '</a> '; 176168f9feeSAndreas Gohr 177122b469fSAndreas Gohr echo html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']); 178122b469fSAndreas Gohr echo ' – '.htmlspecialchars($recent['sum']); 179168f9feeSAndreas Gohr 180122b469fSAndreas Gohr echo ' <span class="user">'; 181122b469fSAndreas Gohr echo $recent['user'].' '.$recent['ip']; 182122b469fSAndreas Gohr echo '</span>'; 183168f9feeSAndreas Gohr 184122b469fSAndreas Gohr echo '</div>'; 185122b469fSAndreas Gohr echo '</li>'; 186168f9feeSAndreas Gohr 187168f9feeSAndreas Gohr @set_time_limit(10); 188168f9feeSAndreas Gohr flush(); 189168f9feeSAndreas Gohr } 190122b469fSAndreas Gohr echo '</ul>'; 191168f9feeSAndreas Gohr 19290f99567SAndreas Gohr echo '<p>'; 193122b469fSAndreas Gohr echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" /> '; 19490f99567SAndreas Gohr printf($this->getLang('note2'),hsc($filter)); 19590f99567SAndreas Gohr echo '</p>'; 196122b469fSAndreas Gohr 197168f9feeSAndreas Gohr echo '</form>'; 198168f9feeSAndreas Gohr } 199168f9feeSAndreas Gohr 200168f9feeSAndreas Gohr} 201168f9feeSAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 : 202