Localisation updates from http://translatewiki.net.
[mediawiki.git] / maintenance / install.php
blobd118747affe24161943e7895939941dddd57d25b
1 <?php
2 /**
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
20 * @file
21 * @ingroup Maintenance
24 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.3.2' ) < 0 ) ) {
25 require_once dirname( __FILE__ ) . '/../includes/PHPVersionError.php';
26 wfPHPVersionError( 'cli' );
29 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
30 define( 'MEDIAWIKI_INSTALL', true );
32 require_once dirname( __DIR__ ) . "/maintenance/Maintenance.php";
34 /**
35 * Maintenance script to install and configure MediaWiki
37 * @ingroup Maintenance
39 class CommandLineInstaller extends Maintenance {
40 function __construct() {
41 parent::__construct();
42 global $IP;
44 $this->addArg( 'name', 'The name of the wiki', true );
46 $this->addArg( 'admin', 'The username of the wiki administrator (WikiSysop)', true );
47 $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
48 $this->addOption( 'passfile', 'An alternative way to provide pass option, as the contents of this file', false, 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 );
52 $this->addOption( 'lang', 'The language to use (en)', false, true );
53 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
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" );
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' );
78 $dbpassfile = $this->getOption( 'dbpassfile', false );
79 if ( $dbpassfile !== false ) {
80 if ( $this->getOption( 'dbpass', false ) !== false ) {
81 $this->error( 'WARNING: You provide the options "dbpass" and "dbpassfile". The content of "dbpassfile" overwrites "dbpass".' );
83 wfSuppressWarnings();
84 $dbpass = file_get_contents( $dbpassfile );
85 wfRestoreWarnings();
86 if ( $dbpass === false ) {
87 $this->error( "Couldn't open $dbpassfile", true );
89 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
92 $passfile = $this->getOption( 'passfile', false );
93 if ( $passfile !== false ) {
94 if ( $this->getOption( 'pass', false ) !== false ) {
95 $this->error( 'WARNING: You provide the options "pass" and "passfile". The content of "passfile" overwrites "pass".' );
97 wfSuppressWarnings();
98 $pass = file_get_contents( $passfile );
99 wfRestoreWarnings();
100 if ( $pass === false ) {
101 $this->error( "Couldn't open $passfile", true );
103 $this->mOptions['pass'] = str_replace( array( "\n", "\r" ), "", $pass );
104 } elseif ( $this->getOption( 'pass', false ) === false ) {
105 $this->error( 'You need to provide the option "pass" or "passfile"', true );
108 $installer =
109 InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
111 $status = $installer->doEnvironmentChecks();
112 if ( $status->isGood() ) {
113 $installer->showMessage( 'config-env-good' );
114 } else {
115 $installer->showStatusMessage( $status );
116 return;
118 if ( !$this->hasOption( 'env-checks' ) ) {
119 $installer->execute();
120 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
124 function validateParamsAndArgs() {
125 if ( !$this->hasOption( 'env-checks' ) ) {
126 parent::validateParamsAndArgs();
131 $maintClass = "CommandLineInstaller";
133 require_once RUN_MAINTENANCE_IF_MAIN;