MediaWiki  REL1_21
install.php
Go to the documentation of this file.
00001 <?php
00024 if ( !function_exists( 'version_compare' ) || ( version_compare( phpversion(), '5.3.2' ) < 0 ) ) {
00025         require_once( dirname( __FILE__ ) . '/../includes/PHPVersionError.php' );
00026         wfPHPVersionError( 'cli' );
00027 }
00028 
00029 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' );
00030 define( 'MEDIAWIKI_INSTALL', true );
00031 
00032 require_once( dirname( __DIR__ )."/maintenance/Maintenance.php" );
00033 
00039 class CommandLineInstaller extends Maintenance {
00040         function __construct() {
00041                 parent::__construct();
00042                 global $IP;
00043 
00044                 $this->addArg( 'name', 'The name of the wiki', true);
00045 
00046                 $this->addArg( 'admin', 'The username of the wiki administrator (WikiSysop)', true );
00047                 $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
00048                 $this->addOption( 'passfile', 'An alternative way to provide pass option, as the contents of this file', false, true );
00049                 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
00050                 $this->addOption( 'scriptpath', 'The relative path of the wiki in the web server (/wiki)', false, true );
00051 
00052                 $this->addOption( 'lang', 'The language to use (en)', false, true );
00053                 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
00054 
00055                 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true );
00056                 $this->addOption( 'dbserver', 'The database host (localhost)', false, true );
00057                 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true );
00058                 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true );
00059                 $this->addOption( 'dbpath', 'The path for the SQLite DB (/var/data)', false, true );
00060                 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true );
00061                 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true );
00062                 $this->addOption( 'installdbpass', 'The pasword for the DB user to install as.', false, true );
00063                 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
00064                 $this->addOption( 'dbpass', 'The pasword for the DB user for normal operations', false, true );
00065                 $this->addOption( 'dbpassfile', 'An alternative way to provide dbpass option, as the contents of this file', false, true );
00066                 $this->addOption( 'confpath', "Path to write LocalSettings.php to, default $IP", false, true );
00067                 /* $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in pg (mediawiki)', false, true ); */
00068                 /* $this->addOption( 'namespace', 'The project namespace (same as the name)', false, true ); */
00069                 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
00070         }
00071 
00072         function execute() {
00073                 global $IP, $wgTitle;
00074                 $siteName = isset( $this->mArgs[0] ) ? $this->mArgs[0] : "Don't care"; // Will not be set if used with --env-checks
00075                 $adminName = isset( $this->mArgs[1] ) ? $this->mArgs[1] : null;
00076                 $wgTitle = Title::newFromText( 'Installer script' );
00077 
00078                 $dbpassfile = $this->getOption( 'dbpassfile', false );
00079                 if ( $dbpassfile !== false ) {
00080                         if ( $this->getOption( 'dbpass', false ) !== false ) {
00081                                 $this->error( 'WARNING: You provide the options "dbpass" and "dbpassfile". The content of "dbpassfile" overwrites "dbpass".' );
00082                         }
00083                         wfSuppressWarnings();
00084                         $dbpass = file_get_contents( $dbpassfile );
00085                         wfRestoreWarnings();
00086                         if ( $dbpass === false ) {
00087                                 $this->error( "Couldn't open $dbpassfile", true );
00088                         }
00089                         $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" );
00090                 }
00091 
00092                 $passfile = $this->getOption( 'passfile', false );
00093                 if ( $passfile !== false ) {
00094                         if ( $this->getOption( 'pass', false ) !== false ) {
00095                                 $this->error( 'WARNING: You provide the options "pass" and "passfile". The content of "passfile" overwrites "pass".' );
00096                         }
00097                         wfSuppressWarnings();
00098                         $pass = file_get_contents( $passfile );
00099                         wfRestoreWarnings();
00100                         if ( $pass === false ) {
00101                                 $this->error( "Couldn't open $passfile", true );
00102                         }
00103                         $this->mOptions['pass'] = str_replace( array( "\n", "\r" ), "", $pass );
00104                 } elseif ( $this->getOption( 'pass', false ) === false ) {
00105                         $this->error( 'You need to provide the option "pass" or "passfile"', true );
00106                 }
00107 
00108                 $installer =
00109                         InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions );
00110 
00111                 $status = $installer->doEnvironmentChecks();
00112                 if( $status->isGood() ) {
00113                         $installer->showMessage( 'config-env-good' );
00114                 } else {
00115                         $installer->showStatusMessage( $status );
00116                         return;
00117                 }
00118                 if( !$this->hasOption( 'env-checks' ) ) {
00119                         $installer->execute();
00120                         $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) );
00121                 }
00122         }
00123 
00124         function validateParamsAndArgs() {
00125                 if ( !$this->hasOption( 'env-checks' ) ) {
00126                         parent::validateParamsAndArgs();
00127                 }
00128         }
00129 }
00130 
00131 $maintClass = "CommandLineInstaller";
00132 
00133 require_once( RUN_MAINTENANCE_IF_MAIN );