r69695 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69694‎ | r69695 | r69696 >
Date:17:31, 21 July 2010
Author:jeroendedauw
Status:ok
Tags:
Comment:
Style and doc improvements
Modified paths:
  • /trunk/phase3/includes/installer/Installer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.php
@@ -695,16 +695,21 @@
696696 return true;
697697 }
698698 }
 699+
699700 if ( function_exists( 'imagejpeg' ) ) {
700701 $this->showMessage( 'config-gd' );
701702 return true;
702703 }
 704+
703705 $this->showMessage( 'no-scaling' );
704706 }
705707
706 - /** Environment check for setting $IP and $wgScriptPath */
 708+ /**
 709+ * Environment check for setting $IP and $wgScriptPath.
 710+ */
707711 public function envCheckPath() {
708712 $IP = dirname( dirname( dirname( __FILE__ ) ) );
 713+
709714 $this->setVar( 'IP', $IP );
710715 $this->showMessage( 'config-dir', $IP );
711716
@@ -722,27 +727,35 @@
723728 $this->showMessage( 'config-no-uri' );
724729 return false;
725730 }
 731+
726732 $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path );
727733 $this->setVar( 'wgScriptPath', $uri );
728734 $this->showMessage( 'config-uri', $uri );
729735 }
730736
731 - /** Environment check for writable config/ directory */
 737+ /**
 738+ * Environment check for writable config/ directory.
 739+ */
732740 public function envCheckWriteableDir() {
733741 $ipDir = $this->getVar( 'IP' );
734742 $configDir = $ipDir . '/config';
 743+
735744 if( !is_writeable( $configDir ) ) {
736745 $webserverGroup = self::maybeGetWebserverPrimaryGroup();
 746+
737747 if ( $webserverGroup !== null ) {
738748 $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup );
739749 } else {
740750 $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup );
741751 }
 752+
742753 return false;
743754 }
744755 }
745756
746 - /** Environment check for setting the preferred PHP file extension */
 757+ /**
 758+ * Environment check for setting the preferred PHP file extension.
 759+ */
747760 public function envCheckExtension() {
748761 // FIXME: detect this properly
749762 if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) {
@@ -750,26 +763,29 @@
751764 } else {
752765 $ext = 'php';
753766 }
 767+
754768 $this->setVar( 'wgScriptExtension', ".$ext" );
755769 $this->showMessage( 'config-file-extension', $ext );
756770 }
757771
758772 public function envCheckShellLocale() {
759 - # Give up now if we're in safe mode or open_basedir
760 - # It's theoretically possible but tricky to work with
 773+ # Give up now if we're in safe mode or open_basedir.
 774+ # It's theoretically possible but tricky to work with.
761775 if ( wfIniGetBool( "safe_mode" ) || ini_get( 'open_basedir' ) || !function_exists( 'exec' ) ) {
762776 return true;
763777 }
764778
765779 $os = php_uname( 's' );
766780 $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these
 781+
767782 if ( !in_array( $os, $supported ) ) {
768783 return true;
769784 }
770785
771 - # Get a list of available locales
 786+ # Get a list of available locales.
772787 $lines = $ret = false;
773788 exec( '/usr/bin/locale -a', $lines, $ret );
 789+
774790 if ( $ret ) {
775791 return true;
776792 }
@@ -777,26 +793,30 @@
778794 $lines = wfArrayMap( 'trim', $lines );
779795 $candidatesByLocale = array();
780796 $candidatesByLang = array();
 797+
781798 foreach ( $lines as $line ) {
782799 if ( $line === '' ) {
783800 continue;
784801 }
 802+
785803 if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) {
786804 continue;
787805 }
 806+
788807 list( $all, $lang, $territory, $charset, $modifier ) = $m;
 808+
789809 $candidatesByLocale[$m[0]] = $m;
790810 $candidatesByLang[$lang][] = $m;
791811 }
792812
793 - # Try the current value of LANG
 813+ # Try the current value of LANG.
794814 if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) {
795815 $this->setVar( 'wgShellLocale', getenv( 'LANG' ) );
796816 $this->showMessage( 'config-shell-locale', getenv( 'LANG' ) );
797817 return true;
798818 }
799819
800 - # Try the most common ones
 820+ # Try the most common ones.
