Old log page -> logging table importer.
[lhc/web/wiklou.git] / install.php
1 <?php
2
3 die("obsolete; remove this file befor 1.3.0 release\n");
4
5 # Install software and create new empty database.
6 #
7
8 include_once( "./install-utils.inc" );
9 install_version_checks();
10
11 if ( ! ( is_readable( "./LocalSettings.php" )
12 && is_readable( "./AdminSettings.php" ) ) ) {
13 print "You must first create the files LocalSettings.php\n" .
14 "and AdminSettings.php based on the samples in the top\n" .
15 "source directory before running this install script.\n";
16 exit();
17 }
18
19 $DP = "./includes";
20 require_once( "./LocalSettings.php" );
21 require_once( "./AdminSettings.php" );
22 require_once( "./maintenance/InitialiseMessages.inc" );
23
24 if( $wgSitename == "MediaWiki" ) {
25 die( "You must set the site name in \$wgSitename before installation.\n\n" );
26 }
27
28 if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
29 print "To use math functions, you must first compile texvc by\n" .
30 "running \"make\" in the math directory.\n";
31 exit();
32 }
33 if ( is_file( "{$IP}/Version.php" ) ) {
34 print "There appears to be an installation of the software\n" .
35 "already present on \"{$IP}\". You may want to run the update\n" .
36 "script instead. If you continue with this installation script,\n" .
37 "that software and all of its data will be overwritten.\n" .
38 "Are you sure you want to do this? (yes/no) ";
39
40 $response = readconsole();
41 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
42 }
43
44 #
45 # Make the necessary directories
46 #
47 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
48 foreach ( $dirs as $d ) { makedirectory( $d ); }
49
50 #
51 # Copy files into installation directories
52 #
53 print "Copying files...\n";
54
55 copyfile( ".", "LocalSettings.php", $IP );
56 copyfile( ".", "Version.php", $IP );
57 copyfile( ".", "index.php", $IP );
58 copyfile( ".", "redirect.php", $IP );
59
60 # compatibility with older versions, can be removed in a year or so
61 # (written in Feb 2004)
62 copyfile( ".", "wiki.phtml", $IP );
63 copyfile( ".", "redirect.phtml", $IP );
64
65 copydirectory( "./includes", $IP );
66 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
67
68 copyfile( "./images", "wiki.png", $wgUploadDirectory );
69 copyfile( "./images", "button_bold.png", $wgUploadDirectory );
70 copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
71 copyfile( "./images", "button_headline.png", $wgUploadDirectory );
72 copyfile( "./images", "button_hr.png", $wgUploadDirectory );
73 copyfile( "./images", "button_image.png", $wgUploadDirectory );
74 copyfile( "./images", "button_italic.png", $wgUploadDirectory );
75 copyfile( "./images", "button_link.png", $wgUploadDirectory );
76 copyfile( "./images", "button_math.png", $wgUploadDirectory );
77 copyfile( "./images", "button_media.png", $wgUploadDirectory );
78 copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
79 copyfile( "./images", "button_sig.png", $wgUploadDirectory );
80 copyfile( "./images", "button_template.png", $wgUploadDirectory );
81 copyfile( "./images", "magnify-clip.png", $wgUploadDirectory );
82 copyfile( "./images", "Arr_.png", $wgUploadDirectory );
83 copyfile( "./images", "Arr_r.png", $wgUploadDirectory );
84 copyfile( "./images", "Arr_d.png", $wgUploadDirectory );
85 copyfile( "./images", "Arr_l.png", $wgUploadDirectory );
86
87 copyfile( "./languages", "Language.php", $IP );
88 copyfile( "./languages", "LanguageUtf8.php", $IP );
89 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
90
91 if ( $wgDebugLogFile ) {
92 $fp = fopen( $wgDebugLogFile, "w" );
93 if ( false === $fp ) {
94 print "Could not create log file \"{$wgDebugLogFile}\".\n";
95 exit();
96 }
97 $d = date( "Y-m-d H:i:s" );
98 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
99 fclose( $fp );
100 }
101
102 if ( $wgUseTeX ) {
103 makedirectory( "{$IP}/math" );
104 makedirectory( $wgMathDirectory );
105 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
106 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
107 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
108 }
109
110 copyfile( ".", "Version.php", $IP );
111
112 #
113 # Make and initialize database
114 #
115 print "\n* * *\nWarning! This script will completely erase any\n" .
116 "existing database \"{$wgDBname}\" and all its contents.\n" .
117 "Are you sure you want to do this? (yes/no) ";
118
119 $response = readconsole();
120 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
121
122 print "Please enter your root password for the database server now.\n";
123 print "It is used to do the following:\n";
124 print "1) Create the database\n";
125 print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
126 print "You do not need to create any user accounts yourself!\n\n";
127 print "MySQL root password (typing will be visible): ";
128 $rootpw=readconsole();
129
130 # Include rest of code to get things like internationalized messages.
131 #
132 $wgUseDatabaseMessages = false; # no DB yet
133
134 require_once( "{$IP}/Setup.php" );
135 $wgTitle = Title::newFromText( "Installation script" );
136
137 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
138 if ( !$wgDatabase->isOpen() ) {
139 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
140 exit();
141 }
142
143 # Now do the actual database creation
144 #
145 print "Creating database...\n";
146 dbsource( "./maintenance/database.sql", $wgDatabase );
147
148 $wgDatabase->selectDB( $wgDBname );
149 dbsource( "./maintenance/tables.sql", $wgDatabase );
150 dbsource( "./maintenance/users.sql", $wgDatabase );
151 dbsource( "./maintenance/initialdata.sql", $wgDatabase );
152 dbsource( "./maintenance/interwiki.sql", $wgDatabase );
153
154 populatedata(); # Needs internationalized messages
155
156 print "Adding indexes...\n";
157 dbsource( "./maintenance/indexes.sql", $wgDatabase );
158
159 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
160 exit();
161
162 #
163 # Functions used above:
164 #
165 function makedirectory( $d ) {
166 global $wgInstallOwner, $wgInstallGroup;
167
168 if ( is_dir( $d ) ) {
169 print "Directory \"{$d}\" exists.\n";
170 } else {
171 if ( mkdir( $d, 0777 ) ) {
172 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
173 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
174 print "Directory \"{$d}\" created.\n";
175 } else {
176 print "Could not create directory \"{$d}\".\n";
177 exit();
178 }
179 }
180 }
181
182
183 function populatedata() {
184 global $wgDBadminpassword, $wgDatabase;
185 $fname = "Installation script: populatedata()";
186
187 $sql = "DELETE FROM site_stats";
188 $wgDatabase->query( $sql, $fname );
189
190 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
191 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
192 $wgDatabase->query( $sql, $fname );
193
194 $sql = "DELETE FROM user";
195 $wgDatabase->query( $sql, $fname );
196
197 print "Do you want to create a sysop account? A sysop can protect,\n";
198 print "delete and undelete pages and ban users. Recomended. [Y/n] ";
199 $response = readconsole();
200 if(strtolower($response)!="n") {
201 print "Enter the username [Sysop]: ";
202 $sysop_user=readconsole();
203 if(!$sysop_user) { $sysop_user="Sysop"; }
204 while(!$sysop_password) {
205 print "Enter the password: ";
206 $sysop_password=readconsole();
207 }
208 $u = User::newFromName( $sysop_user );
209 if ( 0 == $u->idForName() ) {
210 $u->addToDatabase();
211 $u->setPassword( $sysop_password );
212 $u->addRight( "sysop" );
213 $u->saveSettings();
214 } else {
215 print "Could not create user - already exists!\n";
216 }
217 }
218 print "Do you want to create a sysop+developer account? A developer\n";
219 print "can switch the database to read-only mode and run any type of\n";
220 print "query through a web interface. [Y/n] ";
221 $response=readconsole();
222 if(strtolower($response)!="n") {
223 print "Enter the username [Developer]: ";
224 $developer_user=readconsole();
225 if(!$developer_user) { $developer_user="Developer"; }
226 while (!$developer_password) {
227 print "Enter the password: ";
228 $developer_password=readconsole();
229 }
230 $u = User::newFromName( $developer_user );
231 if ( 0 == $u->idForName() ) {
232 $u->addToDatabase();
233 $u->setPassword( $developer_password );
234 $u->addRight( "sysop" );
235 $u->addRight( "developer" );
236 $u->saveSettings();
237 } else {
238 print "Could not create user - already exists!\n";
239 }
240 }
241
242 $wns = Namespace::getWikipedia();
243 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
244 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
245
246 $sql = "DELETE FROM cur";
247 $wgDatabase->query( $sql, $fname );
248
249 $now = wfTimestampNow();
250 $won = wfInvertTimestamp( $now );
251
252 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
253 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
254 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
255 $wgDatabase->query( $sql, $fname );
256
257 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
258 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
259 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
260 $wgDatabase->query( $sql, $fname );
261
262 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
263 $title = $titleobj->getDBkey();
264 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
265 "VALUES (0,'$title','" .
266 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
267 $wgDatabase->query( $sql, $fname );
268
269 initialiseMessages();
270 }
271
272 ?>