Go to the documentation of this file.
40 wfDebug(
"DjVu is disabled, please set \$wgDjvuRenderer and \$wgDjvuDump\n" );
62 return $file->getSize() > static::EXPENSIVE_SIZE_LIMIT;
78 'img_width' =>
'width',
89 if ( $name ===
'page' && trim( $value ) !== (
string)intval( $value ) ) {
94 if ( in_array( $name, [
'width',
'height',
'page' ] ) ) {
110 $page = $params[
'page'] ?? 1;
111 if ( !isset( $params[
'width'] ) ) {
115 return "page{$page}-{$params['width']}px";
124 if ( preg_match(
'/^page(\d+)-(\d+)px$/', $str, $m ) ) {
125 return [
'width' => $m[2],
'page' => $m[1] ];
137 'width' => $params[
'width'],
138 'page' => $params[
'page'],
150 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
156 $width = $params[
'width'];
157 $height = $params[
'height'];
158 $page = $params[
'page'];
160 if ( $flags & self::TRANSFORM_LATER ) {
182 if ( $image->getSize() >= 1e7 ) {
185 'doWork' =>
function () use ( $image ) {
186 return $image->getLocalRefPath();
192 $srcPath = $image->getLocalRefPath();
195 if ( $srcPath ===
false ) {
197 sprintf(
'Thumbnail failed on %s: could not get local copy of "%s"',
201 $params[
'width'], $params[
'height'],
206 # Use a subshell (brackets) to aggregate stderr from both pipeline commands
207 # before redirecting it to the overall stdout. This works in both Linux and Windows XP.
208 $cmd =
'(' . Shell::escape(
212 "-size={$params['physicalWidth']}x{$params['physicalHeight']}",
215 $cmd .=
" | {$wgDjvuPostProcessor}";
217 $cmd .=
' > ' . Shell::escape( $dstPath ) .
') 2>&1';
218 wfDebug( __METHOD__ .
": $cmd\n" );
223 if ( $retval != 0 || $removed ) {
247 $deja =
new DjVuImage(
$path );
248 } elseif ( !isset( $image->dejaImage ) ) {
249 $deja = $image->dejaImage =
new DjVuImage(
$path );
251 $deja = $image->dejaImage;
265 $metadata =
$file->getMetadata();
266 if ( substr( $metadata, 0, 3 ) ===
'<?xml' ) {
271 Wikimedia\suppressWarnings();
273 Wikimedia\restoreWarnings();
274 if ( is_array( $unser ) ) {
275 if ( isset( $unser[
'error'] ) ) {
277 } elseif ( isset( $unser[
'xml'] ) ) {
278 return $unser[
'xml'];
281 throw new MWException(
"Error unserializing DjVu metadata." );
297 if ( $gettext && isset( $image->djvuTextTree ) ) {
298 return $image->djvuTextTree;
300 if ( !$gettext && isset( $image->dejaMetaTree ) ) {
301 return $image->dejaMetaTree;
306 wfDebug(
"DjVu XML metadata is invalid or missing, should have been fixed in upgradeRow\n" );
312 $image->djvuTextTree = $trees[
'TextTree'];
313 $image->dejaMetaTree = $trees[
'MetaTree'];
316 return $image->djvuTextTree;
318 return $image->dejaMetaTree;
328 Wikimedia\suppressWarnings();
333 $tree =
new SimpleXMLElement( $metadata, LIBXML_PARSEHUGE );
334 if ( $tree->getName() ==
'mw-djvu' ) {
336 foreach ( $tree->children() as $b ) {
337 if ( $b->getName() ==
'DjVuTxt' ) {
341 } elseif ( $b->getName() ==
'DjVuXML' ) {
348 }
catch ( Exception $e ) {
349 wfDebug(
"Bogus multipage XML metadata\n" );
351 Wikimedia\restoreWarnings();
353 return [
'MetaTree' => $metaTree,
'TextTree' => $textTree ];
363 if ( !isset( $mime ) ) {
372 wfDebug(
"Getting DjVu metadata for $path\n" );
375 if ( $xml ===
false ) {
377 return serialize( [
'error' =>
'Error extracting metadata' ] );
388 return !empty( $metadata ) && $metadata !=
serialize( [] );
394 return $info ? $info[
'pageCount'] :
false;
401 if ( $info && isset( $info[
'dimensionsByPage'][$index] ) ) {
402 return $info[
'dimensionsByPage'][$index];
409 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
410 return $cache->getWithSetCallback(
411 $cache->makeKey(
'file-djvu',
'dimensions',
$file->getSha1() ),
412 $cache::TTL_INDEFINITE,
413 function () use (
$file ) {
417 [
'pcTTL' => $cache::TTL_INDEFINITE ]
432 $count = count( $metatree->xpath(
'//OBJECT' ) );
433 for ( $i = 0; $i < $count; $i++ ) {
434 $o = $metatree->BODY[0]->OBJECT[$i];
437 'width' => (int)$o[
'width'],
438 'height' => (
int)$o[
'height'],
441 $dimsByPage[$i] =
false;
445 return [
'pageCount' => $count,
'dimensionsByPage' => $dimsByPage ];
459 $o = $tree->BODY[0]->PAGE[$page - 1];
isMetadataValid( $image, $metadata)
Check if the metadata string is valid for this handler.
Media transform output for images.
getDimensionInfoFromMetaTree( $metatree)
Given an XML metadata tree, returns dimension information about the document.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
extractTreesFromMetadata( $metadata)
Extracts metadata and text trees from metadata XML in string form.
$wgDjvuPostProcessor
Shell command for the DJVU post processor Default: pnmtojpeg, since ddjvu generates ppm output Set th...
getUnserializedMetadata(File $file)
Get metadata, unserializing it if necessary.
pageCount(File $image)
Page count for a multi-page document, false if unsupported or unknown.
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.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Convenience class for dealing with PoolCounters using callbacks.
makeParamString( $params)
$wgDjvuRenderer
Path of the ddjvu DJVU renderer Enable this and $wgDjvuDump to enable djvu rendering example: $wgDjvu...
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
const EXPENSIVE_SIZE_LIMIT
getMetadata( $image, $path)
Get handler-specific metadata which will be saved in the img_metadata field.
getDjVuImage( $image, $path)
Cache an instance of DjVuImage in an Image object, return that instance.
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.
$wgDjvuToXML
Path of the djvutoxml executable This works like djvudump except much, much slower as of version 3....
getPageDimensions(File $image, $page)
Get an associative array of page dimensions Currently "width" and "height" are understood,...
Media handler abstract base class for images.
isExpensiveToThumbnail( $file)
True if creating thumbnails from the file is large or otherwise resource-intensive.
validateParam( $name, $value)
$wgDjvuOutputExtension
File extension for the DJVU post processor output.
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)
Get an image size array like that returned by getimagesize(), or false if it can't be determined.
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.
getScriptParams( $params)
unserialize( $serialized)
getThumbType( $ext, $mime, $params=null)
Get the thumbnail extension and MIME type for a given source MIME type.
doTransform( $image, $dstPath, $dstUrl, $params, $flags=0)
getMetaTree( $image, $gettext=false)
Cache a document tree for the DjVu XML metadata.
if(!is_readable( $file)) $ext
$wgDjvuDump
Path of the djvudump executable Enable this and $wgDjvuRenderer to enable djvu rendering example: $wg...
getPageText(File $image, $page)
getDimensionInfo(File $file)
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...