26require_once __DIR__ .
'/Maintenance.php';
28define(
'MW_CONFIG_CALLBACK',
'Installer::overrideConfig' );
29define(
'MEDIAWIKI_INSTALL',
true );
42 parent::__construct();
45 $this->
addDescription(
"CLI-based MediaWiki installation and configuration.\n" .
46 "Default options are indicated in parentheses." );
48 $this->
addArg(
'name',
'The name of the wiki (MediaWiki)',
false );
50 $this->
addArg(
'admin',
'The username of the wiki administrator.' );
51 $this->
addOption(
'pass',
'The password for the wiki administrator.',
false,
true );
54 'An alternative way to provide pass option, as the contents of this file',
61 'The relative path of the wiki in the web server (/wiki)',
67 'The base URL of the web server the wiki will be on (http://localhost)',
72 $this->
addOption(
'lang',
'The language to use (en)',
false,
true );
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 );
87 'An alternative way to provide dbpass option, as the contents of this file',
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 );
98 $this->
addOption(
'env-checks',
"Run environment checks only, don't change anything" );
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 );
108 if ( $this->
hasOption(
'env-checks' ) ) {
111 return parent::getDbType();
117 $siteName = $this->
getArg( 0,
'MediaWiki' );
118 $adminName = $this->
getArg( 1 );
119 $envChecksOnly = $this->
hasOption(
'env-checks' );
122 if ( !$envChecksOnly ) {
129 $this->
output( $e->getStatus()->getMessage(
false,
false,
'en' )->text() .
"\n" );
133 $status = $installer->doEnvironmentChecks();
134 if ( $status->isGood() ) {
135 $installer->showMessage(
'config-env-good' );
137 $installer->showStatusMessage( $status );
141 if ( !$envChecksOnly ) {
142 $status = $installer->execute();
143 if ( !$status->isGood() ) {
144 $installer->showStatusMessage( $status );
148 $installer->writeConfigurationFile( $this->
getOption(
'confpath', $IP ) );
149 $installer->showMessage(
150 'config-install-success',
151 $installer->getVar(
'wgServer' ),
152 $installer->getVar(
'wgScriptPath' )
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".' );
165 Wikimedia\suppressWarnings();
166 $dbpass = file_get_contents( $dbpassfile );
167 Wikimedia\restoreWarnings();
168 if ( $dbpass ===
false ) {
169 $this->
fatalError(
"Couldn't open $dbpassfile" );
171 $this->mOptions[
'dbpass'] = trim( $dbpass,
"\r\n" );
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".' );
182 Wikimedia\suppressWarnings();
183 $pass = file_get_contents( $passfile );
184 Wikimedia\restoreWarnings();
185 if ( $pass ===
false ) {
186 $this->
fatalError(
"Couldn't open $passfile" );
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"' );
195 if ( !$this->
hasOption(
'env-checks' ) ) {
196 parent::validateParamsAndArgs();
203require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to install and configure MediaWiki.
validateParamsAndArgs()
Run some validation checks on the params, etc.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
execute()
Do the actual work.
__construct()
Default constructor.
static getCliInstaller( $siteName, $admin=null, array $options=[])
Instantiates and returns an instance of CliInstaller or its descendant classes.
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.