aboutsummaryrefslogtreecommitdiffstats
path: root/install.php
blob: dab4143ff5b50b1271c5c5994cbd08dd88fc6ef6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php

# Install software and create new empty database.
#

include( "./install-utils.inc" );
install_version_checks();

if ( ! ( is_readable( "./LocalSettings.php" )
  && is_readable( "./AdminSettings.php" ) ) ) {
	print "You must first create the files LocalSettings.php\n" .
	  "and AdminSettings.php based on the samples in the top\n" .
	  "source directory before running this install script.\n";
	exit();
}

$DP = "./includes";
include_once( "./LocalSettings.php" );
include_once( "./AdminSettings.php" );
include_once( "./maintenance/InitialiseMessages.inc" );

if( $wgSitename == "MediaWiki" ) {
	die( "You must set the site name in \$wgSitename before installation.\n\n" );
}

if ( $wgUseTeX && ( ! is_executable( "./math/texvc" ) ) ) {
	print "To use math functions, you must first compile texvc by\n" .
	  "running \"make\" in the math directory.\n";
	exit();
}
if ( is_file( "{$IP}/Version.php" ) ) {
	print "There appears to be an installation of the software\n" .
	  "already present on \"{$IP}\". You may want to run the update\n" .
	  "script instead. If you continue with this installation script,\n" .
	  "that software and all of its data will be overwritten.\n" .
	  "Are you sure you want to do this? (yes/no) ";

	$response = readconsole();
	if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }
}

#
# Make the necessary directories
#
$dirs = array( $IP, $wgUploadDirectory, $wgStyleSheetDirectory, $wgTmpDirectory );
foreach ( $dirs as $d ) { makedirectory( $d ); }

#
# Copy files into installation directories
#
print "Copying files...\n";

copyfile( ".", "LocalSettings.php", $IP );
copyfile( ".", "Version.php", $IP );
copyfile( ".", "index.php", $IP );
copyfile( ".", "redirect.php", $IP );

# compatibility with older versions, can be removed in a year or so
# (written in Feb 2004)
copyfile( ".", "wiki.phtml", $IP );
copyfile( ".", "redirect.phtml", $IP );

copydirectory( "./includes", $IP );
copydirectory( "./stylesheets", $wgStyleSheetDirectory );

copyfile( "./images", "wiki.png", $wgUploadDirectory );
copyfile( "./images", "button_bold.png", $wgUploadDirectory );
copyfile( "./images", "button_extlink.png", $wgUploadDirectory );
copyfile( "./images", "button_headline.png", $wgUploadDirectory );
copyfile( "./images", "button_hr.png", $wgUploadDirectory );
copyfile( "./images", "button_image.png", $wgUploadDirectory );
copyfile( "./images", "button_italic.png", $wgUploadDirectory );
copyfile( "./images", "button_link.png", $wgUploadDirectory );
copyfile( "./images", "button_math.png", $wgUploadDirectory );
copyfile( "./images", "button_media.png", $wgUploadDirectory );
copyfile( "./images", "button_nowiki.png", $wgUploadDirectory );
copyfile( "./images", "button_sig.png", $wgUploadDirectory );
copyfile( "./images", "button_template.png", $wgUploadDirectory );
copyfile( "./images", "magnify-clip.png", $wgUploadDirectory );
copyfile( "./images", "Arr_.png", $wgUploadDirectory );
copyfile( "./images", "Arr_r.png", $wgUploadDirectory );
copyfile( "./images", "Arr_d.png", $wgUploadDirectory );
copyfile( "./images", "Arr_l.png", $wgUploadDirectory );

copyfile( "./languages", "Language.php", $IP );
copyfile( "./languages", "LanguageUtf8.php", $IP );
copyfile( "./languages", "Language" . ucfirst( $wgLanguageCode ) . ".php", $IP );

if ( $wgDebugLogFile ) {
	$fp = fopen( $wgDebugLogFile, "w" );
	if ( false === $fp ) {
		print "Could not create log file \"{$wgDebugLogFile}\".\n";
		exit();
	}
	$d = date( "Y-m-d H:i:s" );
	fwrite( $fp, "Wiki debug log file created {$d}\n\n" );
	fclose( $fp );
}

if ( $wgUseTeX ) {
	makedirectory( "{$IP}/math" );
	makedirectory( $wgMathDirectory );
	copyfile( "./math", "texvc", "{$IP}/math", 0775 );
	copyfile( "./math", "texvc_test", "{$IP}/math", 0775 );
	copyfile( "./math", "texvc_tex", "{$IP}/math", 0775 );
}

copyfile( ".", "Version.php", $IP );

#
# Make and initialize database
#
print "\n* * *\nWarning! This script will completely erase any\n" .
  "existing database \"{$wgDBname}\" and all its contents.\n" .
  "Are you sure you want to do this? (yes/no) ";

$response = readconsole();
if ( ! ( "Y" == $response{0} || "y" == $response{0} ) ) { exit(); }

print "Please enter your root password for the database server now.\n";
print "It is used to do the following:\n";
print "1) Create the database\n";
print "2) Create the users specified in AdminSettings.php and LocalSettings.php\n\n";
print "You do not need to create any user accounts yourself!\n\n";
print "MySQL root password (typing will be visible): ";
$rootpw=readconsole();

