2010-05-07 12:25:01 +00:00
|
|
|
<?php
|
2010-06-23 01:08:34 +00:00
|
|
|
/**
|
2012-07-17 05:40:40 +00:00
|
|
|
* CLI-based MediaWiki installation and configuration.
|
|
|
|
|
*
|
2010-06-23 01:08:34 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2012-07-17 05:40:40 +00:00
|
|
|
* @file
|
2010-06-23 01:08:34 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2024-01-05 18:46:09 +00:00
|
|
|
use MediaWiki\Installer\Installer;
|
|
|
|
|
use MediaWiki\Installer\InstallerOverrides;
|
|
|
|
|
use MediaWiki\Installer\InstallException;
|
2023-01-25 15:11:10 +00:00
|
|
|
use MediaWiki\Settings\SettingsBuilder;
|
2022-01-05 01:31:58 +00:00
|
|
|
use Wikimedia\AtEase\AtEase;
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2016-06-15 00:14:20 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2011-04-12 15:37:51 +00:00
|
|
|
|
2024-01-05 18:46:09 +00:00
|
|
|
define( 'MW_CONFIG_CALLBACK', [ Installer::class, 'overrideConfig' ] );
|
2011-06-05 19:52:03 +00:00
|
|
|
define( 'MEDIAWIKI_INSTALL', true );
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2012-07-17 05:40:40 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to install and configure MediaWiki
|
|
|
|
|
*
|
2022-04-27 14:31:59 +00:00
|
|
|
* Default values for the options are defined in MainConfigSchema.php
|
2014-05-14 11:12:32 +00:00
|
|
|
* (see the mapping in includes/installer/CliInstaller.php)
|
2013-05-26 13:17:24 +00:00
|
|
|
* Default for --dbpath (SQLite-specific) is defined in SqliteInstaller::getGlobalDefaults
|
|
|
|
|
*
|
2012-07-17 05:40:40 +00:00
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2010-06-23 01:08:34 +00:00
|
|
|
class CommandLineInstaller extends Maintenance {
|
2019-10-09 18:41:33 +00:00
|
|
|
public function __construct() {
|
2010-06-27 21:48:51 +00:00
|
|
|
parent::__construct();
|
2010-11-02 17:11:35 +00:00
|
|
|
global $IP;
|
2010-06-27 21:48:51 +00:00
|
|
|
|
2013-05-26 13:17:24 +00:00
|
|
|
$this->addDescription( "CLI-based MediaWiki installation and configuration.\n" .
|
2024-05-04 14:28:00 +00:00
|
|
|
"Default options are indicated in parentheses.\n" .
|
|
|
|
|
"If no options are provided, the script will run in interactive mode." );
|
2013-05-26 13:17:24 +00:00
|
|
|
|
2024-05-04 14:28:00 +00:00
|
|
|
$this->addArg( 'name', 'The name of the wiki', false );
|
|
|
|
|
$this->addArg( 'admin', 'The username of the wiki administrator.', false );
|
2010-06-27 21:48:51 +00:00
|
|
|
|
2012-10-05 21:35:37 +00:00
|
|
|
$this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
|
2014-04-22 21:25:04 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'passfile',
|
|
|
|
|
'An alternative way to provide pass option, as the contents of this file',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'scriptpath',
|
2014-05-14 11:12:32 +00:00
|
|
|
'The relative path of the wiki in the web server (/' . basename( dirname( __DIR__ ) ) . ')',
|
2014-04-22 21:25:04 +00:00
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
2019-07-19 04:04:41 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'server',
|
|
|
|
|
'The base URL of the web server the wiki will be on (http://localhost)',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
2010-06-27 21:48:51 +00:00
|
|
|
|
2010-06-23 01:08:34 +00:00
|
|
|
$this->addOption( 'lang', 'The language to use (en)', false, true );
|
2010-06-27 21:48:51 +00:00
|
|
|
|
|
|
|
|
$this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
|
2010-10-02 07:39:17 +00:00
|
|
|
$this->addOption( 'dbserver', 'The database host (localhost)', false, true );
|
2023-05-03 17:43:43 +00:00
|
|
|
$this->addOption( 'dbssl', 'Connect to the database over SSL' );
|
2010-10-02 07:39:17 +00:00
|
|
|
$this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
|
2010-06-27 21:48:51 +00:00
|
|
|
$this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
|
2013-05-26 13:17:24 +00:00
|
|
|
$this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true );
|
2011-11-11 00:05:04 +00:00
|
|
|
$this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
|
2010-06-27 21:48:51 +00:00
|
|
|
$this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
|
2013-05-26 13:17:24 +00:00
|
|
|
$this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true );
|
2010-10-02 07:39:17 +00:00
|
|
|
$this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
|
2013-05-26 13:17:24 +00:00
|
|
|
$this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true );
|
2014-04-22 21:25:04 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'dbpassfile',
|
|
|
|
|
'An alternative way to provide dbpass option, as the contents of this file',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
2013-05-26 13:17:24 +00:00
|
|
|
$this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
|
2014-07-24 17:03:17 +00:00
|
|
|
$this->addOption( 'dbschema', 'The schema for the MediaWiki DB in '
|
2022-05-13 18:34:21 +00:00
|
|
|
. 'PostgreSQL (mediawiki)', false, true );
|
2023-11-21 12:06:47 +00:00
|
|
|
|
2010-11-16 18:13:35 +00:00
|
|
|
$this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
|
2018-03-13 09:16:15 +00:00
|
|
|
|
|
|
|
|
$this->addOption( 'with-extensions', "Detect and include extensions" );
|
install.php: Allow extensions and skins to be specified
Allow the extensions and skins installed by maintenance/install.php to
be customised using --skins= and --extensions=. If the argument is
am empty string then no extensions/skins are installed. For backwards
compatibility, the default is to install all skins, but to install all
extensions only if --with-extensions is given.
The new CLI options may be specified multiple times, but for
convenience, comma-separated lists can also be used.
Also:
* Rename $option to $options
* If an extension has a dependency error, propagate the very readable
error message generated by ExtensionRegistry back to the user.
* Split getExtensionInfo() from the loop body of findExtensionsByType(),
so that CliInstaller can use it to validate its parameters and get
error messages.
* I didn't like the idea of removing the "s" from the directory name in
order to construct the JSON file name, so I split
findExtensionsByType() from findExtensions(), with the former not
having this hack. In findExtensions(), make the previous assumption
that the directory name is always "extensions" or "skins" explicit,
throwing an exception if it is otherwise.
Change-Id: Id0fb63cd4e61a047ef3396ee1c38d6073dfc7fd1
2018-09-19 05:43:14 +00:00
|
|
|
$this->addOption( 'extensions', 'Comma-separated list of extensions to install',
|
|
|
|
|
false, true, false, true );
|
|
|
|
|
$this->addOption( 'skins', 'Comma-separated list of skins to install (default: all)',
|
|
|
|
|
false, true, false, true );
|
2023-11-24 08:19:18 +00:00
|
|
|
$this->addOption( 'with-developmentsettings', 'Load DevelopmentSettings.php in LocalSettings.php' );
|
2010-06-23 01:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-25 15:11:10 +00:00
|
|
|
public function canExecuteWithoutLocalSettings(): bool {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-02 14:12:21 +00:00
|
|
|
public function finalSetup( SettingsBuilder $settingsBuilder ) {
|
2023-01-25 15:11:10 +00:00
|
|
|
parent::finalSetup( $settingsBuilder );
|
|
|
|
|
Installer::overrideConfig( $settingsBuilder );
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 18:39:42 +00:00
|
|
|
public function getDbType() {
|
|
|
|
|
if ( $this->hasOption( 'env-checks' ) ) {
|
|
|
|
|
return Maintenance::DB_NONE;
|
|
|
|
|
}
|
|
|
|
|
return parent::getDbType();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function execute() {
|
2014-03-13 01:27:58 +00:00
|
|
|
global $IP;
|
2014-04-22 21:25:04 +00:00
|
|
|
|
2024-05-04 14:28:00 +00:00
|
|
|
if ( $this->hasOption( 'help' ) ) {
|
|
|
|
|
$this->maybeHelp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Manually check for required arguments, as 0 arguments allows interactive mode to be used
|
|
|
|
|
if ( $this->getArg( 0 ) && !$this->getArg( 1 ) ) {
|
2024-08-19 09:31:14 +00:00
|
|
|
$this->fatalError( 'Argument <' . $this->getArgName( 1 ) . '> is required!' );
|
2024-05-04 14:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No arguments, means interactive mode
|
|
|
|
|
if ( !$this->getArg( 0 ) || !$this->getArg( 1 ) ) {
|
|
|
|
|
$this->output( "Hello, I'm the MediaWiki installer!\n\n" );
|
|
|
|
|
$this->output( "This script will guide you through the process of installing MediaWiki.\n" );
|
|
|
|
|
$this->output( "If you actually want to see the help for this script, use --help.\n\n" );
|
|
|
|
|
|
|
|
|
|
$siteName = $this->prompt( 'Enter the name of the wiki:', "Wiki" );
|
|
|
|
|
$language = $this->prompt( 'Enter the language code of the wiki:', 'en' );
|
|
|
|
|
$server = $this->prompt(
|
|
|
|
|
'Enter the base URL of the web server the wiki will be on (without a path):',
|
|
|
|
|
'http://localhost'
|
|
|
|
|
);
|
|
|
|
|
$adminName = $this->prompt( 'Enter the username of the MediaWiki account that will be created ' .
|
|
|
|
|
'at the end of the installation and given administrator rights:', "Admin" );
|
|
|
|
|
$adminPass = $this->prompt(
|
|
|
|
|
'Enter the password for the wiki administrator:',
|
|
|
|
|
$this->generateStrongPassword()
|
|
|
|
|
);
|
|
|
|
|
$dbType = $this->prompt( 'Enter the type of database (for example mysql or sqlite):', 'mysql' );
|
|
|
|
|
// Assume that sqlite is the only db type that needs a path
|
|
|
|
|
$dbPath = $dbType == 'sqlite' ?
|
|
|
|
|
$this->prompt(
|
|
|
|
|
'Enter the path for the SQLite DB (advised to be outside the web root):',
|
|
|
|
|
"$IP/data"
|
|
|
|
|
) :
|
|
|
|
|
null;
|
|
|
|
|
$dbName = $this->prompt( 'Enter the name of the database:', 'my_wiki' );
|
|
|
|
|
// Assume that everything other than sqlite needs a server and credentials
|
|
|
|
|
$dbUser = $dbType == 'sqlite' ? null : $this->prompt( 'Enter the database user:', 'wikiuser' );
|
|
|
|
|
$dbPass = $dbType == 'sqlite' ? null : $this->prompt( 'Enter the database password:', '' );
|
|
|
|
|
$dbServer = $dbType == 'sqlite' ? null : $this->prompt( 'Enter the database server:', 'localhost' );
|
|
|
|
|
|
|
|
|
|
$this->output( "\n" );
|
|
|
|
|
$this->setArg( 0, $siteName );
|
|
|
|
|
$this->setArg( 1, $adminName );
|
|
|
|
|
$this->setOption( 'lang', $language );
|
|
|
|
|
$this->setOption( 'server', $server );
|
|
|
|
|
$this->setOption( 'pass', $adminPass );
|
|
|
|
|
$this->setOption( 'dbtype', $dbType );
|
|
|
|
|
$this->setOption( 'dbpath', $dbPath );
|
|
|
|
|
$this->setOption( 'dbname', $dbName );
|
|
|
|
|
$this->setOption( 'dbuser', $dbUser );
|
|
|
|
|
$this->setOption( 'dbpass', $dbPass );
|
|
|
|
|
$this->setOption( 'dbserver', $dbServer );
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-26 13:17:24 +00:00
|
|
|
$siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
|
|
|
|
|
$adminName = $this->getArg( 1 );
|
2017-07-04 18:22:23 +00:00
|
|
|
$envChecksOnly = $this->hasOption( 'env-checks' );
|
2010-06-27 21:48:51 +00:00
|
|
|
|
2014-05-14 11:12:32 +00:00
|
|
|
$scriptpath = $this->getOption( 'scriptpath', false );
|
|
|
|
|
if ( $scriptpath === false ) {
|
2024-08-29 20:08:23 +00:00
|
|
|
$this->setOption( 'scriptpath', '/' . basename( dirname( __DIR__ ) ) );
|
2014-05-14 11:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-04 18:22:23 +00:00
|
|
|
$this->setDbPassOption();
|
|
|
|
|
if ( !$envChecksOnly ) {
|
|
|
|
|
$this->setPassOption();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-27 15:38:54 +00:00
|
|
|
try {
|
2022-07-31 10:39:13 +00:00
|
|
|
$installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->parameters->getOptions() );
|
2024-01-05 18:46:09 +00:00
|
|
|
} catch ( InstallException $e ) {
|
Maintenance: Print errors from StatusValue objects in a consistent way
Allow Maintenance::error() and Maintenance::fatalError() to take
StatusValue objects. They now print each error message from the
status on a separate line, in English, ignoring on-wiki message
overrides, as wikitext but after parser function expansion.
Thoughts on the previously commonly used methods:
- $status->getMessage( false, false, 'en' )->text()
Almost the same as the new output, but it allows on-wiki message
overrides, and if there is more than one error, it prefixes each
line with a '*' (like a wikitext list).
- $status->getMessage( false, false, 'en' )->plain()
- $status->getWikiText( false, false, 'en' )
As above, but these forms do not expand parser functions
such as {{GENDER:}}.
- print_r( $status->getErrorsArray(), true )
- print_r( $status->getErrors(), true )
These forms output the message keys instead of the message text,
which is not very human-readable.
The error messages are now always printed using error() rather
than output(), which means they go to STDERR rather than STDOUT
and they're printed even with the --quiet flag.
Change-Id: I5b8e7c7ed2a896a1029f58857a478d3f1b4b0589
2024-06-06 23:50:00 +00:00
|
|
|
$this->error( $e->getStatus() );
|
2019-07-27 15:38:54 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2017-07-04 18:22:23 +00:00
|
|
|
|
|
|
|
|
$status = $installer->doEnvironmentChecks();
|
|
|
|
|
if ( $status->isGood() ) {
|
|
|
|
|
$installer->showMessage( 'config-env-good' );
|
|
|
|
|
} else {
|
2019-07-27 15:38:54 +00:00
|
|
|
return false;
|
2017-07-04 18:22:23 +00:00
|
|
|
}
|
|
|
|
|
if ( !$envChecksOnly ) {
|
2019-07-27 15:38:54 +00:00
|
|
|
$status = $installer->execute();
|
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-07-04 18:22:23 +00:00
|
|
|
$installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
|
2019-07-27 15:38:54 +00:00
|
|
|
$installer->showMessage(
|
|
|
|
|
'config-install-success',
|
|
|
|
|
$installer->getVar( 'wgServer' ),
|
|
|
|
|
$installer->getVar( 'wgScriptPath' )
|
|
|
|
|
);
|
2017-07-04 18:22:23 +00:00
|
|
|
}
|
2019-07-27 15:38:54 +00:00
|
|
|
return true;
|
2017-07-04 18:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
2024-05-04 14:28:00 +00:00
|
|
|
private function generateStrongPassword() {
|
|
|
|
|
$strongPassword = '';
|
|
|
|
|
$strongPasswordLength = 20;
|
|
|
|
|
$strongPasswordChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}|;:,.<>?';
|
|
|
|
|
$strongPasswordCharsLength = strlen( $strongPasswordChars );
|
|
|
|
|
for ( $i = 0; $i < $strongPasswordLength; $i++ ) {
|
|
|
|
|
$strongPassword .= $strongPasswordChars[ rand( 0, $strongPasswordCharsLength - 1 ) ];
|
|
|
|
|
}
|
|
|
|
|
return $strongPassword;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 18:22:23 +00:00
|
|
|
private function setDbPassOption() {
|
2013-05-26 13:17:24 +00:00
|
|
|
$dbpassfile = $this->getOption( 'dbpassfile' );
|
|
|
|
|
if ( $dbpassfile !== null ) {
|
|
|
|
|
if ( $this->getOption( 'dbpass' ) !== null ) {
|
|
|
|
|
$this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". '
|
|
|
|
|
. 'The content of "dbpassfile" overrides "dbpass".' );
|
2012-10-05 22:28:39 +00:00
|
|
|
}
|
2022-01-05 01:31:58 +00:00
|
|
|
AtEase::suppressWarnings();
|
2013-05-26 13:17:24 +00:00
|
|
|
$dbpass = file_get_contents( $dbpassfile ); // returns false on failure
|
2022-01-05 01:31:58 +00:00
|
|
|
AtEase::restoreWarnings();
|
2011-06-16 20:58:12 +00:00
|
|
|
if ( $dbpass === false ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Couldn't open $dbpassfile" );
|
2011-06-16 20:58:12 +00:00
|
|
|
}
|
2022-07-31 10:39:13 +00:00
|
|
|
$this->setOption( 'dbpass', trim( $dbpass, "\r\n" ) );
|
2011-06-16 20:58:12 +00:00
|
|
|
}
|
2017-07-04 18:22:23 +00:00
|
|
|
}
|
2011-06-16 20:58:12 +00:00
|
|
|
|
2017-07-04 18:22:23 +00:00
|
|
|
private function setPassOption() {
|
2013-05-26 13:17:24 +00:00
|
|
|
$passfile = $this->getOption( 'passfile' );
|
|
|
|
|
if ( $passfile !== null ) {
|
|
|
|
|
if ( $this->getOption( 'pass' ) !== null ) {
|
2023-01-25 15:11:10 +00:00
|
|
|
$this->error( 'WARNING: You have provided the option --pass or --passfile. '
|
2013-05-26 13:17:24 +00:00
|
|
|
. 'The content of "passfile" overrides "pass".' );
|
2012-10-05 22:28:39 +00:00
|
|
|
}
|
2022-01-05 01:31:58 +00:00
|
|
|
AtEase::suppressWarnings();
|
2013-05-26 13:17:24 +00:00
|
|
|
$pass = file_get_contents( $passfile ); // returns false on failure
|
2022-01-05 01:31:58 +00:00
|
|
|
AtEase::restoreWarnings();
|
2012-10-05 21:35:37 +00:00
|
|
|
if ( $pass === false ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Couldn't open $passfile" );
|
2012-10-05 21:35:37 +00:00
|
|
|
}
|
2022-07-31 10:39:13 +00:00
|
|
|
$this->setOption( 'pass', trim( $pass, "\r\n" ) );
|
2013-05-26 13:17:24 +00:00
|
|
|
} elseif ( $this->getOption( 'pass' ) === null ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( 'You need to provide the option "pass" or "passfile"' );
|
2012-10-05 21:35:37 +00:00
|
|
|
}
|
2010-11-16 18:13:35 +00:00
|
|
|
}
|
2010-06-23 01:08:34 +00:00
|
|
|
|
2019-10-09 18:41:33 +00:00
|
|
|
public function validateParamsAndArgs() {
|
2010-11-16 18:13:35 +00:00
|
|
|
if ( !$this->hasOption( 'env-checks' ) ) {
|
2024-05-04 14:28:00 +00:00
|
|
|
$this->parameters->validate();
|
2010-11-16 18:13:35 +00:00
|
|
|
}
|
2010-06-23 01:08:34 +00:00
|
|
|
}
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = CommandLineInstaller::class;
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|