You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

115 lines
3.3 KiB

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