Merge "Test table / list interaction"
[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( phpversion(), '5.3.2' ) < 0 ) ) {
25 echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.3.2 or higher. ABORTING.\n" .
26 "Check if you have a newer php executable with a different name, such as php5.\n";
27 die( 1 );
28 }
29
30 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
31 define( 'MEDIAWIKI_INSTALL', true );
32
33 require_once( dirname( __DIR__ )."/maintenance/Maintenance.php" );
34
35 /**
36 * Maintenance script to install and configure MediaWiki
37 *
38 * @ingroup Maintenance
39 */
40 class CommandLineInstaller extends Maintenance {
41 function __construct() {
42 parent::__construct();
43 global $IP;
44
45 $this->addArg( 'name', 'The name of the wiki', true);
46
47 $this->addArg( 'admin', 'The username of the wiki administrator (WikiSysop)', true );
48 $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
49 $this->addOption( 'passfile', 'An alternative way to provide pass option, as the contents of this file', false, true );
50 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
51 $this->addOption( 'scriptpath', 'The relative path of the wiki in the web server (/wiki)', false, true );
52
53 $this->addOption( 'lang', 'The language to use (en)', false, true );
54 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
55
56 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
57 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
58 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
59 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
60 $this->addOption( 'dbpath', 'The path for the SQLite DB (/var/data)', false, true );
61 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
62 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
63 $this->addOption( 'installdbpass', 'The pasword for the DB user to install as.', false, true );
64 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
65 $this->addOption( 'dbpass', 'The pasword for the DB user for normal operations', false, true );
66 $this->addOption( 'dbpassfile', 'An alternative way to provide dbpass option, as the contents of this file', false, true );
67 $this->addOption( 'confpath', "Path to write LocalSettings.php to, default $IP", false, true );
68 /* $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in pg (mediawiki)', false, true ); */
69 /* $this->addOption( 'namespace', 'The project namespace (same as the name)', false, true ); */
70 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
71 }
72
73 function execute() {
74 global $IP, $wgTitle;
75 $siteName = isset( $this->mArgs[0] ) ? $this->mArgs[0] : "Don't care"; // Will not be set if used with --env-checks
76 $adminName = isset( $this->mArgs[1] ) ? $this->mArgs[1] : null;
77 $wgTitle = Title::newFromText( 'Installer script' );
78
79 $dbpassfile = $this->getOption( 'dbpassfile', false );
80 if ( $dbpassfile !== false ) {
81 if ( $this->getOption( 'dbpass', false ) !== false ) {
82 $this->error( 'WARNING: You provide the options "dbpass" and "dbpassfile". The content of "dbpassfile" overwrites "dbpass".' );
83 }
84 wfSuppressWarnings();
85 $dbpass = file_get_contents( $dbpassfile );
86 wfRestoreWarnings();
87 if ( $dbpass === false ) {
88 $this->error( "Couldn't open $dbpassfile", true );
89 }
90 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
91 }
92
93 $passfile = $this->getOption( 'passfile', false );
94 if ( $passfile !== false ) {
95 if ( $this->getOption( 'pass', false ) !== false ) {
96 $this->error( 'WARNING: You provide the options "pass" and "passfile". The content of "passfile" overwrites "pass".' );
97 }
98 wfSuppressWarnings();
99 $pass = file_get_contents( $passfile );
100 wfRestoreWarnings();
101 if ( $pass === false ) {
102 $this->error( "Couldn't open $passfile", true );
103 }
104 $this->mOptions['pass'] = str_replace( array( "\n", "\r" ), "", $pass );
105 } elseif ( $this->getOption( 'pass', false ) === false ) {
106 $this->error( 'You need to provide the option "pass" or "passfile"', true );
107 }
108
109 $installer =
110 InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
111
112 $status = $installer->doEnvironmentChecks();
113 if( $status->isGood() ) {
114 $installer->showMessage( 'config-env-good' );
115 } else {
116 $installer->showStatusMessage( $status );
117 return;
118 }
119 if( !$this->hasOption( 'env-checks' ) ) {
120 $installer->execute();
121 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
122 }
123 }
124
125 function validateParamsAndArgs() {
126 if ( !$this->hasOption( 'env-checks' ) ) {
127 parent::validateParamsAndArgs();
128 }
129 }
130 }
131
132 $maintClass = "CommandLineInstaller";
133
134 require_once( RUN_MAINTENANCE_IF_MAIN );