MediaWiki
REL1_23
|
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; 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 00077 $dbpassfile = $this->getOption( 'dbpassfile', false ); 00078 if ( $dbpassfile !== false ) { 00079 if ( $this->getOption( 'dbpass', false ) !== false ) { 00080 $this->error( 'WARNING: You provide the options "dbpass" and "dbpassfile". The content of "dbpassfile" overwrites "dbpass".' ); 00081 } 00082 wfSuppressWarnings(); 00083 $dbpass = file_get_contents( $dbpassfile ); 00084 wfRestoreWarnings(); 00085 if ( $dbpass === false ) { 00086 $this->error( "Couldn't open $dbpassfile", true ); 00087 } 00088 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" ); 00089 } 00090 00091 $passfile = $this->getOption( 'passfile', false ); 00092 if ( $passfile !== false ) { 00093 if ( $this->getOption( 'pass', false ) !== false ) { 00094 $this->error( 'WARNING: You provide the options "pass" and "passfile". The content of "passfile" overwrites "pass".' ); 00095 } 00096 wfSuppressWarnings(); 00097 $pass = file_get_contents( $passfile ); 00098 wfRestoreWarnings(); 00099 if ( $pass === false ) { 00100 $this->error( "Couldn't open $passfile", true ); 00101 } 00102 $this->mOptions['pass'] = str_replace( array( "\n", "\r" ), "", $pass ); 00103 } elseif ( $this->getOption( 'pass', false ) === false ) { 00104 $this->error( 'You need to provide the option "pass" or "passfile"', true ); 00105 } 00106 00107 $installer = 00108 InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions ); 00109 00110 $status = $installer->doEnvironmentChecks(); 00111 if ( $status->isGood() ) { 00112 $installer->showMessage( 'config-env-good' ); 00113 } else { 00114 $installer->showStatusMessage( $status ); 00115 return; 00116 } 00117 if ( !$this->hasOption( 'env-checks' ) ) { 00118 $installer->execute(); 00119 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) ); 00120 } 00121 } 00122 00123 function validateParamsAndArgs() { 00124 if ( !$this->hasOption( 'env-checks' ) ) { 00125 parent::validateParamsAndArgs(); 00126 } 00127 } 00128 } 00129 00130 $maintClass = "CommandLineInstaller"; 00131 00132 require_once RUN_MAINTENANCE_IF_MAIN;