MediaWiki REL1_39
install.php
Go to the documentation of this file.
1<?php
24// NO_AUTOLOAD -- file-scope define() used to modify behaviour
25
26use Wikimedia\AtEase\AtEase;
27
28require_once __DIR__ . '/Maintenance.php';
29
30define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
31define( 'MEDIAWIKI_INSTALL', true );
32
43 public 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 $this->addOption(
68 'server',
69 'The base URL of the web server the wiki will be on (http://localhost)',
70 false,
71 true
72 );
73
74 $this->addOption( 'lang', 'The language to use (en)', false, true );
75 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
76
77 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
78 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
79 $this->addOption( 'dbssl', 'Connect to the database over SSL' );
80 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
81 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
82 $this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true );
83 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
84 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
85 $this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true );
86 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
87 $this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true );
88 $this->addOption(
89 'dbpassfile',
90 'An alternative way to provide dbpass option, as the contents of this file',
91 false,
92 true
93 );
94 $this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
95 $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in '
96 . 'PostgreSQL (mediawiki)', false, true );
97 /*
98 $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)',
99 false, true );
100 */
101 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
102
103 $this->addOption( 'with-extensions', "Detect and include extensions" );
104 $this->addOption( 'extensions', 'Comma-separated list of extensions to install',
105 false, true, false, true );
106 $this->addOption( 'skins', 'Comma-separated list of skins to install (default: all)',
107 false, true, false, true );
108 }
109
110 public function getDbType() {
111 if ( $this->hasOption( 'env-checks' ) ) {
113 }
114 return parent::getDbType();
115 }
116
117 public function execute() {
118 global $IP;
119
120 $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
121 $adminName = $this->getArg( 1 );
122 $envChecksOnly = $this->hasOption( 'env-checks' );
123
124 $this->setDbPassOption();
125 if ( !$envChecksOnly ) {
126 $this->setPassOption();
127 }
128
129 try {
130 $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
131 } catch ( \MediaWiki\Installer\InstallException $e ) {
132 $this->output( $e->getStatus()->getMessage( false, false, 'en' )->text() . "\n" );
133 return false;
134 }
135
136 $status = $installer->doEnvironmentChecks();
137 if ( $status->isGood() ) {
138 $installer->showMessage( 'config-env-good' );
139 } else {
140 $installer->showStatusMessage( $status );
141
142 return false;
143 }
144 if ( !$envChecksOnly ) {
145 $status = $installer->execute();
146 if ( !$status->isGood() ) {
147 $installer->showStatusMessage( $status );
148
149 return false;
150 }
151 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
152 $installer->showMessage(
153 'config-install-success',
154 $installer->getVar( 'wgServer' ),
155 $installer->getVar( 'wgScriptPath' )
156 );
157 }
158 return true;
159 }
160
161 private function setDbPassOption() {
162 $dbpassfile = $this->getOption( 'dbpassfile' );
163 if ( $dbpassfile !== null ) {
164 if ( $this->getOption( 'dbpass' ) !== null ) {
165 $this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". '
166 . 'The content of "dbpassfile" overrides "dbpass".' );
167 }
168 AtEase::suppressWarnings();
169 $dbpass = file_get_contents( $dbpassfile ); // returns false on failure
170 AtEase::restoreWarnings();
171 if ( $dbpass === false ) {
172 $this->fatalError( "Couldn't open $dbpassfile" );
173 }
174 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
175 }
176 }
177
178 private function setPassOption() {
179 $passfile = $this->getOption( 'passfile' );
180 if ( $passfile !== null ) {
181 if ( $this->getOption( 'pass' ) !== null ) {
182 $this->error( 'WARNING: You have provided the options "pass" and "passfile". '
183 . 'The content of "passfile" overrides "pass".' );
184 }
185 AtEase::suppressWarnings();
186 $pass = file_get_contents( $passfile ); // returns false on failure
187 AtEase::restoreWarnings();
188 if ( $pass === false ) {
189 $this->fatalError( "Couldn't open $passfile" );
190 }
191 $this->mOptions['pass'] = trim( $pass, "\r\n" );
192 } elseif ( $this->getOption( 'pass' ) === null ) {
193 $this->fatalError( 'You need to provide the option "pass" or "passfile"' );
194 }
195 }
196
197 public function validateParamsAndArgs() {
198 if ( !$this->hasOption( 'env-checks' ) ) {
199 parent::validateParamsAndArgs();
200 }
201 }
202}
203
204$maintClass = CommandLineInstaller::class;
205
206require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:91
Maintenance script to install and configure MediaWiki.
Definition install.php:42
validateParamsAndArgs()
Run some validation checks on the params, etc.
Definition install.php:197
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition install.php:110
execute()
Do the actual work.
Definition install.php:117
__construct()
Default constructor.
Definition install.php:43
static getCliInstaller( $siteName, $admin=null, array $options=[])
Instantiates and returns an instance of CliInstaller or its descendant classes.
Base installer class.
Definition Installer.php:57
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:204
A helper class for throttling authentication attempts.