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