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(
'dbport',
'The database port; only for PostgreSQL (5432)',
false,
true );
80 $this->
addOption(
'dbname',
'The database name (my_wiki)',
false,
true );
81 $this->
addOption(
'dbpath',
'The path for the SQLite DB ($IP/data)',
false,
true );
82 $this->
addOption(
'dbprefix',
'Optional database table name prefix',
false,
true );
83 $this->
addOption(
'installdbuser',
'The user to use for installing (root)',
false,
true );
84 $this->
addOption(
'installdbpass',
'The password for the DB user to install as.',
false,
true );
85 $this->
addOption(
'dbuser',
'The user to use for normal operations (wikiuser)',
false,
true );
86 $this->
addOption(
'dbpass',
'The password for the DB user for normal operations',
false,
true );
89 'An alternative way to provide dbpass option, as the contents of this file',
93 $this->
addOption(
'confpath',
"Path to write LocalSettings.php to ($IP)",
false,
true );
94 $this->
addOption(
'dbschema',
'The schema for the MediaWiki DB in '
95 .
'PostgreSQL (mediawiki)',
false,
true );
100 $this->
addOption(
'env-checks',
"Run environment checks only, don't change anything" );
102 $this->
addOption(
'with-extensions',
"Detect and include extensions" );
103 $this->
addOption(
'extensions',
'Comma-separated list of extensions to install',
104 false,
true,
false,
true );
105 $this->
addOption(
'skins',
'Comma-separated list of skins to install (default: all)',
106 false,
true,
false,
true );
110 if ( $this->
hasOption(
'env-checks' ) ) {
113 return parent::getDbType();
119 $siteName = $this->
getArg( 0,
'MediaWiki' );
120 $adminName = $this->
getArg( 1 );
121 $envChecksOnly = $this->
hasOption(
'env-checks' );
123 $this->setDbPassOption();
124 if ( !$envChecksOnly ) {
125 $this->setPassOption();
131 $this->
output( $e->getStatus()->getMessage(
false,
false,
'en' )->text() .
"\n" );
135 $status = $installer->doEnvironmentChecks();
136 if ( $status->isGood() ) {
137 $installer->showMessage(
'config-env-good' );
139 $installer->showStatusMessage( $status );
143 if ( !$envChecksOnly ) {
144 $status = $installer->execute();
145 if ( !$status->isGood() ) {
146 $installer->showStatusMessage( $status );
150 $installer->writeConfigurationFile( $this->
getOption(
'confpath', $IP ) );
151 $installer->showMessage(
152 'config-install-success',
153 $installer->getVar(
'wgServer' ),
154 $installer->getVar(
'wgScriptPath' )
160 private function setDbPassOption() {
161 $dbpassfile = $this->
getOption(
'dbpassfile' );
162 if ( $dbpassfile !==
null ) {
163 if ( $this->
getOption(
'dbpass' ) !==
null ) {
164 $this->
error(
'WARNING: You have provided the options "dbpass" and "dbpassfile". '
165 .
'The content of "dbpassfile" overrides "dbpass".' );
167 AtEase::suppressWarnings();
168 $dbpass = file_get_contents( $dbpassfile );
169 AtEase::restoreWarnings();
170 if ( $dbpass ===
false ) {
171 $this->
fatalError(
"Couldn't open $dbpassfile" );
173 $this->mOptions[
'dbpass'] = trim( $dbpass,
"\r\n" );
177 private function setPassOption() {
178 $passfile = $this->
getOption(
'passfile' );
179 if ( $passfile !==
null ) {
180 if ( $this->
getOption(
'pass' ) !==
null ) {
181 $this->
error(
'WARNING: You have provided the options "pass" and "passfile". '
182 .
'The content of "passfile" overrides "pass".' );
184 AtEase::suppressWarnings();
185 $pass = file_get_contents( $passfile );
186 AtEase::restoreWarnings();
187 if ( $pass ===
false ) {
188 $this->
fatalError(
"Couldn't open $passfile" );
190 $this->mOptions[
'pass'] = trim( $pass,
"\r\n" );
191 } elseif ( $this->
getOption(
'pass' ) ===
null ) {
192 $this->
fatalError(
'You need to provide the option "pass" or "passfile"' );
197 if ( !$this->
hasOption(
'env-checks' ) ) {
198 parent::validateParamsAndArgs();
205require_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.