801821 $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' );
802822 foreach ( $commonLocales as $commonLocale ) {
803823 if ( isset( $candidatesByLocale[$commonLocale] ) ) {
@@ -808,6 +828,7 @@
809829
810830 # Is there an available locale in the Wiki's language?
811831 $wikiLang = $this->getVar( 'wgLanguageCode' );
 832+
812833 if ( isset( $candidatesByLang[$wikiLang] ) ) {
813834 $m = reset( $candidatesByLang[$wikiLang] );
814835 $this->setVar( 'wgShellLocale', $m[0] );
@@ -823,15 +844,17 @@
824845 return true;
825846 }
826847
827 - # Give up
 848+ # Give up.
828849 return true;
829850 }
830851
831852 public function envCheckUploadsDirectory() {
832853 global $IP, $wgServer;
 854+
833855 $dir = $IP . '/images/';
834856 $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/';
835857 $safe = !$this->dirIsExecutable( $dir, $url );
 858+
836859 if ( $safe ) {
837860 $this->showMessage( 'config-uploads-safe' );
838861 } else {
@@ -849,24 +872,31 @@
850873 "#!/var/env php5\n<?php echo 'ex' . 'ec';",
851874 ),
852875 );
853 - // it would be good to check other popular languages here, but it'll be slow
 876+
 877+ // it would be good to check other popular languages here, but it'll be slow.
854878
855879 wfSuppressWarnings();
 880+
856881 foreach ( $scriptTypes as $ext => $contents ) {
857882 foreach ( $contents as $source ) {
858883 $file = 'exectest.' . $ext;
 884+
859885 if ( !file_put_contents( $dir . $file, $source ) ) {
860886 break;
861887 }
 888+
862889 $text = Http::get( $url . $file );
863890 unlink( $dir . $file );
 891+
864892 if ( $text == 'exec' ) {
865893 wfRestoreWarnings();
866894 return $ext;
867895 }
868896 }
869897 }
 898+
870899 wfRestoreWarnings();
 900+
871901 return false;
872902 }
873903
@@ -888,15 +918,18 @@
889919 */
890920 public function parse( $text, $lineStart = false ) {
891921 global $wgParser;
 922+
892923 try {
893924 $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart );
894925 $html = $out->getText();
895926 } catch ( DBAccessError $e ) {
896927 $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text );
 928+
897929 if ( !empty( $this->debug ) ) {
898930 $html .= "<!--\n" . $e->getTraceAsString() . "\n-->";
899931 }
900932 }
 933+
901934 return $html;
902935 }
903936
@@ -929,15 +962,19 @@
930963 if( $this->getVar( 'IP' ) === null ) {
931964 return false;
932965 }
 966+
933967 $exts = array();
934968 $dir = $this->getVar( 'IP' ) . '/extensions';
935969 $dh = opendir( $dir );
 970+
936971 while ( ( $file = readdir( $dh ) ) !== false ) {
937972 if( file_exists( "$dir/$file/$file.php" ) ) {
938973 $exts[$file] = null;
939974 }
940975 }
 976+
941977 $this->setVar( '_Extensions', $exts );
 978+
942979 return $exts;
943980 }
944981
@@ -945,21 +982,26 @@
946983 if( $this->getVar( '_UpgradeDone' ) ) {
947984 $this->installSteps = array( 'localsettings' );
948985 }
 986+
949987 if( count( $this->getVar( '_Extensions' ) ) ) {
950988 array_unshift( $this->installSteps, 'extensions' );
951989 }
 990+
952991 return $this->installSteps;
953992 }
954993
955994 /**
956995 * Actually perform the installation.
 996+ *
957997 * @param Array $startCB A callback array for the beginning of each step
958998 * @param Array $endCB A callback array for the end of each step
 999+ *
9591000 * @return Array of Status objects
9601001 */
9611002 public function performInstallation( $startCB, $endCB ) {
9621003 $installResults = array();
9631004 $installer = $this->getDBInstaller();
 1005+
9641006 foreach( $this->getInstallSteps() as $stepObj ) {
9651007 $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj;
9661008 call_user_func_array( $startCB, array( $step ) );
@@ -975,45 +1017,56 @@
9761018 $func = 'install' . ucfirst( $step );
9771019 $status = $this->{$func}( $installer );
9781020 }
 1021+
9791022 call_user_func_array( $endCB, array( $step, $status ) );
9801023 $installResults[$step] = $status;
9811024
982 - // If we've hit some sort of fatal, we need to bail. Callback
983 - // already had a chance to do output above.
984 - if( !$status->isOk() )
 1025+ // If we've hit some sort of fatal, we need to bail.
 1026+ // Callback already had a chance to do output above.
 1027+ if( !$status->isOk() ) {
9851028 break;
 1029+ }
 1030+
9861031 }
 1032+
