Revert "merged master"
[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( dirname( __FILE__ ) )."/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.', true, true );
49 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
50 $this->addOption( 'scriptpath', 'The relative path of the wiki in the web server (/wiki)', false, true );
51
52 $this->addOption( 'lang', 'The language to use (en)', false, true );
53 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
54
55 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
56 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
57 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
58 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
59 $this->addOption( 'dbpath', 'The path for the SQLite DB (/var/data)', false, true );
60 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
61 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
62 $this->addOption( 'installdbpass', 'The pasword for the DB user to install as.', false, true );
63 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
64 $this->addOption( 'dbpass', 'The pasword for the DB user for normal operations', false, true );
65 $this->addOption( 'dbpassfile', 'An alternative way to provide dbpass option, as the contents of this file', false, true );
66 $this->addOption( 'confpath', "Path to write LocalSettings.php to, default $IP", false, true );
67 /* $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in pg (mediawiki)', false, true ); */
68 /* $this->addOption( 'namespace', 'The project namespace (same as the name)', false, true ); */
69 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
70 }
71
72 function execute() {
73 global $IP, $wgTitle;
74 $siteName = isset( $this->mArgs[0] ) ? $this->mArgs[0] : "Don't care"; // Will not be set if used with --env-checks
75 $adminName = isset( $this->mArgs[1] ) ? $this->mArgs[1] : null;
76 $wgTitle = Title::newFromText( 'Installer script' );
77
78 $dbpassfile = $this->getOption( 'dbpassfile', false );
79 if ( $dbpassfile !== false ) {
80 wfSuppressWarnings();
81 $dbpass = file_get_contents( $dbpassfile );
82 wfRestoreWarnings();
83 if ( $dbpass === false ) {
84 $this->error( "Couldn't open $dbpassfile", true );
85 }
86 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
87 }
88
89 $installer =
90 InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
91
92 $status = $installer->doEnvironmentChecks();
93 if( $status->isGood() ) {
94 $installer->showMessage( 'config-env-good' );
95 } else {
96 $installer->showStatusMessage( $status );
97 return;
98 }
99 if( !$this->hasOption( 'env-checks' ) ) {
100 $installer->execute();
101 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
102 }
103 }
104
105 function validateParamsAndArgs() {
106 if ( !$this->hasOption( 'env-checks' ) ) {
107 parent::validateParamsAndArgs();
108 }
109 }
110 }
111
112 $maintClass = "CommandLineInstaller";
113
114 require_once( RUN_MAINTENANCE_IF_MAIN );