MediaWiki  master
install.php
Go to the documentation of this file.
1 <?php
24 // NO_AUTOLOAD -- file-scope define() used to modify behaviour
25 
26 use Wikimedia\AtEase\AtEase;
27 
28 require_once __DIR__ . '/Maintenance.php';
29 
30 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
31 define( '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( '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 );
87  $this->addOption(
88  'dbpassfile',
89  'An alternative way to provide dbpass option, as the contents of this file',
90  false,
91  true
92  );
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/Microsoft SQL Server (mediawiki)', false, true );
96  /*
97  $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)',
98  false, true );
99  */
100  $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
101 
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 );
107  }
108 
109  public function getDbType() {
110  if ( $this->hasOption( 'env-checks' ) ) {
111  return Maintenance::DB_NONE;
112  }
113  return parent::getDbType();
114  }
115 
116  public function execute() {
117  global $IP;
118 
119  $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
120  $adminName = $this->getArg( 1 );
121  $envChecksOnly = $this->hasOption( 'env-checks' );
122 
123  $this->setDbPassOption();
124  if ( !$envChecksOnly ) {
125  $this->setPassOption();
126  }
127 
128  try {
129  $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
130  } catch ( \MediaWiki\Installer\InstallException $e ) {
131  $this->output( $e->getStatus()->getMessage( false, false, 'en' )->text() . "\n" );
132  return false;
133  }
134 
135  $status = $installer->doEnvironmentChecks();
136  if ( $status->isGood() ) {
137  $installer->showMessage( 'config-env-good' );
138  } else {
139  $installer->showStatusMessage( $status );
140 
141  return false;
142  }
143  if ( !$envChecksOnly ) {
144  $status = $installer->execute();
145  if ( !$status->isGood() ) {
146  $installer->showStatusMessage( $status );
147 
148  return false;
149  }
150  $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
151  $installer->showMessage(
152  'config-install-success',
153  $installer->getVar( 'wgServer' ),
154  $installer->getVar( 'wgScriptPath' )
155  );
156  }
157  return true;
158  }
159 
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".' );
166  }
167  AtEase::suppressWarnings();
168  $dbpass = file_get_contents( $dbpassfile ); // returns false on failure
169  AtEase::restoreWarnings();
170  if ( $dbpass === false ) {
171  $this->fatalError( "Couldn't open $dbpassfile" );
172  }
173  $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
174  }
175  }
176 
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".' );
183  }
184  AtEase::suppressWarnings();
185  $pass = file_get_contents( $passfile ); // returns false on failure
186  AtEase::restoreWarnings();
187  if ( $pass === false ) {
188  $this->fatalError( "Couldn't open $passfile" );
189  }
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"' );
193  }
194  }
195 
196  public function validateParamsAndArgs() {
197  if ( !$this->hasOption( 'env-checks' ) ) {
198  parent::validateParamsAndArgs();
199  }
200  }
201 }
202 
203 $maintClass = CommandLineInstaller::class;
204 
205 require_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:90
Maintenance script to install and configure MediaWiki.
Definition: install.php:42
validateParamsAndArgs()
Run some validation checks on the params, etc.
Definition: install.php:196
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: install.php:109
execute()
Do the actual work.
Definition: install.php:116
__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...
Definition: Maintenance.php:61
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.
Definition: Maintenance.php:66
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.
The MediaWiki class is the helper class for the index.php entry point.
Definition: MediaWiki.php:38
$maintClass
Definition: install.php:203