Fix for compatibility with short_open_tag = Off
[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 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_nowiki.gif", $wgUploadDirectory );
69 copyfile( "./images", "button_sig.gif", $wgUploadDirectory );
70 copyfile( "./images", "button_template.gif", $wgUploadDirectory );
71
72 copyfile( "./languages", "Language.php", $IP );
73 copyfile( "./languages", "LanguageUtf8.php", $IP );
74 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
75
76 if ( $wgDebugLogFile ) {
77 $fp = fopen( $wgDebugLogFile, "w" );
78 if ( false === $fp ) {
79 print "Could not create log file \"{$wgDebugLogFile}\".\n";
80 exit();
81 }
82 $d = date( "Y-m-d H:i:s" );
83 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
84 fclose( $fp );
85 }
86
87 if ( $wgUseTeX ) {
88 makedirectory( "{$IP}/math" );
89 makedirectory( $wgMathDirectory );
90 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
91 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
92 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
93 }
94
95 copyfile( ".", "Version.php", $IP );
96
97 #
98 # Make and initialize database
99 #
100 print "\n* * *\nWarning! This script will completely erase any\n" .
101 "existing database \"{$wgDBname}\" and all its contents.\n" .
102 "Are you sure you want to do this? (yes/no) ";
103
104 $response = readconsole();
105 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
106
107 print "Please enter your root password for the database server now.\n";
108 print "It is used to do the following:\n";
109 print "1) Create the database\n";
110 print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
111 print "You do not need to create any user accounts yourself!\n\n";
112 print "MySQL root password (typing will be visible): ";
113 $rootpw=readconsole();
114
115 # Include rest of code to get things like internationalized messages.
116 #
117 include_once( "{$IP}/Setup.php" );
118 $wgTitle = Title::newFromText( "Installation script" );
119
120 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
121 if ( !$wgDatabase->isOpen() ) {
122 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
123 exit();
124 }
125
126 # Now do the actual database creation
127 #
128 print "Creating database...\n";
129 dbsource( "./maintenance/database.sql", $wgDatabase );
130
131 $wgDatabase->selectDB( $wgDBname );
132 dbsource( "./maintenance/tables.sql", $wgDatabase );
133 dbsource( "./maintenance/users.sql", $wgDatabase );
134 dbsource( "./maintenance/initialdata.sql", $wgDatabase );
135 dbsource( "./maintenance/interwiki.sql", $wgDatabase );
136
137 populatedata(); # Needs internationalized messages
138
139 print "Adding indexes...\n";
140 dbsource( "./maintenance/indexes.sql", $wgDatabase );
141
142 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
143 exit();
144
145 #
146 # Functions used above:
147 #
148 function makedirectory( $d ) {
149 global $wgInstallOwner, $wgInstallGroup;
150
151 if ( is_dir( $d ) ) {
152 print "Directory \"{$d}\" exists.\n";
153 } else {
154 if ( mkdir( $d, 0777 ) ) {
155 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
156 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
157 print "Directory \"{$d}\" created.\n";
158 } else {
159 print "Could not create directory \"{$d}\".\n";
160 exit();
161 }
162 }
163 }
164
165
166 function populatedata() {
167 global $wgDBadminpassword, $wgDatabase;
168 $fname = "Installation script: populatedata()";
169
170 $sql = "DELETE FROM site_stats";
171 $wgDatabase->query( $sql, $fname );
172
173 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
174 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
175 $wgDatabase->query( $sql, $fname );
176
177 $sql = "DELETE FROM user";
178 $wgDatabase->query( $sql, $fname );
179
180 print "Do you want to create a sysop account? A sysop can protect,\n";
181 print "delete and undelete pages and ban users. Recomended. [Y/n] ";
182 $response = readconsole();
183 if(strtolower($response)!="n") {
184 print "Enter the username [Sysop]: ";
185 $sysop_user=readconsole();
186 if(!$sysop_user) { $sysop_user="Sysop"; }
187 while(!$sysop_password) {
188 print "Enter the password: ";
189 $sysop_password=readconsole();
190 }
191 $u = User::newFromName( $sysop_user );
192 if ( 0 == $u->idForName() ) {
193 $u->addToDatabase();
194 $u->setPassword( $sysop_password );
195 $u->addRight( "sysop" );
196 $u->saveSettings();
197 } else {
198 print "Could not create user - already exists!\n";
199 }
200 }
201 print "Do you want to create a sysop+developer account? A developer\n";
202 print "can switch the database to read-only mode and run any type of\n";
203 print "query through a web interface. [Y/n] ";
204 $response=readconsole();
205 if(strtolower($response)!="n") {
206 print "Enter the username [Developer]: ";
207 $developer_user=readconsole();
208 if(!$developer_user) { $developer_user="Developer"; }
209 while (!$developer_password) {
210 print "Enter the password: ";
211 $developer_password=readconsole();
212 }
213 $u = User::newFromName( $developer_user );
214 if ( 0 == $u->idForName() ) {
215 $u->addToDatabase();
216 $u->setPassword( $developer_password );
217 $u->addRight( "sysop" );
218 $u->addRight( "developer" );
219 $u->saveSettings();
220 } else {
221 print "Could not create user - already exists!\n";
222 }
223 }
224
225 $wns = Namespace::getWikipedia();
226 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
227 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
228
229 $sql = "DELETE FROM cur";
230 $wgDatabase->query( $sql, $fname );
231
232 $now = wfTimestampNow();
233 $won = wfInvertTimestamp( $now );
234
235 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
236 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
237 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
238 $wgDatabase->query( $sql, $fname );
239
240 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
241 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
242 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
243 $wgDatabase->query( $sql, $fname );
244
245 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
246 $title = $titleobj->getDBkey();
247 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
248 "VALUES (0,'$title','" .
249 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
250 $wgDatabase->query( $sql, $fname );
251
252 initialiseMessages();
253 }
254
255 ?>