xref: /dokuwiki/inc/Action/Save.php (revision 8c7c53b0321a3cd3116b8d3b2ad27863a38dece7)
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        global $INFO;
21        if($INFO['exists']) {
22            return AUTH_EDIT;
23        } else {
24            return AUTH_CREATE;
25        }
26    }
27
28    /** @inheritdoc */
29    public function preProcess() {
30        if(!checkSecurityToken()) throw new ActionException('preview');
31
32        global $ID;
33        global $DATE;
34        global $PRE;
35        global $TEXT;
36        global $SUF;
37        global $SUM;
38        global $lang;
39        global $INFO;
40        global $INPUT;
41
42        //spam check
43        if(checkwordblock()) {
44            msg($lang['wordblock'], -1);
45            throw new ActionException('edit');
46        }
47        //conflict check
48        if($DATE != 0
49            && isset($INFO['meta']['date']['modified'])
50            && $INFO['meta']['date']['modified'] > $DATE
51        ) {
52            throw new ActionException('conflict');
53        }
54
55        //save it
56        saveWikiText($ID, con($PRE, $TEXT, $SUF, true), $SUM, $INPUT->bool('minor')); //use pretty mode for con
57        //unlock it
58        unlock($ID);
59
60        // continue with draftdel -> redirect -> show
61        throw new ActionAbort('draftdel');
62    }
63}
64