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