r74902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74901‎ | r74902 | r74903 >
Date:17:20, 17 October 2010
Author:demon
Status:ok
Tags:
Comment:
Followup r74847, reduce some more duplication by moving the foreach() logic to a common method.
Also move these functions together
Modified paths:
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.php
@@ -383,21 +383,6 @@
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 - /**
402387 * Check if we're installing the latest version.
403388 */
404389 public function envLatestVersion() {
@@ -608,20 +593,11 @@
609594 $names = array( "gdiff3", "diff3", "diff3.exe" );
610595 $versionInfo = array( '$1 --version 2>&1', 'diff3 (GNU diffutils)' );
611596
612 - $haveDiff3 = false;
 597+ $diff3 = $this->locateExecutableInDefaultPaths( $names, $versionInfo );
613598
614 - foreach ( $this->getPossibleBinPaths() as $path ) {
615 - $exe = $this->locateExecutable( $path, $names, $versionInfo );
616 -
617 - if ($exe !== false) {
618 - $this->setVar( 'wgDiff3', $exe );
619 - $haveDiff3 = true;
620 - break;
621 - }
622 - }
623 -
624 - if ( $haveDiff3 ) {
625 - $this->showMessage( 'config-diff3-good', $exe );
 599+ if ( $diff3 ) {
 600+ $this->showMessage( 'config-diff3-good', $diff3 );
 601+ $this->setVar( 'wgDiff3', $diff3 );
626602 } else {
627603 $this->setVar( 'wgDiff3', false );
628604 $this->showMessage( 'config-diff3-bad' );
@@ -633,20 +609,11 @@
634610 */
635611 public function envCheckGraphics() {
636612 $names = array( 'convert', 'convert.exe' );
637 - $haveConvert = false;
 613+ $convert = $this->locateExecutableInDefaultPaths( $names );
638614
639 - foreach ( $this->getPossibleBinPaths() as $path ) {
640 - $exe = $this->locateExecutable( $path, $names );
641 -
642 - if ($exe !== false) {
643 - $this->setVar( 'wgImageMagickConvertCommand', $exe );
644 - $haveConvert = true;
645 - break;
646 - }
647 - }
648 -
649 - if ( $haveConvert ) {
650 - $this->showMessage( 'config-imagemagick', $exe );
 615+ if ( $convert ) {
 616+ $this->setVar( 'wgImageMagickConvertCommand', $convert );
 617+ $this->showMessage( 'config-imagemagick', $convert );
651618 return true;
652619 } elseif ( function_exists( 'imagejpeg' ) ) {
653620 $this->showMessage( 'config-gd' );
@@ -889,6 +856,20 @@
890857 }
891858 }
892859
 860+ /**
 861+ * Get an array of likely places we can find executables. Check a bunch
 862+ * of known Unix-like defaults, as well as the PATH environment variable
 863+ * (which should maybe make it work for Windows?)
 864+ *
 865+ * @return Array
 866+ */
 867+ protected function getPossibleBinPaths() {
 868+ return array_merge(
 869+ array( '/usr/bin', '/usr/local/bin', '/opt/csw/bin',
 870+ '/usr/gnu/bin', '/usr/sfw/bin', '/sw/bin', '/opt/local/bin' ),
 871+ explode( PATH_SEPARATOR, getenv( 'PATH' ) )
 872+ );
 873+ }
893874
894875 /**
895876 * Search a path for any of the given executable names. Returns the
@@ -932,7 +913,20 @@
933914 }
934915 }
935916 }
 917+ return false;
 918+ }
936919
 920+ /**
 921+ * Same as locateExecutable(), but checks in getPossibleBinPaths() by default
 922+ * @see locateExecutable()
 923+ */
 924+ protected function locateExecutableInDefaultPaths( $names, $versionInfo = false ) {
 925+ foreach( $this->getPossibleBinPaths() as $path ) {
 926+ $exe = $this->locateExecutable( $path, $names, $versionInfo );
 927+ if( $exe !== false ) {
 928+ return $exe;
 929+ }
 930+ }
937931 return false;
938932 }
939933

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74847Make envCheckGraphics use locateExecutable(). Move path stuff to a single methoddemon18:19, 16 October 2010

Status & tagging log