\n";
$this->addHTML(
$this->parent->label( 'config-db-type', false, $types ) .
$settings
);
$this->endForm();
}
public function submit() {
$r = $this->parent->request;
$type = $r->getVal( 'DBType' );
$this->setVar( 'wgDBtype', $type );
$installer = $this->parent->getDBInstaller( $type );
if ( !$installer ) {
return Status::newFatal( 'config-invalid-db-type' );
}
return $installer->submitConnectForm();
}
}
class WebInstaller_Upgrade extends WebInstallerPage {
public function execute() {
if ( $this->getVar( '_UpgradeDone' ) ) {
// Allow regeneration of LocalSettings.php, unless we are working
// from a pre-existing LocalSettings.php file and we want to avoid
// leaking its contents
if ( $this->parent->request->wasPosted() && !$this->getVar( '_ExistingDBSettings' ) ) {
// Done message acknowledged
return 'continue';
} else {
// Back button click
// Show the done message again
// Make them click back again if they want to do the upgrade again
$this->showDoneMessage();
return 'output';
}
}
// wgDBtype is generally valid here because otherwise the previous page
// (connect) wouldn't have declared its happiness
$type = $this->getVar( 'wgDBtype' );
$installer = $this->parent->getDBInstaller( $type );
if ( !$installer->needsUpgrade() ) {
return 'skip';
}
if ( $this->parent->request->wasPosted() ) {
$installer->preUpgrade();
$this->addHTML(
'
' .
'' .
'
' );
$this->parent->output->flush();
if ( $result ) {
$this->setVar( '_UpgradeDone', true );
$this->showDoneMessage();
return 'output';
}
}
$this->startForm();
$this->addHTML( $this->parent->getInfoBox(
wfMsgNoTrans( 'config-can-upgrade', $GLOBALS['wgVersion'] ) ) );
$this->endForm();
}
public function showDoneMessage() {
$this->startForm();
$regenerate = !$this->getVar( '_ExistingDBSettings' );
if ( $regenerate ) {
$msg = 'config-upgrade-done';
} else {
$msg = 'config-upgrade-done-no-regenerate';
}
$this->parent->disableLinkPopups();
$this->addHTML(
$this->parent->getInfoBox(
wfMsgNoTrans( $msg,
$GLOBALS['wgServer'] .
$this->getVar( 'wgScriptPath' ) . '/index' .
$this->getVar( 'wgScriptExtension' )
), 'tick-32.png'
)
);
$this->parent->restoreLinkPopups();
$this->endForm( $regenerate ? 'regenerate' : false, false );
}
}
class WebInstaller_DBSettings extends WebInstallerPage {
public function execute() {
$installer = $this->parent->getDBInstaller( $this->getVar( 'wgDBtype' ) );
$r = $this->parent->request;
if ( $r->wasPosted() ) {
$status = $installer->submitSettingsForm();
if ( $status === false ) {
return 'skip';
} elseif ( $status->isGood() ) {
return 'continue';
} else {
$this->parent->showStatusBox( $status );
}
}
$form = $installer->getSettingsForm();
if ( $form === false ) {
return 'skip';
}
$this->startForm();
$this->addHTML( $form );
$this->endForm();
}
}
class WebInstaller_Name extends WebInstallerPage {
public function execute() {
$r = $this->parent->request;
if ( $r->wasPosted() ) {
if ( $this->submit() ) {
return 'continue';
}
}
$this->startForm();
// Encourage people to not name their site 'MediaWiki' by blanking the
// field. I think that was the intent with the original $GLOBALS['wgSitename']
// but these two always were the same so had the effect of making the
// installer forget $wgSitename when navigating back to this page.
if ( $this->getVar( 'wgSitename' ) == 'MediaWiki' ) {
$this->setVar( 'wgSitename', '' );
}
// Set wgMetaNamespace to something valid before we show the form.
// $wgMetaNamespace defaults to $wgSiteName which is 'MediaWiki'
$metaNS = $this->getVar( 'wgMetaNamespace' );
$this->setVar( 'wgMetaNamespace', wfMsgForContent( 'config-ns-other-default' ) );
$this->addHTML(
$this->parent->getTextBox( array(
'var' => 'wgSitename',
'label' => 'config-site-name',
'help' => $this->parent->getHelpBox( 'config-site-name-help' )
) ) .
$this->parent->getRadioSet( array(
'var' => '_NamespaceType',
'label' => 'config-project-namespace',
'itemLabelPrefix' => 'config-ns-',
'values' => array( 'site-name', 'generic', 'other' ),
'commonAttribs' => array( 'class' => 'enableForOther', 'rel' => 'config_wgMetaNamespace' ),
'help' => $this->parent->getHelpBox( 'config-project-namespace-help' )
) ) .
$this->parent->getTextBox( array(
'var' => 'wgMetaNamespace',
'label' => '', //TODO: Needs a label?
'attribs' => array( 'readonly' => 'readonly', 'class' => 'enabledByOther' ),
) ) .
$this->getFieldSetStart( 'config-admin-box' ) .
$this->parent->getTextBox( array(
'var' => '_AdminName',
'label' => 'config-admin-name',
'help' => $this->parent->getHelpBox( 'config-admin-help' )
) ) .
$this->parent->getPasswordBox( array(
'var' => '_AdminPassword',
'label' => 'config-admin-password',
) ) .
$this->parent->getPasswordBox( array(
'var' => '_AdminPassword2',
'label' => 'config-admin-password-confirm'
) ) .
$this->parent->getTextBox( array(
'var' => '_AdminEmail',
'label' => 'config-admin-email',
'help' => $this->parent->getHelpBox( 'config-admin-email-help' )
) ) .
$this->parent->getCheckBox( array(
'var' => '_Subscribe',
'label' => 'config-subscribe',
'help' => $this->parent->getHelpBox( 'config-subscribe-help' )
) ) .
$this->getFieldSetEnd() .
$this->parent->getInfoBox( wfMsg( 'config-almost-done' ) ) .
$this->parent->getRadioSet( array(
'var' => '_SkipOptional',
'itemLabelPrefix' => 'config-optional-',
'values' => array( 'continue', 'skip' )
) )
);
// Restore the default value
$this->setVar( 'wgMetaNamespace', $metaNS );
$this->endForm();
return 'output';
}
public function submit() {
$retVal = true;
$this->parent->setVarsFromRequest( array( 'wgSitename', '_NamespaceType',
'_AdminName', '_AdminPassword', '_AdminPassword2', '_AdminEmail',
'_Subscribe', '_SkipOptional', 'wgMetaNamespace' ) );
// Validate site name
if ( strval( $this->getVar( 'wgSitename' ) ) === '' ) {
$this->parent->showError( 'config-site-name-blank' );
$retVal = false;
}
// Fetch namespace
$nsType = $this->getVar( '_NamespaceType' );
if ( $nsType == 'site-name' ) {
$name = $this->getVar( 'wgSitename' );
// Sanitize for namespace
// This algorithm should match the JS one in WebInstallerOutput.php
$name = preg_replace( '/[\[\]\{\}|#<>%+? ]/', '_', $name );
$name = str_replace( '&', '&', $name );
$name = preg_replace( '/__+/', '_', $name );
$name = ucfirst( trim( $name, '_' ) );
} elseif ( $nsType == 'generic' ) {
$name = wfMsg( 'config-ns-generic' );
} else { // other
$name = $this->getVar( 'wgMetaNamespace' );
}
// Validate namespace
if ( strpos( $name, ':' ) !== false ) {
$good = false;
} else {
// Title-style validation
$title = Title::newFromText( $name );
if ( !$title ) {
$good = $nsType == 'site-name';
} else {
$name = $title->getDBkey();
$good = true;
}
}
if ( !$good ) {
$this->parent->showError( 'config-ns-invalid', $name );
$retVal = false;
}
// Make sure it won't conflict with any existing namespaces
global $wgContLang;
$nsIndex = $wgContLang->getNsIndex( $name );
if( $nsIndex !== false && $nsIndex !== NS_PROJECT ) {
$this->parent->showError( 'config-ns-conflict', $name );
$retVal = false;
}
$this->setVar( 'wgMetaNamespace', $name );
// Validate username for creation
$name = $this->getVar( '_AdminName' );
if ( strval( $name ) === '' ) {
$this->parent->showError( 'config-admin-name-blank' );
$cname = $name;
$retVal = false;
} else {
$cname = User::getCanonicalName( $name, 'creatable' );
if ( $cname === false ) {
$this->parent->showError( 'config-admin-name-invalid', $name );
$retVal = false;
} else {
$this->setVar( '_AdminName', $cname );
}
}
// Validate password
$msg = false;
$valid = false;
$pwd = $this->getVar( '_AdminPassword' );
$user = User::newFromName( $cname );
$valid = $user && $user->getPasswordValidity( $pwd );
if ( strval( $pwd ) === '' ) {
# $user->getPasswordValidity just checks for $wgMinimalPasswordLength.
# This message is more specific and helpful.
$msg = 'config-admin-password-blank';
} elseif ( $pwd !== $this->getVar( '_AdminPassword2' ) ) {
$msg = 'config-admin-password-mismatch';
} elseif ( $valid !== true ) {
# As of writing this will only catch the username being e.g. 'FOO' and
# the password 'foo'
$msg = $valid;
}
if ( $msg !== false ) {
call_user_func_array( array( $this->parent, 'showError' ), (array)$msg );
$this->setVar( '_AdminPassword', '' );
$this->setVar( '_AdminPassword2', '' );
$retVal = false;
}
// Validate e-mail if provided
$email = $this->getVar( '_AdminEmail' );
if( $email && !User::isValidEmailAddr( $email ) ) {
$this->parent->showError( 'config-admin-error-bademail' );
$retVal = false;
}
return $retVal;
}
}
class WebInstaller_Options extends WebInstallerPage {
public function execute() {
if ( $this->getVar( '_SkipOptional' ) == 'skip' ) {
return 'skip';
}
if ( $this->parent->request->wasPosted() ) {
if ( $this->submit() ) {
return 'continue';
}
}
$this->startForm();
$this->addHTML(
# User Rights
$this->parent->getRadioSet( array(
'var' => '_RightsProfile',
'label' => 'config-profile',
'itemLabelPrefix' => 'config-profile-',
'values' => array_keys( $this->parent->rightsProfiles ),
) ) .
$this->parent->getInfoBox( wfMsgNoTrans( 'config-profile-help' ) ) .
# Licensing
$this->parent->getRadioSet( array(
'var' => '_LicenseCode',
'label' => 'config-license',
'itemLabelPrefix' => 'config-license-',
'values' => array_keys( $this->parent->licenses ),
'commonAttribs' => array( 'class' => 'licenseRadio' ),
) ) .
$this->getCCChooser() .
$this->parent->getHelpBox( 'config-license-help' ) .
# E-mail
$this->getFieldSetStart( 'config-email-settings' ) .
$this->parent->getCheckBox( array(
'var' => 'wgEnableEmail',
'label' => 'config-enable-email',
'attribs' => array( 'class' => 'showHideRadio', 'rel' => 'emailwrapper' ),
) ) .
$this->parent->getHelpBox( 'config-enable-email-help' ) .
"
\n" .
Html::element( 'iframe', $iframeAttribs, '', false /* not short */ ) .
"
\n";
}
public function getCCDoneBox() {
$js = "parent.document.getElementById('config-cc-wrapper').style.height = '$1';";
// If you change this height, also change it in config.css
$expandJs = str_replace( '$1', '54em', $js );
$reduceJs = str_replace( '$1', '70px', $js );
return
'