1<?php 2if (!defined('DOKU_INC')) die(); 3 4/** 5 * Handles SkillForge downloads outside the admin dispatcher. 6 * 7 * DokuWiki's admin pages can redirect or re-render before a binary download is 8 * sent, especially on compact/on-a-stick installs. A dedicated action avoids 9 * that path completely: 10 * doku.php?id=start&do=skillforge_download&sf_file=...zip§ok=... 11 */ 12class action_plugin_skillforge extends DokuWiki_Action_Plugin { 13 public function register(Doku_Event_Handler $controller) { 14 $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handleDownload'); 15 } 16 17 public function handleDownload(Doku_Event $event, $param) { 18 if (!isset($_REQUEST['do']) || !in_array($_REQUEST['do'], array('skillforge_download', 'skillforge_download_current'), true)) return; 19 20 if (!auth_isadmin()) { 21 http_status(403); 22 echo 'SkillForge download denied.'; 23 exit; 24 } 25 26 if (!checkSecurityToken()) { 27 http_status(403); 28 echo 'SkillForge download denied: invalid security token.'; 29 exit; 30 } 31 32 /** @var helper_plugin_skillforge $helper */ 33 $helper = plugin_load('helper', 'skillforge'); 34 if (!$helper) { 35 http_status(500); 36 echo 'SkillForge helper could not be loaded.'; 37 exit; 38 } 39 40 try { 41 if ($_REQUEST['do'] === 'skillforge_download_current') { 42 global $ID; 43 $page = isset($_REQUEST['sf_page']) ? $_REQUEST['sf_page'] : $ID; 44 $result = $helper->exportPage($page); 45 $helper->sendDownload($result['name']); 46 return; 47 } 48 49 $name = isset($_REQUEST['sf_file']) ? $_REQUEST['sf_file'] : ''; 50 $helper->sendDownload($name); 51 } catch (Exception $e) { 52 http_status(404); 53 echo 'SkillForge download failed: ' . hsc($e->getMessage()); 54 exit; 55 } 56 } 57} 58