<?php
-/**
+/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009, StatusNet, Inc.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ *
* @category Installation
* @package Installation
+ *
+ * @author Adrian Lang <mail@adrianlang.de>
+ * @author Brenda Wallace <shiny@cpan.org>
+ * @author Brett Taylor <brett@webfroot.co.nz>
+ * @author Brion Vibber <brion@pobox.com>
+ * @author CiaranG <ciaran@ciarang.com>
+ * @author Craig Andrews <candrews@integralblue.com>
+ * @author Eric Helgeson <helfire@Erics-MBP.local>
+ * @author Evan Prodromou <evan@status.net>
+ * @author Robin Millette <millette@controlyourself.ca>
+ * @author Sarven Capadisli <csarven@status.net>
+ * @author Tom Adams <tom@holizz.com>
* @license GNU Affero General Public License http://www.gnu.org/licenses/
- *
+ * @version 0.9
+ * @link http://status.net
*/
-
-
define('INSTALLDIR', dirname(__FILE__));
),
);
-/**
+/**
* the actual installation.
* If call libraries are present, then install
- *
+ *
* @return void
*/
function main()
if (!checkPrereqs()) {
return;
}
-
- if ($_GET['checklibs']) {
+
+ if (!empty($_GET['checklibs'])) {
showLibs();
} else {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
}
}
+/**
+ * checks if an external libary is present
+ *
+ * @param string $external_library Name of library
+ *
+ * @return boolean indicates if library present
+ */
function haveExternalLibrary($external_library)
{
- if (isset($external_library['include']) && ! include_once $external_library['include'] ) {
+ if (isset($external_library['include']) && !haveIncludeFile($external_library['include'])) {
return false;
}
if (isset($external_library['check_function']) && ! function_exists($external_library['check_function'])) {
return true;
}
+// Attempt to include a PHP file and report if it worked, while
+// suppressing the annoying warning messages on failure.
+function haveIncludeFile($filename) {
+ $old = error_reporting(error_reporting() & ~E_WARNING);
+ $ok = include_once($filename);
+ error_reporting($old);
+ return $ok;
+}
+
+/**
+ * Check if all is ready for installation
+ *
+ * @return void
+ */
function checkPrereqs()
{
$pass = true;
printf('<p class="error">Cannot load required extension: <code>%s</code></p>', $req);
$pass = false;
}
- }
+ }
// Make sure we have at least one database module available
global $dbModules;
$missingExtensions = array();
$missingExtensions[] = $info['check_module'];
}
}
+
if (count($missingExtensions) == count($dbModules)) {
$req = implode(', ', $missingExtensions);
- printf('<p class="error">Cannot find mysql or pgsql extension. You need one or the other: <code>%s</code></p>', $req);
+ printf('<p class="error">Cannot find mysql or pgsql extension. You need one or the other.');
$pass = false;
}
-
+
if (!is_writable(INSTALLDIR)) {
printf('<p class="error">Cannot write config file to: <code>%s</code></p>', INSTALLDIR);
printf('<p>On your server, try this command: <code>chmod a+w %s</code>', INSTALLDIR);
return $pass;
}
+/**
+ * Checks if a php extension is both installed and loaded
+ *
+ * @param string $name of extension to check
+ *
+ * @return boolean whether extension is installed and loaded
+ */
function checkExtension($name)
{
- if (!extension_loaded($name)) {
- if (!@dl($name.'.so')) {
- return false;
- }
+ if (extension_loaded($name)) {
+ return true;
+ } elseif (function_exists('dl') && ini_get('enable_dl') && !ini_get('safe_mode')) {
+ // dl will throw a fatal error if it's disabled or we're in safe mode.
+ // More fun, it may not even exist under some SAPIs in 5.3.0 or later...
+ $soname = $name . '.' . PHP_SHLIB_SUFFIX;
+ if (PHP_SHLIB_SUFFIX == 'dll') {
+ $soname = "php_" . $soname;
+ }
+ return @dl($soname);
+ } else {
+ return false;
}
- return true;
}
+/**
+ * Show list of libraries
+ *
+ * @return void
+ */
function showLibs()
{
global $external_libraries;
$present_libraries=array();
$absent_libraries=array();
- foreach ($external_libraries as $external_library){
+ foreach ($external_libraries as $external_library) {
if (haveExternalLibrary($external_library)) {
$present_libraries[]=$external_library;
} else {
<h2>Absent Libraries</h2>
<ul id="absent_libraries">
E_O_T;
- foreach($absent_libraries as $library)
- {
+ foreach ($absent_libraries as $library) {
echo '<li>';
- if($library['url']){
+ if (isset($library['url'])) {
echo '<a href=">'.$library['url'].'">'.htmlentities($library['name']).'</a>';
- }else{
+ } else {
echo htmlentities($library['name']);
}
echo '<ul>';
- if($library['deb']){
+ if (isset($library['deb'])) {
echo '<li class="deb package">deb: <a href="apt:' . urlencode($library['deb']) . '">' . htmlentities($library['deb']) . '</a></li>';
}
- if($library['rpm']){
+ if (isset($library['rpm'])) {
echo '<li class="rpm package">rpm: ' . htmlentities($library['rpm']) . '</li>';
}
- if($library['pear']){
+ if (isset($library['pear'])) {
echo '<li class="pear package">pear: ' . htmlentities($library['pear']) . '</li>';
}
echo '</ul>';
<h2>Installed Libraries</h2>
<ul id="present_libraries">
E_O_T;
- foreach($present_libraries as $library)
- {
+ foreach ($present_libraries as $library) {
echo '<li>';
- if($library['url']){
+ if (isset($library['url'])) {
echo '<a href=">'.$library['url'].'">'.htmlentities($library['name']).'</a>';
- }else{
+ } else {
echo htmlentities($library['name']);
}
echo '</li>';
function updateStatus($status, $error=false)
{
- echo '<li ' . ($error) ? 'class="error"': '';
- echo ">$status</li>";
+ echo '<li' . ($error ? ' class="error"': '' ) . ">$status</li>";
}
function handlePost()
$fail = true;
}
-// if (empty($password)) {
-// updateStatus("No password specified.", true);
-// $fail = true;
-// }
-
if (empty($sitename)) {
updateStatus("No sitename specified.", true);
- $fail = true;
+ $fail = true;
}
- if($fail){
- showForm();
+ if ($fail) {
+ showForm();
return;
}
global $dbModules;
- $db = call_user_func($dbModules[$dbtype]['installer'],
- $host, $database, $username, $password);
+ $db = call_user_func($dbModules[$dbtype]['installer'], $host, $database, $username, $password);
if (!$db) {
// database connection failed, do not move on to create config file.
updateStatus("StatusNet has been installed at $link");
updateStatus("You can visit your <a href='$link'>new StatusNet site</a>.");
-?>
-
-<?php
}
-function pgsql_db_installer($host, $database, $username, $password) {
+function Pgsql_Db_installer($host, $database, $username, $password)
+{
$connstring = "dbname=$database host=$host user=$username";
//No password would mean trust authentication used.
if (empty($password)) {
$sqlUrl = "pgsql://$username@$host/$database";
- }
- else {
+ } else {
$sqlUrl = "pgsql://$username:$password@$host/$database";
}
return $db;
}
-function mysql_db_installer($host, $database, $username, $password) {
+function Mysql_Db_installer($host, $database, $username, $password)
+{
updateStatus("Starting installation...");
updateStatus("Checking database...");
/**
* Install schema into the database
*
- * @param filename $filename location of database schema file
- * @param conn $conn connection to database
- * @param type $type type of database, currently mysql or pgsql
+ * @param string $filename location of database schema file
+ * @param dbconn $conn connection to database
+ * @param string $type type of database, currently mysql or pgsql
+ *
* @return boolean - indicating success or failure
*/
-function runDbScript($filename, $conn, $type = 'mysql')
+function runDbScript($filename, $conn, $type = 'mysqli')
{
$sql = trim(file_get_contents($filename));
$stmts = explode(';', $sql);
}
// FIXME: use PEAR::DB or PDO instead of our own switch
switch ($type) {
- case 'mysql':
+ case 'mysqli':
$res = mysql_query($stmt, $conn);
if ($res === false) {
$error = mysql_error();