xref: /dokuwiki/inc/Action/Save.php (revision dccd6b2bba7367e4d1d2d7aa84c9f9d15584b593)
1<?php
2
3namespace dokuwiki\Action;
4
5use dokuwiki\Action\Exception\ActionAbort;
6use dokuwiki\Action\Exception\ActionException;
7
8/**
9 * Class Save
10 *
11 * Save at the end of an edit session
12 *
13 * @package dokuwiki\Action
14 */
15class Save extends AbstractAction
16{
17
18    /** @inheritdoc */
19    public function minimumPermission()
20    {
21        global $INFO;
22        if($INFO['exists']) {
23            return AUTH_EDIT;
24        } else {
25            return AUTH_CREATE;
26        }
27    }
28
29    /** @inheritdoc */
30    public function preProcess()
31    {
32        if(!checkSecurityToken()) throw new ActionException('preview');
33
34        global $ID;
35        global $DATE;
36        global $PRE;
37        global $TEXT;
38        global $SUF;
39        global $SUM;
40        global $lang;
41        global $INFO;
42        global $INPUT;
43
44        //spam check
45        if(checkwordblock()) {
46            msg($lang['wordblock'], -1);
47            throw new ActionException('edit');
48        }
49        //conflict check
50        if($DATE != 0
51            && isset($INFO['meta']['date']['modified'])
52            && $INFO['meta']['date']['modified'] > $DATE
53        ) {
54            throw new ActionException('conflict');
55        }
56
57        //save it
58        saveWikiText($ID, con($PRE, $TEXT, $SUF, true), $SUM, $INPUT->bool('minor')); //use pretty mode for con
59        //unlock it
60        unlock($ID);
61
62        // continue with draftdel -> redirect -> show
63        throw new ActionAbort('draftdel');
64    }
65}
66