xref: /dokuwiki/inc/Action/Save.php (revision 26dfc2323f8f70cb69aac4c8c51bf7997809f2ca)
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 (
51            $DATE != 0
52            && isset($INFO['meta']['date']['modified'])
53            && $INFO['meta']['date']['modified'] > $DATE
54        ) {
55            throw new ActionException('conflict');
56        }
57
58        //save it
59        saveWikiText($ID, con($PRE, $TEXT, $SUF, true), $SUM, $INPUT->bool('minor')); //use pretty mode for con
60        //unlock it
61        unlock($ID);
62
63        // continue with draftdel -> redirect -> show
64        throw new ActionAbort('draftdel');
65    }
66}
67