Merge "Add attributes parameter to ShowSearchHitTitle"
[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 * @param bool $useConfiguration
33 */
34 public function __construct( $useConfiguration = false ) {
35 global $IP, $wgUseTidy, $wgTidyBin, $wgTidyInternal, $wgTidyConfig,
36 $wgTidyConf, $wgTidyOpts;
37
38 $this->enabled = true;
39 if ( $useConfiguration ) {
40 if ( $wgTidyConfig !== null ) {
41 $this->config = $wgTidyConfig;
42 } elseif ( $wgUseTidy ) {
43 $this->config = [
44 'tidyConfigFile' => $wgTidyConf,
45 'debugComment' => false,
46 'tidyBin' => $wgTidyBin,
47 'tidyCommandLine' => $wgTidyOpts
48 ];
49 if ( $wgTidyInternal ) {
50 $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
51 } else {
52 $this->config['driver'] = 'RaggettExternal';
53 }
54 } else {
55 $this->enabled = false;
56 }
57 } else {
58 $this->config = [
59 'tidyConfigFile' => "$IP/includes/tidy/tidy.conf",
60 'tidyCommandLine' => '',
61 ];
62 if ( extension_loaded( 'tidy' ) && ( wfIsHHVM() || class_exists( 'tidy' ) ) ) {
63 $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP';
64 } else {
65 if ( is_executable( $wgTidyBin ) ) {
66 $this->config['driver'] = 'RaggettExternal';
67 $this->config['tidyBin'] = $wgTidyBin;
68 } else {
69 $path = ExecutableFinder::findInDefaultPaths( $wgTidyBin );
70 if ( $path !== false ) {
71 $this->config['driver'] = 'RaggettExternal';
72 $this->config['tidyBin'] = $wgTidyBin;
73 } else {
74 $this->enabled = false;
75 }
76 }
77 }
78 }
79 if ( !$this->enabled ) {
80 $this->config = [ 'driver' => 'disabled' ];
81 }
82 }
83
84 /**
85 * Returns true if tidy is usable
86 *
87 * @return bool
88 */
89 public function isEnabled() {
90 return $this->enabled;
91 }
92
93 public function getConfig() {
94 return $this->config;
95 }
96 }