00001 <?php 00002 00003 die("obsolete; remove this file befor 1.3.0 release\n"); 00004 00005 # Install software and create new empty database. 00006 # 00007 00008 include( "./install-utils.inc" ); 00009 install_version_checks(); 00010 00011 if ( ! ( is_readable( "./LocalSettings.php" ) 00012 && is_readable( "./AdminSettings.php" ) ) ) { 00013 print "You must first create the files LocalSettings.php\n" . 00014 "and AdminSettings.php based on the samples in the top\n" . 00015 "source directory before running this install script.\n"; 00016 exit(); 00017 } 00018 00019 $DP = "./includes"; 00020 require_once( "./LocalSettings.php" ); 00021 require_once( "./AdminSettings.php" ); 00022 require_once( "./maintenance/InitialiseMessages.inc" ); 00023 00024 if( $wgSitename == "MediaWiki" ) { 00025 die( "You must set the site name in \$wgSitename before installation.\n\n" ); 00026 } 00027 00028 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) { 00029 print "To use math functions, you must first compile texvc by\n" . 00030 "running \"make\" in the math directory.\n"; 00031 exit(); 00032 } 00033 if ( is_file( "{$IP}/Version.php" ) ) { 00034 print "There appears to be an installation of the software\n" . 00035 "already present on \"{$IP}\". You may want to run the update\n" . 00036 "script instead. If you continue with this installation script,\n" . 00037 "that software and all of its data will be overwritten.\n" . 00038 "Are you sure you want to do this? (yes/no) "; 00039 00040 $response = readconsole(); 00041 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); } 00042 } 00043 00044 # 00045 # Make the necessary directories 00046 # 00047 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory ); 00048 foreach ( $dirs as $d ) { makedirectory( $d ); } 00049 00050 # 00051 # Copy files into installation directories 00052 # 00053 print "Copying files...\n"; 00054 00055 copyfile( ".", "LocalSettings.php", $IP ); 00056 copyfile( ".", "Version.php", $IP ); 00057 copyfile( ".", "index.php", $IP ); 00058 copyfile( ".", "redirect.php", $IP ); 00059 00060 # compatibility with older versions, can be removed in a year or so 00061 # (written in Feb 2004) 00062 copyfile( ".", "wiki.phtml", $IP ); 00063 copyfile( ".", "redirect.phtml", $IP ); 00064 00065 copydirectory( "./includes", $IP ); 00066 copydirectory( "./stylesheets", $wgStyleSheetDirectory ); 00067 00068 copyfile( "./images", "wiki.png", $wgUploadDirectory ); 00069 copyfile( "./images", "button_bold.png", $wgUploadDirectory ); 00070 copyfile( "./images", "button_extlink.png", $wgUploadDirectory ); 00071 copyfile( "./images", "button_headline.png", $wgUploadDirectory ); 00072 copyfile( "./images", "button_hr.png", $wgUploadDirectory ); 00073 copyfile( "./images", "button_image.png", $wgUploadDirectory ); 00074 copyfile( "./images", "button_italic.png", $wgUploadDirectory ); 00075 copyfile( "./images", "button_link.png", $wgUploadDirectory ); 00076 copyfile( "./images", "button_math.png", $wgUploadDirectory ); 00077 copyfile( "./images", "button_media.png", $wgUploadDirectory ); 00078 copyfile( "./images", "button_nowiki.png", $wgUploadDirectory ); 00079 copyfile( "./images", "button_sig.png", $wgUploadDirectory ); 00080 copyfile( "./images", "button_template.png", $wgUploadDirectory ); 00081 copyfile( "./images", "magnify-clip.png", $wgUploadDirectory ); 00082 copyfile( "./images", "Arr_.png", $wgUploadDirectory ); 00083 copyfile( "./images", "Arr_r.png", $wgUploadDirectory ); 00084 copyfile( "./images", "Arr_d.png", $wgUploadDirectory ); 00085 copyfile( "./images", "Arr_l.png", $wgUploadDirectory ); 00086 00087 copyfile( "./languages", "Language.php", $IP ); 00088 copyfile( "./languages", "LanguageUtf8.php", $IP ); 00089 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP ); 00090 00091 if ( $wgDebugLogFile ) { 00092 $fp = fopen( $wgDebugLogFile, "w" ); 00093 if ( false === $fp ) { 00094 print "Could not create log file \"{$wgDebugLogFile}\".\n"; 00095 exit(); 00096 } 00097 $d = date( "Y-m-d H:i:s" ); 00098 fwrite( $fp, "Wiki debug log file created {$d}\n\n" ); 00099 fclose( $fp ); 00100 } 00101 00102 if ( $wgUseTeX ) { 00103 makedirectory( "{$IP}/math" ); 00104 makedirectory( $wgMathDirectory ); 00105 copyfile( "./math", "texvc", "{$IP}/math", 0775 ); 00106 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 ); 00107 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 ); 00108 } 00109 00110 copyfile( ".", "Version.php", $IP ); 00111 00112 # 00113 # Make and initialize database 00114 # 00115 print "\n* * *\nWarning! This script will completely erase any\n" . 00116 "existing database \"{$wgDBname}\" and all its contents.\n" . 00117 "Are you sure you want to do this? (yes/no) "; 00118 00119 $response = readconsole(); 00120 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); } 00121 00122 print "Please enter your root password for the database server now.\n"; 00123 print "It is used to do the following:\n"; 00124 print "1) Create the database\n"; 00125 print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n"; 00126 print "You do not need to create any user accounts yourself!\n\n"; 00127 print "MySQL root password (typing will be visible): "; 00128 $rootpw=readconsole(); 00129 00130 # Include rest of code to get things like internationalized messages. 00131 # 00132 $wgUseDatabaseMessages = false; # no DB yet 00133 00134 require_once( "{$IP}/Setup.php" ); 00135 $wgTitle = Title::newFromText( "Installation script" ); 00136 00137 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 ); 00138 if ( !$wgDatabase->isOpen() ) { 00139 print "Could not connect to database on \"{$wgDBserver}\" as root.\n"; 00140 exit(); 00141 } 00142 00143 # Now do the actual database creation 00144 # 00145 print "Creating database...\n"; 00146 dbsource( "./maintenance/database.sql", $wgDatabase ); 00147 00148 $wgDatabase->selectDB( $wgDBname ); 00149 dbsource( "./maintenance/tables.sql", $wgDatabase ); 00150 dbsource( "./maintenance/users.sql", $wgDatabase ); 00151 dbsource( "./maintenance/initialdata.sql", $wgDatabase ); 00152 dbsource( "./maintenance/interwiki.sql", $wgDatabase ); 00153 00154 populatedata(); # Needs internationalized messages 00155 00156 print "Adding indexes...\n"; 00157 dbsource( "./maintenance/indexes.sql", $wgDatabase ); 00158 00159 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n"; 00160 exit(); 00161 00162 # 00163 # Functions used above: 00164 # 00165 function makedirectory( $d ) { 00166 global $wgInstallOwner, $wgInstallGroup; 00167 00168 if ( is_dir( $d ) ) { 00169 print "Directory \"{$d}\" exists.\n"; 00170 } else { 00171 if ( mkdir( $d, 0777 ) ) { 00172 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); } 00173 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); } 00174 print "Directory \"{$d}\" created.\n"; 00175 } else { 00176 print "Could not create directory \"{$d}\".\n"; 00177 exit(); 00178 } 00179 } 00180 } 00181 00182 00183 function populatedata() { 00184 global $wgDBadminpassword, $wgDatabase; 00185 $fname = "Installation script: populatedata()"; 00186 00187 $sql = "DELETE FROM site_stats"; 00188 $wgDatabase->query( $sql, $fname ); 00189 00190 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," . 00191 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)"; 00192 $wgDatabase->query( $sql, $fname ); 00193 00194 $sql = "DELETE FROM user"; 00195 $wgDatabase->query( $sql, $fname ); 00196 00197 print "Do you want to create a sysop account? A sysop can protect,\n"; 00198 print "delete and undelete pages and ban users. Recomended. [Y/n] "; 00199 $response = readconsole(); 00200 if(strtolower($response)!="n") { 00201 print "Enter the username [Sysop]: "; 00202 $sysop_user=readconsole(); 00203 if(!$sysop_user) { $sysop_user="Sysop"; } 00204 while(!$sysop_password) { 00205 print "Enter the password: "; 00206 $sysop_password=readconsole(); 00207 } 00208 $u = User::newFromName( $sysop_user ); 00209 if ( 0 == $u->idForName() ) { 00210 $u->addToDatabase(); 00211 $u->setPassword( $sysop_password ); 00212 $u->addRight( "sysop" ); 00213 $u->saveSettings(); 00214 } else { 00215 print "Could not create user - already exists!\n"; 00216 } 00217 } 00218 print "Do you want to create a sysop+developer account? A developer\n"; 00219 print "can switch the database to read-only mode and run any type of\n"; 00220 print "query through a web interface. [Y/n] "; 00221 $response=readconsole(); 00222 if(strtolower($response)!="n") { 00223 print "Enter the username [Developer]: "; 00224 $developer_user=readconsole(); 00225 if(!$developer_user) { $developer_user="Developer"; } 00226 while (!$developer_password) { 00227 print "Enter the password: "; 00228 $developer_password=readconsole(); 00229 } 00230 $u = User::newFromName( $developer_user ); 00231 if ( 0 == $u->idForName() ) { 00232 $u->addToDatabase(); 00233 $u->setPassword( $developer_password ); 00234 $u->addRight( "sysop" ); 00235 $u->addRight( "developer" ); 00236 $u->saveSettings(); 00237 } else { 00238 print "Could not create user - already exists!\n"; 00239 } 00240 } 00241 00242 $wns = Namespace::getWikipedia(); 00243 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) ); 00244 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) ); 00245 00246 $sql = "DELETE FROM cur"; 00247 $wgDatabase->query( $sql, $fname ); 00248 00249 $now = wfTimestampNow(); 00250 $won = wfInvertTimestamp( $now ); 00251 00252 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," . 00253 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" . 00254 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')"; 00255 $wgDatabase->query( $sql, $fname ); 00256 00257 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," . 00258 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" . 00259 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')"; 00260 $wgDatabase->query( $sql, $fname ); 00261 00262 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) ); 00263 $title = $titleobj->getDBkey(); 00264 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " . 00265 "VALUES (0,'$title','" . 00266 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')"; 00267 $wgDatabase->query( $sql, $fname ); 00268 00269 initialiseMessages(); 00270 } 00271 00272 ?>