In case of mysterious write failure, spit out the config file for manual paste. Haven...
[mediawiki.git] / install.php
blobb84252cf1d6696312bdda52e53ed611b17da4307
1 <?php
3 # Install software and create new empty database.
6 include( "./install-utils.inc" );
7 install_version_checks();
9 if ( ! ( is_readable( "./LocalSettings.php" )
10 && is_readable( "./AdminSettings.php" ) ) ) {
11 print "You must first create the files LocalSettings.php\n" .
12 "and AdminSettings.php based on the samples in the top\n" .
13 "source directory before running this install script.\n";
14 exit();
17 $DP = "./includes";
18 include_once( "./LocalSettings.php" );
19 include_once( "./AdminSettings.php" );
20 include_once( "./maintenance/InitialiseMessages.inc" );
22 if( $wgSitename == "MediaWiki" ) {
23 die( "You must set the site name in \$wgSitename before installation.\n\n" );
26 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
27 print "To use math functions, you must first compile texvc by\n" .
28 "running \"make\" in the math directory.\n";
29 exit();
31 if ( is_file( "{$IP}/Version.php" ) ) {
32 print "There appears to be an installation of the software\n" .
33 "already present on \"{$IP}\". You may want to run the update\n" .
34 "script instead. If you continue with this installation script,\n" .
35 "that software and all of its data will be overwritten.\n" .
36 "Are you sure you want to do this? (yes/no) ";
38 $response = readconsole();
39 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
43 # Make the necessary directories
45 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
46 foreach ( $dirs as $d ) { makedirectory( $d ); }
49 # Copy files into installation directories
51 print "Copying files...\n";
53 copyfile( ".", "LocalSettings.php", $IP );
54 copyfile( ".", "Version.php", $IP );
55 copyfile( ".", "index.php", $IP );
56 copyfile( ".", "redirect.php", $IP );
58 # compatibility with older versions, can be removed in a year or so
59 # (written in Feb 2004)
60 copyfile( ".", "wiki.phtml", $IP );
61 copyfile( ".", "redirect.phtml", $IP );
63 copydirectory( "./includes", $IP );
64 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
66 copyfile( "./images", "wiki.png", $wgUploadDirectory );
67 copyfile( "./images", "button_bold.png", $wgUploadDirectory );
68 copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
69 copyfile( "./images", "button_headline.png", $wgUploadDirectory );
70 copyfile( "./images", "button_hr.png", $wgUploadDirectory );
71 copyfile( "./images", "button_image.png", $wgUploadDirectory );
72 copyfile( "./images", "button_italic.png", $wgUploadDirectory );
73 copyfile( "./images", "button_link.png", $wgUploadDirectory );
74 copyfile( "./images", "button_math.png", $wgUploadDirectory );
75 copyfile( "./images", "button_media.png", $wgUploadDirectory );
76 copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
77 copyfile( "./images", "button_sig.png", $wgUploadDirectory );
78 copyfile( "./images", "button_template.png", $wgUploadDirectory );
79 copyfile( "./images", "magnify-clip.png", $wgUploadDirectory );
81 copyfile( "./languages", "Language.php", $IP );
82 copyfile( "./languages", "LanguageUtf8.php", $IP );
83 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
85 if ( $wgDebugLogFile ) {
86 $fp = fopen( $wgDebugLogFile, "w" );
87 if ( false === $fp ) {
88 print "Could not create log file \"{$wgDebugLogFile}\".\n";
89 exit();
91 $d = date( "Y-m-d H:i:s" );
92 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
93 fclose( $fp );
96 if ( $wgUseTeX ) {
97 makedirectory( "{$IP}/math" );
98 makedirectory( $wgMathDirectory );
99 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
100 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
101 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
104 copyfile( ".", "Version.php", $IP );
107 # Make and initialize database
109 print "\n* * *\nWarning! This script will completely erase any\n" .
110 "existing database \"{$wgDBname}\" and all its contents.\n" .
111 "Are you sure you want to do this? (yes/no) ";
113 $response = readconsole();
114 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
116 print "Please enter your root password for the database server now.\n";
117 print "It is used to do the following:\n";
118 print "1) Create the database\n";
119 print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
120 print "You do not need to create any user accounts yourself!\n\n";
121 print "MySQL root password (typing will be visible): ";
122 $rootpw=readconsole();
124 # Include rest of code to get things like internationalized messages.
126 include_once( "{$IP}/Setup.php" );
127 $wgTitle = Title::newFromText( "Installation script" );
129 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
130 if ( !$wgDatabase->isOpen() ) {
131 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
132 exit();
135 # Now do the actual database creation
137 print "Creating database...\n";
138 dbsource( "./maintenance/database.sql", $wgDatabase );
140 $wgDatabase->selectDB( $wgDBname );
141 dbsource( "./maintenance/tables.sql", $wgDatabase );
142 dbsource( "./maintenance/users.sql", $wgDatabase );
143 dbsource( "./maintenance/initialdata.sql", $wgDatabase );
144 dbsource( "./maintenance/interwiki.sql", $wgDatabase );
146 populatedata(); # Needs internationalized messages
148 print "Adding indexes...\n";
149 dbsource( "./maintenance/indexes.sql", $wgDatabase );
151 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
152 exit();
155 # Functions used above:
157 function makedirectory( $d ) {
158 global $wgInstallOwner, $wgInstallGroup;
160 if ( is_dir( $d ) ) {
161 print "Directory \"{$d}\" exists.\n";
162 } else {
163 if ( mkdir( $d, 0777 ) ) {
164 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
165 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
166 print "Directory \"{$d}\" created.\n";
167 } else {
168 print "Could not create directory \"{$d}\".\n";
169 exit();
175 function populatedata() {
176 global $wgDBadminpassword, $wgDatabase;
177 $fname = "Installation script: populatedata()";
179 $sql = "DELETE FROM site_stats";
180 $wgDatabase->query( $sql, $fname );
182 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
183 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
184 $wgDatabase->query( $sql, $fname );
186 $sql = "DELETE FROM user";
187 $wgDatabase->query( $sql, $fname );
189 print "Do you want to create a sysop account? A sysop can protect,\n";
190 print "delete and undelete pages and ban users. Recomended. [Y/n] ";
191 $response = readconsole();
192 if(strtolower($response)!="n") {
193 print "Enter the username [Sysop]: ";
194 $sysop_user=readconsole();
195 if(!$sysop_user) { $sysop_user="Sysop"; }
196 while(!$sysop_password) {
197 print "Enter the password: ";
198 $sysop_password=readconsole();
200 $u = User::newFromName( $sysop_user );
201 if ( 0 == $u->idForName() ) {
202 $u->addToDatabase();
203 $u->setPassword( $sysop_password );
204 $u->addRight( "sysop" );
205 $u->saveSettings();
206 } else {
207 print "Could not create user - already exists!\n";
210 print "Do you want to create a sysop+developer account? A developer\n";
211 print "can switch the database to read-only mode and run any type of\n";
212 print "query through a web interface. [Y/n] ";
213 $response=readconsole();
214 if(strtolower($response)!="n") {
215 print "Enter the username [Developer]: ";
216 $developer_user=readconsole();
217 if(!$developer_user) { $developer_user="Developer"; }
218 while (!$developer_password) {
219 print "Enter the password: ";
220 $developer_password=readconsole();
222 $u = User::newFromName( $developer_user );
223 if ( 0 == $u->idForName() ) {
224 $u->addToDatabase();
225 $u->setPassword( $developer_password );
226 $u->addRight( "sysop" );
227 $u->addRight( "developer" );
228 $u->saveSettings();
229 } else {
230 print "Could not create user - already exists!\n";
234 $wns = Namespace::getWikipedia();
235 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
236 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
238 $sql = "DELETE FROM cur";
239 $wgDatabase->query( $sql, $fname );
241 $now = wfTimestampNow();
242 $won = wfInvertTimestamp( $now );
244 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
245 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
246 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
247 $wgDatabase->query( $sql, $fname );
249 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
250 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
251 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
252 $wgDatabase->query( $sql, $fname );
254 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
255 $title = $titleobj->getDBkey();
256 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
257 "VALUES (0,'$title','" .
258 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
259 $wgDatabase->query( $sql, $fname );
261 initialiseMessages();