xref: /dokuwiki/inc/Action/Revert.php (revision 0f9e19d90383dd0deb85e1c4ef4750811f102d0f)
1<?php
2
3namespace dokuwiki\Action;
4
5use dokuwiki\Action\Exception\ActionAbort;
6use dokuwiki\Action\Exception\ActionException;
7
8/**
9 * Class Revert
10 *
11 * Quick revert to an old revision
12 *
13 * @package dokuwiki\Action
14 */
15class Revert extends AbstractAction {
16
17    /** @inheritdoc */
18    public function minimumPermission() {
19        global $INFO;
20        if($INFO['ismanager']) {
21            return AUTH_EDIT;
22        } else {
23            return AUTH_ADMIN;
24        }
25    }
26
27    /**
28     *
29     * @inheritdoc
30     * @throws ActionAbort
31     * @throws ActionException
32     * @todo check for writability of the current page ($INFO might do it wrong and check the attic version)
33     */
34    public function preProcess() {
35        if(!checkSecurityToken()) throw new ActionException();
36
37        global $ID;
38        global $REV;
39        global $lang;
40        global $INPUT;
41
42        // when no revision is given, delete current one
43        // FIXME this feature is not exposed in the GUI currently
44        $text = '';
45        $sum = $lang['deleted'];
46        if($REV) {
47            $text = rawWiki($ID, $REV);
48            if(!$text) throw new ActionException(); //something went wrong
49            $sum = sprintf($lang['restored'], dformat($REV));
50        }
51
52        // spam check
53        if(checkwordblock($text)) {
54            msg($lang['wordblock'], -1);
55            throw new ActionException('edit');
56        }
57
58        saveWikiText($ID, $text, $sum, false);
59        msg($sum, 1);
60
61        //delete any draft
62        act_draftdel('fixme'); // FIXME replace this utility function
63        //session_write_close(); // FIXME sessions should be close somewhere higher up, maybe ActionRouter
64
65        // when done, show current page
66        $INPUT->server->set('REQUEST_METHOD', 'post'); //should force a redirect // FIXME should we have a RedirectException?
67        $REV = '';
68
69        throw new ActionAbort();
70    }
71
72}
73