* License: * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ define('W2L_SENDFILE', 1); // Some Config-Hacks to allow for including some original Mediawiki-files: define('MEDIAWIKI', 1); require_once "../../includes/GlobalFunctions.php"; require_once "w2lFunctions.php"; $file = addslashes($_GET['fid']); $fmt = addslashes($_GET['fmt']); $title = addslashes($_GET['title']); $tmp = w2lTempDir(); $title = w2lWebsafeTitle($title); $file_loc = $tmp . DIRECTORY_SEPARATOR . 'w2ltmp-' . $file . DIRECTORY_SEPARATOR . 'Main.' . $fmt; switch ($fmt) { case 'pdf': $mime_type = 'application/pdf'; break; case 'tex': $mime_type = 'application/x-tex'; break; default: $mime_type = 'text/plain'; break; } if (file_exists($file_loc)) { header("Content-Type: " . $mime_type); // Es wird downloaded.pdf benannt
private function onPdf($compile = true) { global $wgOut, $wgLang, $IP, $wgScriptPath, $wgUser; if ($this->config['pdfexport'] == false and $compile == true) { // pdf export is not allowed, so don't export $wgOut->addHTML(wfMsg('w2l_pdfexport_disabled')); return false; } $output = ''; $title = $this->mTitle->getEscapedText(); $to_parse = $this->mArticle->getContent(); // Get Template-Vars... $template_vars = $this->getTemplateVars($to_parse); $template_vars = array_merge($template_vars, $this->mwVars); // If title was not set by a <templatevar> tag, use page title // Put some special variables in the template vars wfRunHooks('w2lTemplateVarsLaTeX', array(&$this, &$template_vars)); // we need that template-file... $temp_id = $this->mValues->getVal("template"); $parsed = $this->Parser->parse($to_parse, $this->mTitle); if ($temp_id == 'auto') { // create a template automagically, $template = $this->createMagicTemplate(); } else { if ($temp_id == 'empty') { // Use empty for a complete page of LaTeX-Code $template = '==Wiki2LaTeX\'s Empty Template==' . "\n"; $template .= '<latexfile name="Main">' . "\n"; $template .= '((W2L_CONTENT))' . "\n"; $template .= '</latexfile>'; } else { $template = $this->getTemplate($temp_id); } } $files = $this->createTemplateFiles($template); // Adding some Template-Variables... $template_vars['W2L_CONTENT'] =& $parsed; $template_vars['W2L_VERSION'] = $this->version; // Now the template vars need to be put into ((var)) $tpl_vars = array(); foreach ($template_vars as $tplv_key => $tplv_value) { $tpl_vars['((' . $tplv_key . '))'] = $tplv_value; } // define the path for the files... // Create temp-folder $tmpPiece = $this->getTempDirPiece(); $compiler = new Wiki2LaTeXCompiler($tmpPiece, true); $compiler->addFiles($files); $file_suc = $compiler->generateFiles($tpl_vars); if (true == $compile && true == $file_suc) { // Get states $bibtex = $this->Parser->getBibtexState(); $sort = $this->Parser->getSortState(); $compile_error = $compiler->runLaTeX('Main', $sort, $bibtex); $log = $compiler->getLogFile(); } else { $compile_error = true; } if ($wgUser->getOption('w2lDebug') == true) { $output .= wfMsg('w2l_debug_info', $this->Parser->getParseTime(), $this->Parser->curlyBraceDebugCounter, $this->Parser->curlyBraceLength); //$output .= '<pre>'.htmlspecialchars($parsed).'</pre>'; $output .= $this->Parser->getDebugMessages(); $output .= '<div>Memory-Peak: ' . sprintf("%.2f", memory_get_peak_usage() / 1024 / 1024) . ' MB</div>'; } $output .= $this->getFolderLinks(); $wgOut->setPagetitle(wfMsg('w2l_result_title', $title)); $wgOut->setSubtitle(wfMsg('w2l_result_subtitle', $title)); $wgOut->addHTML(wfMsg('w2l_result_heading')); $title_fn = w2lWebsafeTitle($title); //wfVarDump($title_fn); if (false == $compile_error) { $wgOut->addHTML(wfMsg('w2l_result_folder', $wgScriptPath, $title_fn, $tmpPiece)); $wgOut->addHTML($this->Parser->getErrorMessages()); } elseif ($compile == false) { $wgOut->addHTML(wfMsg('w2l_result_tex', $wgScriptPath, $title_fn, $tmpPiece)); } else { $wgOut->addHTML('<p>' . wfMsg('w2l_latex_failed', $wgScriptPath, $title_fn, $tmpPiece) . '</p>'); } $wgOut->addHTML('<textarea style="height:200px">' . $compiler->getLog() . '</textarea>'); if ($wgUser->getOption('w2lShowParsed') == true) { $wgOut->addHTML('<h2>Parsed LaTeX-Code:</h2><textarea style="height:300px">' . htmlspecialchars($parsed) . '</textarea>'); } if ($wgUser->getOption('w2lShowLog') == true && $compile == true) { $wgOut->addHTML('<h2>Log file:</h2><textarea style="height:200px">' . $compiler->getLogFile() . '</textarea>'); } $wgOut->addHTML($output); return true; }