Export.php 3.3 KB

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