# Include rest of code to get things like internationalized messages.
#
$wgUseDatabaseMessages = false; # no DB yet

include_once( "{$IP}/Setup.php" );
$wgTitle = Title::newFromText( "Installation script" );

$wgDatabase = Database::newFromParams( $wgDBserver, "root", $rootpw, "", 1 );
if ( !$wgDatabase->isOpen() ) {
	print "Could not connect to database on \"{$wgDBserver}\" as root.\n";
	exit();
}

# Now do the actual database creation
#
print "Creating database...\n";
dbsource( "./maintenance/database.sql", $wgDatabase );

$wgDatabase->selectDB( $wgDBname );
dbsource( "./maintenance/tables.sql", $wgDatabase );
dbsource( "./maintenance/users.sql", $wgDatabase );
dbsource( "./maintenance/initialdata.sql", $wgDatabase );
dbsource( "./maintenance/interwiki.sql", $wgDatabase );

populatedata(); # Needs internationalized messages

print "Adding indexes...\n";
dbsource( "./maintenance/indexes.sql", $wgDatabase );

print "Done.\nBrowse \"{$wgServer}{$wgScript}\" to test.\n";
exit();

#
# Functions used above:
#
function makedirectory( $d ) {
	global $wgInstallOwner, $wgInstallGroup;

	if ( is_dir( $d ) ) {
		print "Directory \"{$d}\" exists.\n";
	} else {
		if ( mkdir( $d, 0777 ) ) {
			if ( isset( $wgInstallOwner ) ) { chown( $d, $wgInstallOwner ); }
			if ( isset( $wgInstallGroup ) ) { chgrp( $d, $wgInstallGroup ); }
			print "Directory \"{$d}\" created.\n";
		} else {
			print "Could not create directory \"{$d}\".\n";
			exit();
		}
	}
}


function populatedata() {
	global $wgDBadminpassword, $wgDatabase;
	$fname = "Installation script: populatedata()";

	$sql = "DELETE FROM site_stats";
	$wgDatabase->query( $sql, $fname );

	$sql = "INSERT INTO site_stats (ss_row_id,ss_total_views," .
		"ss_total_edits,ss_good_articles) VALUES (1,0,0,0)";
	$wgDatabase->query( $sql, $fname );

	$sql = "DELETE FROM user";
	$wgDatabase->query( $sql, $fname );

	print "Do you want to create a sysop account? A sysop can protect,\n";
	print "delete and undelete pages and ban users. Recomended. [Y/n] ";
	$response = readconsole();
	if(strtolower($response)!="n") {
		print "Enter the username [Sysop]: ";
		$sysop_user=readconsole();
		if(!$sysop_user) { $sysop_user="Sysop"; }
		while(!$sysop_password) {
			print "Enter the password: ";
			$sysop_password=readconsole();
		}
		$u = User::newFromName( $sysop_user );
		if ( 0 == $u->idForName() ) {
			$u->addToDatabase();
			$u->setPassword( $sysop_password );
			$u->addRight( "sysop" );
			$u->saveSettings();
		} else {
			print "Could not create user - already exists!\n";
		}
	}
	print "Do you want to create a sysop+developer account? A developer\n";
	print "can switch the database to read-only mode and run any type of\n";
	print "query through a web interface. [Y/n] ";
	$response=readconsole();
	if(strtolower($response)!="n") {
		print "Enter the username [Developer]: ";
		$developer_user=readconsole();
		if(!$developer_user) { $developer_user="Developer"; }
		while (!$developer_password) {
			print "Enter the password: ";
			$developer_password=readconsole();
		}		
		$u = User::newFromName( $developer_user );
		if ( 0 == $u->idForName() ) {
			$u->addToDatabase();
			$u->setPassword( $developer_password );
			$u->addRight( "sysop" );
			$u->addRight( "developer" );
			$u->saveSettings();
		} else {
			print "Could not create user - already exists!\n";
		}
	}
	
	$wns = Namespace::getWikipedia();
	$ulp = addslashes( wfMsgNoDB( "uploadlogpage" ) );
	$dlp = addslashes( wfMsgNoDB( "dellogpage" ) );

	$sql = "DELETE FROM cur";
	$wgDatabase->query( $sql, $fname );

	$now = wfTimestampNow();
	$won = wfInvertTimestamp( $now );
	
	$sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
	  "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$ulp}','" .
	  wfStrencode( wfMsg( "uploadlogpagetext" ) ) . "','sysop','$now','$won','$now')";
	$wgDatabase->query( $sql, $fname );

	$sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text," .
	  "cur_restrictions,cur_timestamp,inverse_timestamp,cur_touched) VALUES ({$wns},'{$dlp}','" .
	  wfStrencode( wfMsg( "dellogpagetext" ) ) . "','sysop','$now','$won','$now')";
	$wgDatabase->query( $sql, $fname );
	
	$titleobj = Title::newFromText( wfMsgNoDB( "mainpage" ) );
	$title = $titleobj->getDBkey();
	$sql = "INSERT INTO cur (cur_namespace,cur_title,cur_text,cur_timestamp,inverse_timestamp,cur_touched) " .
	  "VALUES (0,'$title','" .
	  wfStrencode( wfMsg( "mainpagetext" ) ) . "','$now','$won','$now')";
	$wgDatabase->query( $sql, $fname );
	
	initialiseMessages();
}

?>