xref: /dokuwiki/inc/Action/Edit.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: 10:42 AM
7*f21dad39SAndreas Gohr */
8*f21dad39SAndreas Gohr
9*f21dad39SAndreas Gohrnamespace dokuwiki\Action;
10*f21dad39SAndreas Gohr
11*f21dad39SAndreas Gohruse dokuwiki\Action\Exception\ActionAbort;
12*f21dad39SAndreas Gohr
13*f21dad39SAndreas Gohrclass Edit extends AbstractAction {
14*f21dad39SAndreas Gohr
15*f21dad39SAndreas Gohr    /** @inheritdoc */
16*f21dad39SAndreas Gohr    function minimumPermission() {
17*f21dad39SAndreas Gohr        global $INFO;
18*f21dad39SAndreas Gohr        if($INFO['exists']) {
19*f21dad39SAndreas Gohr            return AUTH_READ; // we check again below
20*f21dad39SAndreas Gohr        } else {
21*f21dad39SAndreas Gohr            return AUTH_CREATE;
22*f21dad39SAndreas Gohr        }
23*f21dad39SAndreas Gohr    }
24*f21dad39SAndreas Gohr
25*f21dad39SAndreas Gohr    public function checkPermissions() {
26*f21dad39SAndreas Gohr        parent::checkPermissions();
27*f21dad39SAndreas Gohr        global $INFO;
28*f21dad39SAndreas Gohr
29*f21dad39SAndreas Gohr        // no edit permission? view source
30*f21dad39SAndreas Gohr        if($INFO['exists'] && !$INFO['writable']) {
31*f21dad39SAndreas Gohr            throw new ActionAbort('source');
32*f21dad39SAndreas Gohr        }
33*f21dad39SAndreas Gohr    }
34*f21dad39SAndreas Gohr
35*f21dad39SAndreas Gohr    public function preProcess() {
36*f21dad39SAndreas Gohr        global $ID;
37*f21dad39SAndreas Gohr        global $INFO;
38*f21dad39SAndreas Gohr
39*f21dad39SAndreas Gohr        global $TEXT;
40*f21dad39SAndreas Gohr        global $RANGE;
41*f21dad39SAndreas Gohr        global $PRE;
42*f21dad39SAndreas Gohr        global $SUF;
43*f21dad39SAndreas Gohr        global $REV;
44*f21dad39SAndreas Gohr        global $SUM;
45*f21dad39SAndreas Gohr        global $lang;
46*f21dad39SAndreas Gohr        global $DATE;
47*f21dad39SAndreas Gohr
48*f21dad39SAndreas Gohr        if (!isset($TEXT)) {
49*f21dad39SAndreas Gohr            if ($INFO['exists']) {
50*f21dad39SAndreas Gohr                if ($RANGE) {
51*f21dad39SAndreas Gohr                    list($PRE,$TEXT,$SUF) = rawWikiSlices($RANGE,$ID,$REV);
52*f21dad39SAndreas Gohr                } else {
53*f21dad39SAndreas Gohr                    $TEXT = rawWiki($ID,$REV);
54*f21dad39SAndreas Gohr                }
55*f21dad39SAndreas Gohr            } else {
56*f21dad39SAndreas Gohr                $TEXT = pageTemplate($ID);
57*f21dad39SAndreas Gohr            }
58*f21dad39SAndreas Gohr        }
59*f21dad39SAndreas Gohr
60*f21dad39SAndreas Gohr        //set summary default
61*f21dad39SAndreas Gohr        if(!$SUM){
62*f21dad39SAndreas Gohr            if($REV){
63*f21dad39SAndreas Gohr                $SUM = sprintf($lang['restored'], dformat($REV));
64*f21dad39SAndreas Gohr            }elseif(!$INFO['exists']){
65*f21dad39SAndreas Gohr                $SUM = $lang['created'];
66*f21dad39SAndreas Gohr            }
67*f21dad39SAndreas Gohr        }
68*f21dad39SAndreas Gohr
69*f21dad39SAndreas Gohr        // Use the date of the newest revision, not of the revision we edit
70*f21dad39SAndreas Gohr        // This is used for conflict detection
71*f21dad39SAndreas Gohr        if(!$DATE) $DATE = @filemtime(wikiFN($ID));
72*f21dad39SAndreas Gohr
73*f21dad39SAndreas Gohr        //check if locked by anyone - if not lock for my self
74*f21dad39SAndreas Gohr        $lockedby = checklock($ID);
75*f21dad39SAndreas Gohr        if($lockedby) {
76*f21dad39SAndreas Gohr            throw new ActionAbort('locked');
77*f21dad39SAndreas Gohr        };
78*f21dad39SAndreas Gohr        lock($ID);
79*f21dad39SAndreas Gohr    }
80*f21dad39SAndreas Gohr
81*f21dad39SAndreas Gohr    public function tplContent() {
82*f21dad39SAndreas Gohr        html_edit();
83*f21dad39SAndreas Gohr    }
84*f21dad39SAndreas Gohr
85*f21dad39SAndreas Gohr}
86