xref: /dokuwiki/inc/Action/Preview.php (revision 91109d52e565c2a87aeee0650c7248472e54713a)
1<?php
2
3namespace dokuwiki\Action;
4
5/**
6 * Class Preview
7 *
8 * preview during editing
9 *
10 * @package dokuwiki\Action
11 */
12class Preview extends Edit {
13
14    /** @inheritdoc */
15    public function preProcess() {
16        header('X-XSS-Protection: 0');
17        $this->savedraft();
18        parent::preProcess();
19    }
20
21    /** @inheritdoc */
22    public function tplContent() {
23        global $TEXT;
24        html_edit();
25        html_show($TEXT);
26    }
27
28    /**
29     * Saves a draft on preview
30     */
31    protected function savedraft() {
32        global $INFO;
33        global $ID;
34        global $INPUT;
35        global $conf;
36
37        if(!$conf['usedraft']) return;
38        if(!$INPUT->post->has('wikitext')) return;
39
40        // ensure environment (safeguard when used via AJAX)
41        assert(isset($INFO['client']), 'INFO.client should have been set');
42        assert(isset($ID), 'ID should have been set');
43
44        $draft = array(
45            'id' => $ID,
46            'prefix' => substr($INPUT->post->str('prefix'), 0, -1),
47            'text' => $INPUT->post->str('wikitext'),
48            'suffix' => $INPUT->post->str('suffix'),
49            'date' => $INPUT->post->int('date'),
50            'client' => $INFO['client'],
51        );
52        $cname = getCacheName($draft['client'] . $ID, '.draft');
53        if(io_saveFile($cname, serialize($draft))) {
54            $INFO['draft'] = $cname;
55        }
56    }
57
58}
59