2006-06-07 06:40:24 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* @defgroup Exception Exception
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
2007-04-21 12:42:27 +00:00
|
|
|
* MediaWiki exception
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Exception
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2008-03-21 16:56:44 +00:00
|
|
|
class MWException extends Exception {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should the exception use $wgOut to output the error ?
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function useOutputPage() {
|
2008-04-14 07:45:50 +00:00
|
|
|
return !empty( $GLOBALS['wgFullyInitialised'] ) &&
|
2008-04-16 16:17:44 +00:00
|
|
|
( !empty( $GLOBALS['wgArticle'] ) || ( !empty( $GLOBALS['wgOut'] ) && !$GLOBALS['wgOut']->isArticle() ) ) &&
|
|
|
|
|
!empty( $GLOBALS['wgTitle'] );
|
2006-06-07 06:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* Can the extension use wfMsg() to get i18n messages ?
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function useMessageCache() {
|
|
|
|
|
global $wgLang;
|
|
|
|
|
return is_object( $wgLang );
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* Run hook to allow extensions to modify the text of the exception
|
|
|
|
|
*
|
|
|
|
|
* @param String $name class name of the exception
|
|
|
|
|
* @param Array $args arguments to pass to the callback functions
|
|
|
|
|
* @return mixed string to output or null if any hook has been called
|
|
|
|
|
*/
|
2008-01-08 18:34:06 +00:00
|
|
|
function runHooks( $name, $args = array() ) {
|
|
|
|
|
global $wgExceptionHooks;
|
2008-04-14 07:45:50 +00:00
|
|
|
if( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) )
|
2008-01-08 18:34:06 +00:00
|
|
|
return; // Just silently ignore
|
|
|
|
|
if( !array_key_exists( $name, $wgExceptionHooks ) || !is_array( $wgExceptionHooks[ $name ] ) )
|
|
|
|
|
return;
|
|
|
|
|
$hooks = $wgExceptionHooks[ $name ];
|
|
|
|
|
$callargs = array_merge( array( $this ), $args );
|
|
|
|
|
|
|
|
|
|
foreach( $hooks as $hook ) {
|
|
|
|
|
if( is_string( $hook ) || ( is_array( $hook ) && count( $hook ) >= 2 && is_string( $hook[0] ) ) ) { //'function' or array( 'class', hook' )
|
|
|
|
|
$result = call_user_func_array( $hook, $callargs );
|
|
|
|
|
} else {
|
|
|
|
|
$result = null;
|
|
|
|
|
}
|
|
|
|
|
if( is_string( $result ) )
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* Get a message from i18n
|
|
|
|
|
*
|
|
|
|
|
* @param String $key message name
|
|
|
|
|
* @param String $fallback 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
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function msg( $key, $fallback /*[, params...] */ ) {
|
|
|
|
|
$args = array_slice( func_get_args(), 2 );
|
|
|
|
|
if ( $this->useMessageCache() ) {
|
|
|
|
|
return wfMsgReal( $key, $args );
|
|
|
|
|
} else {
|
|
|
|
|
return wfMsgReplaceArgs( $fallback, $args );
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-11 18:57:49 +00:00
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* If $wgShowExceptionDetails is true, return a HTML message with a
|
2008-03-21 16:56:44 +00:00
|
|
|
* backtrace to the error, otherwise show a message to ask to set it to true
|
|
|
|
|
* to show that information.
|
|
|
|
|
*
|
|
|
|
|
* @return String html to output
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function getHTML() {
|
2006-10-11 18:57:49 +00:00
|
|
|
global $wgShowExceptionDetails;
|
|
|
|
|
if( $wgShowExceptionDetails ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
return '<p>' . nl2br( htmlspecialchars( $this->getMessage() ) ) .
|
2006-10-11 18:57:49 +00:00
|
|
|
'</p><p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
|
|
|
|
|
"</p>\n";
|
|
|
|
|
} else {
|
|
|
|
|
return "<p>Set <b><tt>\$wgShowExceptionDetails = true;</tt></b> " .
|
2007-09-30 00:19:43 +00:00
|
|
|
"at the bottom of LocalSettings.php to show detailed " .
|
|
|
|
|
"debugging information.</p>";
|
2006-10-11 18:57:49 +00:00
|
|
|
}
|
2006-06-07 06:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
2008-04-14 07:45:50 +00:00
|
|
|
* If $wgShowExceptionDetails is true, return a text message with a
|
2008-03-21 16:56:44 +00:00
|
|
|
* backtrace to the error.
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function getText() {
|
2006-10-11 18:57:49 +00:00
|
|
|
global $wgShowExceptionDetails;
|
|
|
|
|
if( $wgShowExceptionDetails ) {
|
|
|
|
|
return $this->getMessage() .
|
|
|
|
|
"\nBacktrace:\n" . $this->getTraceAsString() . "\n";
|
|
|
|
|
} else {
|
2008-05-06 02:50:07 +00:00
|
|
|
return "Set \$wgShowExceptionDetails = true; " .
|
|
|
|
|
"in LocalSettings.php to show detailed debugging information.\n";
|
2006-10-11 18:57:49 +00:00
|
|
|
}
|
2006-06-07 06:40:24 +00:00
|
|
|
}
|
2007-04-21 12:42:27 +00:00
|
|
|
|
|
|
|
|
/* Return titles of this error page */
|
2006-06-07 06:40:24 +00:00
|
|
|
function getPageTitle() {
|
|
|
|
|
if ( $this->useMessageCache() ) {
|
|
|
|
|
return wfMsg( 'internalerror' );
|
|
|
|
|
} else {
|
|
|
|
|
global $wgSitename;
|
|
|
|
|
return "$wgSitename error";
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-21 12:42:27 +00:00
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* Return the requested URL and point to file and line number from which the
|
2007-04-21 12:42:27 +00:00
|
|
|
* exception occured
|
2008-03-21 16:56:44 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2007-04-21 12:42:27 +00:00
|
|
|
*/
|
2006-08-02 17:40:09 +00:00
|
|
|
function getLogMessage() {
|
2007-01-16 01:45:51 +00:00
|
|
|
global $wgRequest;
|
2006-08-02 17:40:09 +00:00
|
|
|
$file = $this->getFile();
|
|
|
|
|
$line = $this->getLine();
|
|
|
|
|
$message = $this->getMessage();
|
2007-01-16 01:45:51 +00:00
|
|
|
return $wgRequest->getRequestURL() . " Exception from line $line of $file: $message";
|
2006-08-02 17:40:09 +00:00
|
|
|
}
|
2007-04-21 12:42:27 +00:00
|
|
|
|
|
|
|
|
/** Output the exception report using HTML */
|
2006-06-07 06:40:24 +00:00
|
|
|
function reportHTML() {
|
|
|
|
|
global $wgOut;
|
|
|
|
|
if ( $this->useOutputPage() ) {
|
|
|
|
|
$wgOut->setPageTitle( $this->getPageTitle() );
|
2008-07-23 19:05:43 +00:00
|
|
|
$wgOut->setRobotPolicy( "noindex,nofollow" );
|
2006-06-07 06:40:24 +00:00
|
|
|
$wgOut->setArticleRelated( false );
|
|
|
|
|
$wgOut->enableClientCache( false );
|
|
|
|
|
$wgOut->redirect( '' );
|
|
|
|
|
$wgOut->clearHTML();
|
2008-01-08 18:34:06 +00:00
|
|
|
if( $hookResult = $this->runHooks( get_class( $this ) ) ) {
|
|
|
|
|
$wgOut->addHTML( $hookResult );
|
|
|
|
|
} else {
|
|
|
|
|
$wgOut->addHTML( $this->getHTML() );
|
|
|
|
|
}
|
2006-06-07 06:40:24 +00:00
|
|
|
$wgOut->output();
|
|
|
|
|
} else {
|
2008-01-08 18:34:06 +00:00
|
|
|
if( $hookResult = $this->runHooks( get_class( $this ) . "Raw" ) ) {
|
|
|
|
|
die( $hookResult );
|
|
|
|
|
}
|
2006-06-07 06:40:24 +00:00
|
|
|
echo $this->htmlHeader();
|
|
|
|
|
echo $this->getHTML();
|
|
|
|
|
echo $this->htmlFooter();
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-21 12:42:27 +00:00
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* Output a report about the exception and takes care of formatting.
|
2007-04-21 12:42:27 +00:00
|
|
|
* It will be either HTML or plain text based on $wgCommandLineMode.
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function report() {
|
|
|
|
|
global $wgCommandLineMode;
|
2008-07-07 03:31:00 +00:00
|
|
|
$log = $this->getLogMessage();
|
|
|
|
|
if ( $log ) {
|
|
|
|
|
wfDebugLog( 'exception', $log );
|
|
|
|
|
}
|
2006-06-07 06:40:24 +00:00
|
|
|
if ( $wgCommandLineMode ) {
|
2007-12-07 04:21:35 +00:00
|
|
|
fwrite( STDERR, $this->getText() );
|
2006-06-07 06:40:24 +00:00
|
|
|
} else {
|
|
|
|
|
$this->reportHTML();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* Send headers and output the beginning of the html page if not using
|
|
|
|
|
* $wgOut to output the exception.
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function htmlHeader() {
|
|
|
|
|
global $wgLogo, $wgSitename, $wgOutputEncoding;
|
|
|
|
|
|
|
|
|
|
if ( !headers_sent() ) {
|
|
|
|
|
header( 'HTTP/1.0 500 Internal Server Error' );
|
|
|
|
|
header( 'Content-type: text/html; charset='.$wgOutputEncoding );
|
|
|
|
|
/* Don't cache error pages! They cause no end of trouble... */
|
|
|
|
|
header( 'Cache-control: none' );
|
|
|
|
|
header( 'Pragma: nocache' );
|
|
|
|
|
}
|
|
|
|
|
$title = $this->getPageTitle();
|
|
|
|
|
echo "<html>
|
|
|
|
|
<head>
|
|
|
|
|
<title>$title</title>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1>
|
|
|
|
|
";
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-21 16:56:44 +00:00
|
|
|
/**
|
|
|
|
|
* print the end of the html page if not using $wgOut.
|
|
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
function htmlFooter() {
|
|
|
|
|
echo "</body></html>";
|
2006-07-11 17:40:11 +00:00
|
|
|
}
|
2006-06-07 06:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2006-07-11 17:40:11 +00:00
|
|
|
* Exception class which takes an HTML error message, and does not
|
2006-06-07 06:40:24 +00:00
|
|
|
* produce a backtrace. Replacement for OutputPage::fatalError().
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Exception
|
2006-06-07 06:40:24 +00:00
|
|
|
*/
|
|
|
|
|
class FatalError extends MWException {
|
|
|
|
|
function getHTML() {
|
|
|
|
|
return $this->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getText() {
|
|
|
|
|
return $this->getMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-20 08:55:14 +00:00
|
|
|
/**
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Exception
|
2007-04-20 08:55:14 +00:00
|
|
|
*/
|
2006-06-07 06:40:24 +00:00
|
|
|
class ErrorPageError extends MWException {
|
|
|
|
|
public $title, $msg;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2006-06-07 06:40:24 +00:00
|
|
|
/**
|
|
|
|
|
* Note: these arguments are keys into wfMsg(), not text!
|
|
|
|
|
*/
|
|
|
|
|
function __construct( $title, $msg ) {
|
|
|
|
|
$this->title = $title;
|
|
|
|
|
$this->msg = $msg;
|
|
|
|
|
parent::__construct( wfMsg( $msg ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function report() {
|
|
|
|
|
global $wgOut;
|
|
|
|
|
$wgOut->showErrorPage( $this->title, $this->msg );
|
|
|
|
|
$wgOut->output();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Install an exception handler for MediaWiki exception types.
|
|
|
|
|
*/
|
|
|
|
|
function wfInstallExceptionHandler() {
|
|
|
|
|
set_exception_handler( 'wfExceptionHandler' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Report an exception to the user
|
|
|
|
|
*/
|
|
|
|
|
function wfReportException( Exception $e ) {
|
2006-11-29 05:45:03 +00:00
|
|
|
if ( $e instanceof MWException ) {
|
2006-06-07 06:40:24 +00:00
|
|
|
try {
|
|
|
|
|
$e->report();
|
|
|
|
|
} catch ( Exception $e2 ) {
|
|
|
|
|
// Exception occurred from within exception handler
|
2006-07-11 17:40:11 +00:00
|
|
|
// Show a simpler error message for the original exception,
|
2006-06-07 06:40:24 +00:00
|
|
|
// don't try to invoke report()
|
|
|
|
|
$message = "MediaWiki internal error.\n\n" .
|
2006-07-11 17:40:11 +00:00
|
|
|
"Original exception: " . $e->__toString() .
|
|
|
|
|
"\n\nException caught inside exception handler: " .
|
2006-06-07 06:40:24 +00:00
|
|
|
$e2->__toString() . "\n";
|
|
|
|
|
|
|
|
|
|
if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) {
|
2007-12-06 21:07:49 +00:00
|
|
|
fwrite( STDERR, $message );
|
2006-06-07 06:40:24 +00:00
|
|
|
} else {
|
|
|
|
|
echo nl2br( htmlspecialchars( $message ) ). "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
echo $e->__toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Exception handler which simulates the appropriate catch() handling:
|
2006-07-11 17:40:11 +00:00
|
|
|
*
|
2006-06-07 06:40:24 +00:00
|
|
|
* try {
|
|
|
|
|
* ...
|
|
|
|
|
* } catch ( MWException $e ) {
|
|
|
|
|
* $e->report();
|
|
|
|
|
* } catch ( Exception $e ) {
|
|
|
|
|
* echo $e->__toString();
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
function wfExceptionHandler( $e ) {
|
|
|
|
|
global $wgFullyInitialised;
|
|
|
|
|
wfReportException( $e );
|
2007-04-21 12:42:27 +00:00
|
|
|
|
2006-06-07 06:40:24 +00:00
|
|
|
// Final cleanup, similar to wfErrorExit()
|
|
|
|
|
if ( $wgFullyInitialised ) {
|
|
|
|
|
try {
|
2006-07-14 05:35:31 +00:00
|
|
|
wfLogProfilingData(); // uses $wgRequest, hence the $wgFullyInitialised condition
|
2006-06-07 06:40:24 +00:00
|
|
|
} catch ( Exception $e ) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exit value should be nonzero for the benefit of shell jobs
|
|
|
|
|
exit( 1 );
|
|
|
|
|
}
|