r74847 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74846‎ | r74847 | r74848 >
Date:18:19, 16 October 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Make envCheckGraphics use locateExecutable(). Move path stuff to a single method
Modified paths:
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.php
@@ -383,6 +383,21 @@
384384 }
385385
386386 /**
 387+ * Get an array of likely places we can find executables. Check a bunch
 388+ * of known Unix-like defaults, as well as the PATH environment variable
 389+ * (which should maybe make it work for Windows?)
 390+ *
 391+ * @return Array
 392+ */
 393+ protected function getPossibleBinPaths() {
 394+ return array_merge(
 395+ array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
 396+ '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
 397+ explode( PATH_SEPARATOR, getenv( 'PATH' ) )
 398+ );
 399+ }
 400+
 401+ /**
387402 * Check if we're installing the latest version.
388403 */
389404 public function envLatestVersion() {
@@ -590,23 +605,12 @@
591606 * Search for GNU diff3.
592607 */
593608 public function envCheckDiff3() {
594 - $paths = array_merge(
595 - array(
596 - "/usr/bin",
597 - "/usr/local/bin",
598 - "/opt/csw/bin",
599 - "/usr/gnu/bin",
600 - "/usr/sfw/bin"
601 - ),
602 - explode( PATH_SEPARATOR, getenv( "PATH" ) )
603 - );
604 -
605609 $names = array( "gdiff3", "diff3", "diff3.exe" );
606610 $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
607611
608612 $haveDiff3 = false;
609613
610 - foreach ( $paths as $path ) {
 614+ foreach ( $this->getPossibleBinPaths() as $path ) {
611615 $exe = $this->locateExecutable( $path, $names, $versionInfo );
612616
613617 if ($exe !== false) {
@@ -628,28 +632,28 @@
629633 * Environment check for ImageMagick and GD.
630634 */
631635 public function envCheckGraphics() {
632 - $imcheck = array( "/usr/bin", "/opt/csw/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
 636+ $names = array( 'convert', 'convert.exe' );
 637+ $haveConvert = false;
633638
634 - foreach( $imcheck as $dir ) {
635 - $im = "$dir/convert";
 639+ foreach ( $this->getPossibleBinPaths() as $path ) {
 640+ $exe = $this->locateExecutable( $path, $names );
636641
637 - wfSuppressWarnings();
638 - $file_exists = file_exists( $im );
639 - wfRestoreWarnings();
640 -
641 - if( $file_exists ) {
642 - $this->showMessage( 'config-imagemagick', $im );
643 - $this->setVar( 'wgImageMagickConvertCommand', $im );
644 - return true;
 642+ if ($exe !== false) {
 643+ $this->setVar( 'wgImageMagickConvertCommand', $exe );
 644+ $haveConvert = true;
 645+ break;
645646 }
646647 }
647648
648 - if ( function_exists( 'imagejpeg' ) ) {
 649+ if ( $haveConvert ) {
 650+ $this->showMessage( 'config-imagemagick', $exe );
 651+ return true;
 652+ } elseif ( function_exists( 'imagejpeg' ) ) {
649653 $this->showMessage( 'config-gd' );
650654 return true;
 655+ } else {
 656+ $this->showMessage( 'no-scaling' );
651657 }
652 -
653 - $this->showMessage( 'no-scaling' );
654658 }
655659
656660 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r74902Followup r74847, reduce some more duplication by moving the foreach() logic t...demon17:20, 17 October 2010

Comments

#Comment by Brion VIBBER (talk | contribs)   22:58, 16 October 2010

Some good cleanup! It might make sense to further fold the call to getPossibleBinPaths() down into locateExecutable() (or have a wrapper that runs locateExecutable in all the default paths, if there's a need to use it with different paths).

Status & tagging log