$this->runParsoid = isset( $options['run-parsoid'] );
$this->djVuSupport = new DjVuSupport();
- $this->tidySupport = new TidySupport();
+ $this->tidySupport = new TidySupport( isset( $options['use-tidy-config'] ) );
if ( !$this->tidySupport->isEnabled() ) {
echo "Warning: tidy is not installed, skipping some tests\n";
}
* @return RequestContext
*/
private function setupGlobals( $opts = '', $config = '' ) {
- global $IP;
-
# Find out values for some special options.
$lang =
self::getOptionValue( 'language', $opts, 'en' );
'wgDisableLangConversion' => false,
'wgDisableTitleConversion' => false,
// Tidy options.
- 'wgUseTidy' => isset( $opts['tidy'] ),
- 'wgTidyConfig' => null,
- 'wgDebugTidy' => false,
- 'wgTidyConf' => $IP . '/includes/tidy/tidy.conf',
- 'wgTidyOpts' => '',
- 'wgTidyInternal' => $this->tidySupport->isInternal(),
+ 'wgUseTidy' => false,
+ 'wgTidyConfig' => isset( $opts['tidy'] ) ? $this->tidySupport->getConfig() : null
];
if ( $config ) {
$this->djVuSupport = new DjVuSupport();
// Tidy support
$this->tidySupport = new TidySupport();
- $tmpGlobals['wgTidyConfig'] = null;
+ $tmpGlobals['wgTidyConfig'] = $this->tidySupport->getConfig();
$tmpGlobals['wgUseTidy'] = false;
- $tmpGlobals['wgDebugTidy'] = false;
- $tmpGlobals['wgTidyConf'] = $IP . '/includes/tidy/tidy.conf';
- $tmpGlobals['wgTidyOpts'] = '';
- $tmpGlobals['wgTidyInternal'] = $this->tidySupport->isInternal();
$this->setMwGlobals( $tmpGlobals );
'wgMathDirectory' => $uploadDir . '/math',
'wgDefaultLanguageVariant' => $variant,
'wgLinkHolderBatchSize' => $linkHolderBatchSize,
- 'wgUseTidy' => isset( $opts['tidy'] ),
+ 'wgUseTidy' => false,
+ 'wgTidyConfig' => isset( $opts['tidy'] ) ? $this->tidySupport->getConfig() : null
];
if ( $config ) {
* Initialize and detect the tidy support
*/
class TidySupport {
- private $internalTidy;
- private $externalTidy;
+ private $enabled;
+ private $config;
/**
* Determine if there is a usable tidy.
*/
- public function __construct() {
- global $wgTidyBin;
-
- $this->internalTidy = extension_loaded( 'tidy' ) &&
- class_exists( 'tidy' ) && !wfIsHHVM();
-
- $this->externalTidy = is_executable( $wgTidyBin ) ||
- Installer::locateExecutableInDefaultPaths( [ $wgTidyBin ] )
- !== false;
- }
-
- /**
- * Returns true if we should use internal tidy.
- *
- * @return bool
- */
- public function isInternal() {
- return $this->internalTidy;
+ public function __construct( $useConfiguration = false ) {
+ global $IP, $wgUseTidy, $wgTidyBin, $wgTidyInternal, $wgTidyConfig,
+ $wgTidyConf, $wgTidyOpts;
+
+ $this->enabled = true;
+ if ( $useConfiguration ) {
+ if ( $wgTidyConfig !== null ) {
+ $this->config = $wgTidyConfig;
+ } elseif ( $wgUseTidy ) {
+ $this->config = [
+ 'tidyConfigFile' => $wgTidyConf,
+ 'debugComment' => false,
+ 'tidyBin' => $wgTidyBin,
+ 'tidyCommandLine' => $wgTidyOpts
+ ];
+ if ( $wgTidyInternal ) {
+ $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
+ } else {
+ $this->config['driver'] = 'RaggettExternal';
+ }
+ } else {
+ $this->enabled = false;
+ }
+ } else {
+ $this->config = [
+ 'tidyConfigFile' => "$IP/includes/tidy/tidy.conf",
+ 'tidyCommandLine' => '',
+ ];
+ if ( extension_loaded( 'tidy' ) && class_exists( 'tidy' ) ) {
+ $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
+ } else {
+ if ( is_executable( $wgTidyBin ) ) {
+ $this->config['driver'] = 'RaggettExternal';
+ $this->config['tidyBin'] = $wgTidyBin;
+ } else {
+ $path = Installer::locateExecutableInDefaultPaths( $wgTidyBin );
+ if ( $path !== false ) {
+ $this->config['driver'] = 'RaggettExternal';
+ $this->config['tidyBin'] = $wgTidyBin;
+ } else {
+ $this->enabled = false;
+ }
+ }
+ }
+ }
+ if ( !$this->enabled ) {
+ $this->config = [ 'driver' => 'disabled' ];
+ }
}
/**
* @return bool
*/
public function isEnabled() {
- return $this->internalTidy || $this->externalTidy;
+ return $this->enabled;
+ }
+
+ public function getConfig() {
+ return $this->config;
}
}