Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function download() {
- global $wgOut;
- global $wgRequest;
- global $wgCollectionContentTypeToFilename;
- $collection = CollectionSession::getCollection();
- $tempfile = tmpfile();
- $r = self::mwServeCommand( 'render_status', array(
- 'collection_id' => $wgRequest->getVal( 'collection_id' ),
- 'writer' => $wgRequest->getVal( 'writer' ),
- ) );
- $errorMessage = '';
- $info = false;
- if ( isset( $r['url'] ) ) {
- self::curlreq( 'GET', $r['url'], array(), $errorMessage, $info, $timeout=false, $toFile=$tempfile );
- $content_type = $r['content_type'];
- $content_length = $r['content_length'];
- $content_disposition = $r['content_disposition'];
- } else {
- $info = self::mwServeCommand( 'download', array(
- 'collection_id' => $wgRequest->getVal( 'collection_id' ),
- 'writer' => $wgRequest->getVal( 'writer' ),
- ), $timeout=false, $toFile=$tempfile );
- $content_type = $info['content_type'];
- $content_length = $info['download_content_length'];
- $content_disposition = null;
- }
- if ( !$info ) {
- $wgOut->showErrorPage( 'coll-download_notfound_title', 'coll-download_notfound_text' );
- return;
- }
- $filename = $collection["title"].".";
- switch($wgRequest->getVal( 'writer', 'rl' ))
- {
- case "odf":
- $filename .= "odt";
- break;
- case "xhtml":
- $filename .= "html";
- break;
- case "mwxml":
- $filename .= "xml";
- break;
- default:
- $filename .= "pdf";
- break;
- }
- wfResetOutputBuffers();
- header( 'Content-Type: ' . $content_type );
- header( 'Content-Length: ' . $content_length);
- if ( $content_disposition ) {
- header( 'Content-Disposition: ' . $content_disposition .' name="'.$filename.'"');
- }
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- fseek( $tempfile, 0 );
- fpassthru( $tempfile );
- $wgOut->disable();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement