48 $this->mFilename = $filename;
58 return $info !==
false;
68 if (
$data !==
false ) {
69 $width =
$data[
'width'];
70 $height =
$data[
'height'];
72 return [ $width, $height,
'DjVu',
73 "width=\"$width\" height=\"$height\"" ];
85 $file = fopen( $this->mFilename,
'rb' );
87 $arr = unpack(
'a4magic/a4chunk/NchunkLength',
$header );
88 $chunk = $arr[
'chunk'];
89 $chunkLength = $arr[
'chunkLength'];
90 echo
"$chunk $chunkLength\n";
95 private function dumpForm( $file, $length, $indent ) {
96 $start = ftell(
$file );
97 $secondary = fread(
$file, 4 );
98 echo str_repeat(
' ', $indent * 4 ) .
"($secondary)\n";
99 while ( ftell(
$file ) - $start < $length ) {
100 $chunkHeader = fread(
$file, 8 );
101 if ( $chunkHeader ==
'' ) {
104 $arr = unpack(
'a4chunk/NchunkLength', $chunkHeader );
105 $chunk = $arr[
'chunk'];
106 $chunkLength = $arr[
'chunkLength'];
107 echo str_repeat(
' ', $indent * 4 ) .
"$chunk $chunkLength\n";
109 if ( $chunk ==
'FORM' ) {
112 fseek(
$file, $chunkLength, SEEK_CUR );
113 if ( ( $chunkLength & 1 ) == 1 ) {
115 fseek(
$file, 1, SEEK_CUR );
122 Wikimedia\suppressWarnings();
123 $file = fopen( $this->mFilename,
'rb' );
124 Wikimedia\restoreWarnings();
125 if (
$file ===
false ) {
126 wfDebug( __METHOD__ .
": missing or failed file read\n" );
134 if ( strlen(
$header ) < 16 ) {
135 wfDebug( __METHOD__ .
": too short file header\n" );
137 $arr = unpack(
'a4magic/a4form/NformLength/a4subtype',
$header );
139 $subtype = $arr[
'subtype'];
140 if ( $arr[
'magic'] !=
'AT&T' ) {
141 wfDebug( __METHOD__ .
": not a DjVu file\n" );
142 } elseif ( $subtype ==
'DJVU' ) {
145 } elseif ( $subtype ==
'DJVM' ) {
149 wfDebug( __METHOD__ .
": unrecognized DJVU file type '{$arr['subtype']}'\n" );
162 $arr = unpack(
'a4chunk/Nlength',
$header );
164 return [ $arr[
'chunk'], $arr[
'length'] ];
169 fseek(
$file, $chunkLength, SEEK_CUR );
171 if ( ( $chunkLength & 0x01 ) == 1 && !feof(
$file ) ) {
173 fseek(
$file, 1, SEEK_CUR );
180 $start = ftell(
$file );
187 if ( $chunk ==
'FORM' ) {
188 $subtype = fread(
$file, 4 );
189 if ( $subtype ==
'DJVU' ) {
190 wfDebug( __METHOD__ .
": found first subpage\n" );
196 wfDebug( __METHOD__ .
": skipping '$chunk' chunk\n" );
199 }
while ( $length != 0 && !feof(
$file ) && ftell(
$file ) - $start < $formLength );
201 wfDebug( __METHOD__ .
": multi-page DJVU file contained no pages\n" );
208 if ( $chunk !=
'INFO' ) {
209 wfDebug( __METHOD__ .
": expected INFO chunk, got '$chunk'\n" );
215 wfDebug( __METHOD__ .
": INFO should be 9 or 10 bytes, found $length\n" );
220 if ( strlen(
$data ) < $length ) {
221 wfDebug( __METHOD__ .
": INFO chunk cut off\n" );
234 # Newer files have rotation info in byte 10, but we don't use it yet.
237 'width' => $arr[
'width'],
238 'height' => $arr[
'height'],
239 'version' =>
"{$arr['major']}.{$arr['minor']}",
240 'resolution' => $arr[
'resolution'],
241 'gamma' => $arr[
'gamma'] / 10.0 ];
256 # djvudump is faster as of version 3.5
258 $cmd = Shell::escape(
$wgDjvuDump ) .
' ' . Shell::escape( $this->mFilename );
262 $cmd = Shell::escape(
$wgDjvuToXML ) .
' --without-anno --without-text ' .
263 Shell::escape( $this->mFilename );
270 $cmd = Shell::escape(
$wgDjvuTxt ) .
' --detail=page ' . Shell::escape( $this->mFilename );
271 wfDebug( __METHOD__ .
": $cmd\n" );
273 $txt =
wfShellExec( $cmd, $retval, [], [
'memory' => self::DJVUTXT_MEMORY_LIMIT ] );
274 if ( $retval == 0 ) {
275 # Strip some control characters
276 $txt = preg_replace(
"/[\013\035\037]/",
"", $txt );
278 /\(page\s[\d-]*\s[\d-]*\s[\d-]*\s[\d-]*\s*
"
279 ((?> # Text to match is composed of atoms of either:
280 \\\\. # - any escaped character
281 | # - any character different from " and \
285 | # Or
page can be empty ;
in this case, djvutxt dumps ()
288 $txt = preg_replace_callback( $reg, [ $this,
'pageTextCallback' ], $txt );
289 $txt =
"<DjVuTxt>\n<HEAD></HEAD>\n<BODY>\n" . $txt .
"</BODY>\n</DjVuTxt>\n";
290 $xml = preg_replace(
"/<DjVuXML>/",
"<mw-djvu><DjVuXML>", $xml, 1 ) .
300 # Get rid of invalid UTF-8, strip control characters
301 $val = htmlspecialchars( UtfNormal\Validator::cleanUp( stripcslashes(
$matches[1] ) ) );
302 $val = str_replace( [
"\n",
'�' ], [
' ',
'' ], $val );
303 return '<PAGE value="' . $val .
'" />';
312 if ( strval( $dump ) ==
'' ) {
318<!DOCTYPE DjVuXML PUBLIC
"-//W3C//DTD DjVuXML 1.1//EN" "pubtext/DjVuXML-s.dtd">
324 $dump = str_replace(
"\r",
'', $dump );
325 $line = strtok( $dump,
"\n" );
328 if ( preg_match(
'/^( *)FORM:DJVU/',
$line, $m ) ) {
335 } elseif ( preg_match(
'/^( *)FORM:DJVM/',
$line, $m ) ) {
337 $parentLevel = strlen( $m[1] );
339 $line = strtok(
"\n" );
340 while (
$line !==
false ) {
341 $childLevel = strspn(
$line,
' ' );
342 if ( $childLevel <= $parentLevel ) {
347 if ( preg_match(
'/^ *DIRM.*indirect/',
$line ) ) {
348 wfDebug(
"Indirect multi-page DjVu document, bad for server!\n" );
352 if ( preg_match(
'/^ *FORM:DJVU/',
$line ) ) {
360 $line = strtok(
"\n" );
367 $xml .=
"</BODY>\n</DjVuXML>\n";
373 $parentLevel = strspn(
$line,
' ' );
374 $line = strtok(
"\n" );
377 while (
$line !==
false ) {
378 $childLevel = strspn(
$line,
' ' );
379 if ( $childLevel <= $parentLevel ) {
385 '/^ *INFO *\[\d*\] *DjVu *(\d+)x(\d+), *\w*, *(\d+) *dpi, *gamma=([0-9.-]+)/',
393 #
'type' =>
'image/x.djvu',
399 Xml::element(
'PARAM', [
'name' =>
'DPI',
'value' => $m[3] ] ) .
"\n" .
400 Xml::element(
'PARAM', [
'name' =>
'GAMMA',
'value' => $m[4] ] ) .
"\n"
405 $line = strtok(
"\n" );
and(b) You must cause any modified files to carry prominent notices stating that You changed the files
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgDjvuToXML
Path of the djvutoxml executable This works like djvudump except much, much slower as of version 3....
$wgDjvuTxt
Path of the djvutxt DJVU text extraction utility Enable this and $wgDjvuDump to enable text layer ext...
$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...
Support for detecting/validating DjVu image files and getting some basic file metadata (resolution et...
convertDumpToXML( $dump)
Hack to temporarily work around djvutoxml bug.
parseFormDjvu( $line, &$xml)
retrieveMetaData()
Return an XML string describing the DjVu image.
const DJVUTXT_MEMORY_LIMIT
@const DJVUTXT_MEMORY_LIMIT Memory limit for the DjVu description software
skipChunk( $file, $chunkLength)
dumpForm( $file, $length, $indent)
pageTextCallback( $matches)
dump()
For debugging; dump the IFF chunk structure.
isValid()
Check if the given file is indeed a valid DjVu image file.
getMultiPageInfo( $file, $formLength)
getImageSize()
Return data in the style of getimagesize()
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
null for the local wiki Added in
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file