1 <?php
2 
3 namespace dokuwiki\Action;
4 
5 use dokuwiki\Ui\Editor;
6 use dokuwiki\Ui\PageView;
7 use dokuwiki\Draft;
8 use dokuwiki\Ui;
9 
10 /**
11  * Class Preview
12  *
13  * preview during editing
14  *
15  * @package dokuwiki\Action
16  */
17 class Preview extends Edit
18 {
19     /** @inheritdoc */
20     public function preProcess()
21     {
22         header('X-XSS-Protection: 0');
23         $this->savedraft();
24         parent::preProcess();
25     }
26 
27     /** @inheritdoc */
28     public function tplContent()
29     {
30         global $TEXT;
31         (new Editor())->show();
32         (new PageView($TEXT))->show();
33     }
34 
35     /**
36      * Saves a draft on preview
37      */
38     protected function savedraft()
39     {
40         global $ID, $INFO;
41         $draft = new Draft($ID, $INFO['client']);
42         if (!$draft->saveDraft()) {
43             $errors = $draft->getErrors();
44             foreach ($errors as $error) {
45                 msg(hsc($error), -1);
46             }
47         }
48     }
49 }
50