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