summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/revert
diff options
context:
space:
mode:
Diffstat (limited to 'platform/www/lib/plugins/revert')
-rw-r--r--platform/www/lib/plugins/revert/admin.php193
-rw-r--r--platform/www/lib/plugins/revert/admin.svg1
-rw-r--r--platform/www/lib/plugins/revert/lang/en/intro.txt3
-rw-r--r--platform/www/lib/plugins/revert/lang/en/lang.php23
-rw-r--r--platform/www/lib/plugins/revert/plugin.info.txt7
5 files changed, 227 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/revert/admin.php b/platform/www/lib/plugins/revert/admin.php
new file mode 100644
index 0000000..2d11dc0
--- /dev/null
+++ b/platform/www/lib/plugins/revert/admin.php
@@ -0,0 +1,193 @@
+<?php
+
+use dokuwiki\ChangeLog\PageChangeLog;
+
+/**
+ * All DokuWiki plugins to extend the admin function
+ * need to inherit from this class
+ */
+class admin_plugin_revert extends DokuWiki_Admin_Plugin
+{
+ protected $cmd;
+ // some vars which might need tuning later
+ protected $max_lines = 800; // lines to read from changelog
+ protected $max_revs = 20; // numer of old revisions to check
+
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->setupLocale();
+ }
+
+ /**
+ * access for managers
+ */
+ public function forAdminOnly()
+ {
+ return false;
+ }
+
+ /**
+ * return sort order for position in admin menu
+ */
+ public function getMenuSort()
+ {
+ return 40;
+ }
+
+ /**
+ * handle user request
+ */
+ public function handle()
+ {
+ }
+
+ /**
+ * output appropriate html
+ */
+ public function html()
+ {
+ global $INPUT;
+
+ echo $this->locale_xhtml('intro');
+
+ $this->printSearchForm();
+
+ if (is_array($INPUT->param('revert')) && checkSecurityToken()) {
+ $this->revertEdits($INPUT->arr('revert'), $INPUT->str('filter'));
+ } elseif ($INPUT->has('filter')) {
+ $this->listEdits($INPUT->str('filter'));
+ }
+ }
+
+ /**
+ * Display the form for searching spam pages
+ */
+ protected function printSearchForm()
+ {
+ 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
+ */
+ protected function revertEdits($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
+ */
+ protected function listEdits($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 :
diff --git a/platform/www/lib/plugins/revert/admin.svg b/platform/www/lib/plugins/revert/admin.svg
new file mode 100644
index 0000000..2129d2d
--- /dev/null
+++ b/platform/www/lib/plugins/revert/admin.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M13.5 7a6.5 6.5 0 0 1 6.5 6.5 6.5 6.5 0 0 1-6.5 6.5H10v-2h3.5c2.5 0 4.5-2 4.5-4.5S16 9 13.5 9H7.83l3.08 3.09L9.5 13.5 4 8l5.5-5.5 1.42 1.41L7.83 7h5.67M6 18h2v2H6v-2z"/></svg> \ No newline at end of file
diff --git a/platform/www/lib/plugins/revert/lang/en/intro.txt b/platform/www/lib/plugins/revert/lang/en/intro.txt
new file mode 100644
index 0000000..b8f3558
--- /dev/null
+++ b/platform/www/lib/plugins/revert/lang/en/intro.txt
@@ -0,0 +1,3 @@
+====== Revert Manager ======
+
+This page helps you with the automatic reversion of a spam attack. To find a list of spammy pages first enter a search string (eg. a spam URL), then confirm that the found pages are really spam and revert the edits.
diff --git a/platform/www/lib/plugins/revert/lang/en/lang.php b/platform/www/lib/plugins/revert/lang/en/lang.php
new file mode 100644
index 0000000..6bf867d
--- /dev/null
+++ b/platform/www/lib/plugins/revert/lang/en/lang.php
@@ -0,0 +1,23 @@
+<?php
+/**
+ * english language file
+ */
+
+// for admin plugins, the menu prompt to be displayed in the admin menu
+// if set here, the plugin doesn't need to override the getMenuText() method
+$lang['menu'] = 'Revert Manager';
+
+// custom language strings for the plugin
+
+$lang['filter'] = 'Search spammy pages';
+$lang['revert'] = 'Revert selected pages';
+$lang['reverted'] = '%s reverted to revision %s';
+$lang['removed'] = '%s removed';
+$lang['revstart'] = 'Reversion process started. This can take a long time. If the
+ script times out before finishing, you need to revert in smaller
+ chunks.';
+$lang['revstop'] = 'Reversion process finished successfully.';
+$lang['note1'] = 'Note: this search is case sensitive';
+$lang['note2'] = 'Note: the page will be reverted to the last version not containing the given spam term <i>%s</i>.';
+
+//Setup VIM: ex: et ts=4 :
diff --git a/platform/www/lib/plugins/revert/plugin.info.txt b/platform/www/lib/plugins/revert/plugin.info.txt
new file mode 100644
index 0000000..bba939d
--- /dev/null
+++ b/platform/www/lib/plugins/revert/plugin.info.txt
@@ -0,0 +1,7 @@
+base revert
+author Andreas Gohr
+email andi@splitbrain.org
+date 2015-07-15
+name Revert Manager
+desc Allows you to mass revert recent edits to remove Spam or vandalism
+url http://dokuwiki.org/plugin:revert