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