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
24 * Initialize and detect the tidy support
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 ) {
43 'tidyConfigFile' => $wgTidyConf,
44 'debugComment' => false,
45 'tidyBin' => $wgTidyBin,
46 'tidyCommandLine' => $wgTidyOpts
48 if ( $wgTidyInternal ) {
49 $this->config
['driver'] = wfIsHHVM() ?
'RaggettInternalHHVM' : 'RaggettInternalPHP';
51 $this->config
['driver'] = 'RaggettExternal';
54 $this->enabled
= false;
58 'tidyConfigFile' => "$IP/includes/tidy/tidy.conf",
59 'tidyCommandLine' => '',
61 if ( extension_loaded( 'tidy' ) && class_exists( 'tidy' ) ) {
62 $this->config
['driver'] = wfIsHHVM() ?
'RaggettInternalHHVM' : 'RaggettInternalPHP';
64 if ( is_executable( $wgTidyBin ) ) {
65 $this->config
['driver'] = 'RaggettExternal';
66 $this->config
['tidyBin'] = $wgTidyBin;
68 $path = Installer
::locateExecutableInDefaultPaths( $wgTidyBin );
69 if ( $path !== false ) {
70 $this->config
['driver'] = 'RaggettExternal';
71 $this->config
['tidyBin'] = $wgTidyBin;
73 $this->enabled
= false;
78 if ( !$this->enabled
) {
79 $this->config
= [ 'driver' => 'disabled' ];
84 * Returns true if tidy is usable
88 public function isEnabled() {
89 return $this->enabled
;
92 public function getConfig() {