xref: /dokuwiki/inc/Action/Revert.php (revision 58528803ad1f586696a6719f4ed566b78eb7b1d9)
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
41        // when no revision is given, delete current one
42        // FIXME this feature is not exposed in the GUI currently
43        $text = '';
44        $sum = $lang['deleted'];
45        if($REV) {
46            $text = rawWiki($ID, $REV);
47            if(!$text) throw new ActionException(); //something went wrong
48            $sum = sprintf($lang['restored'], dformat($REV));
49        }
50
51        // spam check
52        if(checkwordblock($text)) {
53            msg($lang['wordblock'], -1);
54            throw new ActionException('edit');
55        }
56
57        saveWikiText($ID, $text, $sum, false);
58        msg($sum, 1);
59
60        //delete any draft
61        act_draftdel('fixme'); // FIXME replace this utility function
62        //session_write_close(); // FIXME sessions should be close somewhere higher up, maybe ActionRouter
63
64        // when done, show current page
65        $REV = '';
66        throw new ActionAbort('redirect');
67    }
68
69}
70