MediaWiki REL1_37
install.php
Go to the documentation of this file.
1<?php
24// NO_AUTOLOAD -- file-scope define() used to modify behaviour
25
26require_once __DIR__ . '/Maintenance.php';
27
28define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
29define( 'MEDIAWIKI_INSTALL', true );
30
41 public function __construct() {
42 parent::__construct();
43 global $IP;
44
45 $this->addDescription( "CLI-based MediaWiki installation and configuration.\n" .
46 "Default options are indicated in parentheses." );
47
48 $this->addArg( 'name', 'The name of the wiki (MediaWiki)', false );
49
50 $this->addArg( 'admin', 'The username of the wiki administrator.' );
51 $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
52 $this->addOption(
53 'passfile',
54 'An alternative way to provide pass option, as the contents of this file',
55 false,
56 true
57 );
58 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
59 $this->addOption(
60 'scriptpath',
61 'The relative path of the wiki in the web server (/wiki)',
62 false,
63 true
64 );
65 $this->addOption(
66 'server',
67 'The base URL of the web server the wiki will be on (http://localhost)',
68 false,
69 true
70 );
71
72 $this->addOption( 'lang', 'The language to use (en)', false, true );
73 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
74
75 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
76 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
77 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
78 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
79 $this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true );
80 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
81 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
82 $this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true );
83 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
84 $this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true );
85 $this->addOption(
86 'dbpassfile',
87 'An alternative way to provide dbpass option, as the contents of this file',
88 false,
89 true
90 );
91 $this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
92 $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in '
93 . 'PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
94 /*
95 $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)',
96 false, true );
97 */
98 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
99
100 $this->addOption( 'with-extensions', "Detect and include extensions" );
101 $this->addOption( 'extensions', 'Comma-separated list of extensions to install',
102 false, true, false, true );
103 $this->addOption( 'skins', 'Comma-separated list of skins to install (default: all)',
104 false, true, false, true );
105 }
106
107 public function getDbType() {
108 if ( $this->hasOption( 'env-checks' ) ) {
110 }
111 return parent::getDbType();
112 }
113
114 public function execute() {
115 global $IP;
116
117 $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
118 $adminName = $this->getArg( 1 );
119 $envChecksOnly = $this->hasOption( 'env-checks' );
120
121 $this->setDbPassOption();
122 if ( !$envChecksOnly ) {
123 $this->setPassOption();
124 }
125
126 try {
127 $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
128 } catch ( \MediaWiki\Installer\InstallException $e ) {
129 $this->output( $e->getStatus()->getMessage( false, false, 'en' )->text() . "\n" );
130 return false;
131 }
132
133 $status = $installer->doEnvironmentChecks();
134 if ( $status->isGood() ) {
135 $installer->showMessage( 'config-env-good' );
136 } else {
137 $installer->showStatusMessage( $status );
138
139 return false;
140 }
141 if ( !$envChecksOnly ) {
142 $status = $installer->execute();
143 if ( !$status->isGood() ) {
144 $installer->showStatusMessage( $status );
145
146 return false;
147 }
148 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
149 $installer->showMessage(
150 'config-install-success',
151 $installer->getVar( 'wgServer' ),
152 $installer->getVar( 'wgScriptPath' )
153 );
154 }
155 return true;
156 }
157
158 private function setDbPassOption() {
159 $dbpassfile = $this->getOption( 'dbpassfile' );
160 if ( $dbpassfile !== null ) {
161 if ( $this->getOption( 'dbpass' ) !== null ) {
162 $this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". '
163 . 'The content of "dbpassfile" overrides "dbpass".' );
164 }
165 Wikimedia\suppressWarnings();
166 $dbpass = file_get_contents( $dbpassfile ); // returns false on failure
167 Wikimedia\restoreWarnings();
168 if ( $dbpass === false ) {
169 $this->fatalError( "Couldn't open $dbpassfile" );
170 }
171 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
172 }
173 }
174
175 private function setPassOption() {
176 $passfile = $this->getOption( 'passfile' );
177 if ( $passfile !== null ) {
178 if ( $this->getOption( 'pass' ) !== null ) {
179 $this->error( 'WARNING: You have provided the options "pass" and "passfile". '
180 . 'The content of "passfile" overrides "pass".' );
181 }
182 Wikimedia\suppressWarnings();
183 $pass = file_get_contents( $passfile ); // returns false on failure
184 Wikimedia\restoreWarnings();
185 if ( $pass === false ) {
186 $this->fatalError( "Couldn't open $passfile" );
187 }
188 $this->mOptions['pass'] = trim( $pass, "\r\n" );
189 } elseif ( $this->getOption( 'pass' ) === null ) {
190 $this->fatalError( 'You need to provide the option "pass" or "passfile"' );
191 }
192 }
193
194 public function validateParamsAndArgs() {
195 if ( !$this->hasOption( 'env-checks' ) ) {
196 parent::validateParamsAndArgs();
197 }
198 }
199}
200
201$maintClass = CommandLineInstaller::class;
202
203require_once RUN_MAINTENANCE_IF_MAIN;
$IP
Definition WebStart.php:49
Maintenance script to install and configure MediaWiki.
Definition install.php:40
validateParamsAndArgs()
Run some validation checks on the params, etc.
Definition install.php:194
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition install.php:107
execute()
Do the actual work.
Definition install.php:114
__construct()
Default constructor.
Definition install.php:41
static getCliInstaller( $siteName, $admin=null, array $options=[])
Instantiates and returns an instance of CliInstaller or its descendant classes.
Base installer class.
Definition Installer.php:54
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true)
Add some args that are needed.
const DB_NONE
Constants for DB access type.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
$maintClass
Definition install.php:201
A helper class for throttling authentication attempts.