Remove mention of obsolete test suite
[lhc/web/wiklou.git] / install.php
1 <?
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( "./languages", "Language.php", $IP );
60 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
61
62 if ( $wgDebugLogFile ) {
63 $fp = fopen( $wgDebugLogFile, "w" );
64 if ( false === $fp ) {
65 print "Could not create log file \"{$wgDebugLogFile}\".\n";
66 exit();
67 }
68 $d = date( "Y-m-d H:i:s" );
69 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
70 fclose( $fp );
71 }
72
73 if ( $wgUseTeX ) {
74 makedirectory( "{$IP}/math" );
75 makedirectory( $wgMathDirectory );
76 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
77 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
78 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
79 }
80
81 copyfile( ".", "Version.php", $IP );
82
83 #
84 # Make and initialize database
85 #
86 print "\n* * *\nWarning! This script will completely erase the\n" .
87 "existing database \"{$wgDBname}\" and all its contents.\n" .
88 "Are you sure you want to do this? (yes/no) ";
89
90 $response = readconsole();
91 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
92
93 print "\nYou should have already created a root password for the database.\n" .
94 "Enter the root password here: ";
95
96 $rootpw = readconsole();
97
98 $rconn = mysql_connect( $wgDBserver, "root", $rootpw );
99 if ( false === $rconn ) {
100 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
101 exit();
102 }
103
104 # Include rest of code to get things like internationalized messages.
105 #
106 include_once( "{$IP}/Setup.php" );
107 $wgTitle = Title::newFromText( "Installation script" );
108
109 # Now do the actual database creation
110 #
111 print "Creating database...\n";
112 dbsource( "./maintenance/database.sql", $rconn );
113
114 mysql_select_db( $wgDBname, $rconn );
115 dbsource( "./maintenance/tables.sql", $rconn );
116 dbsource( "./maintenance/users.sql", $rconn );
117 dbsource( "./maintenance/initialdata.sql", $rconn );
118 dbsource( "./maintenance/interwiki.sql", $rconn );
119
120 populatedata(); # Needs internationalized messages
121
122 print "Adding indexes...\n";
123 dbsource( "./maintenance/indexes.sql", $rconn );
124
125 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
126 exit();
127
128 #
129 # Functions used above:
130 #
131 function makedirectory( $d ) {
132 global $wgInstallOwner, $wgInstallGroup;
133
134 if ( is_dir( $d ) ) {
135 print "Directory \"{$d}\" exists.\n";
136 } else {
137 if ( mkdir( $d, 0777 ) ) {
138 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
139 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
140 print "Directory \"{$d}\" created.\n";
141 } else {
142 print "Could not create directory \"{$d}\".\n";
143 exit();
144 }
145 }
146 }
147
148
149 function populatedata() {
150 global $wgDBadminpassword;
151 $fname = "Installation script: populatedata()";
152
153 $sql = "DELETE FROM site_stats";
154 wfQuery( $sql, DB_WRITE, $fname );
155
156 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
157 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
158 wfQuery( $sql, DB_WRITE, $fname );
159
160 $sql = "DELETE FROM user";
161 wfQuery( $sql, DB_WRITE, $fname );
162
163 $u = User::newFromName( "WikiSysop" );
164 if ( 0 == $u->idForName() ) {
165 $u->addToDatabase();
166 $u->setPassword( $wgDBadminpassword );
167 $u->addRight( "sysop" );
168 $u->saveSettings();
169 }
170 $u = User::newFromName( "WikiDeveloper" );
171 if ( 0 == $u->idForName() ) {
172 $u->addToDatabase();
173 $u->setPassword( $wgDBadminpassword );
174 $u->addRight( "sysop" );
175 $u->addRight( "developer" );
176 $u->saveSettings();
177 }
178
179 $wns = Namespace::getWikipedia();
180 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
181 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
182
183 $sql = "DELETE FROM cur";
184 wfQuery( $sql, DB_WRITE, $fname );
185
186 $now = wfTimestampNow();
187 $won = wfInvertTimestamp( $now );
188
189 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
190 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
191 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
192 wfQuery( $sql, DB_WRITE, $fname );
193
194 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
195 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
196 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
197 wfQuery( $sql, DB_WRITE, $fname );
198
199 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
200 $title = $titleobj->getDBkey();
201 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
202 "VALUES (0,'$title','" .
203 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
204 wfQuery( $sql, DB_WRITE, $fname );
205
206 initialiseMessages();
207 }
208
209 ?>