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