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 AbstractUserAction
16{
17    /** @inheritdoc */
18    public function minimumPermission()
19    {
20        return AUTH_EDIT;
21    }
22
23    /**
24     *
25     * @inheritdoc
26     * @throws ActionAbort
27     * @throws ActionException
28     * @todo check for writability of the current page ($INFO might do it wrong and check the attic version)
29     */
30    public function preProcess()
31    {
32        if (!checkSecurityToken()) throw new ActionException();
33
34        global $ID;
35        global $REV;
36        global $lang;
37
38        // when no revision is given, delete current one
39        // FIXME this feature is not exposed in the GUI currently
40        $text = '';
41        $sum = $lang['deleted'];
42        if ($REV) {
43            $text = rawWiki($ID, $REV);
44            if (!$text) throw new ActionException(); //something went wrong
45            $sum = sprintf($lang['restored'], dformat($REV));
46        }
47
48        // spam check
49        if (checkwordblock($text)) {
50            msg($lang['wordblock'], -1);
51            throw new ActionException('edit');
52        }
53
54        saveWikiText($ID, $text, $sum, false);
55        msg($sum, 1);
56        $REV = '';
57
58        // continue with draftdel -> redirect -> show
59        throw new ActionAbort('draftdel');
60    }
61}
62