Jump to content

Topic on Project:Support desk

Install Mediawiki using settings from LocalSettings.php

4
Lucasbasquerotto (talkcontribs)

Hi!


I would like to know if it's possible to setup Mediawiki with an already defined LocalSettings.php file, instead of following the manual steps to generate one (basic setup), or running install.php to generate the file and prepare the database.


I tried running update.php but it gave me an error (probably because the setup is required before the update can be done).


What I want is to do what the basic setup does, but using the parameters already defined in the LocalSettings.php file (similar to what is done when running install.php. but without defining the parameters in the command line and generating a new file, but using the parameters already defined in the file).


Thanks in advance!

Bawolff (talkcontribs)

i dont think that already exists, but you could probably write a really simple maintenance script wrapper around install.php to do so.

Lucasbasquerotto (talkcontribs)

@Bawolff Thanks for the reply. I ended up creating 2 files to do that, maintenance/upgrade.php and includes/installer/CustomCliInstaller.php.

The upgrade.php file is very similar to install.php, except that it gets the parameters defined in the LocalSettings.php file (instead of getting them from the command line arguments) and calls CustomCliInstaller.php (while install.php calls CliInstaller.php).

The CustomCliInstaller.php extends CliInstaller.php and the main difference is that it overrides the execute method, because CliInstaller.php gives an error at the execute method if the file LocalSettings.php already exists.


Bellow are the code of the 2 files (when I pasted the code, the indentation and empty lines were removed, I don't know if this is normal).


upgrade.php:


<?php

/**

* CLI-based MediaWiki installation and configuration.

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 2 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License along

* with this program; if not, write to the Free Software Foundation, Inc.,

* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

* http://www.gnu.org/copyleft/gpl.html

*

* @file

* @ingroup Maintenance

*/

require_once __DIR__ . '/Maintenance.php';

require_once __DIR__ . '/../includes/AutoLoader.php';

require_once __DIR__ . '/../includes/installer/CustomCliInstaller.php';

define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );

define( 'MEDIAWIKI_INSTALL', true );

/**

* Maintenance script to upgrade MediaWiki

*

* Default values for the options are defined in DefaultSettings.php

* (see the mapping in CliInstaller.php)

*

* @ingroup Maintenance

*/

class CommandLineUpgrader extends Maintenance {

public function __construct() {

parent::__construct();

global $IP;

$this->addDescription( "CLI-based MediaWiki installation and configuration.\n" .

"Will install based on the settings at LocalSettings.php or update (if it's already installed)." );

}

public function execute() {

    global $IP;

$vars = Installer::getExistingLocalSettings();

if ( !$vars ) {

$status = Status::newFatal( "config-download-localsettings" );

$this->showStatusMessage( $status );

return $status;

}

$sitename = $vars['wgSitename'];

$admin = $vars['wgDBuser'];

$options = [

'dbtype' => $vars['wgDBtype'],

'dbserver' => $vars['wgDBserver'],

'dbname' => $vars['wgDBname'],

'dbuser' => $vars['wgDBuser'],

'dbpass' => $vars['wgDBpassword'],

'dbprefix' => $vars['wgDBprefix'],

'dbtableoptions' => $vars['wgDBTableOptions'],

'dbport' => $vars['wgDBport'],

'dbschema' => $vars['wgDBmwschema'],

'dbpath' => $vars['wgSQLiteDataDir'],

'server' => $vars['wgServer'],

'scriptpath' => $vars['wgScriptPath'],

'lang' => $vars['wgLanguageCode'],

'pass' => $vars['wgDBpassword'],

];

try {

$installer = new CustomCliInstaller( $siteName, $admin, $options );

} catch ( \MediaWiki\Installer\InstallException $e ) {

$this->output( $e->getStatus()->getMessage( false, false, 'en' )->text() . "\n" );

return false;

}

$status = $installer->doEnvironmentChecks();

if ( $status->isGood() ) {

$installer->showMessage( 'config-env-good' );

} else {

$installer->showStatusMessage( $status );

return false;

}

$status = $installer->execute();

if ( !$status->isGood() ) {

$installer->showStatusMessage( $status );

return false;

}

$installer->showMessage(

'config-install-success',

$installer->getVar( 'wgServer' ),

$installer->getVar( 'wgScriptPath' )

);

return true;

}

}

$maintClass = CommandLineUpgrader::class;

require_once RUN_MAINTENANCE_IF_MAIN;


CustomCliInstaller.php:


<?php

/**

* Core installer command line interface.

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License as published by

* the Free Software Foundation; either version 2 of the License, or

* (at your option) any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License along

* with this program; if not, write to the Free Software Foundation, Inc.,

* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

* http://www.gnu.org/copyleft/gpl.html

*

* @file

* @ingroup Installer

*/

/**

* Class for the custom installer command line interface.

*

* @ingroup Installer

* @since 1.17

*/

class CustomCliInstaller extends CliInstaller {

/**

* @param string $siteName

* @param string|null $admin

* @param array $options

* @throws InstallException

*/

public function __construct( $siteName, $admin = null, array $options = [] ) {

parent::__construct( $siteName, $admin, $options );

}

/**

* Main entry point.

* @return Status

*/

public function execute() {

// If APC is available, use that as the MainCacheType, instead of nothing.

// This is hacky and should be consolidated with WebInstallerOptions.

// This is here instead of in __construct(), because it should run run after

// doEnvironmentChecks(), which populates '_Caches'.

if ( count( $this->getVar( '_Caches' ) ) ) {

// We detected a CACHE_ACCEL implementation, use it.

$this->setVar( '_MainCacheType', 'accel' );

}

$result = $this->performInstallation(

[ $this, 'startStage' ],

[ $this, 'endStage' ]

);

// PerformInstallation bails on a fatal, so make sure the last item

// completed before giving 'next.' Likewise, only provide back on failure

$lastStepStatus = end( $result );

if ( $lastStepStatus->isOK() ) {

return Status::newGood();

} else {

return $lastStepStatus;

}

}

}


Any possibilities of this being added (or adapted) to the mediawiki code?

SeriouslyThat'sTaken? (talkcontribs)

Took a bit of googling but this is exactly what I need! Thanks!


Something like this should absolutely be included!


I'm using Terraform to deploy my environment in AWS. Having to manually run the stock installer cli tool every time I teardown and deploy is quite the pain. It'd be extra nice if MysqlInstaller respected the $wgDBssl setting.

Reply to "Install Mediawiki using settings from LocalSettings.php"