TidySupport.php 2.0 KB

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