Imported the register_globals hack from REL1_2. Also starting work on
[mediawiki.git] / install.php
blob50153e54003c3a57eb68f54a3b4ac9a3b8e82a93
1 <?php
3 # Install software and create new empty database.
6 include( "./install-utils.inc" );
7 install_version_checks();
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();
17 $DP = "./includes";
18 include_once( "./LocalSettings.php" );
19 include_once( "./AdminSettings.php" );
20 include_once( "./maintenance/InitialiseMessages.inc" );
22 if( $wgSitename == "MediaWiki" ) {
23 die( "You must set the site name in \$wgSitename before installation.\n\n" );
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();
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) ";
38 $response = readconsole();
39 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
43 # Make the necessary directories
45 $dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
46 foreach ( $dirs as $d ) { makedirectory( $d ); }
49 # Copy files into installation directories
51 print "Copying files...\n";
53 copyfile( ".", "LocalSettings.php", $IP );
54 copyfile( ".", "Version.php", $IP );
55 copyfile( ".", "index.php", $IP );
56 copyfile( ".", "redirect.php", $IP );
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 );
63 copydirectory( "./includes", $IP );
64 copydirectory( "./stylesheets", $wgStyleSheetDirectory );
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 );
84 copyfile( "./languages", "Language.php", $IP );
85 copyfile( "./languages", "LanguageUtf8.php", $IP );
86 copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );
88 if ( $wgDebugLogFile ) {
89 $fp = fopen( $wgDebugLogFile, "w" );
90 if ( false === $fp ) {
91 print "Could not create log file \"{$wgDebugLogFile}\".\n";
92 exit();
94 $d = date( "Y-m-d H:i:s" );
95 fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
96 fclose( $fp );
99 if ( $wgUseTeX ) {
100 makedirectory( "{$IP}/math" );
101 makedirectory( $wgMathDirectory );
102 copyfile( "./math", "texvc", "{$IP}/math", 0775 );
103 copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
104 copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
107 copyfile( ".", "Version.php", $IP );
110 # Make and initialize database
112 print "\n* * *\nWarning! This script will completely erase any\n" .
113 "existing database \"{$wgDBname}\" and all its contents.\n" .
114 "Are you sure you want to do this? (yes/no) ";
116 $response = readconsole();
117 if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
119 print "Please enter your root password for the database server now.\n";
120 print "It is used to do the following:\n";
121 print "1) Create the database\n";
122 print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
123 print "You do not need to create any user accounts yourself!\n\n";
124 print "MySQL root password (typing will be visible): ";
125 $rootpw=readconsole();
127 # Include rest of code to get things like internationalized messages.
129 include_once( "{$IP}/Setup.php" );
130 $wgTitle = Title::newFromText( "Installation script" );
132 $wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
133 if ( !$wgDatabase->isOpen() ) {
134 print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
135 exit();
138 # Now do the actual database creation
140 print "Creating database...\n";
141 dbsource( "./maintenance/database.sql", $wgDatabase );
143 $wgDatabase->selectDB( $wgDBname );
144 dbsource( "./maintenance/tables.sql", $wgDatabase );
145 dbsource( "./maintenance/users.sql", $wgDatabase );
146 dbsource( "./maintenance/initialdata.sql", $wgDatabase );
147 dbsource( "./maintenance/interwiki.sql", $wgDatabase );
149 populatedata(); # Needs internationalized messages
151 print "Adding indexes...\n";
152 dbsource( "./maintenance/indexes.sql", $wgDatabase );
154 print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
155 exit();
158 # Functions used above:
160 function makedirectory( $d ) {
161 global $wgInstallOwner, $wgInstallGroup;
163 if ( is_dir( $d ) ) {
164 print "Directory \"{$d}\" exists.\n";
165 } else {
166 if ( mkdir( $d, 0777 ) ) {
167 if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
168 if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
169 print "Directory \"{$d}\" created.\n";
170 } else {
171 print "Could not create directory \"{$d}\".\n";
172 exit();
178 function populatedata() {
179 global $wgDBadminpassword, $wgDatabase;
180 $fname = "Installation script: populatedata()";
182 $sql = "DELETE FROM site_stats";
183 $wgDatabase->query( $sql, $fname );
185 $sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
186 "ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
187 $wgDatabase->query( $sql, $fname );
189 $sql = "DELETE FROM user";
190 $wgDatabase->query( $sql, $fname );
192 print "Do you want to create a sysop account? A sysop can protect,\n";
193 print "delete and undelete pages and ban users. Recomended. [Y/n] ";
194 $response = readconsole();
195 if(strtolower($response)!="n") {
196 print "Enter the username [Sysop]: ";
197 $sysop_user=readconsole();
198 if(!$sysop_user) { $sysop_user="Sysop"; }
199 while(!$sysop_password) {
200 print "Enter the password: ";
201 $sysop_password=readconsole();
203 $u = User::newFromName( $sysop_user );
204 if ( 0 == $u->idForName() ) {
205 $u->addToDatabase();
206 $u->setPassword( $sysop_password );
207 $u->addRight( "sysop" );
208 $u->saveSettings();
209 } else {
210 print "Could not create user - already exists!\n";
213 print "Do you want to create a sysop+developer account? A developer\n";
214 print "can switch the database to read-only mode and run any type of\n";
215 print "query through a web interface. [Y/n] ";
216 $response=readconsole();
217 if(strtolower($response)!="n") {
218 print "Enter the username [Developer]: ";
219 $developer_user=readconsole();
220 if(!$developer_user) { $developer_user="Developer"; }
221 while (!$developer_password) {
222 print "Enter the password: ";
223 $developer_password=readconsole();
225 $u = User::newFromName( $developer_user );
226 if ( 0 == $u->idForName() ) {
227 $u->addToDatabase();
228 $u->setPassword( $developer_password );
229 $u->addRight( "sysop" );
230 $u->addRight( "developer" );
231 $u->saveSettings();
232 } else {
233 print "Could not create user - already exists!\n";
237 $wns = Namespace::getWikipedia();
238 $ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
239 $dlp = addslashes( wfMsgNoDB( "dellogpage" ) );
241 $sql = "DELETE FROM cur";
242 $wgDatabase->query( $sql, $fname );
244 $now = wfTimestampNow();
245 $won = wfInvertTimestamp( $now );
247 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
248 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
249 wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
250 $wgDatabase->query( $sql, $fname );
252 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
253 "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
254 wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
255 $wgDatabase->query( $sql, $fname );
257 $titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
258 $title = $titleobj->getDBkey();
259 $sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
260 "VALUES (0,'$title','" .
261 wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
262 $wgDatabase->query( $sql, $fname );
264 initialiseMessages();