xref: /dokuwiki/inc/Action/Save.php (revision 7d34963b3e75ea04c63ec066a6b7a692e123cb53)
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
8ab583a1bSAndreas Gohr/**
9ab583a1bSAndreas Gohr * Class Save
10ab583a1bSAndreas Gohr *
11ab583a1bSAndreas Gohr * Save at the end of an edit session
12ab583a1bSAndreas Gohr *
13ab583a1bSAndreas Gohr * @package dokuwiki\Action
14ab583a1bSAndreas Gohr */
158c7c53b0SAndreas Gohrclass Save extends AbstractAction
168c7c53b0SAndreas Gohr{
17f21dad39SAndreas Gohr
18f21dad39SAndreas Gohr    /** @inheritdoc */
19d868eb89SAndreas Gohr    public function minimumPermission()
20d868eb89SAndreas Gohr    {
21f21dad39SAndreas Gohr        global $INFO;
22f21dad39SAndreas Gohr        if ($INFO['exists']) {
23f21dad39SAndreas Gohr            return AUTH_EDIT;
24f21dad39SAndreas Gohr        } else {
25f21dad39SAndreas Gohr            return AUTH_CREATE;
26f21dad39SAndreas Gohr        }
27f21dad39SAndreas Gohr    }
28f21dad39SAndreas Gohr
29ab583a1bSAndreas Gohr    /** @inheritdoc */
30d868eb89SAndreas Gohr    public function preProcess()
31d868eb89SAndreas Gohr    {
32f21dad39SAndreas Gohr        if (!checkSecurityToken()) throw new ActionException('preview');
33f21dad39SAndreas Gohr
34f21dad39SAndreas Gohr        global $ID;
35f21dad39SAndreas Gohr        global $DATE;
36f21dad39SAndreas Gohr        global $PRE;
37f21dad39SAndreas Gohr        global $TEXT;
38f21dad39SAndreas Gohr        global $SUF;
39f21dad39SAndreas Gohr        global $SUM;
40f21dad39SAndreas Gohr        global $lang;
41f21dad39SAndreas Gohr        global $INFO;
42f21dad39SAndreas Gohr        global $INPUT;
43f21dad39SAndreas Gohr
44f21dad39SAndreas Gohr        //spam check
45f21dad39SAndreas Gohr        if (checkwordblock()) {
46f21dad39SAndreas Gohr            msg($lang['wordblock'], -1);
47f21dad39SAndreas Gohr            throw new ActionException('edit');
48f21dad39SAndreas Gohr        }
49f21dad39SAndreas Gohr        //conflict check
50*7d34963bSAndreas Gohr        if (
51*7d34963bSAndreas Gohr            $DATE != 0
52056bf31fSDamien Regad            && isset($INFO['meta']['date']['modified'])
53056bf31fSDamien Regad            && $INFO['meta']['date']['modified'] > $DATE
54056bf31fSDamien Regad        ) {
55f21dad39SAndreas Gohr            throw new ActionException('conflict');
56f21dad39SAndreas Gohr        }
57f21dad39SAndreas Gohr
58f21dad39SAndreas Gohr        //save it
59f21dad39SAndreas Gohr        saveWikiText($ID, con($PRE, $TEXT, $SUF, true), $SUM, $INPUT->bool('minor')); //use pretty mode for con
60f21dad39SAndreas Gohr        //unlock it
61f21dad39SAndreas Gohr        unlock($ID);
62f21dad39SAndreas Gohr
63231f749dSAndreas Gohr        // continue with draftdel -> redirect -> show
64231f749dSAndreas Gohr        throw new ActionAbort('draftdel');
65f21dad39SAndreas Gohr    }
66f21dad39SAndreas Gohr}
67