1168f9feeSAndreas Gohr<?php 2168f9feeSAndreas Gohr/** 3168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function 4168f9feeSAndreas Gohr * need to inherit from this class 5168f9feeSAndreas Gohr */ 6*2a7fef40SAndreas Gohrclass admin_plugin_revert extends DokuWiki_Admin_Plugin 7*2a7fef40SAndreas Gohr{ 83dc2d50cSAndreas Gohr protected $cmd; 990f99567SAndreas Gohr // some vars which might need tuning later 103dc2d50cSAndreas Gohr protected $max_lines = 800; // lines to read from changelog 113dc2d50cSAndreas Gohr protected $max_revs = 20; // numer of old revisions to check 1290f99567SAndreas Gohr 13168f9feeSAndreas Gohr 14168f9feeSAndreas Gohr /** 15168f9feeSAndreas Gohr * Constructor 16168f9feeSAndreas Gohr */ 17*2a7fef40SAndreas Gohr public function __construct() 18*2a7fef40SAndreas Gohr { 19168f9feeSAndreas Gohr $this->setupLocale(); 20168f9feeSAndreas Gohr } 21168f9feeSAndreas Gohr 22168f9feeSAndreas Gohr /** 23f8cc712eSAndreas Gohr * access for managers 24f8cc712eSAndreas Gohr */ 25*2a7fef40SAndreas Gohr public function forAdminOnly() 26*2a7fef40SAndreas Gohr { 27f8cc712eSAndreas Gohr return false; 28f8cc712eSAndreas Gohr } 29f8cc712eSAndreas Gohr 30f8cc712eSAndreas Gohr /** 31168f9feeSAndreas Gohr * return sort order for position in admin menu 32168f9feeSAndreas Gohr */ 33*2a7fef40SAndreas Gohr public function getMenuSort() 34*2a7fef40SAndreas Gohr { 35168f9feeSAndreas Gohr return 40; 36168f9feeSAndreas Gohr } 37168f9feeSAndreas Gohr 38168f9feeSAndreas Gohr /** 39168f9feeSAndreas Gohr * handle user request 40168f9feeSAndreas Gohr */ 41*2a7fef40SAndreas Gohr public function handle() 42*2a7fef40SAndreas Gohr { 43168f9feeSAndreas Gohr } 44168f9feeSAndreas Gohr 45168f9feeSAndreas Gohr /** 46168f9feeSAndreas Gohr * output appropriate html 47168f9feeSAndreas Gohr */ 48*2a7fef40SAndreas Gohr public function html() 49*2a7fef40SAndreas Gohr { 5000d58927SMichael Hamann global $INPUT; 51168f9feeSAndreas Gohr 5219ff1b0bSAnika Henke echo $this->locale_xhtml('intro'); 53168f9feeSAndreas Gohr 54*2a7fef40SAndreas Gohr $this->printSearchForm(); 55168f9feeSAndreas Gohr 5600d58927SMichael Hamann if (is_array($INPUT->param('revert')) && checkSecurityToken()) { 57*2a7fef40SAndreas Gohr $this->revertEdits($INPUT->arr('revert'), $INPUT->str('filter')); 5800d58927SMichael Hamann } elseif ($INPUT->has('filter')) { 59*2a7fef40SAndreas Gohr $this->listEdits($INPUT->str('filter')); 60168f9feeSAndreas Gohr } 61122b469fSAndreas Gohr } 62168f9feeSAndreas Gohr 63122b469fSAndreas Gohr /** 64122b469fSAndreas Gohr * Display the form for searching spam pages 65122b469fSAndreas Gohr */ 66*2a7fef40SAndreas Gohr protected function printSearchForm() 67*2a7fef40SAndreas Gohr { 6800d58927SMichael Hamann global $lang, $INPUT; 692404d0edSAnika Henke echo '<form action="" method="post"><div class="no">'; 70122b469fSAndreas Gohr echo '<label>'.$this->getLang('filter').': </label>'; 7100d58927SMichael Hamann echo '<input type="text" name="filter" class="edit" value="'.hsc($INPUT->str('filter')).'" /> '; 72ae614416SAnika Henke echo '<button type="submit">'.$lang['btn_search'].'</button> '; 7390f99567SAndreas Gohr echo '<span>'.$this->getLang('note1').'</span>'; 742404d0edSAnika Henke echo '</div></form><br /><br />'; 75122b469fSAndreas Gohr } 76122b469fSAndreas Gohr 77122b469fSAndreas Gohr /** 78122b469fSAndreas Gohr * Start the reversion process 79122b469fSAndreas Gohr */ 80*2a7fef40SAndreas Gohr protected function revertEdits($revert, $filter) 81*2a7fef40SAndreas Gohr { 82122b469fSAndreas Gohr echo '<hr /><br />'; 83122b469fSAndreas Gohr echo '<p>'.$this->getLang('revstart').'</p>'; 84122b469fSAndreas Gohr 85122b469fSAndreas Gohr echo '<ul>'; 86168f9feeSAndreas Gohr foreach ($revert as $id) { 87168f9feeSAndreas Gohr global $REV; 8890f99567SAndreas Gohr 8990f99567SAndreas Gohr // find the last non-spammy revision 9090f99567SAndreas Gohr $data = ''; 91047bad06SGerrit Uitslag $pagelog = new PageChangeLog($id); 92f523c971SGerrit Uitslag $old = $pagelog->getRevisions(0, $this->max_revs); 9390f99567SAndreas Gohr if (count($old)) { 9490f99567SAndreas Gohr foreach ($old as $REV) { 9590f99567SAndreas Gohr $data = rawWiki($id, $REV); 9690f99567SAndreas Gohr if (strpos($data, $filter) === false) break; 9790f99567SAndreas Gohr } 9890f99567SAndreas Gohr } 9990f99567SAndreas Gohr 10090f99567SAndreas Gohr if ($data) { 10190f99567SAndreas Gohr saveWikiText($id, $data, 'old revision restored', false); 102122b469fSAndreas Gohr printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>', $id, $REV); 103168f9feeSAndreas Gohr } else { 104168f9feeSAndreas Gohr saveWikiText($id, '', '', false); 10590f99567SAndreas Gohr printf('<li><div class="li">'.$this->getLang('removed').'</div></li>', $id); 106168f9feeSAndreas Gohr } 107168f9feeSAndreas Gohr @set_time_limit(10); 108168f9feeSAndreas Gohr flush(); 109168f9feeSAndreas Gohr } 110122b469fSAndreas Gohr echo '</ul>'; 111122b469fSAndreas Gohr 112122b469fSAndreas Gohr echo '<p>'.$this->getLang('revstop').'</p>'; 113168f9feeSAndreas Gohr } 114168f9feeSAndreas Gohr 115122b469fSAndreas Gohr /** 116122b469fSAndreas Gohr * List recent edits matching the given filter 117122b469fSAndreas Gohr */ 118*2a7fef40SAndreas Gohr protected function listEdits($filter) 119*2a7fef40SAndreas Gohr { 120168f9feeSAndreas Gohr global $conf; 121de3eb1d7SAdrian Lang global $lang; 122122b469fSAndreas Gohr echo '<hr /><br />'; 1232404d0edSAnika Henke echo '<form action="" method="post"><div class="no">'; 124122b469fSAndreas Gohr echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />'; 125634d7150SAndreas Gohr formSecurityToken(); 126168f9feeSAndreas Gohr 12790f99567SAndreas Gohr $recents = getRecents(0, $this->max_lines); 128122b469fSAndreas Gohr echo '<ul>'; 129168f9feeSAndreas Gohr 130122b469fSAndreas Gohr $cnt = 0; 131168f9feeSAndreas Gohr foreach ($recents as $recent) { 132168f9feeSAndreas Gohr if ($filter) { 133168f9feeSAndreas Gohr if (strpos(rawWiki($recent['id']), $filter) === false) continue; 134168f9feeSAndreas Gohr } 135168f9feeSAndreas Gohr 136122b469fSAndreas Gohr $cnt++; 137dc235f96SMatthias Schulte $date = dformat($recent['date']); 138168f9feeSAndreas Gohr 139ebf1501fSBen Coburn echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>'; 140122b469fSAndreas Gohr echo '<div class="li">'; 14164159a61SAndreas Gohr echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']). 14264159a61SAndreas Gohr '" checked="checked" id="revert__'.$cnt.'" />'; 143122b469fSAndreas Gohr echo ' <label for="revert__'.$cnt.'">'.$date.'</label> '; 144168f9feeSAndreas Gohr 145122b469fSAndreas Gohr echo '<a href="'.wl($recent['id'], "do=diff").'">'; 146168f9feeSAndreas Gohr $p = array(); 147168f9feeSAndreas Gohr $p['src'] = DOKU_BASE.'lib/images/diff.png'; 148168f9feeSAndreas Gohr $p['width'] = 15; 149168f9feeSAndreas Gohr $p['height'] = 11; 150168f9feeSAndreas Gohr $p['title'] = $lang['diff']; 151168f9feeSAndreas Gohr $p['alt'] = $lang['diff']; 152168f9feeSAndreas Gohr $att = buildAttributes($p); 153122b469fSAndreas Gohr echo "<img $att />"; 154122b469fSAndreas Gohr echo '</a> '; 155168f9feeSAndreas Gohr 156122b469fSAndreas Gohr echo '<a href="'.wl($recent['id'], "do=revisions").'">'; 157168f9feeSAndreas Gohr $p = array(); 158168f9feeSAndreas Gohr $p['src'] = DOKU_BASE.'lib/images/history.png'; 159168f9feeSAndreas Gohr $p['width'] = 12; 160168f9feeSAndreas Gohr $p['height'] = 14; 161168f9feeSAndreas Gohr $p['title'] = $lang['btn_revs']; 162168f9feeSAndreas Gohr $p['alt'] = $lang['btn_revs']; 163168f9feeSAndreas Gohr $att = buildAttributes($p); 164122b469fSAndreas Gohr echo "<img $att />"; 165122b469fSAndreas Gohr echo '</a> '; 166168f9feeSAndreas Gohr 1670ea51e63SMatt Perry echo html_wikilink(':'.$recent['id'], (useHeading('navigation'))?null:$recent['id']); 168e260f93bSAnika Henke echo ' – '.htmlspecialchars($recent['sum']); 169168f9feeSAndreas Gohr 170122b469fSAndreas Gohr echo ' <span class="user">'; 171122b469fSAndreas Gohr echo $recent['user'].' '.$recent['ip']; 172122b469fSAndreas Gohr echo '</span>'; 173168f9feeSAndreas Gohr 174122b469fSAndreas Gohr echo '</div>'; 175122b469fSAndreas Gohr echo '</li>'; 176168f9feeSAndreas Gohr 177168f9feeSAndreas Gohr @set_time_limit(10); 178168f9feeSAndreas Gohr flush(); 179168f9feeSAndreas Gohr } 180122b469fSAndreas Gohr echo '</ul>'; 181168f9feeSAndreas Gohr 18290f99567SAndreas Gohr echo '<p>'; 183ae614416SAnika Henke echo '<button type="submit">'.$this->getLang('revert').'</button> '; 18490f99567SAndreas Gohr printf($this->getLang('note2'), hsc($filter)); 18590f99567SAndreas Gohr echo '</p>'; 186122b469fSAndreas Gohr 1872404d0edSAnika Henke echo '</div></form>'; 188168f9feeSAndreas Gohr } 189168f9feeSAndreas Gohr} 190e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 191