xref: /dokuwiki/lib/plugins/revert/admin.php (revision e44b94a4bd0679ff22e14add34b60590fe7077d3)
1168f9feeSAndreas Gohr<?php
20c3a5702SAndreas Gohr
38553d24dSAndreas Gohruse dokuwiki\Extension\AdminPlugin;
40c3a5702SAndreas Gohruse dokuwiki\ChangeLog\PageChangeLog;
50c3a5702SAndreas Gohr
6168f9feeSAndreas Gohr/**
7168f9feeSAndreas Gohr * All DokuWiki plugins to extend the admin function
8168f9feeSAndreas Gohr * need to inherit from this class
9168f9feeSAndreas Gohr */
108553d24dSAndreas Gohrclass admin_plugin_revert extends AdminPlugin
112a7fef40SAndreas Gohr{
123dc2d50cSAndreas Gohr    protected $cmd;
1390f99567SAndreas Gohr    // some vars which might need tuning later
143dc2d50cSAndreas Gohr    protected $max_lines = 800; // lines to read from changelog
153dc2d50cSAndreas Gohr    protected $max_revs  = 20;  // numer of old revisions to check
1690f99567SAndreas Gohr
17168f9feeSAndreas Gohr
18168f9feeSAndreas Gohr    /**
19168f9feeSAndreas Gohr     * Constructor
20168f9feeSAndreas Gohr     */
212a7fef40SAndreas Gohr    public function __construct()
222a7fef40SAndreas Gohr    {
23168f9feeSAndreas Gohr        $this->setupLocale();
24168f9feeSAndreas Gohr    }
25168f9feeSAndreas Gohr
26168f9feeSAndreas Gohr    /**
27f8cc712eSAndreas Gohr     * access for managers
28f8cc712eSAndreas Gohr     */
292a7fef40SAndreas Gohr    public function forAdminOnly()
302a7fef40SAndreas Gohr    {
31f8cc712eSAndreas Gohr        return false;
32f8cc712eSAndreas Gohr    }
33f8cc712eSAndreas Gohr
34f8cc712eSAndreas Gohr    /**
35168f9feeSAndreas Gohr     * return sort order for position in admin menu
36168f9feeSAndreas Gohr     */
372a7fef40SAndreas Gohr    public function getMenuSort()
382a7fef40SAndreas Gohr    {
39168f9feeSAndreas Gohr        return 40;
40168f9feeSAndreas Gohr    }
41168f9feeSAndreas Gohr
42168f9feeSAndreas Gohr    /**
43168f9feeSAndreas Gohr     * handle user request
44168f9feeSAndreas Gohr     */
452a7fef40SAndreas Gohr    public function handle()
462a7fef40SAndreas Gohr    {
47168f9feeSAndreas Gohr    }
48168f9feeSAndreas Gohr
49168f9feeSAndreas Gohr    /**
50168f9feeSAndreas Gohr     * output appropriate html
51168f9feeSAndreas Gohr     */
522a7fef40SAndreas Gohr    public function html()
532a7fef40SAndreas Gohr    {
5400d58927SMichael Hamann        global $INPUT;
55168f9feeSAndreas Gohr
5619ff1b0bSAnika Henke        echo $this->locale_xhtml('intro');
57168f9feeSAndreas Gohr
582a7fef40SAndreas Gohr        $this->printSearchForm();
59168f9feeSAndreas Gohr
6000d58927SMichael Hamann        if (is_array($INPUT->param('revert')) && checkSecurityToken()) {
612a7fef40SAndreas Gohr            $this->revertEdits($INPUT->arr('revert'), $INPUT->str('filter'));
6200d58927SMichael Hamann        } elseif ($INPUT->has('filter')) {
632a7fef40SAndreas Gohr            $this->listEdits($INPUT->str('filter'));
64168f9feeSAndreas Gohr        }
65122b469fSAndreas Gohr    }
66168f9feeSAndreas Gohr
67122b469fSAndreas Gohr    /**
68122b469fSAndreas Gohr     * Display the form for searching spam pages
69122b469fSAndreas Gohr     */
702a7fef40SAndreas Gohr    protected function printSearchForm()
712a7fef40SAndreas Gohr    {
7200d58927SMichael Hamann        global $lang, $INPUT;
732404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
74122b469fSAndreas Gohr        echo '<label>' . $this->getLang('filter') . ': </label>';
7500d58927SMichael Hamann        echo '<input type="text" name="filter" class="edit" value="' . hsc($INPUT->str('filter')) . '" /> ';
76ae614416SAnika Henke        echo '<button type="submit">' . $lang['btn_search'] . '</button> ';
7790f99567SAndreas Gohr        echo '<span>' . $this->getLang('note1') . '</span>';
782404d0edSAnika Henke        echo '</div></form><br /><br />';
79122b469fSAndreas Gohr    }
80122b469fSAndreas Gohr
81122b469fSAndreas Gohr    /**
82122b469fSAndreas Gohr     * Start the reversion process
83122b469fSAndreas Gohr     */
842a7fef40SAndreas Gohr    protected function revertEdits($revert, $filter)
852a7fef40SAndreas Gohr    {
86122b469fSAndreas Gohr        echo '<hr /><br />';
87122b469fSAndreas Gohr        echo '<p>' . $this->getLang('revstart') . '</p>';
88122b469fSAndreas Gohr
89122b469fSAndreas Gohr        echo '<ul>';
90168f9feeSAndreas Gohr        foreach ($revert as $id) {
91168f9feeSAndreas Gohr            global $REV;
9290f99567SAndreas Gohr
9390f99567SAndreas Gohr            // find the last non-spammy revision
9490f99567SAndreas Gohr            $data = '';
95047bad06SGerrit Uitslag            $pagelog = new PageChangeLog($id);
96f523c971SGerrit Uitslag            $old  = $pagelog->getRevisions(0, $this->max_revs);
9754cc7aa4SAndreas Gohr            if ($old !== []) {
9890f99567SAndreas Gohr                foreach ($old as $REV) {
9990f99567SAndreas Gohr                    $data = rawWiki($id, $REV);
10054cc7aa4SAndreas Gohr                    if (strpos($data, (string) $filter) === false) break;
10190f99567SAndreas Gohr                }
10290f99567SAndreas Gohr            }
10390f99567SAndreas Gohr
10490f99567SAndreas Gohr            if ($data) {
10590f99567SAndreas Gohr                saveWikiText($id, $data, 'old revision restored', false);
106122b469fSAndreas Gohr                printf('<li><div class="li">' . $this->getLang('reverted') . '</div></li>', $id, $REV);
107168f9feeSAndreas Gohr            } else {
108168f9feeSAndreas Gohr                saveWikiText($id, '', '', false);
10990f99567SAndreas Gohr                printf('<li><div class="li">' . $this->getLang('removed') . '</div></li>', $id);
110168f9feeSAndreas Gohr            }
111168f9feeSAndreas Gohr            @set_time_limit(10);
112168f9feeSAndreas Gohr            flush();
113168f9feeSAndreas Gohr        }
114122b469fSAndreas Gohr        echo '</ul>';
115122b469fSAndreas Gohr
116122b469fSAndreas Gohr        echo '<p>' . $this->getLang('revstop') . '</p>';
117168f9feeSAndreas Gohr    }
118168f9feeSAndreas Gohr
119122b469fSAndreas Gohr    /**
120122b469fSAndreas Gohr     * List recent edits matching the given filter
121122b469fSAndreas Gohr     */
1222a7fef40SAndreas Gohr    protected function listEdits($filter)
1232a7fef40SAndreas Gohr    {
124168f9feeSAndreas Gohr        global $conf;
125de3eb1d7SAdrian Lang        global $lang;
126122b469fSAndreas Gohr        echo '<hr /><br />';
1272404d0edSAnika Henke        echo '<form action="" method="post"><div class="no">';
128122b469fSAndreas Gohr        echo '<input type="hidden" name="filter" value="' . hsc($filter) . '" />';
129634d7150SAndreas Gohr        formSecurityToken();
130168f9feeSAndreas Gohr
13190f99567SAndreas Gohr        $recents = getRecents(0, $this->max_lines);
132122b469fSAndreas Gohr        echo '<ul>';
133168f9feeSAndreas Gohr
134122b469fSAndreas Gohr        $cnt = 0;
135168f9feeSAndreas Gohr        foreach ($recents as $recent) {
136168f9feeSAndreas Gohr            if ($filter) {
13754cc7aa4SAndreas Gohr                if (strpos(rawWiki($recent['id']), (string) $filter) === false) continue;
138168f9feeSAndreas Gohr            }
139168f9feeSAndreas Gohr
140122b469fSAndreas Gohr            $cnt++;
141dc235f96SMatthias Schulte            $date = dformat($recent['date']);
142168f9feeSAndreas Gohr
143ebf1501fSBen Coburn            echo ($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
144122b469fSAndreas Gohr            echo '<div class="li">';
14564159a61SAndreas Gohr            echo '<input type="checkbox" name="revert[]" value="' . hsc($recent['id']) .
14664159a61SAndreas Gohr                '" checked="checked" id="revert__' . $cnt . '" />';
147122b469fSAndreas Gohr            echo ' <label for="revert__' . $cnt . '">' . $date . '</label> ';
148168f9feeSAndreas Gohr
149122b469fSAndreas Gohr            echo '<a href="' . wl($recent['id'], "do=diff") . '">';
15054cc7aa4SAndreas Gohr            $p = [];
151*e44b94a4SAndreas Gohr            $p['src']    = DOKU_BASE . 'lib/images/diff.png';
152168f9feeSAndreas Gohr            $p['width']  = 15;
153168f9feeSAndreas Gohr            $p['height'] = 11;
154168f9feeSAndreas Gohr            $p['title']  = $lang['diff'];
155168f9feeSAndreas Gohr            $p['alt']    = $lang['diff'];
156168f9feeSAndreas Gohr            $att = buildAttributes($p);
157122b469fSAndreas Gohr            echo "<img $att />";
158122b469fSAndreas Gohr            echo '</a> ';
159168f9feeSAndreas Gohr
160122b469fSAndreas Gohr            echo '<a href="' . wl($recent['id'], "do=revisions") . '">';
16154cc7aa4SAndreas Gohr            $p = [];
162*e44b94a4SAndreas Gohr            $p['src']    = DOKU_BASE . 'lib/images/history.png';
163168f9feeSAndreas Gohr            $p['width']  = 12;
164168f9feeSAndreas Gohr            $p['height'] = 14;
165168f9feeSAndreas Gohr            $p['title']  = $lang['btn_revs'];
166168f9feeSAndreas Gohr            $p['alt']    = $lang['btn_revs'];
167168f9feeSAndreas Gohr            $att = buildAttributes($p);
168122b469fSAndreas Gohr            echo "<img $att />";
169122b469fSAndreas Gohr            echo '</a> ';
170168f9feeSAndreas Gohr
1710ea51e63SMatt Perry            echo html_wikilink(':' . $recent['id'], (useHeading('navigation')) ? null : $recent['id']);
172e260f93bSAnika Henke            echo ' – ' . htmlspecialchars($recent['sum']);
173168f9feeSAndreas Gohr
174122b469fSAndreas Gohr            echo ' <span class="user">';
175122b469fSAndreas Gohr                echo $recent['user'] . ' ' . $recent['ip'];
176122b469fSAndreas Gohr            echo '</span>';
177168f9feeSAndreas Gohr
178122b469fSAndreas Gohr            echo '</div>';
179122b469fSAndreas Gohr            echo '</li>';
180168f9feeSAndreas Gohr
181168f9feeSAndreas Gohr            @set_time_limit(10);
182168f9feeSAndreas Gohr            flush();
183168f9feeSAndreas Gohr        }
184122b469fSAndreas Gohr        echo '</ul>';
185168f9feeSAndreas Gohr
18690f99567SAndreas Gohr        echo '<p>';
187ae614416SAnika Henke        echo '<button type="submit">' . $this->getLang('revert') . '</button> ';
18890f99567SAndreas Gohr        printf($this->getLang('note2'), hsc($filter));
18990f99567SAndreas Gohr        echo '</p>';
190122b469fSAndreas Gohr
1912404d0edSAnika Henke        echo '</div></form>';
192168f9feeSAndreas Gohr    }
193168f9feeSAndreas Gohr}
194e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
195