38 wfDebug(
"DjVu is disabled, please set \$wgDjvuRenderer and \$wgDjvuDump\n" );
60 return $file->getSize() > static::EXPENSIVE_SIZE_LIMIT;
76 'img_width' =>
'width',
87 if ( $name ===
'page' && trim(
$value ) !== (
string)intval(
$value ) ) {
92 if ( in_array( $name, [
'width',
'height',
'page' ] ) ) {
109 if ( !isset(
$params[
'width'] ) ) {
113 return "page{$page}-{$params['width']}px";
122 if ( preg_match(
'/^page(\d+)-(\d+)px$/', $str, $m ) ) {
123 return [
'width' => $m[2],
'page' => $m[1] ];
158 if ( $flags & self::TRANSFORM_LATER ) {
180 if (
$image->getSize() >= 1e7 ) {
184 return $image->getLocalRefPath();
190 $srcPath =
$image->getLocalRefPath();
193 if ( $srcPath ===
false ) {
195 sprintf(
'Thumbnail failed on %s: could not get local copy of "%s"',
204 # Use a subshell (brackets) to aggregate stderr from both pipeline commands
205 # before redirecting it to the overall stdout. This works in both Linux and Windows XP.
210 "-size={$params['physicalWidth']}x{$params['physicalHeight']}",
213 $cmd .=
" | {$wgDjvuPostProcessor}";
216 wfDebug( __METHOD__ .
": $cmd\n" );
221 if (
$retval != 0 || $removed ) {
245 } elseif ( !isset(
$image->dejaImage ) ) {
248 $deja =
$image->dejaImage;
262 $metadata = $file->getMetadata();
263 if ( substr( $metadata, 0, 3 ) ===
'<?xml' ) {
268 Wikimedia\suppressWarnings();
270 Wikimedia\restoreWarnings();
271 if ( is_array( $unser ) ) {
272 if ( isset( $unser[
'error'] ) ) {
274 } elseif ( isset( $unser[
'xml'] ) ) {
275 return $unser[
'xml'];
278 throw new MWException(
"Error unserializing DjVu metadata." );
293 if ( $gettext && isset(
$image->djvuTextTree ) ) {
294 return $image->djvuTextTree;
296 if ( !$gettext && isset(
$image->dejaMetaTree ) ) {
297 return $image->dejaMetaTree;
302 wfDebug(
"DjVu XML metadata is invalid or missing, should have been fixed in upgradeRow\n" );
308 $image->djvuTextTree = $trees[
'TextTree'];
309 $image->dejaMetaTree = $trees[
'MetaTree'];
312 return $image->djvuTextTree;
314 return $image->dejaMetaTree;
324 Wikimedia\suppressWarnings();
329 $tree =
new SimpleXMLElement( $metadata, LIBXML_PARSEHUGE );
330 if ( $tree->getName() ==
'mw-djvu' ) {
332 foreach ( $tree->children() as $b ) {
333 if ( $b->getName() ==
'DjVuTxt' ) {
337 } elseif ( $b->getName() ==
'DjVuXML' ) {
344 }
catch ( Exception
$e ) {
345 wfDebug(
"Bogus multipage XML metadata\n" );
347 Wikimedia\restoreWarnings();
349 return [
'MetaTree' => $metaTree,
'TextTree' => $textTree ];
359 if ( !isset(
$mime ) ) {
360 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
368 wfDebug(
"Getting DjVu metadata for $path\n" );
371 if ( $xml ===
false ) {
373 return serialize( [
'error' =>
'Error extracting metadata' ] );
384 return !empty( $metadata ) && $metadata !=
serialize( [] );
390 return $info ? $info[
'pageCount'] :
false;
397 if ( $info && isset( $info[
'dimensionsByPage'][$index] ) ) {
398 return $info[
'dimensionsByPage'][$index];
405 $cache = ObjectCache::getMainWANInstance();
406 return $cache->getWithSetCallback(
407 $cache->makeKey(
'file-djvu',
'dimensions', $file->getSha1() ),
408 $cache::TTL_INDEFINITE,
413 [
'pcTTL' => $cache::TTL_INDEFINITE ]
428 $count = count( $metatree->xpath(
'//OBJECT' ) );
429 for ( $i = 0; $i < $count; $i++ ) {
430 $o = $metatree->BODY[0]->OBJECT[$i];
433 'width' => (int)$o[
'width'],
434 'height' => (
int)$o[
'height'],
437 $dimsByPage[$i] =
false;
441 return [
'pageCount' => $count,
'dimensionsByPage' => $dimsByPage ];
455 $o = $tree->BODY[0]->PAGE[$page - 1];
unserialize( $serialized)
$wgDjvuRenderer
Path of the ddjvu DJVU renderer Enable this and $wgDjvuDump to enable djvu rendering example: $wgDjvu...
$wgDjvuOutputExtension
File extension for the DJVU post processor output.
$wgDjvuToXML
Path of the djvutoxml executable This works like djvudump except much, much slower as of version 3....
$wgDjvuPostProcessor
Shell command for the DJVU post processor Default: pnmtojpeg, since ddjvu generates ppm output Set th...
$wgDjvuDump
Path of the djvudump executable Enable this and $wgDjvuRenderer to enable djvu rendering example: $wg...
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfShellExec( $cmd, &$retval=null, $environ=[], $limits=[], $options=[])
Execute a shell command, with time and memory limits mirrored from the PHP configuration if supported...
wfHostname()
Fetch server name for use in error reporting etc.
wfEscapeShellArg()
Version of escapeshellarg() that works better on Windows.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
getDimensionInfoFromMetaTree( $metatree)
Given an XML metadata tree, returns dimension information about the document.
getDjVuImage( $image, $path)
Cache an instance of DjVuImage in an Image object, return that instance.
makeParamString( $params)
isExpensiveToThumbnail( $file)
True if creating thumbnails from the file is large or otherwise resource-intensive.
validateParam( $name, $value)
getDimensionInfo(File $file)
const EXPENSIVE_SIZE_LIMIT
getScriptParams( $params)
doTransform( $image, $dstPath, $dstUrl, $params, $flags=0)
pageCount(File $image)
Page count for a multi-page document, false if unsupported or unknown.
getPageText(File $image, $page)
isMetadataValid( $image, $metadata)
Check if the metadata string is valid for this handler.
getPageDimensions(File $image, $page)
Get an associative array of page dimensions Currently "width" and "height" are understood,...
getMetadataType( $image)
Get a string describing the type of metadata, for display purposes.
getMetaTree( $image, $gettext=false)
Cache a document tree for the DjVu XML metadata.
getThumbType( $ext, $mime, $params=null)
Get the thumbnail extension and MIME type for a given source MIME type.
getUnserializedMetadata(File $file)
Get metadata, unserializing it if neccessary.
extractTreesFromMetadata( $metadata)
Extracts metadata and text trees from metadata XML in string form.
getMetadata( $image, $path)
Get handler-specific metadata which will be saved in the img_metadata field.
getImageSize( $image, $path)
Get an image size array like that returned by getimagesize(), or false if it can't be determined.
Support for detecting/validating DjVu image files and getting some basic file metadata (resolution et...
Implements some public methods and some protected utility functions which are required by multiple ch...
Media handler abstract base class for images.
normaliseParams( $image, &$params)
Convenience class for dealing with PoolCounters using callbacks.
execute( $skipcache=false)
Get the result of the work (whatever it is), or the result of the error() function.
Media transform output for images.
when a variable name is used in a function
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
returning false will NOT prevent logging $e
if( $ext=='php'|| $ext=='php5') $mime
if(!is_readable( $file)) $ext