3 * CLI-based MediaWiki installation and configuration.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @ingroup Maintenance
24 // Checking for old versions of PHP is done in Maintenance.php
25 // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+
26 require_once dirname( __FILE__
) . '/Maintenance.php';
28 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
29 define( 'MEDIAWIKI_INSTALL', true );
32 * Maintenance script to install and configure MediaWiki
34 * Default values for the options are defined in DefaultSettings.php (see the mapping in CliInstaller.php)
35 * Default for --dbpath (SQLite-specific) is defined in SqliteInstaller::getGlobalDefaults
37 * @ingroup Maintenance
39 class CommandLineInstaller
extends Maintenance
{
40 function __construct() {
41 parent
::__construct();
44 $this->addDescription( "CLI-based MediaWiki installation and configuration.\n" .
45 "Defaut options are indicated in parenthesis." );
47 $this->addArg( 'name', 'The name of the wiki (MediaWiki)', false );
49 $this->addArg( 'admin', 'The username of the wiki administrator.' );
50 $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
53 'An alternative way to provide pass option, as the contents of this file',
57 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
60 'The relative path of the wiki in the web server (/wiki)',
65 $this->addOption( 'lang', 'The language to use (en)', false, true );
66 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
68 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
69 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
70 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
71 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
72 $this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true );
73 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
74 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
75 $this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true );
76 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
77 $this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true );
80 'An alternative way to provide dbpass option, as the contents of this file',
84 $this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
85 $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
87 $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)', false, true );
89 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
95 $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
96 $adminName = $this->getArg( 1 );
98 $dbpassfile = $this->getOption( 'dbpassfile' );
99 if ( $dbpassfile !== null ) {
100 if ( $this->getOption( 'dbpass' ) !== null ) {
101 $this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". '
102 . 'The content of "dbpassfile" overrides "dbpass".' );
104 wfSuppressWarnings();
105 $dbpass = file_get_contents( $dbpassfile ); // returns false on failure
107 if ( $dbpass === false ) {
108 $this->error( "Couldn't open $dbpassfile", true );
110 $this->mOptions
['dbpass'] = trim( $dbpass, "\r\n" );
113 $passfile = $this->getOption( 'passfile' );
114 if ( $passfile !== null ) {
115 if ( $this->getOption( 'pass' ) !== null ) {
116 $this->error( 'WARNING: You have provided the options "pass" and "passfile". '
117 . 'The content of "passfile" overrides "pass".' );
119 wfSuppressWarnings();
120 $pass = file_get_contents( $passfile ); // returns false on failure
122 if ( $pass === false ) {
123 $this->error( "Couldn't open $passfile", true );
125 $this->mOptions
['pass'] = trim( $pass, "\r\n" );
126 } elseif ( $this->getOption( 'pass' ) === null ) {
127 $this->error( 'You need to provide the option "pass" or "passfile"', true );
130 $installer = InstallerOverrides
::getCliInstaller( $siteName, $adminName, $this->mOptions
);
132 $status = $installer->doEnvironmentChecks();
133 if ( $status->isGood() ) {
134 $installer->showMessage( 'config-env-good' );
136 $installer->showStatusMessage( $status );
140 if ( !$this->hasOption( 'env-checks' ) ) {
141 $installer->execute();
142 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
146 function validateParamsAndArgs() {
147 if ( !$this->hasOption( 'env-checks' ) ) {
148 parent
::validateParamsAndArgs();
153 $maintClass = 'CommandLineInstaller';
155 require_once RUN_MAINTENANCE_IF_MAIN
;