Go to the documentation of this file.
29 'main' =>
'pdf-file-page-warning',
30 'header' =>
'pdf-file-page-warning-header',
31 'info' =>
'pdf-file-page-warning-info',
32 'footer' =>
'pdf-file-page-warning-footer',
39 global $wgPdfProcessor, $wgPdfPostProcessor, $wgPdfInfo;
41 if ( !isset( $wgPdfProcessor ) || !isset( $wgPdfPostProcessor ) || !isset( $wgPdfInfo ) ) {
42 wfDebug(
"PdfHandler is disabled, please set the following\n" );
43 wfDebug(
"variables in LocalSettings.php:\n" );
44 wfDebug(
"\$wgPdfProcessor, \$wgPdfPostProcessor, \$wgPdfInfo\n" );
72 if ( $name ===
'page' && trim( $value ) !== (
string)intval( $value ) ) {
77 if ( in_array( $name, [
'width',
'height',
'page' ] ) ) {
78 return ( $value > 0 );
88 $page = $params[
'page'] ?? 1;
89 if ( !isset( $params[
'width'] ) ) {
92 return "page{$page}-{$params['width']}px";
102 if ( preg_match(
'/^page(\d+)-(\d+)px$/', $str, $m ) ) {
103 return [
'width' => $m[2],
'page' => $m[1] ];
115 'width' => $params[
'width'],
116 'page' => $params[
'page'],
125 'img_width' =>
'width',
126 'img_page' =>
'page',
138 $width, $height,
wfMessage( $msg )->inContentLanguage()->text() );
149 public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
150 global $wgPdfProcessor, $wgPdfPostProcessor, $wgPdfHandlerDpi, $wgPdfHandlerJpegQuality;
156 $width = (int)$params[
'width'];
157 $height = (int)$params[
'height'];
158 $page = (int)$params[
'page'];
160 if ( $page > $this->
pageCount( $image ) ) {
161 return $this->
doThumbError( $width, $height,
'pdf_page_error' );
164 if ( $flags & self::TRANSFORM_LATER ) {
173 return $this->
doThumbError( $width, $height,
'thumbnail_dest_directory' );
178 if ( $image->getSize() >= 1e7 ) {
181 'doWork' =>
function () use ( $image ) {
182 return $image->getLocalRefPath();
188 $srcPath = $image->getLocalRefPath();
191 if ( $srcPath ===
false ) {
192 return $this->
doThumbError( $width, $height,
'filemissing' );
199 "-dFirstPage={$page}",
200 "-dLastPage={$page}",
202 "-r{$wgPdfHandlerDpi}",
213 $wgPdfHandlerJpegQuality,
221 wfDebug( __METHOD__ .
": $cmd\n" );
227 if ( $retval != 0 || $removed ) {
229 sprintf(
'thumbnail failed on %s: error %d "%s" from "%s"',
230 wfHostname(), $retval, trim( $err ), $cmd ) );
250 } elseif ( !isset( $image->pdfImage ) ) {
253 $pdfimg = $image->pdfImage;
264 if ( isset( $image->pdfMetaArray ) ) {
265 return $image->pdfMetaArray;
268 $metadata = $image->getMetadata();
271 wfDebug(
"Pdf metadata is invalid or missing, should have been fixed in upgradeRow\n" );
276 'PdfHandler-unserialize-metadata',
282 'doWork' =>
function () use ( $image, $metadata ) {
283 Wikimedia\suppressWarnings();
285 Wikimedia\restoreWarnings();
291 return $image->pdfMetaArray;
310 global $wgPdfOutputExtension;
313 if ( !isset( $mime ) ) {
315 $mime = $magic->guessTypesForExtension( $wgPdfOutputExtension );
317 return [ $wgPdfOutputExtension, $mime ];
335 if ( !$metadata || $metadata ===
serialize( [] ) ) {
337 } elseif ( strpos( $metadata,
'mergedMetadata' ) ===
false ) {
349 $meta = $image->getMetadata();
354 Wikimedia\suppressWarnings();
356 Wikimedia\restoreWarnings();
358 if ( !isset( $meta[
'mergedMetadata'] )
359 || !is_array( $meta[
'mergedMetadata'] )
360 || count( $meta[
'mergedMetadata'] ) < 1
376 return $info ? $info[
'pageCount'] :
false;
388 if ( $info && isset( $info[
'dimensionsByPage'][$index] ) ) {
389 return $info[
'dimensionsByPage'][$index];
396 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
397 return $cache->getWithSetCallback(
398 $cache->makeKey(
'file-pdf',
'dimensions',
$file->getSha1() ),
399 $cache::TTL_INDEFINITE,
400 function () use (
$file ) {
402 if ( !$data || !isset( $data[
'Pages'] ) ) {
405 unset( $data[
'text'] );
408 $count = intval( $data[
'Pages'] );
409 for ( $i = 1; $i <= $count; $i++ ) {
413 return [
'pageCount' => $count,
'dimensionsByPage' => $dimsByPage ];
415 [
'pcTTL' => $cache::TTL_INDEFINITE ]
426 if ( !$data || !isset( $data[
'text'] ) || !isset( $data[
'text'][$page - 1] ) ) {
429 return $data[
'text'][$page - 1];
441 'link' =>
'//www.mediawiki.org/wiki/Special:MyLanguage/Help:Security/PDF_files',
442 'module' =>
'pdfhandler.messages',
452 'messages' => array_values( self::$messages ),
Copyright © 2007 Martin Seidel (Xarax) jodeldi@gmx.de
Media transform output for images.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
isMetadataValid( $image, $metadata)
static getPageSize( $data, $page)
makeParamString( $params)
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
wfHostname()
Fetch server name for use in error reporting etc.
getDimensionInfo(File $file)
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
getWarningConfig( $file)
Adds a warning about PDFs being potentially dangerous to the file page.
getPageText(File $image, $page)
Convenience class for dealing with PoolCounters using callbacks.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
inspired by djvuimage from Brion Vibber modified and written by xarax
Implements some public methods and some protected utility functions which are required by multiple ch...
execute( $skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
Media handler abstract base class for images.
static registerWarningModule(&$resourceLoader)
Register a module with the warning messages in it.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
normaliseParams( $image, &$params)
getImageSize( $image, $path)
doThumbError( $width, $height, $msg)
getMetadata( $image, $path)
formatMetadata( $image, $context=false)
getScriptParams( $params)
unserialize( $serialized)
doTransform( $image, $dstPath, $dstUrl, $params, $flags=0)
wfEscapeShellArg(... $args)
Version of escapeshellarg() that works better on Windows.
if(!is_readable( $file)) $ext
getPageDimensions(File $image, $page)
getThumbType( $ext, $mime, $params=null)
getPdfImage( $image, $path)
wfShellExecWithStderr( $cmd, &$retval=null, $environ=[], $limits=[])
Execute a shell command, returning both stdout and stderr.
validateParam( $name, $value)