4aef3d8b846db6c7d6b13d40c700091457de2d01
[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 ( $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 copyfileto( ".", "wiki.phtml", $IP, "wiki.$wgScriptExtension" );
52 copyfileto( ".", "redirect.phtml", $IP, "redirect.$wgScriptExtension" );
53
54 copydirectory( "./includes", $IP );
55 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
56
57 copyfile( "./images", "wiki.png", $wgUploadDirectory );
58 copyfile( "./images", "button_bold.gif", $wgUploadDirectory );
59 copyfile( "./images", "button_extlink.gif", $wgUploadDirectory );
60 copyfile( "./images", "button_headline.gif", $wgUploadDirectory );
61 copyfile( "./images", "button_hr.gif", $wgUploadDirectory );
62 copyfile( "./images", "button_image.gif", $wgUploadDirectory );
63 copyfile( "./images", "button_italic.gif", $wgUploadDirectory );
64 copyfile( "./images", "button_link.gif", $wgUploadDirectory );
65 copyfile( "./images", "button_math.gif", $wgUploadDirectory );
66 copyfile( "./images", "button_media.gif", $wgUploadDirectory );
67 copyfile( "./images", "button_nowiki.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 any\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 "Please enter your root password for the database server now.\n";
107 print "It is used to do the following:\n";
108 print "1) Create the database\n";
109 print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
110 print "You do not need to create any user accounts yourself!\n\n";
111 print "MySQL root password (typing will be visible): ";
112 $rootpw=readconsole();
113
114 # Include rest of code to get things like internationalized messages.
115 #
116 include_once( "{$IP}/Setup.php" );
117 $wgTitle = Title::newFromText( "Installation script" );
118
119 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
120 if ( !$wgDatabase->isOpen() ) {
121 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
122 exit();
123 }
124
125 # Now do the actual database creation
126 #
127 print "Creating database...\n";
128 dbsource( "./maintenance/database.sql", $wgDatabase );
129
130 $wgDatabase->selectDB( $wgDBname );
131 dbsource( "./maintenance/tables.sql", $wgDatabase );
132 dbsource( "./maintenance/users.sql", $wgDatabase );
133 dbsource( "./maintenance/initialdata.sql", $wgDatabase );
134 dbsource( "./maintenance/interwiki.sql", $wgDatabase );
135
136 populatedata(); # Needs internationalized messages
137
138 print "Adding indexes...\n";
139 dbsource( "./maintenance/indexes.sql", $wgDatabase );
140
141 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
142 exit();
143
144 #
145 # Functions used above:
146 #
147 function makedirectory( $d ) {
148 global $wgInstallOwner, $wgInstallGroup;
149
150 if ( is_dir( $d ) ) {
151 print "Directory \"{$d}\" exists.\n";
152 } else {
153 if ( mkdir( $d, 0777 ) ) {
154 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
155 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
156 print "Directory \"{$d}\" created.\n";
157 } else {
158 print "Could not create directory \"{$d}\".\n";
159 exit();
160 }
161 }
162 }
163
164
165 function populatedata() {
166 global $wgDBadminpassword, $wgDatabase;
167 $fname = "Installation script: populatedata()";
168
169 $sql = "DELETE FROM site_stats";
170 $wgDatabase->query( $sql, $fname );
171
172 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
173 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
174 $wgDatabase->query( $sql, $fname );
175
176 $sql = "DELETE FROM user";
177 $wgDatabase->query( $sql, $fname );
178
179 print "Do you want to create a sysop account? A sysop can protect,\n";
180 print "delete and undelete pages and ban users. Recomended. [Y/n] ";
181 $response = readconsole();
182 if(strtolower($response)!="n") {
183 print "Enter the username [Sysop]: ";
184 $sysop_user=readconsole();
185 if(!$sysop_user) { $sysop_user="Sysop"; }
186 while(!$sysop_password) {
187 print "Enter the password: ";
188 $sysop_password=readconsole();
189 }
190 $u = User::newFromName( $sysop_user );
191 if ( 0 == $u->idForName() ) {
192 $u->addToDatabase();
193 $u->setPassword( $sysop_password );
194 $u->addRight( "sysop" );
195 $u->saveSettings();
196 } else {
197 print "Could not create user - already exists!\n";
198 }
199 }
200 print "Do you want to create a sysop+developer account? A developer\n";
201 print "can switch the database to read-only mode and run any type of\n";
202 print "query through a web interface. [Y/n] ";
203 $response=readconsole();
204 if(strtolower($response)!="n") {
205 print "Enter the username [Developer]: ";
206 $developer_user=readconsole();
207 if(!$developer_user) { $developer_user="Developer"; }
208 while (!$developer_password) {
209 print "Enter the password: ";
210 $developer_password=readconsole();
211 }
212 $u = User::newFromName( $developer_user );
213 if ( 0 == $u->idForName() ) {
214 $u->addToDatabase();
215 $u->setPassword( $developer_password );
216 $u->addRight( "sysop" );
217 $u->addRight( "developer" );
218 $u->saveSettings();
219 } else {
220 print "Could not create user - already exists!\n";
221 }
222 }
223
224 $wns = Namespace::getWikipedia();
225 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
226 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
227
228 $sql = "DELETE FROM cur";
229 $wgDatabase->query( $sql, $fname );
230
231 $now = wfTimestampNow();
232 $won = wfInvertTimestamp( $now );
233
234 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
235 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
236 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
237 $wgDatabase->query( $sql, $fname );
238
239 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
240 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
241 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
242 $wgDatabase->query( $sql, $fname );
243
244 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
245 $title = $titleobj->getDBkey();
246 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
247 "VALUES (0,'$title','" .
248 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
249 $wgDatabase->query( $sql, $fname );
250
251 initialiseMessages();
252 }
253
254 ?>