jenkins-bot has submitted this change and it was merged.

Change subject: Use TempFSFile
......................................................................


Use TempFSFile

Bug: T149779
Change-Id: I57ca1f05c8710d30c28f14342d9cde50ce1bfbb1
---
M specials/SpecialElectronPdf.php
1 file changed, 10 insertions(+), 7 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/specials/SpecialElectronPdf.php b/specials/SpecialElectronPdf.php
index 4eda6b4..1dd625b 100644
--- a/specials/SpecialElectronPdf.php
+++ b/specials/SpecialElectronPdf.php
@@ -10,11 +10,11 @@
 
 class SpecialElectronPdf extends SpecialPage {
        /**
-        * @var $tempFile
+        * @var $tempFileHandle
         *
         * Temporary file the PDF will be written to
         */
-       public $tempFile;
+       public $tempFileHandle;
 
        public $config;
 
@@ -132,7 +132,8 @@
        }
 
        public function renderAndShowPdf( Title $title ) {
-               $this->tempFile = tmpfile();
+               $tempFile = TempFSFile::factory( 'electron_', 'pdf' );
+               $this->tempFileHandle = fopen( $tempFile->getPath(), 'w+' );
 
                $request = MWHttpRequest::factory( $this->constructServiceUrl( 
$title ) );
                $request->setCallback( [ $this, 'writeToTempFile' ] );
@@ -146,11 +147,13 @@
                        );
                }
 
+               fclose( $this->tempFileHandle );
+               $tempFile->purge();
                return;
        }
 
        public function writeToTempFile( $res, $content ) {
-               return fwrite( $this->tempFile, $content );
+               return fwrite( $this->tempFileHandle, $content );
        }
 
        public function setHeaders() {
@@ -188,13 +191,13 @@
        }
 
        private function sendPdfToOutput( $page ) {
-               $fileMetaData = stream_get_meta_data( $this->tempFile );
+               $fileMetaData = stream_get_meta_data( $this->tempFileHandle );
                wfResetOutputBuffers();
                header( 'Content-Type:application/pdf' );
                header( 'Content-Length: ' . filesize( $fileMetaData['uri'] ) );
                header( 'Content-Disposition: inline; filename=' . $page . 
'.pdf' );
-               fseek( $this->tempFile, 0 );
-               fpassthru( $this->tempFile );
+               fseek( $this->tempFileHandle, 0 );
+               fpassthru( $this->tempFileHandle );
                $this->getOutput()->disable();
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/319288
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I57ca1f05c8710d30c28f14342d9cde50ce1bfbb1
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/ElectronPdfService
Gerrit-Branch: master
Gerrit-Owner: WMDE-Fisch <christoph.jau...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Tobias Gritschacher <tobias.gritschac...@wikimedia.de>
Gerrit-Reviewer: WMDE-Fisch <christoph.jau...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to