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