Merge "Added a separate error message for mkdir failures"
[lhc/web/wiklou.git] / tests / parser / TidySupport.php
1 <?php
2
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.
8 *
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.
13 *
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
18 *
19 * @file
20 * @ingroup Testing
21 */
22
23 /**
24 * Initialize and detect the tidy support
25 */
26 class TidySupport {
27 private $enabled;
28 private $config;
29
30 /**
31 * Determine if there is a usable tidy.
32 */
33 public function __construct( $useConfiguration = false ) {
34 global $IP, $wgUseTidy, $wgTidyBin, $wgTidyInternal, $wgTidyConfig,
35 $wgTidyConf, $wgTidyOpts;
36
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
47 ];
48 if ( $wgTidyInternal ) {
49 $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
50 } else {
51 $this->config['driver'] = 'RaggettExternal';
52 }
53 } else {
54 $this->enabled = false;
55 }
56 } else {
57 $this->config = [
58 'tidyConfigFile' => "$IP/includes/tidy/tidy.conf",
59 'tidyCommandLine' => '',
60 ];
61 if ( extension_loaded( 'tidy' ) && ( wfIsHHVM() || 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;
74 }
75 }
76 }
77 }
78 if ( !$this->enabled ) {
79 $this->config = [ 'driver' => 'disabled' ];
80 }
81 }
82
83 /**
84 * Returns true if tidy is usable
85 *
86 * @return bool
87 */
88 public function isEnabled() {
89 return $this->enabled;
90 }
91
92 public function getConfig() {
93 return $this->config;
94 }
95 }