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