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
|
|
|
|
2016-06-15 00:14:20 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2011-04-12 15:37:51 +00:00
|
|
|
|
2011-01-21 15:27:16 +00:00
|
|
|
define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
|
2011-06-05 19:52:03 +00:00
|
|
|
define( 'MEDIAWIKI_INSTALL', true );
|
2010-05-07 12:25:01 +00:00
|
|
|
|
2012-07-17 05:40:40 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to install and configure MediaWiki
|
|
|
|
|
*
|
2014-07-24 17:03:17 +00:00
|
|
|
* Default values for the options are defined in DefaultSettings.php
|
|
|
|
|
* (see the mapping in 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 {
|
2011-04-12 15:37:51 +00:00
|
|
|
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" .
|
2015-10-27 19:48:52 +00:00
|
|
|
"Default options are indicated in parentheses." );
|
2013-05-26 13:17:24 +00:00
|
|
|
|
|
|
|
|
$this->addArg( 'name', 'The name of the wiki (MediaWiki)', false );
|
2010-06-27 21:48:51 +00:00
|
|
|
|
2013-05-26 13:17:24 +00:00
|
|
|
$this->addArg( 'admin', 'The username of the wiki administrator.' );
|
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
|
|
|
|
|
);
|
2011-10-06 17:00:18 +00:00
|
|
|
/* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
|
2014-04-22 21:25:04 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'scriptpath',
|
|
|
|
|
'The relative path of the wiki in the web server (/wiki)',
|
|
|
|
|
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 );
|
|
|
|
|
/* $this->addOption( 'cont-lang', 'The content language (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 );
|
|
|
|
|
$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 '
|
|
|
|
|
. 'PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
|
2014-04-22 21:25:04 +00:00
|
|
|
/*
|
2014-07-24 17:03:17 +00:00
|
|
|
$this->addOption( 'namespace', 'The project namespace (same as the "name" argument)',
|
|
|
|
|
false, true );
|
2014-04-22 21:25:04 +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 );
|
2010-06-23 01:08:34 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-04 18:39:42 +00:00
|
|
|
public function getDbType() {
|
|
|
|
|
if ( $this->hasOption( 'env-checks' ) ) {
|
|
|
|
|
return Maintenance::DB_NONE;
|
|
|
|
|
}
|
|
|
|
|
return parent::getDbType();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-12 15:37:51 +00:00
|
|
|
function execute() {
|
2014-03-13 01:27:58 +00:00
|
|
|
global $IP;
|
2014-04-22 21:25:04 +00:00
|
|
|
|
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
|
|
|
|
2017-07-04 18:22:23 +00:00
|
|
|
$this->setDbPassOption();
|
|
|
|
|
if ( !$envChecksOnly ) {
|
|
|
|
|
$this->setPassOption();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-27 15:38:54 +00:00
|
|
|
try {
|
|
|
|
|
$installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
|
|
|
|
|
} catch ( \MediaWiki\Installer\InstallException $e ) {
|
2019-08-19 16:12:32 +00:00
|
|
|
$this->output( $e->getStatus()->getMessage( false, false, 'en' )->text() . "\n" );
|
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 {
|
|
|
|
|
$installer->showStatusMessage( $status );
|
|
|
|
|
|
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() ) {
|
2019-09-10 02:19:51 +00:00
|
|
|
$installer->showStatusMessage( $status );
|
|
|
|
|
|
2019-07-27 15:38:54 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2013-05-26 13:17:24 +00:00
|
|
|
$dbpass = file_get_contents( $dbpassfile ); // returns false on failure
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\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
|
|
|
}
|
2011-06-16 21:01:52 +00:00
|
|
|
$this->mOptions['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 ) {
|
|
|
|
|
$this->error( 'WARNING: You have provided the options "pass" and "passfile". '
|
|
|
|
|
. 'The content of "passfile" overrides "pass".' );
|
2012-10-05 22:28:39 +00:00
|
|
|
}
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\suppressWarnings();
|
2013-05-26 13:17:24 +00:00
|
|
|
$pass = file_get_contents( $passfile ); // returns false on failure
|
2018-02-10 07:52:26 +00:00
|
|
|
Wikimedia\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
|
|
|
}
|
2013-05-26 13:17:24 +00:00
|
|
|
$this->mOptions['pass'] = trim( $pass, "\r\n" );
|
|
|
|
|
} 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
|
|
|
|
2011-04-12 15:37:51 +00:00
|
|
|
function validateParamsAndArgs() {
|
2010-11-16 18:13:35 +00:00
|
|
|
if ( !$this->hasOption( 'env-checks' ) ) {
|
|
|
|
|
parent::validateParamsAndArgs();
|
|
|
|
|
}
|
2010-06-23 01:08:34 +00:00
|
|
|
}
|
2010-05-07 12:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
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;
|