aboutsummaryrefslogtreecommitdiffstats
path: root/config/installer.php
blob: cb0c39f1666164334292e86461e9a247d370a369 (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
271
272
273
274
275
276
<?php

# MediaWiki web-based config/installation
# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
# http://www.mediawiki.org/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html


/**
 * This is to be the fancy new installer package for MediaWiki,
 * which will work with table prefixes, both MySQL and PostgreSQL, and
 * ideally such wacky things as text-based install as well as web.
 *
 * It's not done yet.
 *
 * @todo finish...
 * @package MediaWiki
 * @subpackage Installer
 */

$IP = ".."; # Just to suppress notices, not for anything useful
define( "MEDIAWIKI", true );
define( "MEDIAWIKI_INSTALL", true );
require_once( "../includes/Defines.php" );
require_once( "../includes/DefaultSettings.php" );
require_once( "../includes/MagicWord.php" );
require_once( "../includes/Namespace.php" );
require_once( "../install-utils.inc" );
require_once( "../maintenance/updaters.inc" );
require_once( "../maintenance/convertLinks.inc" );
require_once( "../maintenance/archives/moveCustomMessages.inc" );

class InstallInterface {
	function message( $text ) {
		echo $text . "\n";
	}
	
	function warning( $text ) {
		echo "** $text **\n";
	}
	
	function formatLink( $url, $text = '' ) {
		if( $text ) {
			return "$text ($url)";
		} else {
			return $url;
		}
	}
	
	function showHeader() {
		global $wgVersion;
		echo "MediaWiki $wgVersion installation\n\n";
	}
}

class Installer {
	var $settings = array();
	
	function Installer( &$interface ) {
		$this->ui =& $interface;
	}
	
	function runInstall() {
		$this->ui->showHeader();
		$this->preInstallChecks();
	}
	
	function override( $var, $value ) {
		$this->settings[$var] = $value;
	}
	
	function preInstallChecks() {
		$checks = array(
			'checkConfigured',
			'checkInstalled',
			'checkWritable',
			'checkPHP',
			'checkGlobals',
			'checkSafeMode',
			'checkSAPI',
			'checkMemory',
			'checkZlib',
			'checkImageMagick',
			'checkGD'
		);
		foreach( $checks as $check ) {
			if( !$this->$check() ) {
				$this->ui->warning( "Installation aborted." );
				return false;
			}
		}
	}
	
	function checkConfigured() {
		if( file_exists( "../LocalSettings.php" ) ) {
			$this->ui->warning( "Already configured." );
			return false;
		}
		return true;
	}
	
	function checkInstalled() {
		if( file_exists( "./LocalSettings.php" ) ) {
			$this->ui->warning( "Already configured; move LocalSettings.php from this directory to the parent dir and take the wiki for a spin." );
			return false;
		}
		return true;
	}
	
	function checkWritable() {
		if( !is_writable( "." ) ) {
			$this->ui->warning( "<h2>Can't write config file, aborting</h2>

	<p>In order to configure the wiki you have to make the <tt>config</tt> subdirectory
	writable by the web server. Once configuration is done you'll move the created
	<tt>LocalSettings.php</tt> to the parent directory, and for added safety you can
	then remove the <tt>config</tt> subdirectory entirely.</p>

	<p>To make the directory writable on a Unix/Linux system:</p>

	<pre>
	cd <i>/path/to/wiki</i>
	chmod a+w config
	</pre>" );

			return false;
		}
		return true;
	}
	
	function checkPHP() {
		$ver = phpversion();
		if( version_compare( $ver, "4.1.2", "lt" ) ) {
			$this->ui->warning( "Your version of PHP ($ver) is too old and will probably not work. We try to support 4.1.2 and above, but a current 4.3 or 5.0 release is preferred." );
			return false;
		}
		$this->ui->message( "PHP version $ver, ok" );
		if( version_compare( $ver, "gte", "5.0" ) ) {
			$this->ui->warning( "A PHP5-compatible version of the PHPTAL template system is not yet bundled. To get the regular default page layout, you will need to manually install a development snapshot. (The wiki will function normally using an older layout if you do not.)" );
		}
		return true;
	}
	
	function checkGlobals() {
		if( ini_get( 'register_globals' ) ) {
			$this->ui->warning( "PHP's " .
				$this->ui->formatLink( "http://php.net/register_globals", "register_globals" ) .
				"option is enabled." .
				"MediaWiki will work correctly, but this setting
	increases your exposure to potential security vulnerabilities in PHP-based
	software running on your server. <b>You should disable it if you are able.</b>" );
		}
		return true;
	}
	
	function checkSafeMode() {
		if( ini_get( 'safe_mode' ) ) {
			$this->ui->warning( "PHP's
	<a href='http://www.php.net/features.safe-mode'>safe mode</a> is active!</b>
	You will likely have problems caused by this. You may need to make the
	'images' subdirectory writable or specify a TMP environment variable pointing to
	a writable temporary directory owned by you, since safe mode breaks the system
	temporary directory." );
			$this->ui->message( "...due to safe mode restrictions, uploads will use flat directory mode if enabled." );
			$this->override( 'wgHashedUploadDirectory', true );
		} else {
			$this->ui->message( "PHP is not running in safe mode (this is good!)" );
			$this->ui->message( "...uploads will use hashed directory tree mode if enabled." );
		}
		return true;
	}
	
	function checkSAPI() {
		$sapi = php_sapi_name();
		$this->ui->message( "PHP server API is $sapi..." );
		switch( $sapi ) {
			case "apache":
			case "apache2handler":
				$this->ui->message( "...ok, using pretty URLs (<tt>index.php/Page_Title</tt>)" );
				break;
			case "cgi":
			case "cgi-fcgi":
			case "apache2filter":
				$this->ui->message( "using ugly URLs (<tt>index.php?title=Page_Title</tt>)" );
				$this->override( 'prettyURLs', false );
				# FIXME
				break;
			default:
				$this->ui->message( "unknown; using pretty URLs (<tt>index.php/Page_Title</tt>), if you have trouble change this in <tt>LocalSettings.php</tt>" );
		}
		return true;
	}
	
	function checkMemory() {
		$memlimit = ini_get( "memory_limit" );
		if( empty( $memlimit ) ) {
			$this->ui->message( "PHP is configured with no <tt>memory_limit</tt>." );
			return true;
		} else {
			$this->ui->message( "PHP's <tt>memory_limit</tt> is $memlimit... " );
			$n = IntVal( $memlimit );
			if( preg_match( '/^([0-9]+)[Mm]$/', trim( $memlimit ), $m ) ) {
				$n = IntVal( $m[1] * (1024*1024) );
			}
			if( $n < 20*1024*1024 ) {
				if( false === ini_set( "memory_limit", "20M" ) ) {
					$this->ui->warning( "...failed to raise the limit to 20M; you may have problems" );
				} else {
					$this->ui->message( "...raising limit to 20M" );
					$this->override( 'raiseMemory', true );
				}
			}
			return true;
		}
	}
	
	function checkZlib() {
		$zlib = function_exists( "gzencode" );
		if( $zlib ) {
			$this->ui->message( "Have zlib support; enabling output compression." );
			# This is a runtime thing, we're just letting the user know about it?
		} else {
			$this->ui->message( "No zlib support." );
		}
		return true;
	}
	
	function checkImageMagick() {
		$imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" );
		foreach( $imcheck as $dir ) {
			$im = "$dir/convert";
			if( file_exists( $im ) ) {
				$this->ui->message( "Found ImageMagick: <tt>$im</tt>; image thumbnailing will be enabled if you enable uploads." );
				$this->override( "wgImageMagick", $im );
				$this->override( "wgUseImageResize", true );
				break;
			}
		}
		return true;
	}
	
	function checkGD() {
		$gd = function_exists( "imagejpeg" );
		if( $gd ) {
			$this->ui->message( "Found GD graphics library built-in, image thumbnailing will be enabled if you enable uploads" );
			$this->override( "wgUseImageResize", true );
		} else {
			if( !isset( $this->settings['wgUseImageResize'] ) ) {
				$this->warning( "Couldn't find GD library or ImageMagick; image thumbnailing disabled." );
			}
		}
		return true;
	}
	
	
}

$ui =& new InstallInterface();
$i =& new Installer( $ui );
$i->runInstall();

?>