Make sure output buffering is off for install scripts
[lhc/web/wiklou.git] / install.php
1 <?php
2
3 # Install software and create new empty database.
4 #
5
6 include( "./install-utils.inc" );
7 install_version_checks();
8
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();
15 }
16
17 $DP = "./includes";
18 include_once( "./LocalSettings.php" );
19 include_once( "./AdminSettings.php" );
20 include_once( "./maintenance/InitialiseMessages.inc" );
21
22 if( $wgSitename == "MediaWiki" ) {
23 die( "You must set the site name in \$wgSitename before installation.\n\n" );
24 }
25
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();
30 }
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) ";
37
38 $response = readconsole();
39 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
40 }
41
42 #
43 # Make the necessary directories
44 #
45 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
46 foreach ( $dirs as $d ) { makedirectory( $d ); }
47
48 #
49 # Copy files into installation directories
50 #
51 print "Copying files...\n";
52
53 copyfile( ".", "LocalSettings.php", $IP );
54 copyfile( ".", "Version.php", $IP );
55 copyfile( ".", "index.php", $IP );
56 copyfile( ".", "redirect.php", $IP );
57
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 );
62
63 copydirectory( "./includes", $IP );
64 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
65
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 );
80 copyfile( "./images", "Arr_.png", $wgUploadDirectory );
81 copyfile( "./images", "Arr_r.png", $wgUploadDirectory );
82 copyfile( "./images", "Arr_d.png", $wgUploadDirectory );
83
84 copyfile( "./languages", "Language.php", $IP );
85 copyfile( "./languages", "LanguageUtf8.php", $IP );
86 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
87
88 if ( $wgDebugLogFile ) {
89 $fp = fopen( $wgDebugLogFile, "w" );
90 if ( false === $fp ) {
91 print "Could not create log file \"{$wgDebugLogFile}\".\n";
92 exit();
93 }
94 $d = date( "Y-m-d H:i:s" );
95 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
96 fclose( $fp );
97 }
98
99 if ( $wgUseTeX ) {
100 makedirectory( "{$IP}/math" );
101 makedirectory( $wgMathDirectory );
102 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
103 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
104 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
105 }
106
107 copyfile( ".", "Version.php", $IP );
108
109 #
110 # Make and initialize database
111 #
112 print "\n* * *\nWarning! This script will completely erase any\n" .
113 "existing database \"{$wgDBname}\" and all its contents.\n" .
114 "Are you sure you want to do this? (yes/no) ";
115
116 $response = readconsole();
117 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
118
119 print "Please enter your root password for the database server now.\n";
120 print "It is used to do the following:\n";
121 print "1) Create the database\n";
122 print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
123 print "You do not need to create any user accounts yourself!\n\n";
124 print "MySQL root password (typing will be visible): ";
125 $rootpw=readconsole();
126
127 # Include rest of code to get things like internationalized messages.
128 #
129 $wgUseDatabaseMessages = false; # no DB yet
130
131 include_once( "{$IP}/Setup.php" );
132 $wgTitle = Title::newFromText( "Installation script" );
133
134 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
135 if ( !$wgDatabase->isOpen() ) {
136 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
137 exit();
138 }
139
140 # Now do the actual database creation
141 #
142 print "Creating database...\n";
143 dbsource( "./maintenance/database.sql", $wgDatabase );
144
145 $wgDatabase->selectDB( $wgDBname );
146 dbsource( "./maintenance/tables.sql", $wgDatabase );
147 dbsource( "./maintenance/users.sql", $wgDatabase );
148 dbsource( "./maintenance/initialdata.sql", $wgDatabase );
149 dbsource( "./maintenance/interwiki.sql", $wgDatabase );
150
151 populatedata(); # Needs internationalized messages
152
153 print "Adding indexes...\n";
154 dbsource( "./maintenance/indexes.sql", $wgDatabase );
155
156 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
157 exit();
158
159 #
160 # Functions used above:
161 #
162 function makedirectory( $d ) {
163 global $wgInstallOwner, $wgInstallGroup;
164
165 if ( is_dir( $d ) ) {
166 print "Directory \"{$d}\" exists.\n";
167 } else {
168 if ( mkdir( $d, 0777 ) ) {
169 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
170 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
171 print "Directory \"{$d}\" created.\n";
172 } else {
173 print "Could not create directory \"{$d}\".\n";
174 exit();
175 }
176 }
177 }
178
179
180 function populatedata() {
181 global $wgDBadminpassword, $wgDatabase;
182 $fname = "Installation script: populatedata()";
183
184 $sql = "DELETE FROM site_stats";
185 $wgDatabase->query( $sql, $fname );
186
187 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
188 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
189 $wgDatabase->query( $sql, $fname );
190
191 $sql = "DELETE FROM user";
192 $wgDatabase->query( $sql, $fname );
193
194 print "Do you want to create a sysop account? A sysop can protect,\n";
195 print "delete and undelete pages and ban users. Recomended. [Y/n] ";
196 $response = readconsole();
197 if(strtolower($response)!="n") {
198 print "Enter the username [Sysop]: ";
199 $sysop_user=readconsole();
200 if(!$sysop_user) { $sysop_user="Sysop"; }
201 while(!$sysop_password) {
202 print "Enter the password: ";
203 $sysop_password=readconsole();
204 }
205 $u = User::newFromName( $sysop_user );
206 if ( 0 == $u->idForName() ) {
207 $u->addToDatabase();
208 $u->setPassword( $sysop_password );
209 $u->addRight( "sysop" );
210 $u->saveSettings();
211 } else {
212 print "Could not create user - already exists!\n";
213 }
214 }
215 print "Do you want to create a sysop+developer account? A developer\n";
216 print "can switch the database to read-only mode and run any type of\n";
217 print "query through a web interface. [Y/n] ";
218 $response=readconsole();
219 if(strtolower($response)!="n") {
220 print "Enter the username [Developer]: ";
221 $developer_user=readconsole();
222 if(!$developer_user) { $developer_user="Developer"; }
223 while (!$developer_password) {
224 print "Enter the password: ";
225 $developer_password=readconsole();
226 }
227 $u = User::newFromName( $developer_user );
228 if ( 0 == $u->idForName() ) {
229 $u->addToDatabase();
230 $u->setPassword( $developer_password );
231 $u->addRight( "sysop" );
232 $u->addRight( "developer" );
233 $u->saveSettings();
234 } else {
235 print "Could not create user - already exists!\n";
236 }
237 }
238
239 $wns = Namespace::getWikipedia();
240 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
241 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
242
243 $sql = "DELETE FROM cur";
244 $wgDatabase->query( $sql, $fname );
245
246 $now = wfTimestampNow();
247 $won = wfInvertTimestamp( $now );
248
249 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
250 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
251 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
252 $wgDatabase->query( $sql, $fname );
253
254 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
255 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
256 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
257 $wgDatabase->query( $sql, $fname );
258
259 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
260 $title = $titleobj->getDBkey();
261 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
262 "VALUES (0,'$title','" .
263 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
264 $wgDatabase->query( $sql, $fname );
265
266 initialiseMessages();
267 }
268
269 ?>