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