9871033 if( $status->isOk() ) {
9881034 $this->setVar( '_InstallDone', true );
9891035 }
 1036+
9901037 return $installResults;
9911038 }
9921039
9931040 public function installExtensions() {
9941041 global $wgHooks, $wgAutoloadClasses;
 1042+
9951043 $exts = $this->getVar( '_Extensions' );
9961044 $path = $this->getVar( 'IP' ) . '/extensions';
 1045+
9971046 foreach( $exts as $e ) {
9981047 require( "$path/$e/$e.php" );
9991048 }
 1049+
10001050 return Status::newGood();
10011051 }
10021052
10031053 public function installDatabase( &$installer ) {
1004 - if(!$installer) {
 1054+ if( !$installer ) {
10051055 $type = $this->getVar( 'wgDBtype' );
10061056 $status = Status::newFatal( "config-no-db", $type );
10071057 } else {
10081058 $status = $installer->setupDatabase();
10091059 }
 1060+
10101061 return $status;
10111062 }
10121063
10131064 public function installTables( &$installer ) {
10141065 $status = $installer->createTables();
 1066+
10151067 if( $status->isOK() ) {
10161068 LBFactory::enableBackend();
10171069 }
 1070+
10181071 return $status;
10191072 }
10201073
@@ -1036,12 +1089,15 @@
10371090 $secretKey = bin2hex( fread( $file, 32 ) );
10381091 fclose( $file );
10391092 } else {
1040 - $secretKey = "";
 1093+ $secretKey = '';
 1094+
10411095 for ( $i=0; $i<8; $i++ ) {
10421096 $secretKey .= dechex(mt_rand(0, 0x7fffffff));
10431097 }
 1098+
10441099 $status->warning( 'config-insecure-secretkey' );
10451100 }
 1101+
10461102 $this->setVar( 'wgSecretKey', $secretKey );
10471103
10481104 return $status;
@@ -1050,21 +1106,26 @@
10511107 public function installSysop() {
10521108 $name = $this->getVar( '_AdminName' );
10531109 $user = User::newFromName( $name );
 1110+
10541111 if ( !$user ) {
10551112 // we should've validated this earlier anyway!
10561113 return Status::newFatal( 'config-admin-error-user', $name );
10571114 }
 1115+
10581116 if ( $user->idForName() == 0 ) {
10591117 $user->addToDatabase();
 1118+
10601119 try {
10611120 $user->setPassword( $this->getVar( '_AdminPassword' ) );
10621121 } catch( PasswordError $pwe ) {
10631122 return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() );
10641123 }
 1124+
10651125 $user->addGroup( 'sysop' );
10661126 $user->addGroup( 'bureaucrat' );
10671127 $user->saveSettings();
10681128 }
 1129+
10691130 return Status::newGood();
10701131 }
10711132
@@ -1090,6 +1151,7 @@
10911152 $status->fatal( 'config-localsettings-noupgrade' );
10921153 }
10931154 }
 1155+
10941156 return $status;
10951157 }
10961158
@@ -1105,8 +1167,8 @@
11061168 * @return String
11071169 */
11081170 public static function maybeGetWebserverPrimaryGroup() {
1109 - if ( ! function_exists('posix_getegid') || ! function_exists('posix_getpwuid') ) {
1110 - # I don't know this, this isn't UNIX
 1171+ if ( !function_exists( 'posix_getegid' ) || !function_exists( 'posix_getpwuid' ) ) {
 1172+ # I don't know this, this isn't UNIX.
11111173 return null;
11121174 }
11131175
@@ -1114,7 +1176,7 @@
11151177 # not whoever owns the current script.
11161178 $gid = posix_getegid();
11171179 $getpwuid = posix_getpwuid( $gid );
1118 - $group = $getpwuid["name"];
 1180+ $group = $getpwuid['name'];
11191181
11201182 return $group;
11211183 }
@@ -1139,12 +1201,16 @@
11401202
11411203 /**
11421204 * Add an installation step following the given step.
 1205+ *
11431206 * @param $findStep String the step to find. Use NULL to put the step at the beginning.
11441207 * @param $callback array
11451208 */
11461209 public function addInstallStepFollowing( $findStep, $callback ) {
11471210 $where = 0;
1148 - if( $findStep !== null ) $where = array_search( $findStep, $this->installSteps );
 1211+
 1212+ if( $findStep !== null ) {
 1213+ $where = array_search( $findStep, $this->installSteps );
 1214+ }
11491215
11501216 array_splice( $this->installSteps, $where, 0, $callback );
11511217 }

Status & tagging log