continue;
}
+ if ( $this->section == 'endtransparenthooks' ) {
+ $this->checkSection( 'transparenthooks' );
+
+ foreach ( explode( "\n", $this->sectionData['transparenthooks'] ) as $line ) {
+ $line = trim( $line );
+
+ if ( $line ) {
+ $delayedParserTest->requireTransparentHook( $line );
+ }
+ }
+
+ $this->clearSection();
+
+ continue;
+ }
+
if ( $this->section == 'end' ) {
$this->checkSection( 'test' );
// "input" and "result" are old section names allowed
/** Initialized on construction */
private $hooks;
private $fnHooks;
+ private $transparentHooks;
public function __construct() {
$this->reset();
public function reset() {
$this->hooks = array();
$this->fnHooks = array();
+ $this->transparentHooks = array();
}
/**
}
}
+ # Trigger delayed transparent hooks. Any failure will make us abort
+ foreach ( $this->transparentHooks as $hook ) {
+ $ret = $parserTest->requireTransparentHook( $hook );
+ if ( !$ret ) {
+ return false;
+ }
+ }
+
# Delayed execution was successful.
return true;
}
$this->fnHooks[] = $fnHook;
}
+ /**
+ * Similar to ParserTest object but does not run anything
+ * Use unleash() to really execute the hook function
+ * @param string $fnHook
+ */
+ public function requireTransparentHook( $hook ) {
+ $this->transparentHooks[] = $hook;
+ }
+
+}
+
+/**
+ * Initialize and detect the DjVu files support
+ */
+class DjVuSupport {
+
+ /**
+ * Initialises DjVu tools global with default values
+ */
+ public function __construct() {
+ global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML, $wgFileExtensions, $wgDjvuTxt;
+
+ $wgDjvuRenderer = $wgDjvuRenderer ? $wgDjvuRenderer : '/usr/bin/ddjvu';
+ $wgDjvuDump = $wgDjvuDump ? $wgDjvuDump : '/usr/bin/djvudump';
+ $wgDjvuToXML = $wgDjvuToXML ? $wgDjvuToXML : '/usr/bin/djvutoxml';
+ $wgDjvuTxt = $wgDjvuTxt ? $wgDjvuTxt : '/usr/bin/djvutxt';
+
+ if ( !in_array( 'djvu', $wgFileExtensions ) ) {
+ $wgFileExtensions[] = 'djvu';
+ }
+ }
+
+ /**
+ * Returns if the DjVu tools are usable
+ *
+ * @return bool
+ */
+ public function isEnabled() {
+ global $wgDjvuRenderer, $wgDjvuDump, $wgDjvuToXML, $wgDjvuTxt;
+
+ return is_executable( $wgDjvuRenderer )
+ && is_executable( $wgDjvuDump )
+ && is_executable( $wgDjvuToXML )
+ && is_executable( $wgDjvuTxt );
+ }
}