3 use dokuwiki\Extension\AdminPlugin
;
4 use dokuwiki\ChangeLog\PageChangeLog
;
7 * All DokuWiki plugins to extend the admin function
8 * need to inherit from this class
10 class admin_plugin_revert
extends AdminPlugin
13 // some vars which might need tuning later
14 protected $max_lines = 800; // lines to read from changelog
15 protected $max_revs = 20; // numer of old revisions to check
21 public function __construct()
29 public function forAdminOnly()
35 * return sort order for position in admin menu
37 public function getMenuSort()
45 public function handle()
50 * output appropriate html
52 public function html()
56 echo $this->locale_xhtml('intro');
58 $this->printSearchForm();
60 if (is_array($INPUT->param('revert')) && checkSecurityToken()) {
61 $this->revertEdits($INPUT->arr('revert'), $INPUT->str('filter'));
62 } elseif ($INPUT->has('filter')) {
63 $this->listEdits($INPUT->str('filter'));
68 * Display the form for searching spam pages
70 protected function printSearchForm()
73 echo '<form action="" method="post"><div class="no">';
74 echo '<label>' . $this->getLang('filter') . ': </label>';
75 echo '<input type="text" name="filter" class="edit" value="' . hsc($INPUT->str('filter')) . '" /> ';
76 echo '<button type="submit">' . $lang['btn_search'] . '</button> ';
77 echo '<span>' . $this->getLang('note1') . '</span>';
78 echo '</div></form><br /><br />';
82 * Start the reversion process
84 protected function revertEdits($revert, $filter)
87 echo '<p>' . $this->getLang('revstart') . '</p>';
90 foreach ($revert as $id) {
93 // find the last non-spammy revision
95 $pagelog = new PageChangeLog($id);
96 $old = $pagelog->getRevisions(0, $this->max_revs
);
98 foreach ($old as $REV) {
99 $data = rawWiki($id, $REV);
100 if (strpos($data, (string) $filter) === false) break;
105 saveWikiText($id, $data, 'old revision restored', false);
106 printf('<li><div class="li">' . $this->getLang('reverted') . '</div></li>', $id, $REV);
108 saveWikiText($id, '', '', false);
109 printf('<li><div class="li">' . $this->getLang('removed') . '</div></li>', $id);
116 echo '<p>' . $this->getLang('revstop') . '</p>';
120 * List recent edits matching the given filter
122 protected function listEdits($filter)
127 echo '<form action="" method="post"><div class="no">';
128 echo '<input type="hidden" name="filter" value="' . hsc($filter) . '" />';
131 $recents = getRecents(0, $this->max_lines
);
135 foreach ($recents as $recent) {
137 if (strpos(rawWiki($recent['id']), (string) $filter) === false) continue;
141 $date = dformat($recent['date']);
143 echo ($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT
) ?
'<li class="minor">' : '<li>';
144 echo '<div class="li">';
145 echo '<input type="checkbox" name="revert[]" value="' . hsc($recent['id']) .
146 '" checked="checked" id="revert__' . $cnt . '" />';
147 echo ' <label for="revert__' . $cnt . '">' . $date . '</label> ';
149 echo '<a href="' . wl($recent['id'], "do=diff") . '">';
151 $p['src'] = DOKU_BASE
. 'lib/images/diff.png';
154 $p['title'] = $lang['diff'];
155 $p['alt'] = $lang['diff'];
156 $att = buildAttributes($p);
160 echo '<a href="' . wl($recent['id'], "do=revisions") . '">';
162 $p['src'] = DOKU_BASE
. 'lib/images/history.png';
165 $p['title'] = $lang['btn_revs'];
166 $p['alt'] = $lang['btn_revs'];
167 $att = buildAttributes($p);
171 echo html_wikilink(':' . $recent['id'], (useHeading('navigation')) ?
null : $recent['id']);
172 echo ' – ' . htmlspecialchars($recent['sum']);
174 echo ' <span class="user">';
175 echo $recent['user'] . ' ' . $recent['ip'];
187 echo '<button type="submit">' . $this->getLang('revert') . '</button> ';
188 printf($this->getLang('note2'), hsc($filter));
191 echo '</div></form>';
194 //Setup VIM: ex: et ts=4 :