*
* @var array
*/
- protected $internalDefaults = array();
+ protected $internalDefaults = [];
/**
* Array of MW configuration globals this class uses.
*
* @var array
*/
- protected $globalNames = array();
+ protected $globalNames = [];
/**
* Return the internal name, e.g. 'mysql', or 'sqlite'.
}
/**
- * Create database tables from scratch.
+ * Apply a SQL source file to the database as part of running an installation step.
*
+ * @param string $sourceFileMethod
+ * @param string $stepName
+ * @param string $archiveTableMustNotExist
* @return Status
*/
- public function createTables() {
+ private function stepApplySourceFile(
+ $sourceFileMethod,
+ $stepName,
+ $archiveTableMustNotExist = false
+ ) {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$this->db->selectDB( $this->getVar( 'wgDBname' ) );
- if ( $this->db->tableExists( 'archive', __METHOD__ ) ) {
- $status->warning( 'config-install-tables-exist' );
+ if ( $archiveTableMustNotExist && $this->db->tableExists( 'archive', __METHOD__ ) ) {
+ $status->warning( "config-$stepName-tables-exist" );
$this->enableLB();
return $status;
$this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files
$this->db->begin( __METHOD__ );
- $error = $this->db->sourceFile( $this->db->getSchemaPath() );
+ $error = $this->db->sourceFile(
+ call_user_func( [ $this->db, $sourceFileMethod ] )
+ );
if ( $error !== true ) {
$this->db->reportQueryError( $error, 0, '', __METHOD__ );
$this->db->rollback( __METHOD__ );
- $status->fatal( 'config-install-tables-failed', $error );
+ $status->fatal( "config-$stepName-tables-failed", $error );
} else {
$this->db->commit( __METHOD__ );
}
// Resume normal operations
- if ( $status->isOk() ) {
+ if ( $status->isOK() ) {
$this->enableLB();
}
return $status;
}
+ /**
+ * Create database tables from scratch.
+ *
+ * @return Status
+ */
+ public function createTables() {
+ return $this->stepApplySourceFile( 'getSchemaPath', 'install', true );
+ }
+
+ /**
+ * Insert update keys into table to prevent running unneded updates.
+ *
+ * @return Status
+ */
+ public function insertUpdateKeys() {
+ return $this->stepApplySourceFile( 'getUpdateKeysPath', 'updates', false );
+ }
+
/**
* Create the tables for each extension the user enabled
* @return Status
}
// Now run updates to create tables for old extensions
- DatabaseUpdater::newForDB( $this->db )->doUpdates( array( 'extensions' ) );
+ DatabaseUpdater::newForDB( $this->db )->doUpdates( [ 'extensions' ] );
return $status;
}
* @return array
*/
public function getSchemaVars() {
- return array();
+ return [];
}
/**
if ( !$status->isOK() ) {
throw new MWException( __METHOD__ . ': unexpected DB connection error' );
}
- LBFactory::setInstance( new LBFactorySingle( array(
- 'connection' => $status->value ) ) );
+ LBFactory::setInstance( new LBFactorySingle( [
+ 'connection' => $status->value ] ) );
}
/**
$this->enableLB();
$ret = true;
- ob_start( array( $this, 'outputHandler' ) );
+ ob_start( [ $this, 'outputHandler' ] );
$up = DatabaseUpdater::newForDB( $this->db );
try {
$up->doUpdates();
- } catch ( MWException $e ) {
+ } catch ( Exception $e ) {
echo "\nAn error occurred:\n";
echo $e->getText();
$ret = false;
}
/**
- * Get a name=>value map of MW configuration globals that overrides.
- * DefaultSettings.php
+ * Get a name=>value map of MW configuration globals for the default values.
* @return array
*/
public function getGlobalDefaults() {
- return array();
+ $defaults = [];
+ foreach ( $this->getGlobalNames() as $var ) {
+ if ( isset( $GLOBALS[$var] ) ) {
+ $defaults[$var] = $GLOBALS[$var];
+ }
+ }
+ return $defaults;
}
/**
* @param string $helpData
* @return string
*/
- public function getTextBox( $var, $label, $attribs = array(), $helpData = "" ) {
+ public function getTextBox( $var, $label, $attribs = [], $helpData = "" ) {
$name = $this->getName() . '_' . $var;
$value = $this->getVar( $var );
if ( !isset( $attribs ) ) {
- $attribs = array();
+ $attribs = [];
}
- return $this->parent->getTextBox( array(
+ return $this->parent->getTextBox( [
'var' => $var,
'label' => $label,
'attribs' => $attribs,
'controlName' => $name,
'value' => $value,
'help' => $helpData
- ) );
+ ] );
}
/**
* @param string $helpData
* @return string
*/
- public function getPasswordBox( $var, $label, $attribs = array(), $helpData = "" ) {
+ public function getPasswordBox( $var, $label, $attribs = [], $helpData = "" ) {
$name = $this->getName() . '_' . $var;
$value = $this->getVar( $var );
if ( !isset( $attribs ) ) {
- $attribs = array();
+ $attribs = [];
}
- return $this->parent->getPasswordBox( array(
+ return $this->parent->getPasswordBox( [
'var' => $var,
'label' => $label,
'attribs' => $attribs,
'controlName' => $name,
'value' => $value,
'help' => $helpData
- ) );
+ ] );
}
/**
* @param string $helpData Optional.
* @return string
*/
- public function getCheckBox( $var, $label, $attribs = array(), $helpData = "" ) {
+ public function getCheckBox( $var, $label, $attribs = [], $helpData = "" ) {
$name = $this->getName() . '_' . $var;
$value = $this->getVar( $var );
- return $this->parent->getCheckBox( array(
+ return $this->parent->getCheckBox( [
'var' => $var,
'label' => $label,
'attribs' => $attribs,
'controlName' => $name,
'value' => $value,
'help' => $helpData
- ) );
+ ] );
}
/**
*/
public function getInstallUserBox() {
return Html::openElement( 'fieldset' ) .
- Html::element( 'legend', array(), wfMessage( 'config-db-install-account' )->text() ) .
+ Html::element( 'legend', [], wfMessage( 'config-db-install-account' )->text() ) .
$this->getTextBox(
'_InstallUser',
'config-db-username',
- array( 'dir' => 'ltr' ),
+ [ 'dir' => 'ltr' ],
$this->parent->getHelpBox( 'config-db-install-username' )
) .
$this->getPasswordBox(
'_InstallPassword',
'config-db-password',
- array( 'dir' => 'ltr' ),
+ [ 'dir' => 'ltr' ],
$this->parent->getHelpBox( 'config-db-install-password' )
) .
Html::closeElement( 'fieldset' );
* @return Status
*/
public function submitInstallUserBox() {
- $this->setVarsFromRequest( array( '_InstallUser', '_InstallPassword' ) );
+ $this->setVarsFromRequest( [ '_InstallUser', '_InstallPassword' ] );
return Status::newGood();
}
public function getWebUserBox( $noCreateMsg = false ) {
$wrapperStyle = $this->getVar( '_SameAccount' ) ? 'display: none' : '';
$s = Html::openElement( 'fieldset' ) .
- Html::element( 'legend', array(), wfMessage( 'config-db-web-account' )->text() ) .
+ Html::element( 'legend', [], wfMessage( 'config-db-web-account' )->text() ) .
$this->getCheckBox(
'_SameAccount', 'config-db-web-account-same',
- array( 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' )
+ [ 'class' => 'hideShowRadio', 'rel' => 'dbOtherAccount' ]
) .
- Html::openElement( 'div', array( 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ) ) .
+ Html::openElement( 'div', [ 'id' => 'dbOtherAccount', 'style' => $wrapperStyle ] ) .
$this->getTextBox( 'wgDBuser', 'config-db-username' ) .
$this->getPasswordBox( 'wgDBpassword', 'config-db-password' ) .
$this->parent->getHelpBox( 'config-db-web-help' );
*/
public function submitWebUserBox() {
$this->setVarsFromRequest(
- array( 'wgDBuser', 'wgDBpassword', '_SameAccount', '_CreateDBAccount' )
+ [ 'wgDBuser', 'wgDBpassword', '_SameAccount', '_CreateDBAccount' ]
);
if ( $this->getVar( '_SameAccount' ) ) {
}
$this->db->selectDB( $this->getVar( 'wgDBname' ) );
- if ( $this->db->selectRow( 'interwiki', '*', array(), __METHOD__ ) ) {
+ if ( $this->db->selectRow( 'interwiki', '*', [], __METHOD__ ) ) {
$status->warning( 'config-install-interwiki-exists' );
return $status;
}
global $IP;
- wfSuppressWarnings();
+ MediaWiki\suppressWarnings();
$rows = file( "$IP/maintenance/interwiki.list",
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
- wfRestoreWarnings();
- $interwikis = array();
+ MediaWiki\restoreWarnings();
+ $interwikis = [];
if ( !$rows ) {
return Status::newFatal( 'config-install-interwiki-list' );
}
if ( $row == "" ) {
continue;
}
- $row .= "||";
+ $row .= "|";
$interwikis[] = array_combine(
- array( 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ),
+ [ 'iw_prefix', 'iw_url', 'iw_local', 'iw_api', 'iw_wikiid' ],
explode( '|', $row )
);
}