Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / tests / parser / TidySupport.php
blob6b5fb4847f102116c3c4b2574c811e1e70023800
1 <?php
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
19 * @file
20 * @ingroup Testing
23 /**
24 * Initialize and detect the tidy support
26 class TidySupport {
27 private $enabled;
28 private $config;
30 /**
31 * Determine if there is a usable tidy.
33 public function __construct( $useConfiguration = false ) {
34 global $IP, $wgUseTidy, $wgTidyBin, $wgTidyInternal, $wgTidyConfig,
35 $wgTidyConf, $wgTidyOpts;
37 $this->enabled = true;
38 if ( $useConfiguration ) {
39 if ( $wgTidyConfig !== null ) {
40 $this->config = $wgTidyConfig;
41 } elseif ( $wgUseTidy ) {
42 $this->config = [
43 'tidyConfigFile' => $wgTidyConf,
44 'debugComment' => false,
45 'tidyBin' => $wgTidyBin,
46 'tidyCommandLine' => $wgTidyOpts
48 if ( $wgTidyInternal ) {
49 $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
50 } else {
51 $this->config['driver'] = 'RaggettExternal';
53 } else {
54 $this->enabled = false;
56 } else {
57 $this->config = [
58 'tidyConfigFile' => "$IP/includes/tidy/tidy.conf",
59 'tidyCommandLine' => '',
61 if ( extension_loaded( 'tidy' ) && class_exists( 'tidy' ) ) {
62 $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
63 } else {
64 if ( is_executable( $wgTidyBin ) ) {
65 $this->config['driver'] = 'RaggettExternal';
66 $this->config['tidyBin'] = $wgTidyBin;
67 } else {
68 $path = Installer::locateExecutableInDefaultPaths( $wgTidyBin );
69 if ( $path !== false ) {
70 $this->config['driver'] = 'RaggettExternal';
71 $this->config['tidyBin'] = $wgTidyBin;
72 } else {
73 $this->enabled = false;
78 if ( !$this->enabled ) {
79 $this->config = [ 'driver' => 'disabled' ];
83 /**
84 * Returns true if tidy is usable
86 * @return bool
88 public function isEnabled() {
89 return $this->enabled;
92 public function getConfig() {
93 return $this->config;