Completed
Push — master ( bf6f54...20dc95 )
by Andreas
03:16
created

Revert::minimumPermission()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\Action;
4
5
use dokuwiki\Action\Exception\ActionAbort;
6
use dokuwiki\Action\Exception\ActionException;
7
8
/**
9
 * Class Revert
10
 *
11
 * Quick revert to an old revision
12
 *
13
 * @package dokuwiki\Action
14
 */
15
class 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
        $REV = '';
60
61
        // continue with draftdel -> redirect -> show
62
        throw new ActionAbort('draftdel');
63
    }
64
65
}
66