[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/maintenance/ -> install.php (source)

   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  
  24  // Checking for old versions of PHP is done in Maintenance.php
  25  // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+
  26  require_once dirname( __FILE__ ) . '/Maintenance.php';
  27  
  28  define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
  29  define( 'MEDIAWIKI_INSTALL', true );
  30  
  31  /**
  32   * Maintenance script to install and configure MediaWiki
  33   *
  34   * Default values for the options are defined in DefaultSettings.php
  35   * (see the mapping in CliInstaller.php)
  36   * Default for --dbpath (SQLite-specific) is defined in SqliteInstaller::getGlobalDefaults
  37   *
  38   * @ingroup Maintenance
  39   */
  40  class CommandLineInstaller extends Maintenance {
  41  	function __construct() {
  42          parent::__construct();
  43          global $IP;
  44  
  45          $this->addDescription( "CLI-based MediaWiki installation and configuration.\n" .
  46              "Defaut options are indicated in parenthesis." );
  47  
  48          $this->addArg( 'name', 'The name of the wiki (MediaWiki)', false );
  49  
  50          $this->addArg( 'admin', 'The username of the wiki administrator.' );
  51          $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
  52          $this->addOption(
  53              'passfile',
  54              'An alternative way to provide pass option, as the contents of this file',
  55              false,
  56              true
  57          );
  58          /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
  59          $this->addOption(
  60              'scriptpath',
  61              'The relative path of the wiki in the web server (/wiki)',
  62              false,
  63              true
  64          );
  65  
  66          $this->addOption( 'lang', 'The language to use (en)', false, true );
  67          /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
  68  
  69          $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
  70          $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
  71          $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
  72          $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
  73          $this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true );
  74          $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
  75          $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
  76          $this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true );
  77          $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
  78          $this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true );
  79          $this->addOption(
  80              'dbpassfile',
  81              'An alternative way to provide dbpass option, as the contents of this file',
  82              false,
  83              true
  84          );
  85          $this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true );
  86          $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in '
  87              . 'PostgreSQL/Microsoft SQL Server (mediawiki)', false, true );
  88          /*
  89          $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)',
  90              false, true );
  91          */
  92          $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
  93      }
  94  
  95  	function execute() {
  96          global $IP;
  97  
  98          $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks
  99          $adminName = $this->getArg( 1 );
 100  
 101          $dbpassfile = $this->getOption( 'dbpassfile' );
 102          if ( $dbpassfile !== null ) {
 103              if ( $this->getOption( 'dbpass' ) !== null ) {
 104                  $this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". '
 105                      . 'The content of "dbpassfile" overrides "dbpass".' );
 106              }
 107              wfSuppressWarnings();
 108              $dbpass = file_get_contents( $dbpassfile ); // returns false on failure
 109              wfRestoreWarnings();
 110              if ( $dbpass === false ) {
 111                  $this->error( "Couldn't open $dbpassfile", true );
 112              }
 113              $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
 114          }
 115  
 116          $passfile = $this->getOption( 'passfile' );
 117          if ( $passfile !== null ) {
 118              if ( $this->getOption( 'pass' ) !== null ) {
 119                  $this->error( 'WARNING: You have provided the options "pass" and "passfile". '
 120                      . 'The content of "passfile" overrides "pass".' );
 121              }
 122              wfSuppressWarnings();
 123              $pass = file_get_contents( $passfile ); // returns false on failure
 124              wfRestoreWarnings();
 125              if ( $pass === false ) {
 126                  $this->error( "Couldn't open $passfile", true );
 127              }
 128              $this->mOptions['pass'] = trim( $pass, "\r\n" );
 129          } elseif ( $this->getOption( 'pass' ) === null ) {
 130              $this->error( 'You need to provide the option "pass" or "passfile"', true );
 131          }
 132  
 133          $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
 134  
 135          $status = $installer->doEnvironmentChecks();
 136          if ( $status->isGood() ) {
 137              $installer->showMessage( 'config-env-good' );
 138          } else {
 139              $installer->showStatusMessage( $status );
 140  
 141              return;
 142          }
 143          if ( !$this->hasOption( 'env-checks' ) ) {
 144              $installer->execute();
 145              $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
 146          }
 147      }
 148  
 149  	function validateParamsAndArgs() {
 150          if ( !$this->hasOption( 'env-checks' ) ) {
 151              parent::validateParamsAndArgs();
 152          }
 153      }
 154  }
 155  
 156  $maintClass = 'CommandLineInstaller';
 157  
 158  require_once RUN_MAINTENANCE_IF_MAIN;


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1