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