From: Mikael Nordfeldth Date: Thu, 14 Jan 2016 20:21:34 +0000 (+0100) Subject: ErrorAction to autodiscoverable file. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bc0a903bd4ba15f9050f623e599a02095c30442a;p=quix0rs-gnu-social.git ErrorAction to autodiscoverable file. --- diff --git a/lib/action.php b/lib/action.php index 68019ce108..71441a31ff 100644 --- a/lib/action.php +++ b/lib/action.php @@ -1457,6 +1457,8 @@ class Action extends HTMLOutputter // lawsuit break; default: common_log(LOG_ERR, 'Handled serverError ('._ve($code).') but cannot output into desired format ('._ve($this->format).'): '._ve($msg)); + $action = new ServerErrorAction($msg, $code); + $action->execute(); } exit((int)$code); @@ -1513,6 +1515,8 @@ class Action extends HTMLOutputter // lawsuit break; default: common_log(LOG_ERR, 'Handled clientError ('._ve($code).') but cannot output into desired format ('._ve($this->format).'): '._ve($msg)); + $action = new ClientErrorAction($msg, $code); + $action->execute(); } exit((int)$code); } diff --git a/lib/clienterroraction.php b/lib/clienterroraction.php index 37f722291e..c2e35e62ee 100644 --- a/lib/clienterroraction.php +++ b/lib/clienterroraction.php @@ -28,11 +28,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR . '/lib/error.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Class for displaying HTTP client errors diff --git a/lib/error.php b/lib/error.php deleted file mode 100644 index 03a1960c62..0000000000 --- a/lib/error.php +++ /dev/null @@ -1,122 +0,0 @@ - - * @author Zach Copley - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 - * @link http://status.net/ - * - * StatusNet - the distributed open-source microblogging tool - * Copyright (C) 2008, 2009, StatusNet, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -/** - * Base class for displaying HTTP errors - * - * @category Action - * @package StatusNet - * @author Zach Copley - * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 - * @link http://status.net/ - */ -class ErrorAction extends InfoAction -{ - static $status = array(); - - var $code = null; - var $message = null; - var $default = null; - - function __construct($message, $code, $output='php://output', $indent=null) - { - parent::__construct(null, $message, $output, $indent); - - $this->code = $code; - $this->message = $message; - $this->minimal = GNUsocial::isApi(); - - // XXX: hack alert: usually we aren't going to - // call this page directly, but because it's - // an action it needs an args array anyway - $this->prepare($_REQUEST); - } - - function showPage() - { - if (GNUsocial::isAjax()) { - $this->extraHeaders(); - $this->ajaxErrorMsg(); - exit(); - } if ($this->minimal) { - // Even more minimal -- we're in a machine API - // and don't want to flood the output. - $this->extraHeaders(); - $this->showContent(); - } else { - parent::showPage(); - } - - // We don't want to have any more output after this - exit(); - } - - /** - * Display content. - * - * @return nothing - */ - function showContent() - { - $this->element('div', array('class' => 'error'), $this->message); - } - - function showNoticeForm() - { - } - - /** - * Show an Ajax-y error message - * - * Goes back to the browser, where it's shown in a popup. - * - * @param string $msg Message to show - * - * @return void - */ - - function ajaxErrorMsg() - { - $this->startHTML('text/xml;charset=utf-8', true); - $this->elementStart('head'); - // TRANS: Page title after an AJAX error occurs on the send notice page. - $this->element('title', null, _('Ajax Error')); - $this->elementEnd('head'); - $this->elementStart('body'); - $this->element('p', array('id' => 'error'), $this->message); - $this->elementEnd('body'); - $this->endHTML(); - } -} diff --git a/lib/erroraction.php b/lib/erroraction.php new file mode 100644 index 0000000000..03a1960c62 --- /dev/null +++ b/lib/erroraction.php @@ -0,0 +1,122 @@ + + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + * + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2008, 2009, StatusNet, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +if (!defined('STATUSNET') && !defined('LACONICA')) { + exit(1); +} + +/** + * Base class for displaying HTTP errors + * + * @category Action + * @package StatusNet + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 + * @link http://status.net/ + */ +class ErrorAction extends InfoAction +{ + static $status = array(); + + var $code = null; + var $message = null; + var $default = null; + + function __construct($message, $code, $output='php://output', $indent=null) + { + parent::__construct(null, $message, $output, $indent); + + $this->code = $code; + $this->message = $message; + $this->minimal = GNUsocial::isApi(); + + // XXX: hack alert: usually we aren't going to + // call this page directly, but because it's + // an action it needs an args array anyway + $this->prepare($_REQUEST); + } + + function showPage() + { + if (GNUsocial::isAjax()) { + $this->extraHeaders(); + $this->ajaxErrorMsg(); + exit(); + } if ($this->minimal) { + // Even more minimal -- we're in a machine API + // and don't want to flood the output. + $this->extraHeaders(); + $this->showContent(); + } else { + parent::showPage(); + } + + // We don't want to have any more output after this + exit(); + } + + /** + * Display content. + * + * @return nothing + */ + function showContent() + { + $this->element('div', array('class' => 'error'), $this->message); + } + + function showNoticeForm() + { + } + + /** + * Show an Ajax-y error message + * + * Goes back to the browser, where it's shown in a popup. + * + * @param string $msg Message to show + * + * @return void + */ + + function ajaxErrorMsg() + { + $this->startHTML('text/xml;charset=utf-8', true); + $this->elementStart('head'); + // TRANS: Page title after an AJAX error occurs on the send notice page. + $this->element('title', null, _('Ajax Error')); + $this->elementEnd('head'); + $this->elementStart('body'); + $this->element('p', array('id' => 'error'), $this->message); + $this->elementEnd('body'); + $this->endHTML(); + } +} diff --git a/lib/servererroraction.php b/lib/servererroraction.php index c8e3067b82..2f9a6585c2 100644 --- a/lib/servererroraction.php +++ b/lib/servererroraction.php @@ -29,11 +29,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { - exit(1); -} - -require_once INSTALLDIR.'/lib/error.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Class for displaying HTTP server errors