var $logId;
/**
- * Should the exception use $wgOut to output the error ?
+ * Should the exception use $wgOut to output the error?
+ *
* @return bool
*/
function useOutputPage() {
}
/**
- * Can the extension use wfMsg() to get i18n messages ?
+ * Can the extension use wfMsg() to get i18n messages?
+ *
* @return bool
*/
function useMessageCache() {
/**
* Run hook to allow extensions to modify the text of the exception
*
- * @param $name String: class name of the exception
- * @param $args Array: arguments to pass to the callback functions
- * @return Mixed: string to output or null if any hook has been called
+ * @param $name string: class name of the exception
+ * @param $args array: arguments to pass to the callback functions
+ * @return string|null string to output or null if any hook has been called
*/
function runHooks( $name, $args = array() ) {
global $wgExceptionHooks;
/**
* Get a message from i18n
*
- * @param $key String: message name
- * @param $fallback String: default message if the message cache can't be
+ * @param $key string: message name
+ * @param $fallback string: default message if the message cache can't be
* called by the exception
* The function also has other parameters that are arguments for the message
- * @return String message with arguments replaced
+ * @return string message with arguments replaced
*/
function msg( $key, $fallback /*[, params...] */ ) {
$args = array_slice( func_get_args(), 2 );
* backtrace to the error, otherwise show a message to ask to set it to true
* to show that information.
*
- * @return String html to output
+ * @return string html to output
*/
function getHTML() {
global $wgShowExceptionDetails;
'</p><p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
"</p>\n";
} else {
- return
+ return
"<div class=\"errorbox\">" .
'[' . $this->getLogId() . '] ' .
- gmdate( 'Y-m-d H:i:s' ) .
+ gmdate( 'Y-m-d H:i:s' ) .
": Fatal exception of type " . get_class( $this ) . "</div>\n" .
"<!-- Set \$wgShowExceptionDetails = true; " .
"at the bottom of LocalSettings.php to show detailed " .
}
/**
+ * Get the text to display when reporting the error on the command line.
* If $wgShowExceptionDetails is true, return a text message with a
* backtrace to the error.
+ *
* @return string
*/
function getText() {
}
/**
- * Return titles of this error page
- * @return String
+ * Return the title of the page when reporting this error in a HTTP response.
+ *
+ * @return string
*/
function getPageTitle() {
return $this->msg( 'internalerror', "Internal error" );
}
+ /**
+ * Get a random ID for this error.
+ * This allows to link the exception to its correspoding log entry when
+ * $wgShowExceptionDetails is set to false.
+ *
+ * @return string
+ */
function getLogId() {
if ( $this->logId === null ) {
$this->logId = wfRandomString( 8 );
/**
* Return the requested URL and point to file and line number from which the
- * exception occured
+ * exception occurred
*
- * @return String
+ * @return string
*/
function getLogMessage() {
global $wgRequest;
return "[$id] $url Exception from line $line of $file: $message";
}
- /** Output the exception report using HTML */
+ /**
+ * Output the exception report using HTML.
+ */
function reportHTML() {
global $wgOut;
if ( $this->useOutputPage() ) {
$wgOut->output();
} else {
header( "Content-Type: text/html; charset=utf-8" );
+ echo "<!doctype html>\n" .
+ '<html><head>' .
+ '<title>' . htmlspecialchars( $this->getPageTitle() ) . '</title>' .
+ "</head><body>\n";
+
$hookResult = $this->runHooks( get_class( $this ) . "Raw" );
if ( $hookResult ) {
- die( $hookResult );
+ echo $hookResult;
+ } else {
+ echo $this->getHTML();
}
- echo $this->getHTML();
- die(1);
+ echo "</body></html>\n";
+ die( 1 );
}
}
}
/**
- * @static
+ * Check whether we are in command line mode or not to report the exception
+ * in the correct format.
+ *
* @return bool
*/
static function isCommandLine() {
/**
* Exception class which takes an HTML error message, and does not
* produce a backtrace. Replacement for OutputPage::fatalError().
+ *
+ * @since 1.7
* @ingroup Exception
*/
class FatalError extends MWException {
}
/**
- * An error page which can definitely be safely rendered using the OutputPage
+ * An error page which can definitely be safely rendered using the OutputPage.
+ *
+ * @since 1.7
* @ingroup Exception
*/
class ErrorPageError extends MWException {
* Show an error page on a badtitle.
* Similar to ErrorPage, but emit a 400 HTTP error code to let mobile
* browser it is not really a valid content.
+ *
+ * @since 1.19
+ * @ingroup Exception
*/
class BadTitleError extends ErrorPageError {
/**
* Show an error when a user tries to do something they do not have the necessary
* permissions for.
+ *
+ * @since 1.18
* @ingroup Exception
*/
class PermissionsError extends ErrorPageError {
/**
* Show an error when the wiki is locked/read-only and the user tries to do
- * something that requires write access
+ * something that requires write access.
+ *
+ * @since 1.18
* @ingroup Exception
*/
class ReadOnlyError extends ErrorPageError {
}
/**
- * Show an error when the user hits a rate limit
+ * Show an error when the user hits a rate limit.
+ *
+ * @since 1.18
* @ingroup Exception
*/
class ThrottledError extends ErrorPageError {
}
/**
- * Show an error when the user tries to do something whilst blocked
+ * Show an error when the user tries to do something whilst blocked.
+ *
+ * @since 1.18
* @ingroup Exception
*/
class UserBlockedError extends ErrorPageError {
* This is essentially an ErrorPageError exception which by default use the
* 'exception-nologin' as a title and 'exception-nologin-text' for the message.
* @see bug 37627
+ * @since 1.20
*
* @par Example:
* @code
* }
* @endcode
*
- * @param $reasonMsg A message key containing the reason for the error.
- * Optional, default: 'exception-nologin-text'
- * @param $titleMsg A message key to set the page title.
- * Optional, default: 'exception-nologin'
- * @param $params Parameters to wfMsg().
- * Optiona, default: null
+ * @ingroup Exception
*/
class UserNotLoggedIn extends ErrorPageError {
+ /**
+ * @param $reasonMsg A message key containing the reason for the error.
+ * Optional, default: 'exception-nologin-text'
+ * @param $titleMsg A message key to set the page title.
+ * Optional, default: 'exception-nologin'
+ * @param $params Parameters to wfMsg().
+ * Optiona, default: null
+ */
public function __construct(
$reasonMsg = 'exception-nologin-text',
$titleMsg = 'exception-nologin',
* Show an error that looks like an HTTP server error.
* Replacement for wfHttpError().
*
+ * @since 1.19
* @ingroup Exception
*/
class HttpError extends MWException {
/**
* Print a message, if possible to STDERR.
* Use this in command line mode only (see isCommandLine)
- * @param $message String Failure text
+ *
+ * @param $message string Failure text
*/
public static function printError( $message ) {
# NOTE: STDERR may not be available, especially if php-cgi is used from the command line (bug #15602).
/**
* Print a message after escaping it and converting newlines to <br>
- * Use this for non-command line failures
- * @param $message String Failure text
+ * Use this for non-command line failures.
+ *
+ * @param $message string Failure text
*/
private static function escapeEchoAndDie( $message ) {
echo nl2br( htmlspecialchars( $message ) ) . "\n";