install.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * CLI-based MediaWiki installation and configuration.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Maintenance
  22. */
  23. require_once __DIR__ . '/Maintenance.php';
  24. define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
  25. define( 'MEDIAWIKI_INSTALL', true );
  26. /**
  27. * Maintenance script to install and configure MediaWiki
  28. *
  29. * Default values for the options are defined in DefaultSettings.php
  30. * (see the mapping in CliInstaller.php)
  31. * Default for --dbpath (SQLite-specific) is defined in SqliteInstaller::getGlobalDefaults
  32. *
  33. * @ingroup Maintenance
  34. */
  35. class CommandLineInstaller extends Maintenance {
  36. function __construct() {
  37. parent::__construct();
  38. global $IP;
  39. $this->addDescription( "CLI-based MediaWiki installation and configuration.\n" .
  40. "Default options are indicated in parentheses." );
  41. $this->addArg( 'name', 'The name of the wiki (MediaWiki)', false );
  42. $this->addArg( 'admin', 'The username of the wiki administrator.' );
  43. $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
  44. $this->addOption(
  45. 'passfile',
  46. 'An alternative way to provide pass option, as the contents of this file',
  47. false,
  48. true
  49. );
  50. /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
  51. $this->addOption(
  52. 'scriptpath',
  53. 'The relative path of the wiki in the web server (/wiki)',
  54. false,
  55. true
  56. );
  57. $this->addOption( 'lang', 'The language to use (en)', false, true );
  58. /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
  59. $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
  60. $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
  61. $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
  62. $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
  63. $this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true );
  64. $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
  65. $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
  66. $this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true );
  67. $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
  68. $this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true );
  69. $this->addOption(
  70. 'dbpassfile',
  71. 'An alternative way to provide dbpass option, as the contents of this file',
  72. false,
  73. true
  74. );
  75. $this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
  76. $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in '
  77. . 'PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
  78. /*
  79. $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)',
  80. false, true );
  81. */
  82. $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
  83. }
  84. function execute() {
  85. global $IP;
  86. $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
  87. $adminName = $this->getArg( 1 );
  88. $dbpassfile = $this->getOption( 'dbpassfile' );
  89. if ( $dbpassfile !== null ) {
  90. if ( $this->getOption( 'dbpass' ) !== null ) {
  91. $this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". '
  92. . 'The content of "dbpassfile" overrides "dbpass".' );
  93. }
  94. MediaWiki\suppressWarnings();
  95. $dbpass = file_get_contents( $dbpassfile ); // returns false on failure
  96. MediaWiki\restoreWarnings();
  97. if ( $dbpass === false ) {
  98. $this->error( "Couldn't open $dbpassfile", true );
  99. }
  100. $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
  101. }
  102. $passfile = $this->getOption( 'passfile' );
  103. if ( $passfile !== null ) {
  104. if ( $this->getOption( 'pass' ) !== null ) {
  105. $this->error( 'WARNING: You have provided the options "pass" and "passfile". '
  106. . 'The content of "passfile" overrides "pass".' );
  107. }
  108. MediaWiki\suppressWarnings();
  109. $pass = file_get_contents( $passfile ); // returns false on failure
  110. MediaWiki\restoreWarnings();
  111. if ( $pass === false ) {
  112. $this->error( "Couldn't open $passfile", true );
  113. }
  114. $this->mOptions['pass'] = trim( $pass, "\r\n" );
  115. } elseif ( $this->getOption( 'pass' ) === null ) {
  116. $this->error( 'You need to provide the option "pass" or "passfile"', true );
  117. }
  118. $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
  119. $status = $installer->doEnvironmentChecks();
  120. if ( $status->isGood() ) {
  121. $installer->showMessage( 'config-env-good' );
  122. } else {
  123. $installer->showStatusMessage( $status );
  124. return;
  125. }
  126. if ( !$this->hasOption( 'env-checks' ) ) {
  127. $installer->execute();
  128. $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
  129. }
  130. }
  131. function validateParamsAndArgs() {
  132. if ( !$this->hasOption( 'env-checks' ) ) {
  133. parent::validateParamsAndArgs();
  134. }
  135. }
  136. }
  137. $maintClass = 'CommandLineInstaller';
  138. require_once RUN_MAINTENANCE_IF_MAIN;