'TestFileIterator' => "$testDir/testHelpers.inc",
'TestRecorder' => "$testDir/testHelpers.inc",
'ITestRecorder' => "$testDir/testHelpers.inc",
+ 'DjVuSupport' => "$testDir/testHelpers.inc",
# tests/phpunit
'MediaWikiTestCase' => "$testDir/phpunit/MediaWikiTestCase.php",
'MockBitmapHandler' => "$testDir/phpunit/mocks/media/MockBitmapHandler.php",
'MockImageHandler' => "$testDir/phpunit/mocks/media/MockImageHandler.php",
'MockSvgHandler' => "$testDir/phpunit/mocks/media/MockSvgHandler.php",
+ 'MockDjVuHandler' => "$testDir/phpunit/mocks/media/MockDjVuHandler.php",
# tests/parser
'NewParserTest' => "$testDir/phpunit/includes/parser/NewParserTest.php",
*/
private $dbClone;
+ /**
+ * @var DjVuSupport
+ */
+ private $djVuSupport;
+
/**
* @var string $oldTablePrefix Original table prefix
*/
$this->runDisabled = isset( $options['run-disabled'] );
$this->runParsoid = isset( $options['run-parsoid'] );
+ $this->djVuSupport = new DjVuSupport();
+
$this->hooks = array();
$this->functionHooks = array();
self::setUp();
$user = $context->getUser();
$options = ParserOptions::newFromContext( $context );
+ if ( isset( $opts['djvu'] ) ) {
+ if ( !$this->djVuSupport->isEnabled() ) {
+ return $this->showSkipped();
+ }
+ }
+
if ( isset( $opts['title'] ) ) {
$titleText = $opts['title'];
} else {
'sha1' => wfBaseConvert( '3', 16, 36, 31 ),
'fileExists' => true
), $this->db->timestamp( '20010115123500' ), $user );
+
+ # A DjVu file
+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
+ $image->recordUpload2( '', 'Upload a DjVu', 'A DjVu', array(
+ 'size' => 3249,
+ 'width' => 2480,
+ 'height' => 3508,
+ 'media_type' => MEDIATYPE_BITMAP,
+ 'mime' => 'image/vnd.djvu',
+ 'metadata' => '<?xml version="1.0" ?>
+<!DOCTYPE DjVuXML PUBLIC "-//W3C//DTD DjVuXML 1.1//EN" "pubtext/DjVuXML-s.dtd">
+<DjVuXML>
+<HEAD></HEAD>
+<BODY><OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+</BODY>
+</DjVuXML>',
+ 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+ 'fileExists' => true
+ ), $this->db->timestamp( '20010115123600' ), $user );
}
public function teardownDatabase() {
'<?xml version="1.0" encoding="utf-8"?>' .
'<svg xmlns="http://www.w3.org/2000/svg"' .
' version="1.1" width="240" height="180"/>' );
+ wfMkdirParents( $dir . '/5/5f', null, __METHOD__ );
+ copy( "$IP/tests/phpunit/data/media/LoremIpsum.djvu", "$dir/5/5f/LoremIpsum.djvu" );
+
return $dir;
}
"$dir/0/09/Bad.jpg",
+ "$dir/5/5f/LoremIpsum.djvu",
+ "$dir/thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg",
+ "$dir/thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg",
+ "$dir/thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg",
+
"$dir/f/ff/Foobar.svg",
"$dir/thumb/f/ff/Foobar.svg/180px-Foobar.svg.png",
"$dir/thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png",
"$dir/thumb/f/",
"$dir/0/09/",
"$dir/0/",
+ "$dir/5/5f",
+ "$dir/5",
+ "$dir/thumb/5/5f/LoremIpsum.djvu",
+ "$dir/thumb/5/5f",
+ "$dir/thumb/5",
"$dir/thumb",
"$dir/math/f/a/5",
"$dir/math/f/a",
return false;
}
+ /**
+ * Print a skipped message.
+ *
+ * @return boolean
+ */
+ protected function showSkipped() {
+ if ( $this->showProgress ) {
+ print $this->term->color( '1;33' ) . 'SKIPPED' . $this->term->reset() . "\n";
+ }
+
+ return true;
+ }
+
/**
* Run given strings through a diff and return the (colorized) output.
* Requires writable /tmp directory and a 'diff' command in the PATH.
!! wikitext
{{NUMBEROFFILES}}
!! html
-<p>4
+<p>5
</p>
!! end
</p>
!!end
+!! test
+Image with page parameter
+!! options
+djvu
+!! wikitext
+[[File:LoremIpsum.djvu|page=2]]
+!! html
+<p><a href="/index.php?title=File:LoremIpsum.djvu&page=2" class="image"><img alt="LoremIpsum.djvu" src="http://example.com/images/thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg" width="2480" height="3508" srcset="http://example.com/images/thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg 1.5x, http://example.com/images/thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg 2x" /></a>
+</p>
+!! end
+
!! test
Another italics / bold test
!! wikitext
protected $handler;
protected function setUp() {
- global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML;
parent::setUp();
//cli tool setup
- $wgDjvuRenderer = $wgDjvuRenderer ? $wgDjvuRenderer : '/usr/bin/ddjvu';
- $wgDjvuDump = $wgDjvuDump ? $wgDjvuDump : '/usr/bin/djvudump';
- $wgDjvuToXML = $wgDjvuToXML ? $wgDjvuToXML : '/usr/bin/djvutoxml';
- if (
- !$this->checkIfToolExists( $wgDjvuRenderer ) ||
- !$this->checkIfToolExists( $wgDjvuDump ) ||
- !$this->checkIfToolExists( $wgDjvuToXML )
- ) {
- $this->markTestSkipped( 'This test needs the installation of the '
- . 'ddjvu, djvutoxml and djvudump tools' );
+ $djvuSupport = new DjVuSupport();
+
+ if ( !$djvuSupport->isEnabled() ) {
+ $this->markTestSkipped( 'This test needs the installation of the ddjvu, djvutoxml and djvudump tools' );
}
//file repo setup
$this->handler = new DjVuHandler();
}
- /**
- * Check if a tool exist
- *
- * @param string $path path to the tool
- * @return bool
- */
- protected function checkIfToolExists( $path ) {
- wfSuppressWarnings();
- $result = file_exists( $path );
- wfRestoreWarnings();
- return $result;
- }
-
protected function dataFile( $name, $type ) {
return new UnregisteredLocalFile(
false,
public $fuzzSeed = 0;
public $memoryLimit = 50;
+ /**
+ * @var DjVuSupport
+ */
+ private $djVuSupport;
+
protected $file = false;
public static function setUpBeforeClass() {
// Vector images have to be handled slightly differently
$tmpGlobals['wgMediaHandlers']['image/svg+xml'] = 'MockSvgHandler';
+ // DjVu images have to be handled slightly differently
+ $tmpGlobals['wgMediaHandlers']['image/vnd.djvu'] = 'MockDjVuHandler';
+
$tmpHooks = $wgHooks;
$tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
$tmpHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
# proper precedence when resolving links. (bug 51680)
$tmpGlobals['wgExtraNamespaces'] = array( 100 => 'MemoryAlpha' );
+ //DjVu support
+ $this->djVuSupport = new DjVuSupport();
+
$this->setMwGlobals( $tmpGlobals );
$this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
'fileExists' => true
), $this->db->timestamp( '20010115123500' ), $user );
}
+
+ # A DjVu file
+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'LoremIpsum.djvu' ) );
+ if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
+ $image->recordUpload2( '', 'Upload a DjVu', 'A DjVu', array(
+ 'size' => 3249,
+ 'width' => 2480,
+ 'height' => 3508,
+ 'bits' => 24,
+ 'media_type' => MEDIATYPE_BITMAP,
+ 'mime' => 'image/vnd.djvu',
+ 'metadata' => '<?xml version="1.0" ?>
+<!DOCTYPE DjVuXML PUBLIC "-//W3C//DTD DjVuXML 1.1//EN" "pubtext/DjVuXML-s.dtd">
+<DjVuXML>
+<HEAD></HEAD>
+<BODY><OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+<OBJECT height="3508" width="2480">
+<PARAM name="DPI" value="300" />
+<PARAM name="GAMMA" value="2.2" />
+</OBJECT>
+</BODY>
+</DjVuXML>',
+ 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+ 'fileExists' => true
+ ), $this->db->timestamp( '20140115123600' ), $user );
+ }
}
//ParserTest setup/teardown functions
$backend->store( array(
'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/0/09/Bad.jpg"
) );
+ $backend->prepare( array( 'dir' => "$base/local-public/5/5f" ) );
+ $backend->store( array(
+ 'src' => "$IP/tests/phpunit/data/media/LoremIpsum.djvu", 'dst' => "$base/local-public/5/5f/LoremIpsum.djvu"
+ ) );
// No helpful SVG file to copy, so make one ourselves
$data = '<?xml version="1.0" encoding="utf-8"?>' .
"$base/local-public/0/09/Bad.jpg",
+ "$base/local-public/5/5f/LoremIpsum.djvu",
+ "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg",
+ "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg",
+ "$base/local-thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg",
+
"$base/local-public/f/ff/Foobar.svg",
"$base/local-thumb/f/ff/Foobar.svg/180px-Foobar.svg.png",
"$base/local-thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png",
. "Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
}
}
+ if ( isset( $opts['djvu'] ) ) {
+ if ( !$this->djVuSupport->isEnabled() ) {
+ $this->markTestSkipped( "SKIPPED: djvu binaries do not exist or are not executable.\n" );
+ }
+ }
if ( isset( $opts['pst'] ) ) {
$out = $parser->preSaveTransform( $input, $title, $user, $options );
--- /dev/null
+<?php
+/**
+ * Fake handler for DjVu images.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Media
+ */
+
+class MockDjVuHandler extends DjVuHandler {
+ function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
+ if ( !$this->normaliseParams( $image, $params ) ) {
+ return new TransformParameterError( $params );
+ }
+ $width = $params['width'];
+ $height = $params['height'];
+ $page = $params['page'];
+ if ( $page > $this->pageCount( $image ) ) {
+ return new MediaTransformError(
+ 'thumbnail_error',
+ $width,
+ $height,
+ wfMessage( 'djvu_page_error' )->text()
+ );
+ }
+
+ $params = array(
+ 'width' => $width,
+ 'height' => $height,
+ 'page' => $page
+ );
+
+ return new ThumbnailImage( $image, $dstUrl, $dstPath, $params );
+ }
+}
}
}
+
+/**
+ * Initialize and detect the DjVu files support
+ */
+class DjVuSupport {
+
+ /**
+ * Initialises DjVu tools global with default values
+ */
+ public function __construct() {
+ global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML, $wgFileExtensions;
+
+ $wgDjvuRenderer = $wgDjvuRenderer ? $wgDjvuRenderer : '/usr/bin/ddjvu';
+ $wgDjvuDump = $wgDjvuDump ? $wgDjvuDump : '/usr/bin/djvudump';
+ $wgDjvuToXML = $wgDjvuToXML ? $wgDjvuToXML : '/usr/bin/djvutoxml';
+
+ if ( !in_array( 'djvu', $wgFileExtensions ) ) {
+ $wgFileExtensions[] = 'djvu';
+ }
+ }
+
+ /**
+ * Returns if the DjVu tools are usable
+ *
+ * @return bool
+ */
+ public function isEnabled() {
+ global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML;
+
+ return is_executable( $wgDjvuRenderer )
+ && is_executable( $wgDjvuDump )
+ && is_executable( $wgDjvuToXML );
+ }
+}