MediaWiki
REL1_24
|
00001 <?php 00024 // Checking for old versions of PHP is done in Maintenance.php 00025 // We need to use dirname( __FILE__ ) here cause __DIR__ is PHP5.3+ 00026 require_once dirname( __FILE__ ) . '/Maintenance.php'; 00027 00028 define( 'MW_CONFIG_CALLBACK', 'Installer::overrideConfig' ); 00029 define( 'MEDIAWIKI_INSTALL', true ); 00030 00040 class CommandLineInstaller extends Maintenance { 00041 function __construct() { 00042 parent::__construct(); 00043 global $IP; 00044 00045 $this->addDescription( "CLI-based MediaWiki installation and configuration.\n" . 00046 "Defaut options are indicated in parenthesis." ); 00047 00048 $this->addArg( 'name', 'The name of the wiki (MediaWiki)', false ); 00049 00050 $this->addArg( 'admin', 'The username of the wiki administrator.' ); 00051 $this->addOption( 'pass', 'The password for the wiki administrator.', false, true ); 00052 $this->addOption( 00053 'passfile', 00054 'An alternative way to provide pass option, as the contents of this file', 00055 false, 00056 true 00057 ); 00058 /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */ 00059 $this->addOption( 00060 'scriptpath', 00061 'The relative path of the wiki in the web server (/wiki)', 00062 false, 00063 true 00064 ); 00065 00066 $this->addOption( 'lang', 'The language to use (en)', false, true ); 00067 /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */ 00068 00069 $this->addOption( 'dbtype', 'The type of database (mysql)', false, true ); 00070 $this->addOption( 'dbserver', 'The database host (localhost)', false, true ); 00071 $this->addOption( 'dbport', 'The database port; only for PostgreSQL (5432)', false, true ); 00072 $this->addOption( 'dbname', 'The database name (my_wiki)', false, true ); 00073 $this->addOption( 'dbpath', 'The path for the SQLite DB ($IP/data)', false, true ); 00074 $this->addOption( 'dbprefix', 'Optional database table name prefix', false, true ); 00075 $this->addOption( 'installdbuser', 'The user to use for installing (root)', false, true ); 00076 $this->addOption( 'installdbpass', 'The password for the DB user to install as.', false, true ); 00077 $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true ); 00078 $this->addOption( 'dbpass', 'The password for the DB user for normal operations', false, true ); 00079 $this->addOption( 00080 'dbpassfile', 00081 'An alternative way to provide dbpass option, as the contents of this file', 00082 false, 00083 true 00084 ); 00085 $this->addOption( 'confpath', "Path to write LocalSettings.php to ($IP)", false, true ); 00086 $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in ' 00087 . 'PostgreSQL/Microsoft SQL Server (mediawiki)', false, true ); 00088 /* 00089 $this->addOption( 'namespace', 'The project namespace (same as the "name" argument)', 00090 false, true ); 00091 */ 00092 $this->addOption( 'env-checks', "Run environment checks only, don't change anything" ); 00093 } 00094 00095 function execute() { 00096 global $IP; 00097 00098 $siteName = $this->getArg( 0, 'MediaWiki' ); // Will not be set if used with --env-checks 00099 $adminName = $this->getArg( 1 ); 00100 00101 $dbpassfile = $this->getOption( 'dbpassfile' ); 00102 if ( $dbpassfile !== null ) { 00103 if ( $this->getOption( 'dbpass' ) !== null ) { 00104 $this->error( 'WARNING: You have provided the options "dbpass" and "dbpassfile". ' 00105 . 'The content of "dbpassfile" overrides "dbpass".' ); 00106 } 00107 wfSuppressWarnings(); 00108 $dbpass = file_get_contents( $dbpassfile ); // returns false on failure 00109 wfRestoreWarnings(); 00110 if ( $dbpass === false ) { 00111 $this->error( "Couldn't open $dbpassfile", true ); 00112 } 00113 $this->mOptions['dbpass'] = trim( $dbpass, "\r\n" ); 00114 } 00115 00116 $passfile = $this->getOption( 'passfile' ); 00117 if ( $passfile !== null ) { 00118 if ( $this->getOption( 'pass' ) !== null ) { 00119 $this->error( 'WARNING: You have provided the options "pass" and "passfile". ' 00120 . 'The content of "passfile" overrides "pass".' ); 00121 } 00122 wfSuppressWarnings(); 00123 $pass = file_get_contents( $passfile ); // returns false on failure 00124 wfRestoreWarnings(); 00125 if ( $pass === false ) { 00126 $this->error( "Couldn't open $passfile", true ); 00127 } 00128 $this->mOptions['pass'] = trim( $pass, "\r\n" ); 00129 } elseif ( $this->getOption( 'pass' ) === null ) { 00130 $this->error( 'You need to provide the option "pass" or "passfile"', true ); 00131 } 00132 00133 $installer = InstallerOverrides::getCliInstaller( $siteName, $adminName, $this->mOptions ); 00134 00135 $status = $installer->doEnvironmentChecks(); 00136 if ( $status->isGood() ) { 00137 $installer->showMessage( 'config-env-good' ); 00138 } else { 00139 $installer->showStatusMessage( $status ); 00140 00141 return; 00142 } 00143 if ( !$this->hasOption( 'env-checks' ) ) { 00144 $installer->execute(); 00145 $installer->writeConfigurationFile( $this->getOption( 'confpath', $IP ) ); 00146 } 00147 } 00148 00149 function validateParamsAndArgs() { 00150 if ( !$this->hasOption( 'env-checks' ) ) { 00151 parent::validateParamsAndArgs(); 00152 } 00153 } 00154 } 00155 00156 $maintClass = 'CommandLineInstaller'; 00157 00158 require_once RUN_MAINTENANCE_IF_MAIN;