Index: trunk/phase3/includes/installer/WebInstaller.php |
— | — | @@ -316,16 +316,18 @@ |
317 | 317 | * Get a WebInstallerPage from the main sequence, by ID. |
318 | 318 | */ |
319 | 319 | public function getPageById( $id ) { |
320 | | - $pageName = $this->pageSequence[$id]; |
321 | | - $pageClass = 'WebInstaller_' . $pageName; |
322 | | - return new $pageClass( $this ); |
| 320 | + return $this->getPageByName( $this->pageSequence[$id] ); |
323 | 321 | } |
324 | 322 | |
325 | 323 | /** |
326 | 324 | * Get a WebInstallerPage by name. |
327 | 325 | */ |
328 | 326 | public function getPageByName( $pageName ) { |
| 327 | + // Totally lame way to force autoload of WebInstallerPage.php |
| 328 | + class_exists( 'WebInstallerPage' ); |
| 329 | + |
329 | 330 | $pageClass = 'WebInstaller_' . $pageName; |
| 331 | + |
330 | 332 | return new $pageClass( $this ); |
331 | 333 | } |
332 | 334 | |
— | — | @@ -827,934 +829,3 @@ |
828 | 830 | return $url; |
829 | 831 | } |
830 | 832 | } |
831 | | - |
832 | | -abstract class WebInstallerPage { |
833 | | - public function __construct( $parent ) { |
834 | | - $this->parent = $parent; |
835 | | - } |
836 | | - |
837 | | - public function addHTML( $html ) { |
838 | | - $this->parent->output->addHTML( $html ); |
839 | | - } |
840 | | - |
841 | | - public function startForm() { |
842 | | - $this->addHTML( |
843 | | - "<div class=\"config-section\">\n" . |
844 | | - Xml::openElement( |
845 | | - 'form', |
846 | | - array( |
847 | | - 'method' => 'post', |
848 | | - 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) ) |
849 | | - ) |
850 | | - ) . "\n" |
851 | | - ); |
852 | | - } |
853 | | - |
854 | | - public function endForm( $continue = 'continue' ) { |
855 | | - $this->parent->output->outputWarnings(); |
856 | | - $s = "<div class=\"config-submit\">\n"; |
857 | | - $id = $this->getId(); |
858 | | - if ( $id === false ) { |
859 | | - $s .= Xml::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) ); |
860 | | - } |
861 | | - if ( $continue ) { |
862 | | - // Fake submit button for enter keypress |
863 | | - $s .= Xml::submitButton( wfMsg( "config-$continue" ), |
864 | | - array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n"; |
865 | | - } |
866 | | - if ( $id !== 0 ) { |
867 | | - $s .= Xml::submitButton( wfMsg( 'config-back' ), |
868 | | - array( |
869 | | - 'name' => 'submit-back', |
870 | | - 'tabindex' => $this->parent->nextTabIndex() |
871 | | - ) ) . "\n"; |
872 | | - } |
873 | | - if ( $continue ) { |
874 | | - $s .= Xml::submitButton( wfMsg( "config-$continue" ), |
875 | | - array( |
876 | | - 'name' => "submit-$continue", |
877 | | - 'tabindex' => $this->parent->nextTabIndex(), |
878 | | - ) ) . "\n"; |
879 | | - } |
880 | | - $s .= "</div></form></div>\n"; |
881 | | - $this->addHTML( $s ); |
882 | | - } |
883 | | - |
884 | | - public function getName() { |
885 | | - return str_replace( 'WebInstaller_', '', get_class( $this ) ); |
886 | | - } |
887 | | - |
888 | | - public function getId() { |
889 | | - return array_search( $this->getName(), $this->parent->pageSequence ); |
890 | | - } |
891 | | - |
892 | | - public abstract function execute(); |
893 | | - |
894 | | - public function getVar( $var ) { |
895 | | - return $this->parent->getVar( $var ); |
896 | | - } |
897 | | - |
898 | | - public function setVar( $name, $value ) { |
899 | | - $this->parent->setVar( $name, $value ); |
900 | | - } |
901 | | -} |
902 | | - |
903 | | -class WebInstaller_Language extends WebInstallerPage { |
904 | | - function execute() { |
905 | | - global $wgLang; |
906 | | - $r = $this->parent->request; |
907 | | - $userLang = $r->getVal( 'UserLang' ); |
908 | | - $contLang = $r->getVal( 'ContLang' ); |
909 | | - |
910 | | - $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) ); |
911 | | - if ( !$lifetime ) { |
912 | | - $lifetime = 1440; // PHP default |
913 | | - } |
914 | | - |
915 | | - if ( $r->wasPosted() ) { |
916 | | - # Do session test |
917 | | - if ( $this->parent->getSession( 'test' ) === null ) { |
918 | | - $requestTime = $r->getVal( 'LanguageRequestTime' ); |
919 | | - if ( !$requestTime ) { |
920 | | - // The most likely explanation is that the user was knocked back |
921 | | - // from another page on POST due to session expiry |
922 | | - $msg = 'config-session-expired'; |
923 | | - } elseif ( time() - $requestTime > $lifetime ) { |
924 | | - $msg = 'config-session-expired'; |
925 | | - } else { |
926 | | - $msg = 'config-no-session'; |
927 | | - } |
928 | | - $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) ); |
929 | | - } else { |
930 | | - $languages = Language::getLanguageNames(); |
931 | | - if ( isset( $languages[$userLang] ) ) { |
932 | | - $this->setVar( '_UserLang', $userLang ); |
933 | | - } |
934 | | - if ( isset( $languages[$contLang] ) ) { |
935 | | - $this->setVar( 'wgLanguageCode', $contLang ); |
936 | | - } |
937 | | - return 'continue'; |
938 | | - } |
939 | | - } elseif ( $this->parent->showSessionWarning ) { |
940 | | - # The user was knocked back from another page to the start |
941 | | - # This probably indicates a session expiry |
942 | | - $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) ); |
943 | | - } |
944 | | - |
945 | | - $this->parent->setSession( 'test', true ); |
946 | | - |
947 | | - if ( !isset( $languages[$userLang] ) ) { |
948 | | - $userLang = $this->getVar( '_UserLang', 'en' ); |
949 | | - } |
950 | | - if ( !isset( $languages[$contLang] ) ) { |
951 | | - $contLang = $this->getVar( 'wgLanguageCode', 'en' ); |
952 | | - } |
953 | | - $this->startForm(); |
954 | | - $s = |
955 | | - Xml::hidden( 'LanguageRequestTime', time() ) . |
956 | | - $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang ) . |
957 | | - $this->parent->getHelpBox( 'config-your-language-help' ) . |
958 | | - $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang ) . |
959 | | - $this->parent->getHelpBox( 'config-wiki-language-help' ); |
960 | | - |
961 | | - |
962 | | - $this->addHTML( $s ); |
963 | | - $this->endForm(); |
964 | | - } |
965 | | - |
966 | | - /** |
967 | | - * Get a <select> for selecting languages |
968 | | - */ |
969 | | - function getLanguageSelector( $name, $label, $selectedCode ) { |
970 | | - global $wgDummyLanguageCodes; |
971 | | - $s = Xml::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n"; |
972 | | - |
973 | | - $languages = Language::getLanguageNames(); |
974 | | - ksort( $languages ); |
975 | | - $dummies = array_flip( $wgDummyLanguageCodes ); |
976 | | - foreach ( $languages as $code => $lang ) { |
977 | | - if ( isset( $dummies[$code] ) ) continue; |
978 | | - $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode ); |
979 | | - } |
980 | | - $s .= "\n</select>\n"; |
981 | | - return $this->parent->label( $label, $name, $s ); |
982 | | - } |
983 | | -} |
984 | | - |
985 | | -class WebInstaller_Welcome extends WebInstallerPage { |
986 | | - function execute() { |
987 | | - if ( $this->parent->request->wasPosted() ) { |
988 | | - if ( $this->getVar( '_Environment' ) ) { |
989 | | - return 'continue'; |
990 | | - } |
991 | | - } |
992 | | - $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) ); |
993 | | - $status = $this->parent->doEnvironmentChecks(); |
994 | | - if ( $status ) { |
995 | | - $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright', wfMsg( 'config-authors' ) ) ); |
996 | | - $this->startForm(); |
997 | | - $this->endForm(); |
998 | | - } |
999 | | - } |
1000 | | -} |
1001 | | - |
1002 | | -class WebInstaller_DBConnect extends WebInstallerPage { |
1003 | | - function execute() { |
1004 | | - $r = $this->parent->request; |
1005 | | - if ( $r->wasPosted() ) { |
1006 | | - $status = $this->submit(); |
1007 | | - if ( $status->isGood() ) { |
1008 | | - $this->setVar( '_UpgradeDone', false ); |
1009 | | - return 'continue'; |
1010 | | - } else { |
1011 | | - $this->parent->showStatusBox( $status ); |
1012 | | - } |
1013 | | - } |
1014 | | - |
1015 | | - |
1016 | | - $this->startForm(); |
1017 | | - |
1018 | | - $types = "<ul class=\"config-settings-block\">\n"; |
1019 | | - $settings = ''; |
1020 | | - $defaultType = $this->getVar( 'wgDBtype' ); |
1021 | | - foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) { |
1022 | | - $installer = $this->parent->getDBInstaller( $type ); |
1023 | | - $types .= |
1024 | | - '<li>' . |
1025 | | - Xml::radioLabel( |
1026 | | - $installer->getReadableName(), |
1027 | | - 'DBType', |
1028 | | - $type, |
1029 | | - "DBType_$type", |
1030 | | - $type == $defaultType, |
1031 | | - array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" ) |
1032 | | - ) . |
1033 | | - "</li>\n"; |
1034 | | - |
1035 | | - $settings .= |
1036 | | - Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) . |
1037 | | - Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) . |
1038 | | - $installer->getConnectForm() . |
1039 | | - "</div>\n"; |
1040 | | - } |
1041 | | - $types .= "</ul><br clear=\"left\"/>\n"; |
1042 | | - |
1043 | | - $this->addHTML( |
1044 | | - $this->parent->label( 'config-db-type', false, $types ) . |
1045 | | - $settings |
1046 | | - ); |
1047 | | - |
1048 | | - $this->endForm(); |
1049 | | - } |
1050 | | - |
1051 | | - function submit() { |
1052 | | - $r = $this->parent->request; |
1053 | | - $type = $r->getVal( 'DBType' ); |
1054 | | - $this->setVar( 'wgDBtype', $type ); |
1055 | | - $installer = $this->parent->getDBInstaller( $type ); |
1056 | | - if ( !$installer ) { |
1057 | | - return Status::newFatal( 'config-invalid-db-type' ); |
1058 | | - } |
1059 | | - return $installer->submitConnectForm(); |
1060 | | - } |
1061 | | -} |
1062 | | - |
1063 | | -class WebInstaller_Upgrade extends WebInstallerPage { |
1064 | | - function execute() { |
1065 | | - if ( $this->getVar( '_UpgradeDone' ) ) { |
1066 | | - if ( $this->parent->request->wasPosted() ) { |
1067 | | - // Done message acknowledged |
1068 | | - return 'continue'; |
1069 | | - } else { |
1070 | | - // Back button click |
1071 | | - // Show the done message again |
1072 | | - // Make them click back again if they want to do the upgrade again |
1073 | | - $this->showDoneMessage(); |
1074 | | - return 'output'; |
1075 | | - } |
1076 | | - } |
1077 | | - |
1078 | | - // wgDBtype is generally valid here because otherwise the previous page |
1079 | | - // (connect) wouldn't have declared its happiness |
1080 | | - $type = $this->getVar( 'wgDBtype' ); |
1081 | | - $installer = $this->parent->getDBInstaller( $type ); |
1082 | | - |
1083 | | - if ( !$installer->needsUpgrade() ) { |
1084 | | - return 'skip'; |
1085 | | - } |
1086 | | - |
1087 | | - if ( $this->parent->request->wasPosted() ) { |
1088 | | - $this->addHTML( |
1089 | | - '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' . |
1090 | | - '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' . |
1091 | | - '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">' |
1092 | | - ); |
1093 | | - $this->parent->output->flush(); |
1094 | | - $result = $installer->doUpgrade(); |
1095 | | - $this->addHTML( '</textarea> |
1096 | | -<script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' ); |
1097 | | - $this->parent->output->flush(); |
1098 | | - if ( $result ) { |
1099 | | - $this->setVar( '_UpgradeDone', true ); |
1100 | | - $this->showDoneMessage(); |
1101 | | - return 'output'; |
1102 | | - } |
1103 | | - } |
1104 | | - |
1105 | | - $this->startForm(); |
1106 | | - $this->addHTML( $this->parent->getInfoBox( |
1107 | | - wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) ); |
1108 | | - $this->endForm(); |
1109 | | - } |
1110 | | - |
1111 | | - function showDoneMessage() { |
1112 | | - $this->startForm(); |
1113 | | - $this->addHTML( |
1114 | | - $this->parent->getInfoBox( |
1115 | | - wfMsgNoTrans( 'config-upgrade-done', |
1116 | | - $GLOBALS['wgServer'] . |
1117 | | - $this->getVar( 'wgScriptPath' ) . '/index' . |
1118 | | - $this->getVar( 'wgScriptExtension' ) |
1119 | | - ), 'tick-32.png' |
1120 | | - ) |
1121 | | - ); |
1122 | | - $this->endForm( 'regenerate' ); |
1123 | | - } |
1124 | | -} |
1125 | | - |
1126 | | -class WebInstaller_DBSettings extends WebInstallerPage { |
1127 | | - function execute() { |
1128 | | - $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) ); |
1129 | | - |
1130 | | - $r = $this->parent->request; |
1131 | | - if ( $r->wasPosted() ) { |
1132 | | - $status = $installer->submitSettingsForm(); |
1133 | | - if ( $status === false ) { |
1134 | | - return 'skip'; |
1135 | | - } elseif ( $status->isGood() ) { |
1136 | | - return 'continue'; |
1137 | | - } else { |
1138 | | - $this->parent->showStatusBox( $status ); |
1139 | | - } |
1140 | | - } |
1141 | | - |
1142 | | - $form = $installer->getSettingsForm(); |
1143 | | - if ( $form === false ) { |
1144 | | - return 'skip'; |
1145 | | - } |
1146 | | - |
1147 | | - $this->startForm(); |
1148 | | - $this->addHTML( $form ); |
1149 | | - $this->endForm(); |
1150 | | - } |
1151 | | - |
1152 | | -} |
1153 | | - |
1154 | | -class WebInstaller_Name extends WebInstallerPage { |
1155 | | - function execute() { |
1156 | | - $r = $this->parent->request; |
1157 | | - if ( $r->wasPosted() ) { |
1158 | | - if ( $this->submit() ) { |
1159 | | - return 'continue'; |
1160 | | - } |
1161 | | - } |
1162 | | - |
1163 | | - $this->startForm(); |
1164 | | - |
1165 | | - if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) { |
1166 | | - $this->setVar( 'wgSitename', '' ); |
1167 | | - } |
1168 | | - |
1169 | | - // Set wgMetaNamespace to something valid before we show the form. |
1170 | | - // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki' |
1171 | | - $metaNS = $this->getVar( 'wgMetaNamespace' ); |
1172 | | - $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) ); |
1173 | | - |
1174 | | - $this->addHTML( |
1175 | | - $this->parent->getTextBox( array( |
1176 | | - 'var' => 'wgSitename', |
1177 | | - 'label' => 'config-site-name', |
1178 | | - ) ) . |
1179 | | - $this->parent->getHelpBox( 'config-site-name-help' ) . |
1180 | | - $this->parent->getRadioSet( array( |
1181 | | - 'var' => '_NamespaceType', |
1182 | | - 'label' => 'config-project-namespace', |
1183 | | - 'itemLabelPrefix' => 'config-ns-', |
1184 | | - 'values' => array( 'site-name', 'generic', 'other' ), |
1185 | | - 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ), |
1186 | | - ) ) . |
1187 | | - $this->parent->getTextBox( array( |
1188 | | - 'var' => 'wgMetaNamespace', |
1189 | | - 'label' => '', |
1190 | | - 'attribs' => array( 'disabled' => '' ), |
1191 | | - ) ) . |
1192 | | - $this->parent->getHelpBox( 'config-project-namespace-help' ) . |
1193 | | - $this->parent->getFieldsetStart( 'config-admin-box' ) . |
1194 | | - $this->parent->getTextBox( array( |
1195 | | - 'var' => '_AdminName', |
1196 | | - 'label' => 'config-admin-name' |
1197 | | - ) ) . |
1198 | | - $this->parent->getPasswordBox( array( |
1199 | | - 'var' => '_AdminPassword', |
1200 | | - 'label' => 'config-admin-password', |
1201 | | - ) ) . |
1202 | | - $this->parent->getPasswordBox( array( |
1203 | | - 'var' => '_AdminPassword2', |
1204 | | - 'label' => 'config-admin-password-confirm' |
1205 | | - ) ) . |
1206 | | - $this->parent->getHelpBox( 'config-admin-help' ) . |
1207 | | - $this->parent->getTextBox( array( |
1208 | | - 'var' => '_AdminEmail', |
1209 | | - 'label' => 'config-admin-email' |
1210 | | - ) ) . |
1211 | | - $this->parent->getHelpBox( 'config-admin-email-help' ) . |
1212 | | - $this->parent->getCheckBox( array( |
1213 | | - 'var' => '_Subscribe', |
1214 | | - 'label' => 'config-subscribe' |
1215 | | - ) ) . |
1216 | | - $this->parent->getHelpBox( 'config-subscribe-help' ) . |
1217 | | - $this->parent->getFieldsetEnd() . |
1218 | | - $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) . |
1219 | | - $this->parent->getRadioSet( array( |
1220 | | - 'var' => '_SkipOptional', |
1221 | | - 'itemLabelPrefix' => 'config-optional-', |
1222 | | - 'values' => array( 'continue', 'skip' ) |
1223 | | - ) ) |
1224 | | - ); |
1225 | | - |
1226 | | - // Restore the default value |
1227 | | - $this->setVar( 'wgMetaNamespace', $metaNS ); |
1228 | | - |
1229 | | - $this->endForm(); |
1230 | | - return 'output'; |
1231 | | - } |
1232 | | - |
1233 | | - function submit() { |
1234 | | - $retVal = true; |
1235 | | - $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType', |
1236 | | - '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail', |
1237 | | - '_Subscribe', '_SkipOptional' ) ); |
1238 | | - |
1239 | | - // Validate site name |
1240 | | - if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) { |
1241 | | - $this->parent->showError( 'config-site-name-blank' ); |
1242 | | - $retVal = false; |
1243 | | - } |
1244 | | - |
1245 | | - // Fetch namespace |
1246 | | - $nsType = $this->getVar( '_NamespaceType' ); |
1247 | | - if ( $nsType == 'site-name' ) { |
1248 | | - $name = $this->getVar( 'wgSitename' ); |
1249 | | - // Sanitize for namespace |
1250 | | - // This algorithm should match the JS one in WebInstallerOutput.php |
1251 | | - $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name ); |
1252 | | - $name = str_replace( '&', '&', $name ); |
1253 | | - $name = preg_replace( '/__+/', '_', $name ); |
1254 | | - $name = ucfirst( trim( $name, '_' ) ); |
1255 | | - } elseif ( $nsType == 'generic' ) { |
1256 | | - $name = wfMsg( 'config-ns-generic' ); |
1257 | | - } else { // other |
1258 | | - $name = $this->getVar( 'wgMetaNamespace' ); |
1259 | | - } |
1260 | | - |
1261 | | - // Validate namespace |
1262 | | - if ( strpos( $name, ':' ) !== false ) { |
1263 | | - $good = false; |
1264 | | - } else { |
1265 | | - // Title-style validation |
1266 | | - $title = Title::newFromText( $name ); |
1267 | | - if ( !$title ) { |
1268 | | - $good = $nsType == 'site-name' ? true : false; |
1269 | | - } else { |
1270 | | - $name = $title->getDBkey(); |
1271 | | - $good = true; |
1272 | | - } |
1273 | | - } |
1274 | | - if ( !$good ) { |
1275 | | - $this->parent->showError( 'config-ns-invalid', $name ); |
1276 | | - $retVal = false; |
1277 | | - } |
1278 | | - $this->setVar( 'wgMetaNamespace', $name ); |
1279 | | - |
1280 | | - // Validate username for creation |
1281 | | - $name = $this->getVar( '_AdminName' ); |
1282 | | - if ( strval( $name ) === '' ) { |
1283 | | - $this->parent->showError( 'config-admin-name-blank' ); |
1284 | | - $cname = $name; |
1285 | | - $retVal = false; |
1286 | | - } else { |
1287 | | - $cname = User::getCanonicalName( $name, 'creatable' ); |
1288 | | - if ( $cname === false ) { |
1289 | | - $this->parent->showError( 'config-admin-name-invalid', $name ); |
1290 | | - $retVal = false; |
1291 | | - } else { |
1292 | | - $this->setVar( '_AdminName', $cname ); |
1293 | | - } |
1294 | | - } |
1295 | | - |
1296 | | - // Validate password |
1297 | | - $msg = false; |
1298 | | - $pwd = $this->getVar( '_AdminPassword' ); |
1299 | | - $user = User::newFromName( $cname ); |
1300 | | - $valid = $user->getPasswordValidity( $pwd ); |
1301 | | - if ( strval( $pwd ) === '' ) { |
1302 | | - # $user->getPasswordValidity just checks for $wgMinimalPasswordLength. |
1303 | | - # This message is more specific and helpful. |
1304 | | - $msg = 'config-admin-password-blank'; |
1305 | | - } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) { |
1306 | | - $msg = 'config-admin-password-mismatch'; |
1307 | | - } elseif ( $valid !== true ) { |
1308 | | - # As of writing this will only catch the username being e.g. 'FOO' and |
1309 | | - # the password 'foo' |
1310 | | - $msg = $valid; |
1311 | | - } |
1312 | | - if ( $msg !== false ) { |
1313 | | - $this->parent->showError( $msg ); |
1314 | | - $this->setVar( '_AdminPassword', '' ); |
1315 | | - $this->setVar( '_AdminPassword2', '' ); |
1316 | | - $retVal = false; |
1317 | | - } |
1318 | | - return $retVal; |
1319 | | - } |
1320 | | -} |
1321 | | - |
1322 | | -class WebInstaller_Options extends WebInstallerPage { |
1323 | | - function execute() { |
1324 | | - if ( $this->getVar( '_SkipOptional' ) == 'skip' ) { |
1325 | | - return 'skip'; |
1326 | | - } |
1327 | | - if ( $this->parent->request->wasPosted() ) { |
1328 | | - if ( $this->submit() ) { |
1329 | | - return 'continue'; |
1330 | | - } |
1331 | | - } |
1332 | | - |
1333 | | - $this->startForm(); |
1334 | | - $this->addHTML( |
1335 | | - # User Rights |
1336 | | - $this->parent->getRadioSet( array( |
1337 | | - 'var' => '_RightsProfile', |
1338 | | - 'label' => 'config-profile', |
1339 | | - 'itemLabelPrefix' => 'config-profile-', |
1340 | | - 'values' => array_keys( $this->parent->rightsProfiles ), |
1341 | | - ) ) . |
1342 | | - $this->parent->getHelpBox( 'config-profile-help' ) . |
1343 | | - |
1344 | | - # Licensing |
1345 | | - $this->parent->getRadioSet( array( |
1346 | | - 'var' => '_LicenseCode', |
1347 | | - 'label' => 'config-license', |
1348 | | - 'itemLabelPrefix' => 'config-license-', |
1349 | | - 'values' => array_keys( $this->parent->licenses ), |
1350 | | - 'commonAttribs' => array( 'class' => 'licenseRadio' ), |
1351 | | - ) ) . |
1352 | | - $this->getCCChooser() . |
1353 | | - $this->parent->getHelpBox( 'config-license-help' ) . |
1354 | | - |
1355 | | - # E-mail |
1356 | | - $this->parent->getFieldsetStart( 'config-email-settings' ) . |
1357 | | - $this->parent->getCheckBox( array( |
1358 | | - 'var' => 'wgEnableEmail', |
1359 | | - 'label' => 'config-enable-email', |
1360 | | - 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ), |
1361 | | - ) ) . |
1362 | | - $this->parent->getHelpBox( 'config-enable-email-help' ) . |
1363 | | - "<div id=\"emailwrapper\">" . |
1364 | | - $this->parent->getTextBox( array( |
1365 | | - 'var' => 'wgPasswordSender', |
1366 | | - 'label' => 'config-email-sender' |
1367 | | - ) ) . |
1368 | | - $this->parent->getHelpBox( 'config-email-sender-help' ) . |
1369 | | - $this->parent->getCheckBox( array( |
1370 | | - 'var' => 'wgEnableUserEmail', |
1371 | | - 'label' => 'config-email-user', |
1372 | | - ) ) . |
1373 | | - $this->parent->getHelpBox( 'config-email-user-help' ) . |
1374 | | - $this->parent->getCheckBox( array( |
1375 | | - 'var' => 'wgEnotifUserTalk', |
1376 | | - 'label' => 'config-email-usertalk', |
1377 | | - ) ) . |
1378 | | - $this->parent->getHelpBox( 'config-email-usertalk-help' ) . |
1379 | | - $this->parent->getCheckBox( array( |
1380 | | - 'var' => 'wgEnotifWatchlist', |
1381 | | - 'label' => 'config-email-watchlist', |
1382 | | - ) ) . |
1383 | | - $this->parent->getHelpBox( 'config-email-watchlist-help' ) . |
1384 | | - $this->parent->getCheckBox( array( |
1385 | | - 'var' => 'wgEmailAuthentication', |
1386 | | - 'label' => 'config-email-auth', |
1387 | | - ) ) . |
1388 | | - $this->parent->getHelpBox( 'config-email-auth-help' ) . |
1389 | | - "</div>" . |
1390 | | - $this->parent->getFieldsetEnd() |
1391 | | - ); |
1392 | | - |
1393 | | - $extensions = $this->parent->findExtensions(); |
1394 | | - if( $extensions ) { |
1395 | | - $extHtml = $this->parent->getFieldsetStart( 'config-extensions' ); |
1396 | | - foreach( array_keys($extensions) as $ext ) { |
1397 | | - $extHtml .= $this->parent->getCheckBox( array( |
1398 | | - 'var' => "ext-$ext", |
1399 | | - 'rawtext' => $ext, |
1400 | | - ) ); |
1401 | | - } |
1402 | | - $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) . |
1403 | | - $this->parent->getFieldsetEnd(); |
1404 | | - $this->addHTML( $extHtml ); |
1405 | | - } |
1406 | | - |
1407 | | - $this->addHTML( |
1408 | | - # Uploading |
1409 | | - $this->parent->getFieldsetStart( 'config-upload-settings' ) . |
1410 | | - $this->parent->getCheckBox( array( |
1411 | | - 'var' => 'wgEnableUploads', |
1412 | | - 'label' => 'config-upload-enable', |
1413 | | - 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ), |
1414 | | - ) ) . |
1415 | | - $this->parent->getHelpBox( 'config-upload-help' ) . |
1416 | | - '<div id="uploadwrapper" style="display: none;">' . |
1417 | | - $this->parent->getTextBox( array( |
1418 | | - 'var' => 'wgDeletedDirectory', |
1419 | | - 'label' => 'config-upload-deleted', |
1420 | | - ) ) . |
1421 | | - $this->parent->getHelpBox( 'config-upload-deleted-help' ) . |
1422 | | - '</div>' . |
1423 | | - $this->parent->getTextBox( array( |
1424 | | - 'var' => 'wgLogo', |
1425 | | - 'label' => 'config-logo' |
1426 | | - ) ) . |
1427 | | - $this->parent->getHelpBox( 'config-logo-help' ) |
1428 | | - ); |
1429 | | - $canUse = $this->getVar( '_ExternalHTTP' ) ? |
1430 | | - 'config-instantcommons-good' : 'config-instantcommons-bad'; |
1431 | | - $this->addHTML( |
1432 | | - $this->parent->getCheckBox( array( |
1433 | | - 'var' => 'wgUseInstantCommons', |
1434 | | - 'label' => 'config-instantcommons', |
1435 | | - ) ) . |
1436 | | - $this->parent->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) . |
1437 | | - $this->parent->getFieldsetEnd() |
1438 | | - ); |
1439 | | - |
1440 | | - $caches = array( 'none' ); |
1441 | | - if( count( $this->getVar( '_Caches' ) ) ) { |
1442 | | - $caches[] = 'accel'; |
1443 | | - } |
1444 | | - $caches[] = 'memcached'; |
1445 | | - |
1446 | | - $this->addHTML( |
1447 | | - # Advanced settings |
1448 | | - $this->parent->getFieldsetStart( 'config-advanced-settings' ) . |
1449 | | - # Object cache settings |
1450 | | - $this->parent->getRadioSet( array( |
1451 | | - 'var' => 'wgMainCacheType', |
1452 | | - 'label' => 'config-cache-options', |
1453 | | - 'itemLabelPrefix' => 'config-cache-', |
1454 | | - 'values' => $caches, |
1455 | | - 'value' => 'none', |
1456 | | - ) ) . |
1457 | | - $this->parent->getHelpBox( 'config-cache-help' ) . |
1458 | | - '<div id="config-memcachewrapper">' . |
1459 | | - $this->parent->getTextBox( array( |
1460 | | - 'var' => '_MemCachedServers', |
1461 | | - 'label' => 'config-memcached-servers', |
1462 | | - ) ) . |
1463 | | - $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' . |
1464 | | - $this->parent->getFieldsetEnd() |
1465 | | - ); |
1466 | | - $this->endForm(); |
1467 | | - } |
1468 | | - |
1469 | | - function getCCPartnerUrl() { |
1470 | | - global $wgServer; |
1471 | | - $exitUrl = $wgServer . $this->parent->getUrl( array( |
1472 | | - 'page' => 'Options', |
1473 | | - 'SubmitCC' => 'indeed', |
1474 | | - 'config__LicenseCode' => 'cc', |
1475 | | - 'config_wgRightsUrl' => '[license_url]', |
1476 | | - 'config_wgRightsText' => '[license_name]', |
1477 | | - 'config_wgRightsIcon' => '[license_button]', |
1478 | | - ) ); |
1479 | | - $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) . |
1480 | | - '/skins/common/config-cc.css'; |
1481 | | - $iframeUrl = 'http://creativecommons.org/license/?' . |
1482 | | - wfArrayToCGI( array( |
1483 | | - 'partner' => 'MediaWiki', |
1484 | | - 'exit_url' => $exitUrl, |
1485 | | - 'lang' => $this->getVar( '_UserLang' ), |
1486 | | - 'stylesheet' => $styleUrl, |
1487 | | - ) ); |
1488 | | - return $iframeUrl; |
1489 | | - } |
1490 | | - |
1491 | | - function getCCChooser() { |
1492 | | - $iframeAttribs = array( |
1493 | | - 'class' => 'config-cc-iframe', |
1494 | | - 'name' => 'config-cc-iframe', |
1495 | | - 'id' => 'config-cc-iframe', |
1496 | | - 'frameborder' => 0, |
1497 | | - 'width' => '100%', |
1498 | | - 'height' => '100%', |
1499 | | - ); |
1500 | | - if ( $this->getVar( '_CCDone' ) ) { |
1501 | | - $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) ); |
1502 | | - } else { |
1503 | | - $iframeAttribs['src'] = $this->getCCPartnerUrl(); |
1504 | | - } |
1505 | | - |
1506 | | - return |
1507 | | - "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" . |
1508 | | - Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) . |
1509 | | - "</div>\n"; |
1510 | | - } |
1511 | | - |
1512 | | - function getCCDoneBox() { |
1513 | | - $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';"; |
1514 | | - // If you change this height, also change it in config.css |
1515 | | - $expandJs = str_replace( '$1', '54em', $js ); |
1516 | | - $reduceJs = str_replace( '$1', '70px', $js ); |
1517 | | - return |
1518 | | - '<p>'. |
1519 | | - Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) . |
1520 | | - '  ' . |
1521 | | - htmlspecialchars( $this->getVar( 'wgRightsText' ) ) . |
1522 | | - "</p>\n" . |
1523 | | - "<p style=\"text-align: center\">" . |
1524 | | - Xml::element( 'a', |
1525 | | - array( |
1526 | | - 'href' => $this->getCCPartnerUrl(), |
1527 | | - 'onclick' => $expandJs, |
1528 | | - ), |
1529 | | - wfMsg( 'config-cc-again' ) |
1530 | | - ) . |
1531 | | - "</p>\n" . |
1532 | | - "<script type=\"text/javascript\">\n" . |
1533 | | - # Reduce the wrapper div height |
1534 | | - htmlspecialchars( $reduceJs ) . |
1535 | | - "\n" . |
1536 | | - "</script>\n"; |
1537 | | - } |
1538 | | - |
1539 | | - |
1540 | | - function submitCC() { |
1541 | | - $newValues = $this->parent->setVarsFromRequest( |
1542 | | - array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) ); |
1543 | | - if ( count( $newValues ) != 3 ) { |
1544 | | - $this->parent->showError( 'config-cc-error' ); |
1545 | | - return; |
1546 | | - } |
1547 | | - $this->setVar( '_CCDone', true ); |
1548 | | - $this->addHTML( $this->getCCDoneBox() ); |
1549 | | - } |
1550 | | - |
1551 | | - function submit() { |
1552 | | - $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode', |
1553 | | - 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUpload', 'wgLogo', |
1554 | | - 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist', |
1555 | | - 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers', |
1556 | | - 'wgUseInstantCommons' ) ); |
1557 | | - |
1558 | | - if ( !in_array( $this->getVar( '_RightsProfile' ), |
1559 | | - array_keys( $this->parent->rightsProfiles ) ) ) |
1560 | | - { |
1561 | | - reset( $this->parent->rightsProfiles ); |
1562 | | - $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) ); |
1563 | | - } |
1564 | | - |
1565 | | - $code = $this->getVar( '_LicenseCode' ); |
1566 | | - if ( $code == 'cc-choose' ) { |
1567 | | - if ( !$this->getVar( '_CCDone' ) ) { |
1568 | | - $this->parent->showError( 'config-cc-not-chosen' ); |
1569 | | - return false; |
1570 | | - } |
1571 | | - } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) { |
1572 | | - $entry = $this->parent->licenses[$code]; |
1573 | | - if ( isset( $entry['text'] ) ) { |
1574 | | - $this->setVar( 'wgRightsText', $entry['text'] ); |
1575 | | - } else { |
1576 | | - $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) ); |
1577 | | - } |
1578 | | - $this->setVar( 'wgRightsUrl', $entry['url'] ); |
1579 | | - $this->setVar( 'wgRightsIcon', $entry['icon'] ); |
1580 | | - } else { |
1581 | | - $this->setVar( 'wgRightsText', '' ); |
1582 | | - $this->setVar( 'wgRightsUrl', '' ); |
1583 | | - $this->setVar( 'wgRightsIcon', '' ); |
1584 | | - } |
1585 | | - |
1586 | | - $exts = $this->parent->getVar( '_Extensions' ); |
1587 | | - foreach( $exts as $key => $ext ) { |
1588 | | - if( !$this->parent->request->getCheck( 'config_ext-' . $ext ) ) { |
1589 | | - unset( $exts[$key] ); |
1590 | | - } |
1591 | | - } |
1592 | | - $this->parent->setVar( '_Extensions', $exts ); |
1593 | | - return true; |
1594 | | - } |
1595 | | -} |
1596 | | - |
1597 | | -class WebInstaller_Install extends WebInstallerPage { |
1598 | | - |
1599 | | - function execute() { |
1600 | | - if( $this->parent->request->wasPosted() ) { |
1601 | | - return 'continue'; |
1602 | | - } elseif( $this->getVar( '_InstallDone' ) ) { |
1603 | | - $this->startForm(); |
1604 | | - $status = new Status(); |
1605 | | - $status->warning( 'config-install-alreadydone' ); |
1606 | | - $this->parent->showStatusBox( $status ); |
1607 | | - } else { |
1608 | | - $this->startForm(); |
1609 | | - $this->addHTML("<ul>"); |
1610 | | - $this->parent->performInstallation( |
1611 | | - array( $this, 'startStage'), |
1612 | | - array( $this, 'endStage' ) |
1613 | | - ); |
1614 | | - $this->addHTML("</ul>"); |
1615 | | - } |
1616 | | - $this->endForm(); |
1617 | | - return true; |
1618 | | - } |
1619 | | - |
1620 | | - public function startStage( $step ) { |
1621 | | - $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') ); |
1622 | | - } |
1623 | | - |
1624 | | - public function endStage( $step, $status ) { |
1625 | | - $success = $status->isGood(); |
1626 | | - $msg = $success ? 'config-install-step-done' : 'config-install-step-failed'; |
1627 | | - $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg ); |
1628 | | - if ( !$success ) { |
1629 | | - $html = "<span class=\"error\">$html</span>"; |
1630 | | - } |
1631 | | - $this->addHTML( $html . "</li>\n" ); |
1632 | | - if( !$success ) { |
1633 | | - $this->parent->showStatusBox( $status ); |
1634 | | - } |
1635 | | - } |
1636 | | -} |
1637 | | - |
1638 | | -class WebInstaller_Complete extends WebInstallerPage { |
1639 | | - public function execute() { |
1640 | | - global $IP; |
1641 | | - $this->startForm(); |
1642 | | - $this->addHTML( |
1643 | | - $this->parent->getInfoBox( |
1644 | | - wfMsgNoTrans( 'config-install-done', |
1645 | | - $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) ), |
1646 | | - $GLOBALS['wgServer'] . |
1647 | | - $this->getVar( 'wgScriptPath' ) . '/index' . |
1648 | | - $this->getVar( 'wgScriptExtension' ) |
1649 | | - ), 'tick-32.png' |
1650 | | - ) |
1651 | | - ); |
1652 | | - $this->endForm( false ); |
1653 | | - } |
1654 | | -} |
1655 | | - |
1656 | | -class WebInstaller_Restart extends WebInstallerPage { |
1657 | | - function execute() { |
1658 | | - $r = $this->parent->request; |
1659 | | - if ( $r->wasPosted() ) { |
1660 | | - $really = $r->getVal( 'submit-restart' ); |
1661 | | - if ( $really ) { |
1662 | | - $this->parent->session = array(); |
1663 | | - $this->parent->happyPages = array(); |
1664 | | - $this->parent->settings = array(); |
1665 | | - } |
1666 | | - return 'continue'; |
1667 | | - } |
1668 | | - |
1669 | | - $this->startForm(); |
1670 | | - $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) ); |
1671 | | - $this->addHTML( $s ); |
1672 | | - $this->endForm( 'restart' ); |
1673 | | - } |
1674 | | -} |
1675 | | - |
1676 | | -abstract class WebInstaller_Document extends WebInstallerPage { |
1677 | | - abstract function getFileName(); |
1678 | | - |
1679 | | - function execute() { |
1680 | | - $text = $this->getFileContents(); |
1681 | | - $this->parent->output->addWikiText( $text ); |
1682 | | - $this->startForm(); |
1683 | | - $this->endForm( false ); |
1684 | | - } |
1685 | | - |
1686 | | - function getFileContents() { |
1687 | | - return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() ); |
1688 | | - } |
1689 | | - |
1690 | | - protected function formatTextFile( $text ) { |
1691 | | - $text = str_replace( array( '<', '{{', '[[' ), |
1692 | | - array( '<', '{{', '[[' ), $text ); |
1693 | | - // replace numbering with [1], [2], etc with MW-style numbering |
1694 | | - $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text ); |
1695 | | - // join word-wrapped lines into one |
1696 | | - do { |
1697 | | - $prev = $text; |
1698 | | - $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text ); |
1699 | | - } while ( $text != $prev ); |
1700 | | - // turn (bug nnnn) into links |
1701 | | - $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text ); |
1702 | | - // add links to manual to every global variable mentioned |
1703 | | - $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text ); |
1704 | | - // special case for <pre> - formatted links |
1705 | | - do { |
1706 | | - $prev = $text; |
1707 | | - $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text ); |
1708 | | - } while ( $text != $prev ); |
1709 | | - return $text; |
1710 | | - } |
1711 | | - |
1712 | | - private function replaceBugLinks( $matches ) { |
1713 | | - return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' . |
1714 | | - $matches[1] . ' bug ' . $matches[1] . ']</span>'; |
1715 | | - } |
1716 | | - |
1717 | | - private function replaceConfigLinks( $matches ) { |
1718 | | - return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' . |
1719 | | - $matches[1] . ' ' . $matches[1] . ']</span>'; |
1720 | | - } |
1721 | | -} |
1722 | | - |
1723 | | -class WebInstaller_Readme extends WebInstaller_Document { |
1724 | | - function getFileName() { return 'README'; } |
1725 | | - |
1726 | | - function getFileContents() { |
1727 | | - return $this->formatTextFile( parent::getFileContents() ); |
1728 | | - } |
1729 | | -} |
1730 | | - |
1731 | | -class WebInstaller_ReleaseNotes extends WebInstaller_Document { |
1732 | | - function getFileName() { return 'RELEASE-NOTES'; } |
1733 | | - |
1734 | | - function getFileContents() { |
1735 | | - return $this->formatTextFile( parent::getFileContents() ); |
1736 | | - } |
1737 | | -} |
1738 | | - |
1739 | | -class WebInstaller_UpgradeDoc extends WebInstaller_Document { |
1740 | | - function getFileName() { return 'UPGRADE'; } |
1741 | | - |
1742 | | - function getFileContents() { |
1743 | | - return $this->formatTextFile( parent::getFileContents() ); |
1744 | | - } |
1745 | | -} |
1746 | | - |
1747 | | -class WebInstaller_Copying extends WebInstaller_Document { |
1748 | | - function getFileName() { return 'COPYING'; } |
1749 | | - |
1750 | | - function getFileContents() { |
1751 | | - $text = parent::getFileContents(); |
1752 | | - $text = str_replace( "\x0C", '', $text ); |
1753 | | - $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text ); |
1754 | | - $text = '<tt>' . nl2br( $text ) . '</tt>'; |
1755 | | - return $text; |
1756 | | - } |
1757 | | - |
1758 | | - private static function replaceLeadingSpaces( $matches ) { |
1759 | | - return "\n" . str_repeat( ' ', strlen( $matches[0] ) ); |
1760 | | - } |
1761 | | -} |
\ No newline at end of file |
Index: trunk/phase3/includes/installer/WebInstallerPage.php |
— | — | @@ -0,0 +1,938 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Abstract class to define pages for the web installer. |
| 6 | + */ |
| 7 | +abstract class WebInstallerPage { |
| 8 | + |
| 9 | + public abstract function execute(); |
| 10 | + |
| 11 | + public function __construct( $parent ) { |
| 12 | + // TODO: This field is not defined?? |
| 13 | + $this->parent = $parent; |
| 14 | + } |
| 15 | + |
| 16 | + public function addHTML( $html ) { |
| 17 | + $this->parent->output->addHTML( $html ); |
| 18 | + } |
| 19 | + |
| 20 | + public function startForm() { |
| 21 | + $this->addHTML( |
| 22 | + "<div class=\"config-section\">\n" . |
| 23 | + Xml::openElement( |
| 24 | + 'form', |
| 25 | + array( |
| 26 | + 'method' => 'post', |
| 27 | + 'action' => $this->parent->getUrl( array( 'page' => $this->getName() ) ) |
| 28 | + ) |
| 29 | + ) . "\n" |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + public function endForm( $continue = 'continue' ) { |
| 34 | + $this->parent->output->outputWarnings(); |
| 35 | + $s = "<div class=\"config-submit\">\n"; |
| 36 | + $id = $this->getId(); |
| 37 | + if ( $id === false ) { |
| 38 | + $s .= Xml::hidden( 'lastPage', $this->parent->request->getVal( 'lastPage' ) ); |
| 39 | + } |
| 40 | + if ( $continue ) { |
| 41 | + // Fake submit button for enter keypress |
| 42 | + $s .= Xml::submitButton( wfMsg( "config-$continue" ), |
| 43 | + array( 'name' => "enter-$continue", 'style' => 'display:none' ) ) . "\n"; |
| 44 | + } |
| 45 | + if ( $id !== 0 ) { |
| 46 | + $s .= Xml::submitButton( wfMsg( 'config-back' ), |
| 47 | + array( |
| 48 | + 'name' => 'submit-back', |
| 49 | + 'tabindex' => $this->parent->nextTabIndex() |
| 50 | + ) ) . "\n"; |
| 51 | + } |
| 52 | + if ( $continue ) { |
| 53 | + $s .= Xml::submitButton( wfMsg( "config-$continue" ), |
| 54 | + array( |
| 55 | + 'name' => "submit-$continue", |
| 56 | + 'tabindex' => $this->parent->nextTabIndex(), |
| 57 | + ) ) . "\n"; |
| 58 | + } |
| 59 | + $s .= "</div></form></div>\n"; |
| 60 | + $this->addHTML( $s ); |
| 61 | + } |
| 62 | + |
| 63 | + public function getName() { |
| 64 | + return str_replace( 'WebInstaller_', '', get_class( $this ) ); |
| 65 | + } |
| 66 | + |
| 67 | + public function getId() { |
| 68 | + return array_search( $this->getName(), $this->parent->pageSequence ); |
| 69 | + } |
| 70 | + |
| 71 | + public function getVar( $var ) { |
| 72 | + return $this->parent->getVar( $var ); |
| 73 | + } |
| 74 | + |
| 75 | + public function setVar( $name, $value ) { |
| 76 | + $this->parent->setVar( $name, $value ); |
| 77 | + } |
| 78 | + |
| 79 | +} |
| 80 | + |
| 81 | +class WebInstaller_Language extends WebInstallerPage { |
| 82 | + function execute() { |
| 83 | + global $wgLang; |
| 84 | + $r = $this->parent->request; |
| 85 | + $userLang = $r->getVal( 'UserLang' ); |
| 86 | + $contLang = $r->getVal( 'ContLang' ); |
| 87 | + |
| 88 | + $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) ); |
| 89 | + if ( !$lifetime ) { |
| 90 | + $lifetime = 1440; // PHP default |
| 91 | + } |
| 92 | + |
| 93 | + if ( $r->wasPosted() ) { |
| 94 | + # Do session test |
| 95 | + if ( $this->parent->getSession( 'test' ) === null ) { |
| 96 | + $requestTime = $r->getVal( 'LanguageRequestTime' ); |
| 97 | + if ( !$requestTime ) { |
| 98 | + // The most likely explanation is that the user was knocked back |
| 99 | + // from another page on POST due to session expiry |
| 100 | + $msg = 'config-session-expired'; |
| 101 | + } elseif ( time() - $requestTime > $lifetime ) { |
| 102 | + $msg = 'config-session-expired'; |
| 103 | + } else { |
| 104 | + $msg = 'config-no-session'; |
| 105 | + } |
| 106 | + $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) ); |
| 107 | + } else { |
| 108 | + $languages = Language::getLanguageNames(); |
| 109 | + if ( isset( $languages[$userLang] ) ) { |
| 110 | + $this->setVar( '_UserLang', $userLang ); |
| 111 | + } |
| 112 | + if ( isset( $languages[$contLang] ) ) { |
| 113 | + $this->setVar( 'wgLanguageCode', $contLang ); |
| 114 | + } |
| 115 | + return 'continue'; |
| 116 | + } |
| 117 | + } elseif ( $this->parent->showSessionWarning ) { |
| 118 | + # The user was knocked back from another page to the start |
| 119 | + # This probably indicates a session expiry |
| 120 | + $this->parent->showError( 'config-session-expired', $wgLang->formatTimePeriod( $lifetime ) ); |
| 121 | + } |
| 122 | + |
| 123 | + $this->parent->setSession( 'test', true ); |
| 124 | + |
| 125 | + if ( !isset( $languages[$userLang] ) ) { |
| 126 | + $userLang = $this->getVar( '_UserLang', 'en' ); |
| 127 | + } |
| 128 | + if ( !isset( $languages[$contLang] ) ) { |
| 129 | + $contLang = $this->getVar( 'wgLanguageCode', 'en' ); |
| 130 | + } |
| 131 | + $this->startForm(); |
| 132 | + $s = |
| 133 | + Xml::hidden( 'LanguageRequestTime', time() ) . |
| 134 | + $this->getLanguageSelector( 'UserLang', 'config-your-language', $userLang ) . |
| 135 | + $this->parent->getHelpBox( 'config-your-language-help' ) . |
| 136 | + $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang ) . |
| 137 | + $this->parent->getHelpBox( 'config-wiki-language-help' ); |
| 138 | + |
| 139 | + |
| 140 | + $this->addHTML( $s ); |
| 141 | + $this->endForm(); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Get a <select> for selecting languages |
| 146 | + */ |
| 147 | + function getLanguageSelector( $name, $label, $selectedCode ) { |
| 148 | + global $wgDummyLanguageCodes; |
| 149 | + $s = Xml::openElement( 'select', array( 'id' => $name, 'name' => $name ) ) . "\n"; |
| 150 | + |
| 151 | + $languages = Language::getLanguageNames(); |
| 152 | + ksort( $languages ); |
| 153 | + $dummies = array_flip( $wgDummyLanguageCodes ); |
| 154 | + foreach ( $languages as $code => $lang ) { |
| 155 | + if ( isset( $dummies[$code] ) ) continue; |
| 156 | + $s .= "\n" . Xml::option( "$code - $lang", $code, $code == $selectedCode ); |
| 157 | + } |
| 158 | + $s .= "\n</select>\n"; |
| 159 | + return $this->parent->label( $label, $name, $s ); |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +class WebInstaller_Welcome extends WebInstallerPage { |
| 164 | + function execute() { |
| 165 | + if ( $this->parent->request->wasPosted() ) { |
| 166 | + if ( $this->getVar( '_Environment' ) ) { |
| 167 | + return 'continue'; |
| 168 | + } |
| 169 | + } |
| 170 | + $this->parent->output->addWikiText( wfMsgNoTrans( 'config-welcome' ) ); |
| 171 | + $status = $this->parent->doEnvironmentChecks(); |
| 172 | + if ( $status ) { |
| 173 | + $this->parent->output->addWikiText( wfMsgNoTrans( 'config-copyright', wfMsg( 'config-authors' ) ) ); |
| 174 | + $this->startForm(); |
| 175 | + $this->endForm(); |
| 176 | + } |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +class WebInstaller_DBConnect extends WebInstallerPage { |
| 181 | + function execute() { |
| 182 | + $r = $this->parent->request; |
| 183 | + if ( $r->wasPosted() ) { |
| 184 | + $status = $this->submit(); |
| 185 | + if ( $status->isGood() ) { |
| 186 | + $this->setVar( '_UpgradeDone', false ); |
| 187 | + return 'continue'; |
| 188 | + } else { |
| 189 | + $this->parent->showStatusBox( $status ); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + |
| 194 | + $this->startForm(); |
| 195 | + |
| 196 | + $types = "<ul class=\"config-settings-block\">\n"; |
| 197 | + $settings = ''; |
| 198 | + $defaultType = $this->getVar( 'wgDBtype' ); |
| 199 | + foreach ( $this->parent->getVar( '_CompiledDBs' ) as $type ) { |
| 200 | + $installer = $this->parent->getDBInstaller( $type ); |
| 201 | + $types .= |
| 202 | + '<li>' . |
| 203 | + Xml::radioLabel( |
| 204 | + $installer->getReadableName(), |
| 205 | + 'DBType', |
| 206 | + $type, |
| 207 | + "DBType_$type", |
| 208 | + $type == $defaultType, |
| 209 | + array( 'class' => 'dbRadio', 'rel' => "DB_wrapper_$type" ) |
| 210 | + ) . |
| 211 | + "</li>\n"; |
| 212 | + |
| 213 | + $settings .= |
| 214 | + Xml::openElement( 'div', array( 'id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper' ) ) . |
| 215 | + Xml::element( 'h3', array(), wfMsg( 'config-header-' . $type ) ) . |
| 216 | + $installer->getConnectForm() . |
| 217 | + "</div>\n"; |
| 218 | + } |
| 219 | + $types .= "</ul><br clear=\"left\"/>\n"; |
| 220 | + |
| 221 | + $this->addHTML( |
| 222 | + $this->parent->label( 'config-db-type', false, $types ) . |
| 223 | + $settings |
| 224 | + ); |
| 225 | + |
| 226 | + $this->endForm(); |
| 227 | + } |
| 228 | + |
| 229 | + function submit() { |
| 230 | + $r = $this->parent->request; |
| 231 | + $type = $r->getVal( 'DBType' ); |
| 232 | + $this->setVar( 'wgDBtype', $type ); |
| 233 | + $installer = $this->parent->getDBInstaller( $type ); |
| 234 | + if ( !$installer ) { |
| 235 | + return Status::newFatal( 'config-invalid-db-type' ); |
| 236 | + } |
| 237 | + return $installer->submitConnectForm(); |
| 238 | + } |
| 239 | +} |
| 240 | + |
| 241 | +class WebInstaller_Upgrade extends WebInstallerPage { |
| 242 | + function execute() { |
| 243 | + if ( $this->getVar( '_UpgradeDone' ) ) { |
| 244 | + if ( $this->parent->request->wasPosted() ) { |
| 245 | + // Done message acknowledged |
| 246 | + return 'continue'; |
| 247 | + } else { |
| 248 | + // Back button click |
| 249 | + // Show the done message again |
| 250 | + // Make them click back again if they want to do the upgrade again |
| 251 | + $this->showDoneMessage(); |
| 252 | + return 'output'; |
| 253 | + } |
| 254 | + } |
| 255 | + |
| 256 | + // wgDBtype is generally valid here because otherwise the previous page |
| 257 | + // (connect) wouldn't have declared its happiness |
| 258 | + $type = $this->getVar( 'wgDBtype' ); |
| 259 | + $installer = $this->parent->getDBInstaller( $type ); |
| 260 | + |
| 261 | + if ( !$installer->needsUpgrade() ) { |
| 262 | + return 'skip'; |
| 263 | + } |
| 264 | + |
| 265 | + if ( $this->parent->request->wasPosted() ) { |
| 266 | + $this->addHTML( |
| 267 | + '<div id="config-spinner" style="display:none;"><img src="../skins/common/images/ajax-loader.gif" /></div>' . |
| 268 | + '<script>jQuery( "#config-spinner" )[0].style.display = "block";</script>' . |
| 269 | + '<textarea id="config-update-log" name="UpdateLog" rows="10" readonly="readonly">' |
| 270 | + ); |
| 271 | + $this->parent->output->flush(); |
| 272 | + $result = $installer->doUpgrade(); |
| 273 | + $this->addHTML( '</textarea> |
| 274 | +<script>jQuery( "#config-spinner" )[0].style.display = "none";</script>' ); |
| 275 | + $this->parent->output->flush(); |
| 276 | + if ( $result ) { |
| 277 | + $this->setVar( '_UpgradeDone', true ); |
| 278 | + $this->showDoneMessage(); |
| 279 | + return 'output'; |
| 280 | + } |
| 281 | + } |
| 282 | + |
| 283 | + $this->startForm(); |
| 284 | + $this->addHTML( $this->parent->getInfoBox( |
| 285 | + wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) ); |
| 286 | + $this->endForm(); |
| 287 | + } |
| 288 | + |
| 289 | + function showDoneMessage() { |
| 290 | + $this->startForm(); |
| 291 | + $this->addHTML( |
| 292 | + $this->parent->getInfoBox( |
| 293 | + wfMsgNoTrans( 'config-upgrade-done', |
| 294 | + $GLOBALS['wgServer'] . |
| 295 | + $this->getVar( 'wgScriptPath' ) . '/index' . |
| 296 | + $this->getVar( 'wgScriptExtension' ) |
| 297 | + ), 'tick-32.png' |
| 298 | + ) |
| 299 | + ); |
| 300 | + $this->endForm( 'regenerate' ); |
| 301 | + } |
| 302 | +} |
| 303 | + |
| 304 | +class WebInstaller_DBSettings extends WebInstallerPage { |
| 305 | + function execute() { |
| 306 | + $installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) ); |
| 307 | + |
| 308 | + $r = $this->parent->request; |
| 309 | + if ( $r->wasPosted() ) { |
| 310 | + $status = $installer->submitSettingsForm(); |
| 311 | + if ( $status === false ) { |
| 312 | + return 'skip'; |
| 313 | + } elseif ( $status->isGood() ) { |
| 314 | + return 'continue'; |
| 315 | + } else { |
| 316 | + $this->parent->showStatusBox( $status ); |
| 317 | + } |
| 318 | + } |
| 319 | + |
| 320 | + $form = $installer->getSettingsForm(); |
| 321 | + if ( $form === false ) { |
| 322 | + return 'skip'; |
| 323 | + } |
| 324 | + |
| 325 | + $this->startForm(); |
| 326 | + $this->addHTML( $form ); |
| 327 | + $this->endForm(); |
| 328 | + } |
| 329 | + |
| 330 | +} |
| 331 | + |
| 332 | +class WebInstaller_Name extends WebInstallerPage { |
| 333 | + function execute() { |
| 334 | + $r = $this->parent->request; |
| 335 | + if ( $r->wasPosted() ) { |
| 336 | + if ( $this->submit() ) { |
| 337 | + return 'continue'; |
| 338 | + } |
| 339 | + } |
| 340 | + |
| 341 | + $this->startForm(); |
| 342 | + |
| 343 | + if ( $this->getVar( 'wgSitename' ) == $GLOBALS['wgSitename'] ) { |
| 344 | + $this->setVar( 'wgSitename', '' ); |
| 345 | + } |
| 346 | + |
| 347 | + // Set wgMetaNamespace to something valid before we show the form. |
| 348 | + // $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki' |
| 349 | + $metaNS = $this->getVar( 'wgMetaNamespace' ); |
| 350 | + $this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) ); |
| 351 | + |
| 352 | + $this->addHTML( |
| 353 | + $this->parent->getTextBox( array( |
| 354 | + 'var' => 'wgSitename', |
| 355 | + 'label' => 'config-site-name', |
| 356 | + ) ) . |
| 357 | + $this->parent->getHelpBox( 'config-site-name-help' ) . |
| 358 | + $this->parent->getRadioSet( array( |
| 359 | + 'var' => '_NamespaceType', |
| 360 | + 'label' => 'config-project-namespace', |
| 361 | + 'itemLabelPrefix' => 'config-ns-', |
| 362 | + 'values' => array( 'site-name', 'generic', 'other' ), |
| 363 | + 'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ), |
| 364 | + ) ) . |
| 365 | + $this->parent->getTextBox( array( |
| 366 | + 'var' => 'wgMetaNamespace', |
| 367 | + 'label' => '', |
| 368 | + 'attribs' => array( 'disabled' => '' ), |
| 369 | + ) ) . |
| 370 | + $this->parent->getHelpBox( 'config-project-namespace-help' ) . |
| 371 | + $this->parent->getFieldsetStart( 'config-admin-box' ) . |
| 372 | + $this->parent->getTextBox( array( |
| 373 | + 'var' => '_AdminName', |
| 374 | + 'label' => 'config-admin-name' |
| 375 | + ) ) . |
| 376 | + $this->parent->getPasswordBox( array( |
| 377 | + 'var' => '_AdminPassword', |
| 378 | + 'label' => 'config-admin-password', |
| 379 | + ) ) . |
| 380 | + $this->parent->getPasswordBox( array( |
| 381 | + 'var' => '_AdminPassword2', |
| 382 | + 'label' => 'config-admin-password-confirm' |
| 383 | + ) ) . |
| 384 | + $this->parent->getHelpBox( 'config-admin-help' ) . |
| 385 | + $this->parent->getTextBox( array( |
| 386 | + 'var' => '_AdminEmail', |
| 387 | + 'label' => 'config-admin-email' |
| 388 | + ) ) . |
| 389 | + $this->parent->getHelpBox( 'config-admin-email-help' ) . |
| 390 | + $this->parent->getCheckBox( array( |
| 391 | + 'var' => '_Subscribe', |
| 392 | + 'label' => 'config-subscribe' |
| 393 | + ) ) . |
| 394 | + $this->parent->getHelpBox( 'config-subscribe-help' ) . |
| 395 | + $this->parent->getFieldsetEnd() . |
| 396 | + $this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) . |
| 397 | + $this->parent->getRadioSet( array( |
| 398 | + 'var' => '_SkipOptional', |
| 399 | + 'itemLabelPrefix' => 'config-optional-', |
| 400 | + 'values' => array( 'continue', 'skip' ) |
| 401 | + ) ) |
| 402 | + ); |
| 403 | + |
| 404 | + // Restore the default value |
| 405 | + $this->setVar( 'wgMetaNamespace', $metaNS ); |
| 406 | + |
| 407 | + $this->endForm(); |
| 408 | + return 'output'; |
| 409 | + } |
| 410 | + |
| 411 | + function submit() { |
| 412 | + $retVal = true; |
| 413 | + $this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType', |
| 414 | + '_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail', |
| 415 | + '_Subscribe', '_SkipOptional' ) ); |
| 416 | + |
| 417 | + // Validate site name |
| 418 | + if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) { |
| 419 | + $this->parent->showError( 'config-site-name-blank' ); |
| 420 | + $retVal = false; |
| 421 | + } |
| 422 | + |
| 423 | + // Fetch namespace |
| 424 | + $nsType = $this->getVar( '_NamespaceType' ); |
| 425 | + if ( $nsType == 'site-name' ) { |
| 426 | + $name = $this->getVar( 'wgSitename' ); |
| 427 | + // Sanitize for namespace |
| 428 | + // This algorithm should match the JS one in WebInstallerOutput.php |
| 429 | + $name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name ); |
| 430 | + $name = str_replace( '&', '&', $name ); |
| 431 | + $name = preg_replace( '/__+/', '_', $name ); |
| 432 | + $name = ucfirst( trim( $name, '_' ) ); |
| 433 | + } elseif ( $nsType == 'generic' ) { |
| 434 | + $name = wfMsg( 'config-ns-generic' ); |
| 435 | + } else { // other |
| 436 | + $name = $this->getVar( 'wgMetaNamespace' ); |
| 437 | + } |
| 438 | + |
| 439 | + // Validate namespace |
| 440 | + if ( strpos( $name, ':' ) !== false ) { |
| 441 | + $good = false; |
| 442 | + } else { |
| 443 | + // Title-style validation |
| 444 | + $title = Title::newFromText( $name ); |
| 445 | + if ( !$title ) { |
| 446 | + $good = $nsType == 'site-name' ? true : false; |
| 447 | + } else { |
| 448 | + $name = $title->getDBkey(); |
| 449 | + $good = true; |
| 450 | + } |
| 451 | + } |
| 452 | + if ( !$good ) { |
| 453 | + $this->parent->showError( 'config-ns-invalid', $name ); |
| 454 | + $retVal = false; |
| 455 | + } |
| 456 | + $this->setVar( 'wgMetaNamespace', $name ); |
| 457 | + |
| 458 | + // Validate username for creation |
| 459 | + $name = $this->getVar( '_AdminName' ); |
| 460 | + if ( strval( $name ) === '' ) { |
| 461 | + $this->parent->showError( 'config-admin-name-blank' ); |
| 462 | + $cname = $name; |
| 463 | + $retVal = false; |
| 464 | + } else { |
| 465 | + $cname = User::getCanonicalName( $name, 'creatable' ); |
| 466 | + if ( $cname === false ) { |
| 467 | + $this->parent->showError( 'config-admin-name-invalid', $name ); |
| 468 | + $retVal = false; |
| 469 | + } else { |
| 470 | + $this->setVar( '_AdminName', $cname ); |
| 471 | + } |
| 472 | + } |
| 473 | + |
| 474 | + // Validate password |
| 475 | + $msg = false; |
| 476 | + $pwd = $this->getVar( '_AdminPassword' ); |
| 477 | + $user = User::newFromName( $cname ); |
| 478 | + $valid = $user->getPasswordValidity( $pwd ); |
| 479 | + if ( strval( $pwd ) === '' ) { |
| 480 | + # $user->getPasswordValidity just checks for $wgMinimalPasswordLength. |
| 481 | + # This message is more specific and helpful. |
| 482 | + $msg = 'config-admin-password-blank'; |
| 483 | + } elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) { |
| 484 | + $msg = 'config-admin-password-mismatch'; |
| 485 | + } elseif ( $valid !== true ) { |
| 486 | + # As of writing this will only catch the username being e.g. 'FOO' and |
| 487 | + # the password 'foo' |
| 488 | + $msg = $valid; |
| 489 | + } |
| 490 | + if ( $msg !== false ) { |
| 491 | + $this->parent->showError( $msg ); |
| 492 | + $this->setVar( '_AdminPassword', '' ); |
| 493 | + $this->setVar( '_AdminPassword2', '' ); |
| 494 | + $retVal = false; |
| 495 | + } |
| 496 | + return $retVal; |
| 497 | + } |
| 498 | +} |
| 499 | + |
| 500 | +class WebInstaller_Options extends WebInstallerPage { |
| 501 | + function execute() { |
| 502 | + if ( $this->getVar( '_SkipOptional' ) == 'skip' ) { |
| 503 | + return 'skip'; |
| 504 | + } |
| 505 | + if ( $this->parent->request->wasPosted() ) { |
| 506 | + if ( $this->submit() ) { |
| 507 | + return 'continue'; |
| 508 | + } |
| 509 | + } |
| 510 | + |
| 511 | + $this->startForm(); |
| 512 | + $this->addHTML( |
| 513 | + # User Rights |
| 514 | + $this->parent->getRadioSet( array( |
| 515 | + 'var' => '_RightsProfile', |
| 516 | + 'label' => 'config-profile', |
| 517 | + 'itemLabelPrefix' => 'config-profile-', |
| 518 | + 'values' => array_keys( $this->parent->rightsProfiles ), |
| 519 | + ) ) . |
| 520 | + $this->parent->getHelpBox( 'config-profile-help' ) . |
| 521 | + |
| 522 | + # Licensing |
| 523 | + $this->parent->getRadioSet( array( |
| 524 | + 'var' => '_LicenseCode', |
| 525 | + 'label' => 'config-license', |
| 526 | + 'itemLabelPrefix' => 'config-license-', |
| 527 | + 'values' => array_keys( $this->parent->licenses ), |
| 528 | + 'commonAttribs' => array( 'class' => 'licenseRadio' ), |
| 529 | + ) ) . |
| 530 | + $this->getCCChooser() . |
| 531 | + $this->parent->getHelpBox( 'config-license-help' ) . |
| 532 | + |
| 533 | + # E-mail |
| 534 | + $this->parent->getFieldsetStart( 'config-email-settings' ) . |
| 535 | + $this->parent->getCheckBox( array( |
| 536 | + 'var' => 'wgEnableEmail', |
| 537 | + 'label' => 'config-enable-email', |
| 538 | + 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ), |
| 539 | + ) ) . |
| 540 | + $this->parent->getHelpBox( 'config-enable-email-help' ) . |
| 541 | + "<div id=\"emailwrapper\">" . |
| 542 | + $this->parent->getTextBox( array( |
| 543 | + 'var' => 'wgPasswordSender', |
| 544 | + 'label' => 'config-email-sender' |
| 545 | + ) ) . |
| 546 | + $this->parent->getHelpBox( 'config-email-sender-help' ) . |
| 547 | + $this->parent->getCheckBox( array( |
| 548 | + 'var' => 'wgEnableUserEmail', |
| 549 | + 'label' => 'config-email-user', |
| 550 | + ) ) . |
| 551 | + $this->parent->getHelpBox( 'config-email-user-help' ) . |
| 552 | + $this->parent->getCheckBox( array( |
| 553 | + 'var' => 'wgEnotifUserTalk', |
| 554 | + 'label' => 'config-email-usertalk', |
| 555 | + ) ) . |
| 556 | + $this->parent->getHelpBox( 'config-email-usertalk-help' ) . |
| 557 | + $this->parent->getCheckBox( array( |
| 558 | + 'var' => 'wgEnotifWatchlist', |
| 559 | + 'label' => 'config-email-watchlist', |
| 560 | + ) ) . |
| 561 | + $this->parent->getHelpBox( 'config-email-watchlist-help' ) . |
| 562 | + $this->parent->getCheckBox( array( |
| 563 | + 'var' => 'wgEmailAuthentication', |
| 564 | + 'label' => 'config-email-auth', |
| 565 | + ) ) . |
| 566 | + $this->parent->getHelpBox( 'config-email-auth-help' ) . |
| 567 | + "</div>" . |
| 568 | + $this->parent->getFieldsetEnd() |
| 569 | + ); |
| 570 | + |
| 571 | + $extensions = $this->parent->findExtensions(); |
| 572 | + if( $extensions ) { |
| 573 | + $extHtml = $this->parent->getFieldsetStart( 'config-extensions' ); |
| 574 | + foreach( array_keys($extensions) as $ext ) { |
| 575 | + $extHtml .= $this->parent->getCheckBox( array( |
| 576 | + 'var' => "ext-$ext", |
| 577 | + 'rawtext' => $ext, |
| 578 | + ) ); |
| 579 | + } |
| 580 | + $extHtml .= $this->parent->getHelpBox( 'config-extensions-help' ) . |
| 581 | + $this->parent->getFieldsetEnd(); |
| 582 | + $this->addHTML( $extHtml ); |
| 583 | + } |
| 584 | + |
| 585 | + $this->addHTML( |
| 586 | + # Uploading |
| 587 | + $this->parent->getFieldsetStart( 'config-upload-settings' ) . |
| 588 | + $this->parent->getCheckBox( array( |
| 589 | + 'var' => 'wgEnableUploads', |
| 590 | + 'label' => 'config-upload-enable', |
| 591 | + 'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'uploadwrapper' ), |
| 592 | + ) ) . |
| 593 | + $this->parent->getHelpBox( 'config-upload-help' ) . |
| 594 | + '<div id="uploadwrapper" style="display: none;">' . |
| 595 | + $this->parent->getTextBox( array( |
| 596 | + 'var' => 'wgDeletedDirectory', |
| 597 | + 'label' => 'config-upload-deleted', |
| 598 | + ) ) . |
| 599 | + $this->parent->getHelpBox( 'config-upload-deleted-help' ) . |
| 600 | + '</div>' . |
| 601 | + $this->parent->getTextBox( array( |
| 602 | + 'var' => 'wgLogo', |
| 603 | + 'label' => 'config-logo' |
| 604 | + ) ) . |
| 605 | + $this->parent->getHelpBox( 'config-logo-help' ) |
| 606 | + ); |
| 607 | + $canUse = $this->getVar( '_ExternalHTTP' ) ? |
| 608 | + 'config-instantcommons-good' : 'config-instantcommons-bad'; |
| 609 | + $this->addHTML( |
| 610 | + $this->parent->getCheckBox( array( |
| 611 | + 'var' => 'wgUseInstantCommons', |
| 612 | + 'label' => 'config-instantcommons', |
| 613 | + ) ) . |
| 614 | + $this->parent->getHelpBox( 'config-instantcommons-help', wfMsgNoTrans( $canUse ) ) . |
| 615 | + $this->parent->getFieldsetEnd() |
| 616 | + ); |
| 617 | + |
| 618 | + $caches = array( 'none' ); |
| 619 | + if( count( $this->getVar( '_Caches' ) ) ) { |
| 620 | + $caches[] = 'accel'; |
| 621 | + } |
| 622 | + $caches[] = 'memcached'; |
| 623 | + |
| 624 | + $this->addHTML( |
| 625 | + # Advanced settings |
| 626 | + $this->parent->getFieldsetStart( 'config-advanced-settings' ) . |
| 627 | + # Object cache settings |
| 628 | + $this->parent->getRadioSet( array( |
| 629 | + 'var' => 'wgMainCacheType', |
| 630 | + 'label' => 'config-cache-options', |
| 631 | + 'itemLabelPrefix' => 'config-cache-', |
| 632 | + 'values' => $caches, |
| 633 | + 'value' => 'none', |
| 634 | + ) ) . |
| 635 | + $this->parent->getHelpBox( 'config-cache-help' ) . |
| 636 | + '<div id="config-memcachewrapper">' . |
| 637 | + $this->parent->getTextBox( array( |
| 638 | + 'var' => '_MemCachedServers', |
| 639 | + 'label' => 'config-memcached-servers', |
| 640 | + ) ) . |
| 641 | + $this->parent->getHelpBox( 'config-memcached-help' ) . '</div>' . |
| 642 | + $this->parent->getFieldsetEnd() |
| 643 | + ); |
| 644 | + $this->endForm(); |
| 645 | + } |
| 646 | + |
| 647 | + function getCCPartnerUrl() { |
| 648 | + global $wgServer; |
| 649 | + $exitUrl = $wgServer . $this->parent->getUrl( array( |
| 650 | + 'page' => 'Options', |
| 651 | + 'SubmitCC' => 'indeed', |
| 652 | + 'config__LicenseCode' => 'cc', |
| 653 | + 'config_wgRightsUrl' => '[license_url]', |
| 654 | + 'config_wgRightsText' => '[license_name]', |
| 655 | + 'config_wgRightsIcon' => '[license_button]', |
| 656 | + ) ); |
| 657 | + $styleUrl = $wgServer . dirname( dirname( $this->parent->getUrl() ) ) . |
| 658 | + '/skins/common/config-cc.css'; |
| 659 | + $iframeUrl = 'http://creativecommons.org/license/?' . |
| 660 | + wfArrayToCGI( array( |
| 661 | + 'partner' => 'MediaWiki', |
| 662 | + 'exit_url' => $exitUrl, |
| 663 | + 'lang' => $this->getVar( '_UserLang' ), |
| 664 | + 'stylesheet' => $styleUrl, |
| 665 | + ) ); |
| 666 | + return $iframeUrl; |
| 667 | + } |
| 668 | + |
| 669 | + function getCCChooser() { |
| 670 | + $iframeAttribs = array( |
| 671 | + 'class' => 'config-cc-iframe', |
| 672 | + 'name' => 'config-cc-iframe', |
| 673 | + 'id' => 'config-cc-iframe', |
| 674 | + 'frameborder' => 0, |
| 675 | + 'width' => '100%', |
| 676 | + 'height' => '100%', |
| 677 | + ); |
| 678 | + if ( $this->getVar( '_CCDone' ) ) { |
| 679 | + $iframeAttribs['src'] = $this->parent->getUrl( array( 'ShowCC' => 'yes' ) ); |
| 680 | + } else { |
| 681 | + $iframeAttribs['src'] = $this->getCCPartnerUrl(); |
| 682 | + } |
| 683 | + |
| 684 | + return |
| 685 | + "<div class=\"config-cc-wrapper\" id=\"config-cc-wrapper\" style=\"display: none;\">\n" . |
| 686 | + Xml::element( 'iframe', $iframeAttribs, '', false /* not short */ ) . |
| 687 | + "</div>\n"; |
| 688 | + } |
| 689 | + |
| 690 | + function getCCDoneBox() { |
| 691 | + $js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';"; |
| 692 | + // If you change this height, also change it in config.css |
| 693 | + $expandJs = str_replace( '$1', '54em', $js ); |
| 694 | + $reduceJs = str_replace( '$1', '70px', $js ); |
| 695 | + return |
| 696 | + '<p>'. |
| 697 | + Xml::element( 'img', array( 'src' => $this->getVar( 'wgRightsIcon' ) ) ) . |
| 698 | + '  ' . |
| 699 | + htmlspecialchars( $this->getVar( 'wgRightsText' ) ) . |
| 700 | + "</p>\n" . |
| 701 | + "<p style=\"text-align: center\">" . |
| 702 | + Xml::element( 'a', |
| 703 | + array( |
| 704 | + 'href' => $this->getCCPartnerUrl(), |
| 705 | + 'onclick' => $expandJs, |
| 706 | + ), |
| 707 | + wfMsg( 'config-cc-again' ) |
| 708 | + ) . |
| 709 | + "</p>\n" . |
| 710 | + "<script type=\"text/javascript\">\n" . |
| 711 | + # Reduce the wrapper div height |
| 712 | + htmlspecialchars( $reduceJs ) . |
| 713 | + "\n" . |
| 714 | + "</script>\n"; |
| 715 | + } |
| 716 | + |
| 717 | + |
| 718 | + function submitCC() { |
| 719 | + $newValues = $this->parent->setVarsFromRequest( |
| 720 | + array( 'wgRightsUrl', 'wgRightsText', 'wgRightsIcon' ) ); |
| 721 | + if ( count( $newValues ) != 3 ) { |
| 722 | + $this->parent->showError( 'config-cc-error' ); |
| 723 | + return; |
| 724 | + } |
| 725 | + $this->setVar( '_CCDone', true ); |
| 726 | + $this->addHTML( $this->getCCDoneBox() ); |
| 727 | + } |
| 728 | + |
| 729 | + function submit() { |
| 730 | + $this->parent->setVarsFromRequest( array( '_RightsProfile', '_LicenseCode', |
| 731 | + 'wgEnableEmail', 'wgPasswordSender', 'wgEnableUpload', 'wgLogo', |
| 732 | + 'wgEnableUserEmail', 'wgEnotifUserTalk', 'wgEnotifWatchlist', |
| 733 | + 'wgEmailAuthentication', 'wgMainCacheType', '_MemCachedServers', |
| 734 | + 'wgUseInstantCommons' ) ); |
| 735 | + |
| 736 | + if ( !in_array( $this->getVar( '_RightsProfile' ), |
| 737 | + array_keys( $this->parent->rightsProfiles ) ) ) |
| 738 | + { |
| 739 | + reset( $this->parent->rightsProfiles ); |
| 740 | + $this->setVar( '_RightsProfile', key( $this->parent->rightsProfiles ) ); |
| 741 | + } |
| 742 | + |
| 743 | + $code = $this->getVar( '_LicenseCode' ); |
| 744 | + if ( $code == 'cc-choose' ) { |
| 745 | + if ( !$this->getVar( '_CCDone' ) ) { |
| 746 | + $this->parent->showError( 'config-cc-not-chosen' ); |
| 747 | + return false; |
| 748 | + } |
| 749 | + } elseif ( in_array( $code, array_keys( $this->parent->licenses ) ) ) { |
| 750 | + $entry = $this->parent->licenses[$code]; |
| 751 | + if ( isset( $entry['text'] ) ) { |
| 752 | + $this->setVar( 'wgRightsText', $entry['text'] ); |
| 753 | + } else { |
| 754 | + $this->setVar( 'wgRightsText', wfMsg( 'config-license-' . $code ) ); |
| 755 | + } |
| 756 | + $this->setVar( 'wgRightsUrl', $entry['url'] ); |
| 757 | + $this->setVar( 'wgRightsIcon', $entry['icon'] ); |
| 758 | + } else { |
| 759 | + $this->setVar( 'wgRightsText', '' ); |
| 760 | + $this->setVar( 'wgRightsUrl', '' ); |
| 761 | + $this->setVar( 'wgRightsIcon', '' ); |
| 762 | + } |
| 763 | + |
| 764 | + $exts = $this->parent->getVar( '_Extensions' ); |
| 765 | + foreach( $exts as $key => $ext ) { |
| 766 | + if( !$this->parent->request->getCheck( 'config_ext-' . $ext ) ) { |
| 767 | + unset( $exts[$key] ); |
| 768 | + } |
| 769 | + } |
| 770 | + $this->parent->setVar( '_Extensions', $exts ); |
| 771 | + return true; |
| 772 | + } |
| 773 | +} |
| 774 | + |
| 775 | +class WebInstaller_Install extends WebInstallerPage { |
| 776 | + |
| 777 | + function execute() { |
| 778 | + if( $this->parent->request->wasPosted() ) { |
| 779 | + return 'continue'; |
| 780 | + } elseif( $this->getVar( '_InstallDone' ) ) { |
| 781 | + $this->startForm(); |
| 782 | + $status = new Status(); |
| 783 | + $status->warning( 'config-install-alreadydone' ); |
| 784 | + $this->parent->showStatusBox( $status ); |
| 785 | + } else { |
| 786 | + $this->startForm(); |
| 787 | + $this->addHTML("<ul>"); |
| 788 | + $this->parent->performInstallation( |
| 789 | + array( $this, 'startStage'), |
| 790 | + array( $this, 'endStage' ) |
| 791 | + ); |
| 792 | + $this->addHTML("</ul>"); |
| 793 | + } |
| 794 | + $this->endForm(); |
| 795 | + return true; |
| 796 | + } |
| 797 | + |
| 798 | + public function startStage( $step ) { |
| 799 | + $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') ); |
| 800 | + } |
| 801 | + |
| 802 | + public function endStage( $step, $status ) { |
| 803 | + $success = $status->isGood(); |
| 804 | + $msg = $success ? 'config-install-step-done' : 'config-install-step-failed'; |
| 805 | + $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg ); |
| 806 | + if ( !$success ) { |
| 807 | + $html = "<span class=\"error\">$html</span>"; |
| 808 | + } |
| 809 | + $this->addHTML( $html . "</li>\n" ); |
| 810 | + if( !$success ) { |
| 811 | + $this->parent->showStatusBox( $status ); |
| 812 | + } |
| 813 | + } |
| 814 | +} |
| 815 | + |
| 816 | +class WebInstaller_Complete extends WebInstallerPage { |
| 817 | + public function execute() { |
| 818 | + global $IP; |
| 819 | + $this->startForm(); |
| 820 | + $this->addHTML( |
| 821 | + $this->parent->getInfoBox( |
| 822 | + wfMsgNoTrans( 'config-install-done', |
| 823 | + $GLOBALS['wgServer'] . $this->parent->getURL( array( 'localsettings' => 1 ) ), |
| 824 | + $GLOBALS['wgServer'] . |
| 825 | + $this->getVar( 'wgScriptPath' ) . '/index' . |
| 826 | + $this->getVar( 'wgScriptExtension' ) |
| 827 | + ), 'tick-32.png' |
| 828 | + ) |
| 829 | + ); |
| 830 | + $this->endForm( false ); |
| 831 | + } |
| 832 | +} |
| 833 | + |
| 834 | +class WebInstaller_Restart extends WebInstallerPage { |
| 835 | + function execute() { |
| 836 | + $r = $this->parent->request; |
| 837 | + if ( $r->wasPosted() ) { |
| 838 | + $really = $r->getVal( 'submit-restart' ); |
| 839 | + if ( $really ) { |
| 840 | + $this->parent->session = array(); |
| 841 | + $this->parent->happyPages = array(); |
| 842 | + $this->parent->settings = array(); |
| 843 | + } |
| 844 | + return 'continue'; |
| 845 | + } |
| 846 | + |
| 847 | + $this->startForm(); |
| 848 | + $s = $this->parent->getWarningBox( wfMsgNoTrans( 'config-help-restart' ) ); |
| 849 | + $this->addHTML( $s ); |
| 850 | + $this->endForm( 'restart' ); |
| 851 | + } |
| 852 | +} |
| 853 | + |
| 854 | +abstract class WebInstaller_Document extends WebInstallerPage { |
| 855 | + abstract function getFileName(); |
| 856 | + |
| 857 | + function execute() { |
| 858 | + $text = $this->getFileContents(); |
| 859 | + $this->parent->output->addWikiText( $text ); |
| 860 | + $this->startForm(); |
| 861 | + $this->endForm( false ); |
| 862 | + } |
| 863 | + |
| 864 | + function getFileContents() { |
| 865 | + return file_get_contents( dirname( __FILE__ ) . '/../../' . $this->getFileName() ); |
| 866 | + } |
| 867 | + |
| 868 | + protected function formatTextFile( $text ) { |
| 869 | + $text = str_replace( array( '<', '{{', '[[' ), |
| 870 | + array( '<', '{{', '[[' ), $text ); |
| 871 | + // replace numbering with [1], [2], etc with MW-style numbering |
| 872 | + $text = preg_replace( "/\r?\n(\r?\n)?\\[\\d+\\]/m", "\\1#", $text ); |
| 873 | + // join word-wrapped lines into one |
| 874 | + do { |
| 875 | + $prev = $text; |
| 876 | + $text = preg_replace( "/\n([\\*#])([^\r\n]*?)\r?\n([^\r\n#\\*:]+)/", "\n\\1\\2 \\3", $text ); |
| 877 | + } while ( $text != $prev ); |
| 878 | + // turn (bug nnnn) into links |
| 879 | + $text = preg_replace_callback('/bug (\d+)/', array( $this, 'replaceBugLinks' ), $text ); |
| 880 | + // add links to manual to every global variable mentioned |
| 881 | + $text = preg_replace_callback('/(\$wg[a-z0-9_]+)/i', array( $this, 'replaceConfigLinks' ), $text ); |
| 882 | + // special case for <pre> - formatted links |
| 883 | + do { |
| 884 | + $prev = $text; |
| 885 | + $text = preg_replace( '/^([^\\s].*?)\r?\n[\\s]+(https?:\/\/)/m', "\\1\n:\\2", $text ); |
| 886 | + } while ( $text != $prev ); |
| 887 | + return $text; |
| 888 | + } |
| 889 | + |
| 890 | + private function replaceBugLinks( $matches ) { |
| 891 | + return '<span class="config-plainlink">[https://bugzilla.wikimedia.org/' . |
| 892 | + $matches[1] . ' bug ' . $matches[1] . ']</span>'; |
| 893 | + } |
| 894 | + |
| 895 | + private function replaceConfigLinks( $matches ) { |
| 896 | + return '<span class="config-plainlink">[http://www.mediawiki.org/wiki/Manual:' . |
| 897 | + $matches[1] . ' ' . $matches[1] . ']</span>'; |
| 898 | + } |
| 899 | +} |
| 900 | + |
| 901 | +class WebInstaller_Readme extends WebInstaller_Document { |
| 902 | + function getFileName() { return 'README'; } |
| 903 | + |
| 904 | + function getFileContents() { |
| 905 | + return $this->formatTextFile( parent::getFileContents() ); |
| 906 | + } |
| 907 | +} |
| 908 | + |
| 909 | +class WebInstaller_ReleaseNotes extends WebInstaller_Document { |
| 910 | + function getFileName() { return 'RELEASE-NOTES'; } |
| 911 | + |
| 912 | + function getFileContents() { |
| 913 | + return $this->formatTextFile( parent::getFileContents() ); |
| 914 | + } |
| 915 | +} |
| 916 | + |
| 917 | +class WebInstaller_UpgradeDoc extends WebInstaller_Document { |
| 918 | + function getFileName() { return 'UPGRADE'; } |
| 919 | + |
| 920 | + function getFileContents() { |
| 921 | + return $this->formatTextFile( parent::getFileContents() ); |
| 922 | + } |
| 923 | +} |
| 924 | + |
| 925 | +class WebInstaller_Copying extends WebInstaller_Document { |
| 926 | + function getFileName() { return 'COPYING'; } |
| 927 | + |
| 928 | + function getFileContents() { |
| 929 | + $text = parent::getFileContents(); |
| 930 | + $text = str_replace( "\x0C", '', $text ); |
| 931 | + $text = preg_replace_callback( '/\n[ \t]+/m', array( 'WebInstaller_Copying', 'replaceLeadingSpaces' ), $text ); |
| 932 | + $text = '<tt>' . nl2br( $text ) . '</tt>'; |
| 933 | + return $text; |
| 934 | + } |
| 935 | + |
| 936 | + private static function replaceLeadingSpaces( $matches ) { |
| 937 | + return "\n" . str_repeat( ' ', strlen( $matches[0] ) ); |
| 938 | + } |
| 939 | +} |
\ No newline at end of file |
Property changes on: trunk/phase3/includes/installer/WebInstallerPage.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 940 | + native |