From adf2733fea469f42d29c2a0f4bb33a35fb6e4d5f Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 17 Oct 2017 20:00:52 -0700 Subject: [PATCH] Switch to the new shell framework Change-Id: Ibb28f4f62603c77fc719593afb20f2e738a79352 --- PdfHandler.image.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/PdfHandler.image.php b/PdfHandler.image.php index 8346b31..e3f3534 100644 --- a/PdfHandler.image.php +++ b/PdfHandler.image.php @@ -20,6 +20,7 @@ */ use MediaWiki\Logger\LoggerFactory; +use MediaWiki\Shell\Shell; use UtfNormal\Validator; /** @@ -113,13 +114,17 @@ class PdfImage { global $wgPdfInfo, $wgPdftoText; if ( $wgPdfInfo ) { - $cmd = wfEscapeShellArg( $wgPdfInfo ) . - " -enc UTF-8 " . # Report metadata as UTF-8 text... - " -l 9999999 " . # Report page sizes for all pages - " -meta " . # Report XMP metadata - wfEscapeShellArg( $this->mFilename ); - $retval = ''; - $dump = wfShellExec( $cmd, $retval ); + $cmd = [ + $wgPdfInfo, + '-enc', 'UTF-8', # Report metadata as UTF-8 text... + '-l', '9999999', # Report page sizes for all pages + '-meta', # Report XMP metadata + $this->mFilename, + ]; + $result = Shell::command( $cmd ) + ->execute(); + + $dump = $result->getStdout(); $data = $this->convertDumpToArray( $dump ); } else { $data = null; @@ -127,10 +132,11 @@ class PdfImage { // Read text layer if ( isset( $wgPdftoText ) ) { - $cmd = wfEscapeShellArg( $wgPdftoText ) . ' '. wfEscapeShellArg( $this->mFilename ) . ' - '; - wfDebug( __METHOD__.": $cmd\n" ); - $retval = ''; - $txt = wfShellExec( $cmd, $retval ); + $cmd = [ $wgPdftoText, $this->mFilename, '-' ]; + $result = Shell::command( $cmd ) + ->execute(); + $retval = $result->getExitCode(); + $txt = $result->getStdout(); if ( $retval == 0 ) { $txt = str_replace( "\r\n", "\n", $txt ); $pages = explode( "\f", $txt );