Index: trunk/phase3/includes/installer/Installer.php |
— | — | @@ -695,16 +695,21 @@ |
696 | 696 | return true; |
697 | 697 | } |
698 | 698 | } |
| 699 | + |
699 | 700 | if ( function_exists( 'imagejpeg' ) ) { |
700 | 701 | $this->showMessage( 'config-gd' ); |
701 | 702 | return true; |
702 | 703 | } |
| 704 | + |
703 | 705 | $this->showMessage( 'no-scaling' ); |
704 | 706 | } |
705 | 707 | |
706 | | - /** Environment check for setting $IP and $wgScriptPath */ |
| 708 | + /** |
| 709 | + * Environment check for setting $IP and $wgScriptPath. |
| 710 | + */ |
707 | 711 | public function envCheckPath() { |
708 | 712 | $IP = dirname( dirname( dirname( __FILE__ ) ) ); |
| 713 | + |
709 | 714 | $this->setVar( 'IP', $IP ); |
710 | 715 | $this->showMessage( 'config-dir', $IP ); |
711 | 716 | |
— | — | @@ -722,27 +727,35 @@ |
723 | 728 | $this->showMessage( 'config-no-uri' ); |
724 | 729 | return false; |
725 | 730 | } |
| 731 | + |
726 | 732 | $uri = preg_replace( '{^(.*)/config.*$}', '$1', $path ); |
727 | 733 | $this->setVar( 'wgScriptPath', $uri ); |
728 | 734 | $this->showMessage( 'config-uri', $uri ); |
729 | 735 | } |
730 | 736 | |
731 | | - /** Environment check for writable config/ directory */ |
| 737 | + /** |
| 738 | + * Environment check for writable config/ directory. |
| 739 | + */ |
732 | 740 | public function envCheckWriteableDir() { |
733 | 741 | $ipDir = $this->getVar( 'IP' ); |
734 | 742 | $configDir = $ipDir . '/config'; |
| 743 | + |
735 | 744 | if( !is_writeable( $configDir ) ) { |
736 | 745 | $webserverGroup = self::maybeGetWebserverPrimaryGroup(); |
| 746 | + |
737 | 747 | if ( $webserverGroup !== null ) { |
738 | 748 | $this->showMessage( 'config-dir-not-writable-group', $ipDir, $webserverGroup ); |
739 | 749 | } else { |
740 | 750 | $this->showMessage( 'config-dir-not-writable-nogroup', $ipDir, $webserverGroup ); |
741 | 751 | } |
| 752 | + |
742 | 753 | return false; |
743 | 754 | } |
744 | 755 | } |
745 | 756 | |
746 | | - /** Environment check for setting the preferred PHP file extension */ |
| 757 | + /** |
| 758 | + * Environment check for setting the preferred PHP file extension. |
| 759 | + */ |
747 | 760 | public function envCheckExtension() { |
748 | 761 | // FIXME: detect this properly |
749 | 762 | if ( defined( 'MW_INSTALL_PHP5_EXT' ) ) { |
— | — | @@ -750,26 +763,29 @@ |
751 | 764 | } else { |
752 | 765 | $ext = 'php'; |
753 | 766 | } |
| 767 | + |
754 | 768 | $this->setVar( 'wgScriptExtension', ".$ext" ); |
755 | 769 | $this->showMessage( 'config-file-extension', $ext ); |
756 | 770 | } |
757 | 771 | |
758 | 772 | 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. |
761 | 775 | if ( wfIniGetBool( "safe_mode" ) || ini_get( 'open_basedir' ) || !function_exists( 'exec' ) ) { |
762 | 776 | return true; |
763 | 777 | } |
764 | 778 | |
765 | 779 | $os = php_uname( 's' ); |
766 | 780 | $supported = array( 'Linux', 'SunOS', 'HP-UX' ); # Tested these |
| 781 | + |
767 | 782 | if ( !in_array( $os, $supported ) ) { |
768 | 783 | return true; |
769 | 784 | } |
770 | 785 | |
771 | | - # Get a list of available locales |
| 786 | + # Get a list of available locales. |
772 | 787 | $lines = $ret = false; |
773 | 788 | exec( '/usr/bin/locale -a', $lines, $ret ); |
| 789 | + |
774 | 790 | if ( $ret ) { |
775 | 791 | return true; |
776 | 792 | } |
— | — | @@ -777,26 +793,30 @@ |
778 | 794 | $lines = wfArrayMap( 'trim', $lines ); |
779 | 795 | $candidatesByLocale = array(); |
780 | 796 | $candidatesByLang = array(); |
| 797 | + |
781 | 798 | foreach ( $lines as $line ) { |
782 | 799 | if ( $line === '' ) { |
783 | 800 | continue; |
784 | 801 | } |
| 802 | + |
785 | 803 | if ( !preg_match( '/^([a-zA-Z]+)(_[a-zA-Z]+|)\.(utf8|UTF-8)(@[a-zA-Z_]*|)$/i', $line, $m ) ) { |
786 | 804 | continue; |
787 | 805 | } |
| 806 | + |
788 | 807 | list( $all, $lang, $territory, $charset, $modifier ) = $m; |
| 808 | + |
789 | 809 | $candidatesByLocale[$m[0]] = $m; |
790 | 810 | $candidatesByLang[$lang][] = $m; |
791 | 811 | } |
792 | 812 | |
793 | | - # Try the current value of LANG |
| 813 | + # Try the current value of LANG. |
794 | 814 | if ( isset( $candidatesByLocale[ getenv( 'LANG' ) ] ) ) { |
795 | 815 | $this->setVar( 'wgShellLocale', getenv( 'LANG' ) ); |
796 | 816 | $this->showMessage( 'config-shell-locale', getenv( 'LANG' ) ); |
797 | 817 | return true; |
798 | 818 | } |
799 | 819 | |
800 | | - # Try the most common ones |
| 820 | + # Try the most common ones. |
801 | 821 | $commonLocales = array( 'en_US.UTF-8', 'en_US.utf8', 'de_DE.UTF-8', 'de_DE.utf8' ); |
802 | 822 | foreach ( $commonLocales as $commonLocale ) { |
803 | 823 | if ( isset( $candidatesByLocale[$commonLocale] ) ) { |
— | — | @@ -808,6 +828,7 @@ |
809 | 829 | |
810 | 830 | # Is there an available locale in the Wiki's language? |
811 | 831 | $wikiLang = $this->getVar( 'wgLanguageCode' ); |
| 832 | + |
812 | 833 | if ( isset( $candidatesByLang[$wikiLang] ) ) { |
813 | 834 | $m = reset( $candidatesByLang[$wikiLang] ); |
814 | 835 | $this->setVar( 'wgShellLocale', $m[0] ); |
— | — | @@ -823,15 +844,17 @@ |
824 | 845 | return true; |
825 | 846 | } |
826 | 847 | |
827 | | - # Give up |
| 848 | + # Give up. |
828 | 849 | return true; |
829 | 850 | } |
830 | 851 | |
831 | 852 | public function envCheckUploadsDirectory() { |
832 | 853 | global $IP, $wgServer; |
| 854 | + |
833 | 855 | $dir = $IP . '/images/'; |
834 | 856 | $url = $wgServer . $this->getVar( 'wgScriptPath' ) . '/images/'; |
835 | 857 | $safe = !$this->dirIsExecutable( $dir, $url ); |
| 858 | + |
836 | 859 | if ( $safe ) { |
837 | 860 | $this->showMessage( 'config-uploads-safe' ); |
838 | 861 | } else { |
— | — | @@ -849,24 +872,31 @@ |
850 | 873 | "#!/var/env php5\n<?php echo 'ex' . 'ec';", |
851 | 874 | ), |
852 | 875 | ); |
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. |
854 | 878 | |
855 | 879 | wfSuppressWarnings(); |
| 880 | + |
856 | 881 | foreach ( $scriptTypes as $ext => $contents ) { |
857 | 882 | foreach ( $contents as $source ) { |
858 | 883 | $file = 'exectest.' . $ext; |
| 884 | + |
859 | 885 | if ( !file_put_contents( $dir . $file, $source ) ) { |
860 | 886 | break; |
861 | 887 | } |
| 888 | + |
862 | 889 | $text = Http::get( $url . $file ); |
863 | 890 | unlink( $dir . $file ); |
| 891 | + |
864 | 892 | if ( $text == 'exec' ) { |
865 | 893 | wfRestoreWarnings(); |
866 | 894 | return $ext; |
867 | 895 | } |
868 | 896 | } |
869 | 897 | } |
| 898 | + |
870 | 899 | wfRestoreWarnings(); |
| 900 | + |
871 | 901 | return false; |
872 | 902 | } |
873 | 903 | |
— | — | @@ -888,15 +918,18 @@ |
889 | 919 | */ |
890 | 920 | public function parse( $text, $lineStart = false ) { |
891 | 921 | global $wgParser; |
| 922 | + |
892 | 923 | try { |
893 | 924 | $out = $wgParser->parse( $text, $this->parserTitle, $this->parserOptions, $lineStart ); |
894 | 925 | $html = $out->getText(); |
895 | 926 | } catch ( DBAccessError $e ) { |
896 | 927 | $html = '<!--DB access attempted during parse--> ' . htmlspecialchars( $text ); |
| 928 | + |
897 | 929 | if ( !empty( $this->debug ) ) { |
898 | 930 | $html .= "<!--\n" . $e->getTraceAsString() . "\n-->"; |
899 | 931 | } |
900 | 932 | } |
| 933 | + |
901 | 934 | return $html; |
902 | 935 | } |
903 | 936 | |
— | — | @@ -929,15 +962,19 @@ |
930 | 963 | if( $this->getVar( 'IP' ) === null ) { |
931 | 964 | return false; |
932 | 965 | } |
| 966 | + |
933 | 967 | $exts = array(); |
934 | 968 | $dir = $this->getVar( 'IP' ) . '/extensions'; |
935 | 969 | $dh = opendir( $dir ); |
| 970 | + |
936 | 971 | while ( ( $file = readdir( $dh ) ) !== false ) { |
937 | 972 | if( file_exists( "$dir/$file/$file.php" ) ) { |
938 | 973 | $exts[$file] = null; |
939 | 974 | } |
940 | 975 | } |
| 976 | + |
941 | 977 | $this->setVar( '_Extensions', $exts ); |
| 978 | + |
942 | 979 | return $exts; |
943 | 980 | } |
944 | 981 | |
— | — | @@ -945,21 +982,26 @@ |
946 | 983 | if( $this->getVar( '_UpgradeDone' ) ) { |
947 | 984 | $this->installSteps = array( 'localsettings' ); |
948 | 985 | } |
| 986 | + |
949 | 987 | if( count( $this->getVar( '_Extensions' ) ) ) { |
950 | 988 | array_unshift( $this->installSteps, 'extensions' ); |
951 | 989 | } |
| 990 | + |
952 | 991 | return $this->installSteps; |
953 | 992 | } |
954 | 993 | |
955 | 994 | /** |
956 | 995 | * Actually perform the installation. |
| 996 | + * |
957 | 997 | * @param Array $startCB A callback array for the beginning of each step |
958 | 998 | * @param Array $endCB A callback array for the end of each step |
| 999 | + * |
959 | 1000 | * @return Array of Status objects |
960 | 1001 | */ |
961 | 1002 | public function performInstallation( $startCB, $endCB ) { |
962 | 1003 | $installResults = array(); |
963 | 1004 | $installer = $this->getDBInstaller(); |
| 1005 | + |
964 | 1006 | foreach( $this->getInstallSteps() as $stepObj ) { |
965 | 1007 | $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj; |
966 | 1008 | call_user_func_array( $startCB, array( $step ) ); |
— | — | @@ -975,45 +1017,56 @@ |
976 | 1018 | $func = 'install' . ucfirst( $step ); |
977 | 1019 | $status = $this->{$func}( $installer ); |
978 | 1020 | } |
| 1021 | + |
979 | 1022 | call_user_func_array( $endCB, array( $step, $status ) ); |
980 | 1023 | $installResults[$step] = $status; |
981 | 1024 | |
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() ) { |
985 | 1028 | break; |
| 1029 | + } |
| 1030 | + |
986 | 1031 | } |
| 1032 | + |
987 | 1033 | if( $status->isOk() ) { |
988 | 1034 | $this->setVar( '_InstallDone', true ); |
989 | 1035 | } |
| 1036 | + |
990 | 1037 | return $installResults; |
991 | 1038 | } |
992 | 1039 | |
993 | 1040 | public function installExtensions() { |
994 | 1041 | global $wgHooks, $wgAutoloadClasses; |
| 1042 | + |
995 | 1043 | $exts = $this->getVar( '_Extensions' ); |
996 | 1044 | $path = $this->getVar( 'IP' ) . '/extensions'; |
| 1045 | + |
997 | 1046 | foreach( $exts as $e ) { |
998 | 1047 | require( "$path/$e/$e.php" ); |
999 | 1048 | } |
| 1049 | + |
1000 | 1050 | return Status::newGood(); |
1001 | 1051 | } |
1002 | 1052 | |
1003 | 1053 | public function installDatabase( &$installer ) { |
1004 | | - if(!$installer) { |
| 1054 | + if( !$installer ) { |
1005 | 1055 | $type = $this->getVar( 'wgDBtype' ); |
1006 | 1056 | $status = Status::newFatal( "config-no-db", $type ); |
1007 | 1057 | } else { |
1008 | 1058 | $status = $installer->setupDatabase(); |
1009 | 1059 | } |
| 1060 | + |
1010 | 1061 | return $status; |
1011 | 1062 | } |
1012 | 1063 | |
1013 | 1064 | public function installTables( &$installer ) { |
1014 | 1065 | $status = $installer->createTables(); |
| 1066 | + |
1015 | 1067 | if( $status->isOK() ) { |
1016 | 1068 | LBFactory::enableBackend(); |
1017 | 1069 | } |
| 1070 | + |
1018 | 1071 | return $status; |
1019 | 1072 | } |
1020 | 1073 | |
— | — | @@ -1036,12 +1089,15 @@ |
1037 | 1090 | $secretKey = bin2hex( fread( $file, 32 ) ); |
1038 | 1091 | fclose( $file ); |
1039 | 1092 | } else { |
1040 | | - $secretKey = ""; |
| 1093 | + $secretKey = ''; |
| 1094 | + |
1041 | 1095 | for ( $i=0; $i<8; $i++ ) { |
1042 | 1096 | $secretKey .= dechex(mt_rand(0, 0x7fffffff)); |
1043 | 1097 | } |
| 1098 | + |
1044 | 1099 | $status->warning( 'config-insecure-secretkey' ); |
1045 | 1100 | } |
| 1101 | + |
1046 | 1102 | $this->setVar( 'wgSecretKey', $secretKey ); |
1047 | 1103 | |
1048 | 1104 | return $status; |
— | — | @@ -1050,21 +1106,26 @@ |
1051 | 1107 | public function installSysop() { |
1052 | 1108 | $name = $this->getVar( '_AdminName' ); |
1053 | 1109 | $user = User::newFromName( $name ); |
| 1110 | + |
1054 | 1111 | if ( !$user ) { |
1055 | 1112 | // we should've validated this earlier anyway! |
1056 | 1113 | return Status::newFatal( 'config-admin-error-user', $name ); |
1057 | 1114 | } |
| 1115 | + |
1058 | 1116 | if ( $user->idForName() == 0 ) { |
1059 | 1117 | $user->addToDatabase(); |
| 1118 | + |
1060 | 1119 | try { |
1061 | 1120 | $user->setPassword( $this->getVar( '_AdminPassword' ) ); |
1062 | 1121 | } catch( PasswordError $pwe ) { |
1063 | 1122 | return Status::newFatal( 'config-admin-error-password', $name, $pwe->getMessage() ); |
1064 | 1123 | } |
| 1124 | + |
1065 | 1125 | $user->addGroup( 'sysop' ); |
1066 | 1126 | $user->addGroup( 'bureaucrat' ); |
1067 | 1127 | $user->saveSettings(); |
1068 | 1128 | } |
| 1129 | + |
1069 | 1130 | return Status::newGood(); |
1070 | 1131 | } |
1071 | 1132 | |
— | — | @@ -1090,6 +1151,7 @@ |
1091 | 1152 | $status->fatal( 'config-localsettings-noupgrade' ); |
1092 | 1153 | } |
1093 | 1154 | } |
| 1155 | + |
1094 | 1156 | return $status; |
1095 | 1157 | } |
1096 | 1158 | |
— | — | @@ -1105,8 +1167,8 @@ |
1106 | 1168 | * @return String |
1107 | 1169 | */ |
1108 | 1170 | 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. |
1111 | 1173 | return null; |
1112 | 1174 | } |
1113 | 1175 | |
— | — | @@ -1114,7 +1176,7 @@ |
1115 | 1177 | # not whoever owns the current script. |
1116 | 1178 | $gid = posix_getegid(); |
1117 | 1179 | $getpwuid = posix_getpwuid( $gid ); |
1118 | | - $group = $getpwuid["name"]; |
| 1180 | + $group = $getpwuid['name']; |
1119 | 1181 | |
1120 | 1182 | return $group; |
1121 | 1183 | } |
— | — | @@ -1139,12 +1201,16 @@ |
1140 | 1202 | |
1141 | 1203 | /** |
1142 | 1204 | * Add an installation step following the given step. |
| 1205 | + * |
1143 | 1206 | * @param $findStep String the step to find. Use NULL to put the step at the beginning. |
1144 | 1207 | * @param $callback array |
1145 | 1208 | */ |
1146 | 1209 | public function addInstallStepFollowing( $findStep, $callback ) { |
1147 | 1210 | $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 | + } |
1149 | 1215 | |
1150 | 1216 | array_splice( $this->installSteps, $where, 0, $callback ); |
1151 | 1217 | } |