Merge "Add support for 'hu-formal'"
[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 $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 = [ 'driver' => 'RemexHtml' ];
59 }
60 if ( !$this->enabled ) {
61 $this->config = [ 'driver' => 'disabled' ];
62 }
63 }
64
65 /**
66 * Returns true if tidy is usable
67 *
68 * @return bool
69 */
70 public function isEnabled() {
71 return $this->enabled;
72 }
73
74 public function getConfig() {
75 return $this->config;
76 }
77 }