| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Installer; |
| 24 |
|
| 25 |
use MediaWiki\Status\Status; |
| 26 |
|
| 27 |
class WebInstallerExistingWiki extends WebInstallerPage { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function execute() { |
| 33 |
|
| 34 |
$vars = Installer::getExistingLocalSettings(); |
| 35 |
if ( !$vars ) { |
| 36 |
return 'skip'; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
if ( $vars['wgUpgradeKey'] !== false |
| 41 |
&& $this->getVar( '_UpgradeKeySupplied' ) |
| 42 |
&& $this->getVar( 'wgUpgradeKey' ) === $vars['wgUpgradeKey'] |
| 43 |
) { |
| 44 |
|
| 45 |
$status = $this->handleExistingUpgrade( $vars ); |
| 46 |
if ( $status->isOK() ) { |
| 47 |
return 'skip'; |
| 48 |
} else { |
| 49 |
$this->startForm(); |
| 50 |
$this->parent->showStatusBox( $status ); |
| 51 |
$this->endForm( 'continue' ); |
| 52 |
|
| 53 |
return 'output'; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
if ( $vars['wgUpgradeKey'] === false ) { |
| 59 |
if ( $this->getVar( 'wgUpgradeKey', false ) === false ) { |
| 60 |
$secretKey = $this->getVar( 'wgSecretKey' ); |
| 61 |
$this->parent->generateKeys(); |
| 62 |
$this->setVar( 'wgSecretKey', $secretKey ); |
| 63 |
$this->setVar( '_UpgradeKeySupplied', true ); |
| 64 |
} |
| 65 |
$this->startForm(); |
| 66 |
$this->addHTML( $this->parent->getInfoBox( |
| 67 |
wfMessage( 'config-upgrade-key-missing', "<pre dir=\"ltr\">\$wgUpgradeKey = '" . |
| 68 |
$this->getVar( 'wgUpgradeKey' ) . "';</pre>" )->plain() |
| 69 |
) ); |
| 70 |
$this->endForm( 'continue' ); |
| 71 |
|
| 72 |
return 'output'; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
$r = $this->parent->request; |
| 78 |
if ( $r->wasPosted() ) { |
| 79 |
$key = $r->getText( 'config_wgUpgradeKey' ); |
| 80 |
if ( !$key || $key !== $vars['wgUpgradeKey'] ) { |
| 81 |
$this->parent->showError( 'config-localsettings-badkey' ); |
| 82 |
$this->showKeyForm(); |
| 83 |
|
| 84 |
return 'output'; |
| 85 |
} |
| 86 |
|
| 87 |
$status = $this->handleExistingUpgrade( $vars ); |
| 88 |
if ( $status->isOK() ) { |
| 89 |
return 'continue'; |
| 90 |
} else { |
| 91 |
$this->parent->showStatusBox( $status ); |
| 92 |
$this->showKeyForm(); |
| 93 |
|
| 94 |
return 'output'; |
| 95 |
} |
| 96 |
} else { |
| 97 |
$this->showKeyForm(); |
| 98 |
|
| 99 |
return 'output'; |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
protected function showKeyForm() { |
| 107 |
$this->startForm(); |
| 108 |
$this->addHTML( |
| 109 |
$this->parent->getInfoBox( wfMessage( 'config-localsettings-upgrade' )->plain() ) . |
| 110 |
'<br />' . |
| 111 |
$this->parent->getTextBox( [ |
| 112 |
'var' => 'wgUpgradeKey', |
| 113 |
'label' => 'config-localsettings-key', |
| 114 |
'attribs' => [ 'autocomplete' => 'off' ], |
| 115 |
] ) |
| 116 |
); |
| 117 |
$this->endForm( 'continue' ); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
protected function importVariables( $names, $vars ) { |
| 127 |
$status = Status::newGood(); |
| 128 |
foreach ( $names as $name ) { |
| 129 |
if ( !isset( $vars[$name] ) ) { |
| 130 |
$status->fatal( 'config-localsettings-incomplete', $name ); |
| 131 |
} |
| 132 |
$this->setVar( $name, $vars[$name] ); |
| 133 |
} |
| 134 |
|
| 135 |
return $status; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
protected function handleExistingUpgrade( $vars ) { |
| 146 |
|
| 147 |
if ( !isset( $vars['wgDBtype'] ) || |
| 148 |
!in_array( $vars['wgDBtype'], Installer::getDBTypes() ) |
| 149 |
) { |
| 150 |
return Status::newFatal( 'config-localsettings-connection-error', '' ); |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
$requiredVars = [ 'wgDBtype' ]; |
| 155 |
$status = $this->importVariables( $requiredVars, $vars ); |
| 156 |
$installer = $this->parent->getDBInstaller(); |
| 157 |
$status->merge( $this->importVariables( $installer->getGlobalNames(), $vars ) ); |
| 158 |
if ( !$status->isOK() ) { |
| 159 |
return $status; |
| 160 |
} |
| 161 |
|
| 162 |
$this->setVar( '_InstallUser', $vars['wgDBadminuser'] ?? $vars['wgDBuser'] ); |
| 163 |
$this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] ?? $vars['wgDBpassword'] ); |
| 164 |
|
| 165 |
|
| 166 |
$status = $installer->getConnection( DatabaseInstaller::CONN_CREATE_DATABASE ); |
| 167 |
if ( !$status->isOK() ) { |
| 168 |
|
| 169 |
$status->replaceMessage( 'config-connection-error', |
| 170 |
'config-localsettings-connection-error' ); |
| 171 |
|
| 172 |
return $status; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
$this->setVar( '_ExistingDBSettings', true ); |
| 177 |
|
| 178 |
|
| 179 |
$this->setVar( 'wgAuthenticationTokenVersion', |
| 180 |
$vars['wgAuthenticationTokenVersion'] ?? null |
| 181 |
); |
| 182 |
|
| 183 |
return $status; |
| 184 |
} |
| 185 |
|
| 186 |
} |