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