show infobox in all KHTML browsers
[lhc/web/wiklou.git] / install.php
1 <?
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 ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
23 print "To use math functions, you must first compile texvc by\n" .
24 "running \"make\" in the math directory.\n";
25 exit();
26 }
27 if ( is_file( "{$IP}/Version.php" ) ) {
28 print "There appears to be an installation of the software\n" .
29 "already present on \"{$IP}\". You may want to run the update\n" .
30 "script instead. If you continue with this installation script,\n" .
31 "that software and all of its data will be overwritten.\n" .
32 "Are you sure you want to do this? (yes/no) ";
33
34 $response = readconsole();
35 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
36 }
37
38 #
39 # Make the necessary directories
40 #
41 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
42 foreach ( $dirs as $d ) { makedirectory( $d ); }
43
44 #
45 # Copy files into installation directories
46 #
47 print "Copying files...\n";
48
49 copyfile( ".", "LocalSettings.php", $IP );
50 copyfile( ".", "Version.php", $IP );
51 copyfile( ".", "wiki.phtml", $IP );
52 copyfile( ".", "redirect.phtml", $IP );
53 copyfile( ".", "texvc.phtml", $IP );
54
55 copydirectory( "./includes", $IP );
56 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
57
58 copyfile( "./images", "wiki.png", $wgUploadDirectory );
59 copyfile( "./images", "button_bold.gif", $wgUploadDirectory );
60 copyfile( "./images", "button_extlink.gif", $wgUploadDirectory );
61 copyfile( "./images", "button_headline.gif", $wgUploadDirectory );
62 copyfile( "./images", "button_hr.gif", $wgUploadDirectory );
63 copyfile( "./images", "button_image.gif", $wgUploadDirectory );
64 copyfile( "./images", "button_italic.gif", $wgUploadDirectory );
65 copyfile( "./images", "button_link.gif", $wgUploadDirectory );
66 copyfile( "./images", "button_math.gif", $wgUploadDirectory );
67 copyfile( "./images", "button_media.gif", $wgUploadDirectory );
68 copyfile( "./images", "button_sig.gif", $wgUploadDirectory );
69 copyfile( "./images", "button_template.gif", $wgUploadDirectory );
70
71 copyfile( "./languages", "Language.php", $IP );
72 copyfile( "./languages", "LanguageUtf8.php", $IP );
73 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
74
75 if ( $wgDebugLogFile ) {
76 $fp = fopen( $wgDebugLogFile, "w" );
77 if ( false === $fp ) {
78 print "Could not create log file \"{$wgDebugLogFile}\".\n";
79 exit();
80 }
81 $d = date( "Y-m-d H:i:s" );
82 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
83 fclose( $fp );
84 }
85
86 if ( $wgUseTeX ) {
87 makedirectory( "{$IP}/math" );
88 makedirectory( $wgMathDirectory );
89 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
90 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
91 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
92 }
93
94 copyfile( ".", "Version.php", $IP );
95
96 #
97 # Make and initialize database
98 #
99 print "\n* * *\nWarning! This script will completely erase the\n" .
100 "existing database \"{$wgDBname}\" and all its contents.\n" .
101 "Are you sure you want to do this? (yes/no) ";
102
103 $response = readconsole();
104 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
105
106 print "\nYou should have already created a root password for the database.\n" .
107 "Enter the root password here: ";
108
109 $rootpw = readconsole();
110
111 # Include rest of code to get things like internationalized messages.
112 #
113 include_once( "{$IP}/Setup.php" );
114 $wgTitle = Title::newFromText( "Installation script" );
115
116 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
117 if ( !$wgDatabase->isOpen() ) {
118 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
119 exit();
120 }
121
122 # Now do the actual database creation
123 #
124 print "Creating database...\n";
125 dbsource( "./maintenance/database.sql", $wgDatabase );
126
127 $wgDatabase->selectDB( $wgDBname );
128 dbsource( "./maintenance/tables.sql", $wgDatabase );
129 dbsource( "./maintenance/users.sql", $wgDatabase );
130 dbsource( "./maintenance/initialdata.sql", $wgDatabase );
131 dbsource( "./maintenance/interwiki.sql", $wgDatabase );
132
133 populatedata(); # Needs internationalized messages
134
135 print "Adding indexes...\n";
136 dbsource( "./maintenance/indexes.sql", $wgDatabase );
137
138 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
139 exit();
140
141 #
142 # Functions used above:
143 #
144 function makedirectory( $d ) {
145 global $wgInstallOwner, $wgInstallGroup;
146
147 if ( is_dir( $d ) ) {
148 print "Directory \"{$d}\" exists.\n";
149 } else {
150 if ( mkdir( $d, 0777 ) ) {
151 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
152 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
153 print "Directory \"{$d}\" created.\n";
154 } else {
155 print "Could not create directory \"{$d}\".\n";
156 exit();
157 }
158 }
159 }
160
161
162 function populatedata() {
163 global $wgDBadminpassword, $wgDatabase;
164 $fname = "Installation script: populatedata()";
165
166 $sql = "DELETE FROM site_stats";
167 $wgDatabase->query( $sql, $fname );
168
169 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
170 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
171 $wgDatabase->query( $sql, $fname );
172
173 $sql = "DELETE FROM user";
174 $wgDatabase->query( $sql, $fname );
175
176 $u = User::newFromName( "WikiSysop" );
177 if ( 0 == $u->idForName() ) {
178 $u->addToDatabase();
179 $u->setPassword( $wgDBadminpassword );
180 $u->addRight( "sysop" );
181 $u->saveSettings();
182 }
183 $u = User::newFromName( "WikiDeveloper" );
184 if ( 0 == $u->idForName() ) {
185 $u->addToDatabase();
186 $u->setPassword( $wgDBadminpassword );
187 $u->addRight( "sysop" );
188 $u->addRight( "developer" );
189 $u->saveSettings();
190 }
191
192 $wns = Namespace::getWikipedia();
193 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
194 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
195
196 $sql = "DELETE FROM cur";
197 $wgDatabase->query( $sql, $fname );
198
199 $now = wfTimestampNow();
200 $won = wfInvertTimestamp( $now );
201
202 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
203 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
204 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
205 $wgDatabase->query( $sql, $fname );
206
207 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
208 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
209 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
210 $wgDatabase->query( $sql, $fname );
211
212 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
213 $title = $titleobj->getDBkey();
214 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
215 "VALUES (0,'$title','" .
216 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
217 $wgDatabase->query( $sql, $fname );
218
219 initialiseMessages();
220 }
221
222 ?>