Merge pull request #4165 from dokuwiki/bot/autofix
[dokuwiki.git] / lib / plugins / revert / admin.php
blob4b9fe85849a940fd1a0f6e3738f3ff91b6546266
1 <?php
3 use dokuwiki\Extension\AdminPlugin;
4 use dokuwiki\ChangeLog\PageChangeLog;
6 /**
7 * All DokuWiki plugins to extend the admin function
8 * need to inherit from this class
9 */
10 class admin_plugin_revert extends AdminPlugin
12 protected $cmd;
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
18 /**
19 * Constructor
21 public function __construct()
23 $this->setupLocale();
26 /**
27 * access for managers
29 public function forAdminOnly()
31 return false;
34 /**
35 * return sort order for position in admin menu
37 public function getMenuSort()
39 return 40;
42 /**
43 * handle user request
45 public function handle()
49 /**
50 * output appropriate html
52 public function html()
54 global $INPUT;
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'));
67 /**
68 * Display the form for searching spam pages
70 protected function printSearchForm()
72 global $lang, $INPUT;
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 />';
81 /**
82 * Start the reversion process
84 protected function revertEdits($revert, $filter)
86 echo '<hr /><br />';
87 echo '<p>' . $this->getLang('revstart') . '</p>';
89 echo '<ul>';
90 foreach ($revert as $id) {
91 global $REV;
93 // find the last non-spammy revision
94 $data = '';
95 $pagelog = new PageChangeLog($id);
96 $old = $pagelog->getRevisions(0, $this->max_revs);
97 if ($old !== []) {
98 foreach ($old as $REV) {
99 $data = rawWiki($id, $REV);
100 if (strpos($data, (string) $filter) === false) break;
104 if ($data) {
105 saveWikiText($id, $data, 'old revision restored', false);
106 printf('<li><div class="li">' . $this->getLang('reverted') . '</div></li>', $id, $REV);
107 } else {
108 saveWikiText($id, '', '', false);
109 printf('<li><div class="li">' . $this->getLang('removed') . '</div></li>', $id);
111 @set_time_limit(10);
112 flush();
114 echo '</ul>';
116 echo '<p>' . $this->getLang('revstop') . '</p>';
120 * List recent edits matching the given filter
122 protected function listEdits($filter)
124 global $conf;
125 global $lang;
126 echo '<hr /><br />';
127 echo '<form action="" method="post"><div class="no">';
128 echo '<input type="hidden" name="filter" value="' . hsc($filter) . '" />';
129 formSecurityToken();
131 $recents = getRecents(0, $this->max_lines);
132 echo '<ul>';
134 $cnt = 0;
135 foreach ($recents as $recent) {
136 if ($filter) {
137 if (strpos(rawWiki($recent['id']), (string) $filter) === false) continue;
140 $cnt++;
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") . '">';
150 $p = [];
151 $p['src'] = DOKU_BASE . 'lib/images/diff.png';
152 $p['width'] = 15;
153 $p['height'] = 11;
154 $p['title'] = $lang['diff'];
155 $p['alt'] = $lang['diff'];
156 $att = buildAttributes($p);
157 echo "<img $att />";
158 echo '</a> ';
160 echo '<a href="' . wl($recent['id'], "do=revisions") . '">';
161 $p = [];
162 $p['src'] = DOKU_BASE . 'lib/images/history.png';
163 $p['width'] = 12;
164 $p['height'] = 14;
165 $p['title'] = $lang['btn_revs'];
166 $p['alt'] = $lang['btn_revs'];
167 $att = buildAttributes($p);
168 echo "<img $att />";
169 echo '</a> ';
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'];
176 echo '</span>';
178 echo '</div>';
179 echo '</li>';
181 @set_time_limit(10);
182 flush();
184 echo '</ul>';
186 echo '<p>';
187 echo '<button type="submit">' . $this->getLang('revert') . '</button> ';
188 printf($this->getLang('note2'), hsc($filter));
189 echo '</p>';
191 echo '</div></form>';
194 //Setup VIM: ex: et ts=4 :