Merge "Add white-space to get pre to wrap in Firefox"
[lhc/web/wiklou.git] / maintenance / install.php
1 <?php
2 /**
3 * CLI-based MediaWiki installation and configuration.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Maintenance
22 */
23
24 if ( !function_exists( 'version_compare' ) || ( version_compare( PHP_VERSION, '5.3.2' ) < 0 ) ) {
25 require_once dirname( __FILE__ ) . '/../includes/PHPVersionError.php';
26 wfPHPVersionError( 'cli' );
27 }
28
29 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
30 define( 'MEDIAWIKI_INSTALL', true );
31
32 require_once dirname( __DIR__ ) . '/maintenance/Maintenance.php';
33
34 /**
35 * Maintenance script to install and configure MediaWiki
36 *
37 * Default values for the options are defined in DefaultSettings.php
38 * (see the mapping in CliInstaller.php)
39 * Default for --dbpath (SQLite-specific) is defined in SqliteInstaller::getGlobalDefaults
40 *
41 * @ingroup Maintenance
42 */
43 class CommandLineInstaller extends Maintenance {
44 function __construct() {
45 parent::__construct();
46 global $IP;
47
48 $this->addDescription( "CLI-based MediaWiki installation and configuration.\n" .
49 "Defaut options are indicated in parenthesis." );
50
51 $this->addArg( 'name', 'The name of the wiki (MediaWiki)', false );
52
53 $this->addArg( 'admin', 'The username of the wiki administrator.' );
54 $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
55 $this->addOption(
56 'passfile',
57 'An alternative way to provide pass option, as the contents of this file',
58 false,
59 true
60 );
61 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
62 $this->addOption(
63 'scriptpath',
64 'The relative path of the wiki in the web server (/wiki)',
65 false,
66 true
67 );
68
69 $this->addOption( 'lang', 'The language to use (en)', false, true );
70 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
71
72 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
73 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
74 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
75 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
76 $this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true );
77 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
78 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
79 $this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true );
80 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
81 $this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true );
82 $this->addOption(
83 'dbpassfile',
84 'An alternative way to provide dbpass option, as the contents of this file',
85 false,
86 true
87 );
88 $this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
89 $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in '
90 . 'PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
91 /*
92 $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)',
93 false, true );
94 */
95 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
96 }
97
98 function execute() {
99 global $IP;
100
101 $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
102 $adminName = $this->getArg( 1 );
103
104 $dbpassfile = $this->getOption( 'dbpassfile' );
105 if ( $dbpassfile !== null ) {
106 if ( $this->getOption( 'dbpass' ) !== null ) {
107 $this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". '
108 . 'The content of "dbpassfile" overrides "dbpass".' );
109 }
110 wfSuppressWarnings();
111 $dbpass = file_get_contents( $dbpassfile ); // returns false on failure
112 wfRestoreWarnings();
113 if ( $dbpass === false ) {
114 $this->error( "Couldn't open $dbpassfile", true );
115 }
116 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
117 }
118
119 $passfile = $this->getOption( 'passfile' );
120 if ( $passfile !== null ) {
121 if ( $this->getOption( 'pass' ) !== null ) {
122 $this->error( 'WARNING: You have provided the options "pass" and "passfile". '
123 . 'The content of "passfile" overrides "pass".' );
124 }
125 wfSuppressWarnings();
126 $pass = file_get_contents( $passfile ); // returns false on failure
127 wfRestoreWarnings();
128 if ( $pass === false ) {
129 $this->error( "Couldn't open $passfile", true );
130 }
131 $this->mOptions['pass'] = trim( $pass, "\r\n" );
132 } elseif ( $this->getOption( 'pass' ) === null ) {
133 $this->error( 'You need to provide the option "pass" or "passfile"', true );
134 }
135
136 $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
137
138 $status = $installer->doEnvironmentChecks();
139 if ( $status->isGood() ) {
140 $installer->showMessage( 'config-env-good' );
141 } else {
142 $installer->showStatusMessage( $status );
143
144 return;
145 }
146 if ( !$this->hasOption( 'env-checks' ) ) {
147 $installer->execute();
148 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
149 }
150 }
151
152 function validateParamsAndArgs() {
153 if ( !$this->hasOption( 'env-checks' ) ) {
154 parent::validateParamsAndArgs();
155 }
156 }
157 }
158
159 $maintClass = 'CommandLineInstaller';
160
161 require_once RUN_MAINTENANCE_IF_MAIN;