26use Wikimedia\AtEase\AtEase;
28require_once __DIR__ .
'/Maintenance.php';
30define(
'MW_CONFIG_CALLBACK',
'Installer::overrideConfig' );
31define(
'MEDIAWIKI_INSTALL',
true );
44 parent::__construct();
47 $this->
addDescription(
"CLI-based MediaWiki installation and configuration.\n" .
48 "Default options are indicated in parentheses." );
50 $this->
addArg(
'name',
'The name of the wiki (MediaWiki)',
false );
52 $this->
addArg(
'admin',
'The username of the wiki administrator.' );
53 $this->
addOption(
'pass',
'The password for the wiki administrator.',
false,
true );
56 'An alternative way to provide pass option, as the contents of this file',
63 'The relative path of the wiki in the web server (/wiki)',
69 'The base URL of the web server the wiki will be on (http://localhost)',
74 $this->
addOption(
'lang',
'The language to use (en)',
false,
true );
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 );
90 'An alternative way to provide dbpass option, as the contents of this file',
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 );
101 $this->
addOption(
'env-checks',
"Run environment checks only, don't change anything" );
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 );
111 if ( $this->
hasOption(
'env-checks' ) ) {
114 return parent::getDbType();
120 $siteName = $this->
getArg( 0,
'MediaWiki' );
121 $adminName = $this->
getArg( 1 );
122 $envChecksOnly = $this->
hasOption(
'env-checks' );
124 $this->setDbPassOption();
125 if ( !$envChecksOnly ) {
126 $this->setPassOption();
132 $this->
output( $e->getStatus()->getMessage(
false,
false,
'en' )->text() .
"\n" );
136 $status = $installer->doEnvironmentChecks();
137 if ( $status->isGood() ) {
138 $installer->showMessage(
'config-env-good' );
140 $installer->showStatusMessage( $status );
144 if ( !$envChecksOnly ) {
145 $status = $installer->execute();
146 if ( !$status->isGood() ) {
147 $installer->showStatusMessage( $status );
151 $installer->writeConfigurationFile( $this->
getOption(
'confpath', $IP ) );
152 $installer->showMessage(
153 'config-install-success',
154 $installer->getVar(
'wgServer' ),
155 $installer->getVar(
'wgScriptPath' )
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".' );
168 AtEase::suppressWarnings();
169 $dbpass = file_get_contents( $dbpassfile );
170 AtEase::restoreWarnings();
171 if ( $dbpass ===
false ) {
172 $this->
fatalError(
"Couldn't open $dbpassfile" );
174 $this->mOptions[
'dbpass'] = trim( $dbpass,
"\r\n" );
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".' );
185 AtEase::suppressWarnings();
186 $pass = file_get_contents( $passfile );
187 AtEase::restoreWarnings();
188 if ( $pass ===
false ) {
189 $this->
fatalError(
"Couldn't open $passfile" );
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"' );
198 if ( !$this->
hasOption(
'env-checks' ) ) {
199 parent::validateParamsAndArgs();
206require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
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.