Merge "CSSMin: Clean up $remote trailing slash fix"
[lhc/web/wiklou.git] / maintenance / install.php
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @ingroup Maintenance
20 * @see wfWaitForSlaves()
21 */
22
23 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.3.2' ) < 0 ) ) {
24 echo "You are using PHP version " . phpversion() . " but MediaWiki needs PHP 5.3.2 or higher. ABORTING.\n" .
25 "Check if you have a newer php executable with a different name, such as php5.\n";
26 die( 1 );
27 }
28
29 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
30 define( 'MEDIAWIKI_INSTALL', true );
31
32 require_once( dirname( dirname( __FILE__ ) )."/maintenance/Maintenance.php" );
33
34 class CommandLineInstaller extends Maintenance {
35 function __construct() {
36 parent::__construct();
37 global $IP;
38
39 $this->addArg( 'name', 'The name of the wiki', true);
40
41 $this->addArg( 'admin', 'The username of the wiki administrator (WikiSysop)', true );
42 $this->addOption( 'pass', 'The password for the wiki administrator. You will be prompted for this if it isn\'t provided', false, true );
43 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
44 $this->addOption( 'scriptpath', 'The relative path of the wiki in the web server (/wiki)', false, true );
45
46 $this->addOption( 'lang', 'The language to use (en)', false, true );
47 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
48
49 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
50 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
51 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
52 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
53 $this->addOption( 'dbpath', 'The path for the SQLite DB (/var/data)', false, true );
54 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
55 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
56 $this->addOption( 'installdbpass', 'The pasword for the DB user to install as.', false, true );
57 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
58 $this->addOption( 'dbpass', 'The pasword for the DB user for normal operations', false, true );
59 $this->addOption( 'dbpassfile', 'An alternative way to provide dbpass option, as the contents of this file', false, true );
60 $this->addOption( 'confpath', "Path to write LocalSettings.php to, default $IP", false, true );
61 /* $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in pg (mediawiki)', false, true ); */
62 /* $this->addOption( 'namespace', 'The project namespace (same as the name)', false, true ); */
63 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
64 }
65
66 function execute() {
67 global $IP, $wgTitle;
68 $siteName = isset( $this->mArgs[0] ) ? $this->mArgs[0] : "Don't care"; // Will not be set if used with --env-checks
69 $adminName = isset( $this->mArgs[1] ) ? $this->mArgs[1] : null;
70 $wgTitle = Title::newFromText( 'Installer script' );
71
72 $dbpassfile = $this->getOption( 'dbpassfile', false );
73 if ( $dbpassfile !== false ) {
74 wfSuppressWarnings();
75 $dbpass = file_get_contents( $dbpassfile );
76 wfRestoreWarnings();
77 if ( $dbpass === false ) {
78 $this->error( "Couldn't open $dbpassfile", true );
79 }
80 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
81 }
82
83 $installer =
84 InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
85
86 $status = $installer->doEnvironmentChecks();
87 if( $status->isGood() ) {
88 $installer->showMessage( 'config-env-good' );
89 } else {
90 $installer->showStatusMessage( $status );
91 return;
92 }
93 if( !$this->hasOption( 'env-checks' ) ) {
94 $installer->execute();
95 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
96 }
97 }
98
99 function validateParamsAndArgs() {
100 if ( !$this->hasOption( 'env-checks' ) ) {
101 parent::validateParamsAndArgs();
102 }
103 }
104 }
105
106 $maintClass = "CommandLineInstaller";
107
108 require_once( RUN_MAINTENANCE_IF_MAIN );