Advertisement
Guest User

Untitled

a guest
Jan 25th, 2011
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1.         function download() {
  2.                 global $wgOut;
  3.                 global $wgRequest;
  4.                 global $wgCollectionContentTypeToFilename;
  5.  
  6.                 $collection = CollectionSession::getCollection();
  7.  
  8.                 $tempfile = tmpfile();
  9.                 $r = self::mwServeCommand( 'render_status', array(
  10.                         'collection_id' => $wgRequest->getVal( 'collection_id' ),
  11.                         'writer' => $wgRequest->getVal( 'writer' ),
  12.                 ) );
  13.                 $errorMessage = '';
  14.                 $info = false;
  15.                 if ( isset( $r['url'] ) ) {
  16.                         self::curlreq( 'GET', $r['url'], array(), $errorMessage, $info, $timeout=false, $toFile=$tempfile );
  17.                         $content_type = $r['content_type'];
  18.                         $content_length = $r['content_length'];
  19.                         $content_disposition = $r['content_disposition'];
  20.                 } else {
  21.                         $info = self::mwServeCommand( 'download', array(
  22.                                 'collection_id' => $wgRequest->getVal( 'collection_id' ),
  23.                                 'writer' => $wgRequest->getVal( 'writer' ),
  24.                         ), $timeout=false, $toFile=$tempfile );
  25.                         $content_type = $info['content_type'];
  26.                         $content_length = $info['download_content_length'];
  27.                         $content_disposition = null;
  28.                 }
  29.                 if ( !$info ) {
  30.                         $wgOut->showErrorPage( 'coll-download_notfound_title', 'coll-download_notfound_text' );
  31.                         return;
  32.                 }
  33.                 $filename = $collection["title"].".";
  34.                 switch($wgRequest->getVal( 'writer', 'rl' ))
  35.                 {
  36.                         case "odf":
  37.                         $filename .= "odt";
  38.                         break;
  39.                         case "xhtml":
  40.                         $filename .= "html";
  41.                         break;
  42.                         case "mwxml":
  43.                         $filename .= "xml";
  44.                         break;
  45.                         default:
  46.                         $filename .= "pdf";
  47.                         break;
  48.                 }
  49.  
  50.                 wfResetOutputBuffers();
  51.                 header( 'Content-Type: ' . $content_type );
  52.                 header( 'Content-Length: ' . $content_length);
  53.                 if ( $content_disposition ) {
  54.                         header( 'Content-Disposition: ' . $content_disposition .' name="'.$filename.'"');
  55.                 }
  56.                 header('Content-Disposition: attachment; filename="'.$filename.'"');
  57.  
  58.                 fseek( $tempfile, 0 );
  59.                 fpassthru( $tempfile );
  60.                 $wgOut->disable();
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement