]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - index.php
Merge branch 'testing' into 0.9.x
[quix0rs-gnu-social.git] / index.php
index 215d1f676e1f28dca36c2ae360fef123a6665097..9501e2275da6d610b9263bcb5a9e911e721d64de 100644 (file)
--- a/index.php
+++ b/index.php
  * @category StatusNet
  * @package  StatusNet
  * @author   Brenda Wallace <shiny@cpan.org>
+ * @author   Brion Vibber <brion@pobox.com>
  * @author   Christopher Vollick <psycotica0@gmail.com>
  * @author   CiaranG <ciaran@ciarang.com>
  * @author   Craig Andrews <candrews@integralblue.com>
  * @author   Evan Prodromou <evan@controlezvous.ca>
  * @author   Gina Haeussge <osd@foosel.net>
+ * @author   James Walker <walkah@walkah.net>
  * @author   Jeffery To <jeffery.to@gmail.com>
  * @author   Mike Cochrane <mikec@mikenz.geek.nz>
  * @author   Robin Millette <millette@controlyourself.ca>
  * @author   Sarven Capadisli <csarven@controlyourself.ca>
  * @author   Tom Adams <tom@holizz.com>
+ * @author   Zach Copley <zach@status.net>
+ * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  *
  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
  */
@@ -37,6 +41,8 @@ define('INSTALLDIR', dirname(__FILE__));
 define('STATUSNET', true);
 define('LACONICA', true); // compatibility
 
+require_once INSTALLDIR . '/lib/common.php';
+
 $user = null;
 $action = null;
 
@@ -66,69 +72,52 @@ function getPath($req)
  */
 function handleError($error)
 {
-    try {
-
-        if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
-            return;
-        }
+    if ($error->getCode() == DB_DATAOBJECT_ERROR_NODATA) {
+        return;
+    }
 
-        $logmsg = "PEAR error: " . $error->getMessage();
-        if ($error instanceof PEAR_Exception && common_config('site', 'logdebug')) {
-            $logmsg .= " : ". $error->toText();
-        }
-        // DB queries often end up with a lot of newlines; merge to a single line
-        // for easier grepability...
-        $logmsg = str_replace("\n", " ", $logmsg);
-        common_log(LOG_ERR, $logmsg);
-
-        // @fixme backtrace output should be consistent with exception handling
-        if (common_config('site', 'logdebug')) {
-            $bt = $error->getTrace();
-            foreach ($bt as $n => $line) {
-                common_log(LOG_ERR, formatBacktraceLine($n, $line));
-            }
-        }
-        if ($error instanceof DB_DataObject_Error
-            || $error instanceof DB_Error
-            || ($error instanceof PEAR_Exception && $error->getCode() == -24)
-        ) {
-            //If we run into a DB error, assume we can't connect to the DB at all
-            //so set the current user to null, so we don't try to access the DB
-            //while rendering the error page.
-            global $_cur;
-            $_cur = null;
-
-            $msg = sprintf(
-                _(
-                    'The database for %s isn\'t responding correctly, '.
-                    'so the site won\'t work properly. '.
-                    'The site admins probably know about the problem, '.
-                    'but you can contact them at %s to make sure. '.
-                    'Otherwise, wait a few minutes and try again.'
-                ),
-                common_config('site', 'name'),
-                common_config('site', 'email')
-            );
-        } else {
-            $msg = _(
-                'An important error occured, probably related to email setup. '.
-                'Check logfiles for more info..'
-            );
+    $logmsg = "PEAR error: " . $error->getMessage();
+    if (common_config('site', 'logdebug')) {
+        $logmsg .= " : ". $error->getDebugInfo();
+    }
+    // DB queries often end up with a lot of newlines; merge to a single line
+    // for easier grepability...
+    $logmsg = str_replace("\n", " ", $logmsg);
+    common_log(LOG_ERR, $logmsg);
+
+    // @fixme backtrace output should be consistent with exception handling
+    if (common_config('site', 'logdebug')) {
+        $bt = $error->getBacktrace();
+        foreach ($bt as $n => $line) {
+            common_log(LOG_ERR, formatBacktraceLine($n, $line));
         }
-
-        $dac = new DBErrorAction($msg, 500);
-        $dac->showPage();
-
-    } catch (Exception $e) {
-        echo _('An error occurred.');
     }
+    if ($error instanceof DB_DataObject_Error
+        || $error instanceof DB_Error
+    ) {
+        $msg = sprintf(
+            _(
+                'The database for %s isn\'t responding correctly, '.
+                'so the site won\'t work properly. '.
+                'The site admins probably know about the problem, '.
+                'but you can contact them at %s to make sure. '.
+                'Otherwise, wait a few minutes and try again.'
+            ),
+            common_config('site', 'name'),
+            common_config('site', 'email')
+        );
+    } else {
+        $msg = _(
+            'An important error occured, probably related to email setup. '.
+            'Check logfiles for more info..'
+        );
+    }
+
+    $dac = new DBErrorAction($msg, 500);
+    $dac->showPage();
     exit(-1);
 }
 
-set_exception_handler('handleError');
-
-require_once INSTALLDIR . '/lib/common.php';
-
 /**
  * Format a backtrace line for debug output roughly like debug_print_backtrace() does.
  * Exceptions already have this built in, but PEAR error objects just give us the array.
@@ -200,7 +189,7 @@ function checkMirror($action_obj, $args)
 
 function isLoginAction($action)
 {
-    static $loginActions =  array('login', 'recoverpassword', 'api', 'doc', 'register', 'publicxrds');
+    static $loginActions =  array('login', 'recoverpassword', 'api', 'doc', 'register', 'publicxrds', 'otp', 'opensearch', 'rsd');
 
     $login = null;
 
@@ -221,12 +210,12 @@ function main()
         if ($_lighty_url['path'] != '/index.php' && $_lighty_url['path'] != '/') {
             $_lighty_path = preg_replace('/^'.preg_quote(common_config('site', 'path')).'\//', '', substr($_lighty_url['path'], 1));
             $_SERVER['QUERY_STRING'] = 'p='.$_lighty_path;
-            if ($_lighty_url['query']) {
+            if (isset($_lighty_url['query']) && $_lighty_url['query'] != '') {
                 $_SERVER['QUERY_STRING'] .= '&'.$_lighty_url['query'];
-            }
-            parse_str($_lighty_url['query'], $_lighty_query);
-            foreach ($_lighty_query as $key => $val) {
-                $_GET[$key] = $_REQUEST[$key] = $val;
+                parse_str($_lighty_url['query'], $_lighty_query);
+                foreach ($_lighty_query as $key => $val) {
+                    $_GET[$key] = $_REQUEST[$key] = $val;
+                }
             }
             $_GET['p'] = $_REQUEST['p'] = $_lighty_path;
         }
@@ -253,6 +242,10 @@ function main()
         return;
     }
 
+    // For database errors
+
+    PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handleError');
+
     // Make sure RW database is setup
 
     setupRW();
@@ -335,10 +328,10 @@ function main()
             $cac = new ClientErrorAction($cex->getMessage(), $cex->getCode());
             $cac->showPage();
         } catch (ServerException $sex) { // snort snort guffaw
-            $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode());
+            $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode(), $sex);
             $sac->showPage();
         } catch (Exception $ex) {
-            $sac = new ServerErrorAction($ex->getMessage());
+            $sac = new ServerErrorAction($ex->getMessage(), 500, $ex);
             $sac->showPage();
         }
     }