1<?php 2 3namespace dokuwiki\Action; 4 5use dokuwiki\Action\Exception\ActionAbort; 6use dokuwiki\Extension\Event; 7 8/** 9 * Class Export 10 * 11 * Handle exporting by calling the appropriate renderer 12 * 13 * @package dokuwiki\Action 14 */ 15class Export extends AbstractAction 16{ 17 18 /** @inheritdoc */ 19 public function minimumPermission() 20 { 21 return AUTH_READ; 22 } 23 24 /** 25 * Export a wiki page for various formats 26 * 27 * Triggers ACTION_EXPORT_POSTPROCESS 28 * 29 * Event data: 30 * data['id'] -- page id 31 * data['mode'] -- requested export mode 32 * data['headers'] -- export headers 33 * data['output'] -- export output 34 * 35 * @author Andreas Gohr <andi@splitbrain.org> 36 * @author Michael Klier <chi@chimeric.de> 37 * @inheritdoc 38 */ 39 public function preProcess() 40 { 41 global $ID; 42 global $REV; 43 global $conf; 44 global $lang; 45 46 $pre = ''; 47 $post = ''; 48 $headers = []; 49 50 // search engines: never cache exported docs! (Google only currently) 51 $headers['X-Robots-Tag'] = 'noindex'; 52 53 $mode = substr($this->actionname, 7); 54 switch ($mode) { 55 case 'raw': 56 $headers['Content-Type'] = 'text/plain; charset=utf-8'; 57 $headers['Content-Disposition'] = 'attachment; filename=' . noNS($ID) . '.txt'; 58 $output = rawWiki($ID, $REV); 59 break; 60 case 'xhtml': 61 $pre .= '<!DOCTYPE html>' . DOKU_LF; 62 $pre .= '<html lang="' . $conf['lang'] . '" dir="' . $lang['direction'] . '">' . DOKU_LF; 63 $pre .= '<head>' . DOKU_LF; 64 $pre .= ' <meta charset="utf-8" />' . DOKU_LF; // FIXME improve wrapper 65 $pre .= ' <title>' . $ID . '</title>' . DOKU_LF; 66 67 // get metaheaders 68 ob_start(); 69 tpl_metaheaders(); 70 $pre .= ob_get_clean(); 71 72 $pre .= '</head>' . DOKU_LF; 73 $pre .= '<body>' . DOKU_LF; 74 $pre .= '<div class="dokuwiki export">' . DOKU_LF; 75 76 // get toc 77 $pre .= tpl_toc(true); 78 79 $headers['Content-Type'] = 'text/html; charset=utf-8'; 80 $output = p_wiki_xhtml($ID, $REV, false); 81 82 $post .= '</div>' . DOKU_LF; 83 $post .= '</body>' . DOKU_LF; 84 $post .= '</html>' . DOKU_LF; 85 break; 86 case 'xhtmlbody': 87 $headers['Content-Type'] = 'text/html; charset=utf-8'; 88 $output = p_wiki_xhtml($ID, $REV, false); 89 break; 90 default: 91 $output = p_cached_output(wikiFN($ID, $REV), $mode, $ID); 92 $headers = p_get_metadata($ID, "format $mode"); 93 break; 94 } 95 96 // prepare event data 97 $data = []; 98 $data['id'] = $ID; 99 $data['mode'] = $mode; 100 $data['headers'] = $headers; 101 $data['output'] =& $output; 102 103 Event::createAndTrigger('ACTION_EXPORT_POSTPROCESS', $data); 104 105 if (!empty($data['output'])) { 106 if (is_array($data['headers'])) foreach ($data['headers'] as $key => $val) { 107 header("$key: $val"); 108 } 109 print $pre . $data['output'] . $post; 110 exit; 111 } 112 113 throw new ActionAbort(); 114 } 115} 116