Completed
Push — actionrefactor ( 6e4bf0 )
by Andreas
04:36
created

Revert::preProcess()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 37
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 21
nc 6
nop 0
dl 0
loc 37
rs 8.439
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
    function minimumPermission() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
        global $INFO;
20
        if($INFO['ismanager']) {
21
            return AUTH_EDIT;
22
        } else {
23
            return AUTH_ADMIN;
24
        }
25
    }
26
27
    // fixme check for writability of the current page ($INFO might do it wrong and check the attic version)
28
29
    public function preProcess() {
30
        if(!checkSecurityToken()) throw new ActionException();
31
32
        global $ID;
33
        global $REV;
34
        global $lang;
35
        global $INPUT;
36
37
        // when no revision is given, delete current one
38
        // FIXME this feature is not exposed in the GUI currently
39
        $text = '';
40
        $sum = $lang['deleted'];
41
        if($REV) {
42
            $text = rawWiki($ID, $REV);
43
            if(!$text) throw new ActionException(); //something went wrong
44
            $sum = sprintf($lang['restored'], dformat($REV));
45
        }
46
47
        // spam check
48
        if(checkwordblock($text)) {
49
            msg($lang['wordblock'], -1);
50
            throw new ActionException('edit');
51
        }
52
53
        saveWikiText($ID, $text, $sum, false);
54
        msg($sum, 1);
55
56
        //delete any draft
57
        act_draftdel('fixme'); // FIXME replace this utility function
58
        //session_write_close(); // FIXME sessions should be close somewhere higher up, maybe ActionRouter
59
60
        // when done, show current page
61
        $INPUT->server->set('REQUEST_METHOD', 'post'); //should force a redirect // FIXME should we have a RedirectException?
62
        $REV = '';
63
64
        throw new ActionAbort();
65
    }
66
67
}
68