From 02547dac72e11c4ee5932e6418e22d3600df0926 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 7 Jun 2006 06:40:24 +0000 Subject: [PATCH] Removed most exit() calls from the MediaWiki core, by replacing them with either a throw or by classic error checking. OutputPage::fatalError() and similar functions are deprecated, use either OutputPage::showFatalError() to return control or throw new FatalError() to relinquish it. Backwards compatibility of all interfaces has been maintained, thus extensions should continue to work and can be ported at a later date. --- includes/Article.php | 14 +- includes/BagOStuff.php | 26 +- includes/DatabaseFunctions.php | 2 +- includes/Exception.php | 365 +++++++++++++++-------------- includes/Export.php | 2 +- includes/FakeTitle.php | 2 +- includes/GlobalFunctions.php | 12 +- includes/Group.php | 6 +- includes/HistoryBlob.php | 2 +- includes/Hooks.php | 12 +- includes/Image.php | 20 +- includes/ImageGallery.php | 2 +- includes/ImagePage.php | 42 ++-- includes/Linker.php | 6 +- includes/LinksUpdate.php | 2 +- includes/MagicWord.php | 2 +- includes/MessageCache.php | 2 +- includes/OutputPage.php | 96 ++++---- includes/Parser.php | 6 +- includes/ProtectionForm.php | 7 +- includes/Revision.php | 4 +- includes/Sanitizer.php | 2 +- includes/Setup.php | 2 +- includes/Skin.php | 2 +- includes/SpecialContributions.php | 4 +- includes/SpecialEmailuser.php | 10 +- includes/SpecialLockdb.php | 2 +- includes/SpecialMovepage.php | 4 +- includes/SpecialPage.php | 2 +- includes/SpecialPreferences.php | 2 +- includes/SpecialRevisiondelete.php | 2 +- includes/SpecialUndelete.php | 4 +- includes/SpecialUnlockdb.php | 2 +- includes/SpecialUpload.php | 22 +- includes/SpecialUploadMogile.php | 14 +- includes/SpecialWhatlinkshere.php | 4 +- includes/Title.php | 2 +- includes/User.php | 6 +- includes/WebRequest.php | 6 +- includes/Wiki.php | 9 +- 40 files changed, 387 insertions(+), 346 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 1162a9c1d5..ecd5410528 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1464,7 +1464,7 @@ class Article { $wgOut->returnToMain( false, $rcTitle->getPrefixedText() ); } else { - $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' ); + $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' ); } } @@ -1477,7 +1477,7 @@ class Article { global $wgUser, $wgOut; if ( $wgUser->isAnon() ) { - $wgOut->errorpage( 'watchnologin', 'watchnologintext' ); + $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' ); return; } if ( wfReadOnly() ) { @@ -1525,7 +1525,7 @@ class Article { global $wgUser, $wgOut; if ( $wgUser->isAnon() ) { - $wgOut->errorpage( 'watchnologin', 'watchnologintext' ); + $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' ); return; } if ( wfReadOnly() ) { @@ -1658,7 +1658,7 @@ class Article { */ function flattenRestrictions( $limit ) { if( !is_array( $limit ) ) { - wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' ); + throw new MWException( 'Article::flattenRestrictions given non-array restriction set' ); } $bits = array(); ksort( $limit ); @@ -1705,7 +1705,7 @@ class Article { $conds = $this->mTitle->pageCond(); $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname ); if ( $latest === false ) { - $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); + $wgOut->showFatalError( wfMsg( 'cannotdelete' ) ); return; } @@ -1899,7 +1899,7 @@ class Article { $wgOut->returnToMain( false ); wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason)); } else { - $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); + $wgOut->showFatalError( wfMsg( 'cannotdelete' ) ); } } } @@ -2522,7 +2522,7 @@ class Article { $fname = 'Article::info'; if ( !$wgAllowPageInfo ) { - $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' ); + $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); return; } diff --git a/includes/BagOStuff.php b/includes/BagOStuff.php index ae5e6fd11c..c48aef9ef7 100644 --- a/includes/BagOStuff.php +++ b/includes/BagOStuff.php @@ -35,7 +35,7 @@ * @package MediaWiki * @abstract */ -class BagOStuff { +abstract class BagOStuff { var $debugmode; function BagOStuff() { @@ -212,7 +212,7 @@ CREATE TABLE objectcache ( * @abstract * @package MediaWiki */ -class SqlBagOStuff extends BagOStuff { +abstract class SqlBagOStuff extends BagOStuff { var $table; var $lastexpireall = 0; @@ -292,16 +292,9 @@ class SqlBagOStuff extends BagOStuff { function _blobencode($str) { return $str; } - function _doinsert($table, $vals) { - wfDie( 'abstract function SqlBagOStuff::_doinsert() must be defined' ); - } - function _doquery($sql) { - wfDie( 'abstract function SqlBagOStuff::_doquery() must be defined' ); - } - function _fetchrow($res) { - wfDie( 'abstract function SqlBagOStuff::_fetchrow() must be defined' ); - } + abstract function _doinsert($table, $vals); + abstract function _doquery($sql); function _freeresult($result) { /* stub */ @@ -313,13 +306,8 @@ class SqlBagOStuff extends BagOStuff { return 'unknown error'; } - function _maxdatetime() { - wfDie( 'abstract function SqlBagOStuff::_maxdatetime() must be defined' ); - } - - function _fromunixtime() { - wfDie( 'abstract function SqlBagOStuff::_fromunixtime() must be defined' ); - } + abstract function _maxdatetime(); + abstract function _fromunixtime($ts); function garbageCollect() { /* Ignore 99% of requests */ @@ -427,7 +415,7 @@ class MediaWikiBagOStuff extends SqlBagOStuff { /* This is actually a hack, we should be able to use Language classes here... or not */ if (!$dbw) - wfDie("Could not connect to database"); + throw new MWException("Could not connect to database"); $this->table = $dbw->tableName( $this->table ); $this->tableInitialised = true; } diff --git a/includes/DatabaseFunctions.php b/includes/DatabaseFunctions.php index 61ba5ba4e3..74b35a31bf 100644 --- a/includes/DatabaseFunctions.php +++ b/includes/DatabaseFunctions.php @@ -18,7 +18,7 @@ function wfQuery( $sql, $db, $fname = '' ) { global $wgOut; if ( !is_numeric( $db ) ) { # Someone has tried to call this the old way - $wgOut->fatalError( wfMsgNoDB( 'wrong_wfQuery_params', $db, $sql ) ); + throw new FatalError( wfMsgNoDB( 'wrong_wfQuery_params', $db, $sql ) ); } $c =& wfGetDB( $db ); if ( $c !== false ) { diff --git a/includes/Exception.php b/includes/Exception.php index 11bb5971d5..1e24515ba6 100644 --- a/includes/Exception.php +++ b/includes/Exception.php @@ -1,172 +1,193 @@ -useMessageCache() ) { - return wfMsgReal( $key, $args ); - } else { - return wfMsgReplaceArgs( $fallback, $args ); - } - } - - function getHTML() { - return '

' . htmlspecialchars( $this->getMessage() ) . - '

Backtrace:

' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) . - "

\n"; - } - - function getText() { - return $this->getMessage() . - "\nBacktrace:\n" . $this->getTraceAsString() . "\n"; - } - - function getPageTitle() { - if ( $this->useMessageCache() ) { - return wfMsg( 'internalerror' ); - } else { - global $wgSitename; - return "$wgSitename error"; - } - } - - function reportHTML() { - global $wgOut; - if ( $this->useOutputPage() ) { - $wgOut->setPageTitle( $this->getPageTitle() ); - $wgOut->setRobotpolicy( "noindex,nofollow" ); - $wgOut->setArticleRelated( false ); - $wgOut->enableClientCache( false ); - $wgOut->redirect( '' ); - $wgOut->clearHTML(); - $wgOut->addHTML( $this->getHTML() ); - $wgOut->output(); - } else { - echo $this->htmlHeader(); - echo $this->getHTML(); - echo $this->htmlFooter(); - } - } - - function reportText() { - echo $this->getText(); - } - - function report() { - global $wgCommandLineMode; - if ( $wgCommandLineMode ) { - $this->reportText(); - } else { - $this->reportHTML(); - } - } - - 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 " - - $title - - -

$title

- "; - } - - function htmlFooter() { - echo ""; - } -} - -/** - * Exception class which takes an HTML error message, and does not - * produce a backtrace. Replacement for OutputPage::fatalError(). - */ -class FatalError extends MWException { - function getHTML() { - return $this->getMessage(); - } - - function getText() { - return $this->getMessage(); - } -} - -/** - * Install an exception handler for MediaWiki exception types. - */ -function wfInstallExceptionHandler() { - set_exception_handler( 'wfExceptionHandler' ); -} - -/** - * Report an exception to the user - */ -function wfReportException( Exception $e ) { - if ( is_a( $e, 'MWException' ) ) { - try { - $e->report(); - } catch ( Exception $e2 ) { - // Exception occurred from within exception handler - // Show a simpler error message for the original exception, - // don't try to invoke report() - $message = "MediaWiki internal error.\n\n" . - "Original exception: " . $e->__toString() . - "\n\nException caught inside exception handler: " . - $e2->__toString() . "\n"; - - if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) { - echo $message; - } else { - echo nl2br( htmlspecialchars( $message ) ). "\n"; - } - } - } else { - echo $e->__toString(); - } -} - -/** - * Exception handler which simulates the appropriate catch() handling: - * - * try { - * ... - * } catch ( MWException $e ) { - * - * $e->report(); - * } catch ( Exception $e ) { - * echo $e->__toString(); - * } - */ -function wfExceptionHandler( $e ) { - wfReportException( $e ); - - // Final cleanup, similar to wfErrorExit() - try { - wfProfileClose(); - logProfilingData(); - } catch ( Exception $e ) {} - - // Exit value should be nonzero for the benefit of shell jobs - exit( 1 ); -} - -?> +useMessageCache() ) { + return wfMsgReal( $key, $args ); + } else { + return wfMsgReplaceArgs( $fallback, $args ); + } + } + + function getHTML() { + return '

' . htmlspecialchars( $this->getMessage() ) . + '

Backtrace:

' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) . + "

\n"; + } + + function getText() { + return $this->getMessage() . + "\nBacktrace:\n" . $this->getTraceAsString() . "\n"; + } + + function getPageTitle() { + if ( $this->useMessageCache() ) { + return wfMsg( 'internalerror' ); + } else { + global $wgSitename; + return "$wgSitename error"; + } + } + + function reportHTML() { + global $wgOut; + if ( $this->useOutputPage() ) { + $wgOut->setPageTitle( $this->getPageTitle() ); + $wgOut->setRobotpolicy( "noindex,nofollow" ); + $wgOut->setArticleRelated( false ); + $wgOut->enableClientCache( false ); + $wgOut->redirect( '' ); + $wgOut->clearHTML(); + $wgOut->addHTML( $this->getHTML() ); + $wgOut->output(); + } else { + echo $this->htmlHeader(); + echo $this->getHTML(); + echo $this->htmlFooter(); + } + } + + function reportText() { + echo $this->getText(); + } + + function report() { + global $wgCommandLineMode; + if ( $wgCommandLineMode ) { + $this->reportText(); + } else { + $this->reportHTML(); + } + } + + 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 " + + $title + + +

$title

+ "; + } + + function htmlFooter() { + echo ""; + } +} + +/** + * Exception class which takes an HTML error message, and does not + * produce a backtrace. Replacement for OutputPage::fatalError(). + */ +class FatalError extends MWException { + function getHTML() { + return $this->getMessage(); + } + + function getText() { + return $this->getMessage(); + } +} + +class ErrorPageError extends MWException { + public $title, $msg; + + /** + * 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 ) { + if ( is_a( $e, 'MWException' ) ) { + try { + $e->report(); + } catch ( Exception $e2 ) { + // Exception occurred from within exception handler + // Show a simpler error message for the original exception, + // don't try to invoke report() + $message = "MediaWiki internal error.\n\n" . + "Original exception: " . $e->__toString() . + "\n\nException caught inside exception handler: " . + $e2->__toString() . "\n"; + + if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) { + echo $message; + } else { + echo nl2br( htmlspecialchars( $message ) ). "\n"; + } + } + } else { + echo $e->__toString(); + } +} + +/** + * Exception handler which simulates the appropriate catch() handling: + * + * try { + * ... + * } catch ( MWException $e ) { + * $e->report(); + * } catch ( Exception $e ) { + * echo $e->__toString(); + * } + */ +function wfExceptionHandler( $e ) { + global $wgFullyInitialised; + wfReportException( $e ); + + // Final cleanup, similar to wfErrorExit() + if ( $wgFullyInitialised ) { + try { + wfProfileClose(); + logProfilingData(); // uses $wgRequest, hence the $wgFullyInitialised condition + } catch ( Exception $e ) {} + } + + // Exit value should be nonzero for the benefit of shell jobs + exit( 1 ); +} + +?> diff --git a/includes/Export.php b/includes/Export.php index 91eecfa191..88a83d9b2b 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -634,7 +634,7 @@ class DumpNamespaceFilter extends DumpFilter { $ns = intval( $key ); $this->namespaces[$ns] = true; } else { - wfDie( "Unrecognized namespace key '$key'\n" ); + throw new MWException( "Unrecognized namespace key '$key'\n" ); } } } diff --git a/includes/FakeTitle.php b/includes/FakeTitle.php index a6fd8401c3..ae05385ad2 100644 --- a/includes/FakeTitle.php +++ b/includes/FakeTitle.php @@ -4,7 +4,7 @@ * Fake title class that triggers an error if any members are called */ class FakeTitle { - function error() { wfDebugDieBacktrace( "Attempt to call member function of FakeTitle\n" ); } + function error() { throw new MWException( "Attempt to call member function of FakeTitle\n" ); } // PHP 5.1 method overload function __call( $name, $args ) { $this->error(); } diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index a94ed8aa59..ed412590b7 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -642,7 +642,7 @@ function wfErrorExit() { */ function wfDie( $msg='' ) { echo $msg; - die( -1 ); + die( 1 ); } /** @@ -665,7 +665,7 @@ function wfDebugDieBacktrace( $msg = '' ) { } echo $msg; echo wfReportTime()."\n"; - die( -1 ); + die( 1 ); } /** @@ -1364,7 +1364,7 @@ function wfTimestamp($outputtype=TS_UNIX,$ts=0) { case TS_ORACLE: return gmdate( 'd-M-y h.i.s A', $uts) . ' +00:00'; default: - wfDebugDieBacktrace( 'wfTimestamp() called with illegal output type.'); + throw new MWException( 'wfTimestamp() called with illegal output type.'); } } @@ -1605,7 +1605,7 @@ function wfEncryptPassword( $userid, $password ) { */ function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) { if ( is_null( $changed ) ) { - wfDebugDieBacktrace('GlobalFunctions::wfAppendToArrayIfNotDefault got null'); + throw new MWException('GlobalFunctions::wfAppendToArrayIfNotDefault got null'); } if ( $default[$key] !== $value ) { $changed[$key] = $value; @@ -1726,7 +1726,7 @@ function wfUsePHP( $req_ver ) { $php_ver = PHP_VERSION; if ( version_compare( $php_ver, (string)$req_ver, '<' ) ) - wfDebugDieBacktrace( "PHP $req_ver required--this is only $php_ver" ); + throw new MWException( "PHP $req_ver required--this is only $php_ver" ); } /** @@ -1746,7 +1746,7 @@ function wfUseMW( $req_ver ) { global $wgVersion; if ( version_compare( $wgVersion, (string)$req_ver, '<' ) ) - wfDebugDieBacktrace( "MediaWiki $req_ver required--this is only $wgVersion" ); + throw new MWException( "MediaWiki $req_ver required--this is only $wgVersion" ); } /** diff --git a/includes/Group.php b/includes/Group.php index f50f1908b9..cc94a6919e 100644 --- a/includes/Group.php +++ b/includes/Group.php @@ -90,7 +90,7 @@ class Group { /** Initialise a new row in the database */ function addToDatabase() { if ( Group::getStaticGroups() ) { - wfDebugDieBacktrace( "Can't modify groups in static mode" ); + throw new MWException( "Can't modify groups in static mode" ); } $fname = 'Group::addToDatabase'; @@ -110,7 +110,7 @@ class Group { global $wgMemc; if ( Group::getStaticGroups() ) { - wfDebugDieBacktrace( "Can't modify groups in static mode" ); + throw new MWException( "Can't modify groups in static mode" ); } if($this->id == 0) { return; } @@ -136,7 +136,7 @@ class Group { global $wgMemc; if ( Group::getStaticGroups() ) { - wfDebugDieBacktrace( "Can't modify groups in static mode" ); + throw new MWException( "Can't modify groups in static mode" ); } if($this->id == 0) { return; } diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php index 4dee4da5d1..8f5d362485 100644 --- a/includes/HistoryBlob.php +++ b/includes/HistoryBlob.php @@ -59,7 +59,7 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob function ConcatenatedGzipHistoryBlob() { if ( !function_exists( 'gzdeflate' ) ) { - wfDie( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" ); + throw new MWException( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" ); } } diff --git a/includes/Hooks.php b/includes/Hooks.php index fc408e8b36..4daffaf322 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -34,7 +34,7 @@ function wfRunHooks($event, $args = null) { $fname = 'wfRunHooks'; if (!is_array($wgHooks)) { - wfDebugDieBacktrace("Global hooks array is not an array!\n"); + throw new MWException("Global hooks array is not an array!\n"); return false; } @@ -43,7 +43,7 @@ function wfRunHooks($event, $args = null) { } if (!is_array($wgHooks[$event])) { - wfDebugDieBacktrace("Hooks array for event '$event' is not an array!\n"); + throw new MWException("Hooks array for event '$event' is not an array!\n"); return false; } @@ -62,7 +62,7 @@ function wfRunHooks($event, $args = null) { if (is_array($hook)) { if (count($hook) < 1) { - wfDebugDieBacktrace("Empty array in hooks for " . $event . "\n"); + throw new MWException("Empty array in hooks for " . $event . "\n"); } else if (is_object($hook[0])) { $object =& $wgHooks[$event][$index][0]; if (count($hook) < 2) { @@ -82,7 +82,7 @@ function wfRunHooks($event, $args = null) { } } else { var_dump( $wgHooks ); - wfDebugDieBacktrace("Unknown datatype in hooks for " . $event . "\n"); + throw new MWException("Unknown datatype in hooks for " . $event . "\n"); } } else if (is_string($hook)) { # functions look like strings, too $func = $hook; @@ -90,7 +90,7 @@ function wfRunHooks($event, $args = null) { $object =& $wgHooks[$event][$index]; $method = "on" . $event; } else { - wfDebugDieBacktrace("Unknown datatype in hooks for " . $event . "\n"); + throw new MWException("Unknown datatype in hooks for " . $event . "\n"); } /* We put the first data element on, if needed. */ @@ -119,7 +119,7 @@ function wfRunHooks($event, $args = null) { if (is_string($retval)) { global $wgOut; - $wgOut->fatalError($retval); + $wgOut->showFatalError($retval); return false; } else if (!$retval) { return false; diff --git a/includes/Image.php b/includes/Image.php index 8e6cf43273..9f4fc7f2d0 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -75,7 +75,7 @@ class Image function Image( $title ) { if( !is_object( $title ) ) { - wfDebugDieBacktrace( 'Image constructor given bogus title.' ); + throw new MWException( 'Image constructor given bogus title.' ); } $this->title =& $title; $this->name = $title->getDBkey(); @@ -994,7 +994,7 @@ class Image unlink( $thumbPath ); } else { // This should have been dealt with already - wfDebugDieBacktrace( "Directory where image should be: $thumbPath" ); + throw new MWException( "Directory where image should be: $thumbPath" ); } } // Rename the old image into the new location @@ -1270,16 +1270,24 @@ class Image } # img_name must be unique if ( !$db->indexUnique( 'image', 'img_name' ) && !$db->indexExists('image','PRIMARY') ) { - wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' ); + throw new MWException( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' ); } - #new fields must exist + # new fields must exist + # + # Not really, there's hundreds of checks like this that we could do and they're all pointless, because + # if the fields are missing, the database will loudly report a query error, the first time you try to do + # something. The only reason I put the above schema check in was because the absence of that particular + # index would lead to an annoying subtle bug. No error message, just some very odd behaviour on duplicate + # uploads. -- TS + /* if ( !$db->fieldExists( 'image', 'img_media_type' ) || !$db->fieldExists( 'image', 'img_metadata' ) || !$db->fieldExists( 'image', 'img_width' ) ) { - wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/update.php' ); - } + throw new MWException( 'Database schema not up to date, please run maintenance/update.php' ); + } + */ } /** diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index 53ecd86a6c..08528f50bb 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -1,6 +1,6 @@ setPagetitle( wfMsg( 'confirmdelete' ) ); if ( ( !is_null( $image ) ) && ( '' == trim( $image ) ) ) { - $wgOut->fatalError( wfMsg( 'cannotdelete' ) ); + $wgOut->showFatalError( wfMsg( 'cannotdelete' ) ); return; } @@ -464,7 +464,7 @@ END if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { $this->doDelete(); } else { - $wgOut->fatalError( wfMsg( 'sessionfailure' ) ); + $wgOut->showFatalError( wfMsg( 'sessionfailure' ) ); } return; } @@ -492,11 +492,11 @@ END if ( !is_null( $oldimage ) ) { if ( strlen( $oldimage ) < 16 ) { - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); return; } if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) { - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); return; } @@ -511,7 +511,9 @@ END ); wfPurgeSquidServers($urlArr); } - $this->doDeleteOldImage( $oldimage ); + if ( !$this->doDeleteOldImage( $oldimage ) ) { + return; + } $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) ); $deleted = $oldimage; } else { @@ -524,7 +526,7 @@ END $targetFile = "{$dest}/{$image}"; if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) { # If the deletion operation actually failed, bug out: - $wgOut->fileDeleteError( $targetFile ); + $wgOut->showFileDeleteError( $targetFile ); return; } $dbw->delete( 'image', array( 'img_name' => $image ) ); @@ -541,7 +543,9 @@ END # Purge archive URLs from the squid $urlArr = Array(); while ( $s = $dbw->fetchObject( $res ) ) { - $this->doDeleteOldImage( $s->oi_archive_name ); + if ( !$this->doDeleteOldImage( $s->oi_archive_name ) ) { + return; + } $urlArr[] = wfImageArchiveUrl( $s->oi_archive_name ); } @@ -581,6 +585,9 @@ END $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() ); } + /** + * @return success + */ function doDeleteOldImage( $oldimage ) { global $wgOut; @@ -598,11 +605,13 @@ END $targetFile = "{$archive}/{$oldimage}"; if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) { # If we actually have a file and can't delete it, throw an error. - $wgOut->fileDeleteError( "{$archive}/{$oldimage}" ); + $wgOut->showFileDeleteError( "{$archive}/{$oldimage}" ); + return false; } else { # Log the deletion $log = new LogPage( 'delete' ); $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) ); + return true; } } @@ -611,11 +620,11 @@ END $oldimage = $wgRequest->getText( 'oldimage' ); if ( strlen( $oldimage ) < 16 ) { - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); return; } if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) { - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); + $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) ); return; } @@ -624,7 +633,7 @@ END return; } if( $wgUser->isAnon() ) { - $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' ); + $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); return; } if ( ! $this->mTitle->userCanEdit() ) { @@ -635,7 +644,7 @@ END return $this->blockedIPpage(); } if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) { - $wgOut->errorpage( 'internalerror', 'sessionfailure' ); + $wgOut->showErrorPage( 'internalerror', 'sessionfailure' ); return; } $name = substr( $oldimage, 15 ); @@ -645,7 +654,7 @@ END $curfile = "{$dest}/{$name}"; if ( ! is_file( $curfile ) ) { - $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) ); + $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) ); return; } $oldver = wfTimestampNow() . "!{$name}"; @@ -654,11 +663,12 @@ END $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) ); if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) { - $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" ); + $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" ); return; } if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) { - $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile ); + $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile ); + return; } # Record upload and update metadata cache diff --git a/includes/Linker.php b/includes/Linker.php index 12cd4bc17d..8a1946261e 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -194,7 +194,7 @@ class Linker { # Fail gracefully if ( ! is_object($nt) ) { - # wfDebugDieBacktrace(); + # throw new MWException(); wfProfileOut( $fname ); return "{$prefix}{$text}{$trail}"; } @@ -343,7 +343,7 @@ class Linker { function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { # Fail gracefully if ( ! isset($nt) ) { - # wfDebugDieBacktrace(); + # throw new MWException(); return "{$prefix}{$text}{$trail}"; } @@ -658,7 +658,7 @@ class Linker { function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) { # Fail gracefully if ( ! isset($nt) ) { - # wfDebugDieBacktrace(); + # throw new MWException(); return "{$prefix}{$text}{$trail}"; } diff --git a/includes/LinksUpdate.php b/includes/LinksUpdate.php index 54728582dd..caa1c97689 100644 --- a/includes/LinksUpdate.php +++ b/includes/LinksUpdate.php @@ -44,7 +44,7 @@ class LinksUpdate { $this->mDb =& wfGetDB( DB_MASTER ); if ( !is_object( $title ) ) { - wfDebugDieBacktrace( "The calling convention to LinksUpdate::LinksUpdate() has changed. " . + throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " . "Please see Article::editUpdates() for an invocation example.\n" ); } $this->mTitle = $title; diff --git a/includes/MagicWord.php b/includes/MagicWord.php index a2e08f7c5e..e015bb7759 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -192,7 +192,7 @@ class MagicWord { global $wgMagicWords; if ( !is_array( $wgMagicWords ) ) { - wfDebugDieBacktrace( "Incorrect initialisation order, \$wgMagicWords does not exist\n" ); + throw new MWException( "Incorrect initialisation order, \$wgMagicWords does not exist\n" ); } if (!array_key_exists( $id, $wgMagicWords ) ) { $mw = new MagicWord(); diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 083e220570..ed9e5ec6da 100644 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -291,7 +291,7 @@ class MessageCache { $fname = 'MessageCache::loadFromDB'; $dbr =& wfGetDB( DB_SLAVE ); if ( !$dbr ) { - wfDebugDieBacktrace( 'Invalid database object' ); + throw new MWException( 'Invalid database object' ); } $conditions = array( 'page_is_redirect' => 0, 'page_namespace' => NS_MEDIAWIKI); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index e78c072a14..b717292d51 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1,6 +1,6 @@ mDebugtext .= 'Original title: ' . @@ -681,11 +681,13 @@ class OutputPage { $this->mBodytext = ''; $this->addWikiText( wfMsg( $msg ) ); $this->returnToMain( false ); - - $this->output(); - wfErrorExit(); } + /** @obsolete */ + function errorpage( $title, $msg ) { + throw new ErrorPageError( $title, $msg ); + } + /** * Display an error page indicating that a given version of MediaWiki is * required to use it @@ -779,34 +781,9 @@ class OutputPage { $this->returnToMain(); } + /** @obsolete */ function databaseError( $fname, $sql, $error, $errno ) { - global $wgUser, $wgCommandLineMode, $wgShowSQLErrors; - - $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) ); - $this->setRobotpolicy( 'noindex,nofollow' ); - $this->setArticleRelated( false ); - $this->enableClientCache( false ); - $this->mRedirect = ''; - - if( !$wgShowSQLErrors ) { - $sql = wfMsg( 'sqlhidden' ); - } - - if ( $wgCommandLineMode ) { - $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ), - htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) ); - } else { - $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ), - htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) ); - } - - if ( $wgCommandLineMode || !is_object( $wgUser )) { - print $msg."\n"; - wfErrorExit(); - } - $this->mBodytext = $msg; - $this->output(); - wfErrorExit(); + throw new MWException( "OutputPage::databaseError is obsolete\n" ); } function readOnlyPage( $source = null, $protected = false ) { @@ -857,36 +834,63 @@ class OutputPage { $this->returnToMain( false ); } - function fatalError( $message ) { + /** @obsolete */ + function fatalError( $message ) { + throw new FatalError( $message ); + } + + /** @obsolete */ + function unexpectedValueError( $name, $val ) { + throw new FatalError( wfMsg( 'unexpected', $name, $val ) ); + } + + /** @obsolete */ + function fileCopyError( $old, $new ) { + throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) ); + } + + /** @obsolete */ + function fileRenameError( $old, $new ) { + throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) ); + } + + /** @obsolete */ + function fileDeleteError( $name ) { + throw new FatalError( wfMsg( 'filedeleteerror', $name ) ); + } + + /** @obsolete */ + function fileNotFoundError( $name ) { + throw new FatalError( wfMsg( 'filenotfound', $name ) ); + } + + function showFatalError( $message ) { $this->setPageTitle( wfMsg( "internalerror" ) ); $this->setRobotpolicy( "noindex,nofollow" ); $this->setArticleRelated( false ); $this->enableClientCache( false ); $this->mRedirect = ''; - $this->mBodytext = $message; - $this->output(); - wfErrorExit(); } - function unexpectedValueError( $name, $val ) { - $this->fatalError( wfMsg( 'unexpected', $name, $val ) ); + function showUnexpectedValueError( $name, $val ) { + $this->showFatalError( wfMsg( 'unexpected', $name, $val ) ); } - function fileCopyError( $old, $new ) { - $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) ); + function showFileCopyError( $old, $new ) { + $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) ); } - function fileRenameError( $old, $new ) { - $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) ); + function showFileRenameError( $old, $new ) { + $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) ); } - function fileDeleteError( $name ) { - $this->fatalError( wfMsg( 'filedeleteerror', $name ) ); + function showFileDeleteError( $name ) { + $this->showFatalError( wfMsg( 'filedeleteerror', $name ) ); } - function fileNotFoundError( $name ) { - $this->fatalError( wfMsg( 'filenotfound', $name ) ); + function showFileNotFoundError( $name ) { + $this->showFatalError( wfMsg( 'filenotfound', $name ) ); } /** diff --git a/includes/Parser.php b/includes/Parser.php index 61de1bf1a1..d1f48cf082 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -471,7 +471,7 @@ class Parser $output = call_user_func_array( $this->mTagHooks[$tagName], array( $content, $params, $this ) ); } else { - wfDebugDieBacktrace( "Invalid call hook $element" ); + throw new MWException( "Invalid call hook $element" ); } } } else { @@ -1329,7 +1329,7 @@ class Parser $useLinkPrefixExtension = $wgContLang->linkPrefixExtension(); if( is_null( $this->mTitle ) ) { - wfDebugDieBacktrace( 'nooo' ); + throw new MWException( 'nooo' ); } $nottalk = !$this->mTitle->isTalkPage(); @@ -2119,7 +2119,7 @@ class Parser } break; default: - wfDebugDieBacktrace( "State machine error in $fname" ); + throw new MWException( "State machine error in $fname" ); } } if( $stack > 0 ) { diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 1da49dc80e..2a40a37680 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -65,7 +65,7 @@ class ProtectionForm { if( is_null( $this->mTitle ) || !$this->mTitle->exists() || $this->mTitle->getNamespace() == NS_MEDIAWIKI ) { - $wgOut->fatalError( wfMsg( 'badarticleerror' ) ); + $wgOut->showFatalError( wfMsg( 'badarticleerror' ) ); return; } @@ -98,13 +98,12 @@ class ProtectionForm { $token = $wgRequest->getVal( 'wpEditToken' ); if( !$wgUser->matchEditToken( $token ) ) { - $wgOut->fatalError( wfMsg( 'sessionfailure' ) ); - return false; + throw new FatalError( wfMsg( 'sessionfailure' ) ); } $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason ); if( !$ok ) { - $wgOut->fatalError( "Unknown error at restriction save time." ); + throw new FatalError( "Unknown error at restriction save time." ); } return $ok; } diff --git a/includes/Revision.php b/includes/Revision.php index 3e3cef4338..b2f8e1890b 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -284,7 +284,7 @@ class Revision { $this->mTitle = null; # Load on demand if needed $this->mCurrent = false; } else { - wfDebugDieBacktrace( 'Revision constructor passed invalid row format.' ); + throw new MWException( 'Revision constructor passed invalid row format.' ); } } @@ -606,7 +606,7 @@ class Revision { $data = ExternalStore::insert( $store, $data ); if ( !$data ) { # This should only happen in the case of a configuration error, where the external store is not valid - wfDebugDieBacktrace( "Unable to store text to external storage $store" ); + throw new MWException( "Unable to store text to external storage $store" ); } if ( $flags ) { $flags .= ','; diff --git a/includes/Sanitizer.php b/includes/Sanitizer.php index ca7831acd2..00b96908dc 100644 --- a/includes/Sanitizer.php +++ b/includes/Sanitizer.php @@ -742,7 +742,7 @@ class Sanitizer { # For 'reduced' form, return explicitly the attribute name here. return $set[1]; } else { - wfDebugDieBacktrace( "Tag conditions not met. This should never happen and is a bug." ); + throw new MWException( "Tag conditions not met. This should never happen and is a bug." ); } } diff --git a/includes/Setup.php b/includes/Setup.php index b5480d65f2..acdca9c5a0 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -19,7 +19,7 @@ if( defined( 'MEDIAWIKI' ) ) { // Check to see if we are at the file scope if ( !isset( $wgVersion ) ) { echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n"; - die( -1 ); + die( 1 ); } if( !isset( $wgProfiling ) ) diff --git a/includes/Skin.php b/includes/Skin.php index 5bf36abec4..dc14640d1e 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1,6 +1,6 @@ getVal( 'target' ); if (!strlen($target)) { - $wgOut->errorpage('notargettitle', 'notargettext'); + $wgOut->showErrorPage('notargettitle', 'notargettext'); return; } $nt = Title::newFromURL( $target ); if (!$nt) { - $wgOut->errorpage( 'notargettitle', 'notargettext' ); + $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); return; } diff --git a/includes/SpecialEmailuser.php b/includes/SpecialEmailuser.php index 78ea5c3a92..c66389e103 100644 --- a/includes/SpecialEmailuser.php +++ b/includes/SpecialEmailuser.php @@ -14,13 +14,13 @@ function wfSpecialEmailuser( $par ) { global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgEnableUserEmail; if( !( $wgEnableEmail && $wgEnableUserEmail ) ) { - $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" ); + $wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" ); return; } if( !$wgUser->canSendEmail() ) { wfDebug( "User can't send.\n" ); - $wgOut->errorpage( "mailnologin", "mailnologintext" ); + $wgOut->showErrorPage( "mailnologin", "mailnologintext" ); return; } @@ -28,21 +28,21 @@ function wfSpecialEmailuser( $par ) { $target = isset($par) ? $par : $wgRequest->getVal( 'target' ); if ( "" == $target ) { wfDebug( "Target is empty.\n" ); - $wgOut->errorpage( "notargettitle", "notargettext" ); + $wgOut->showErrorPage( "notargettitle", "notargettext" ); return; } $nt = Title::newFromURL( $target ); if ( is_null( $nt ) ) { wfDebug( "Target is invalid title.\n" ); - $wgOut->errorpage( "notargettitle", "notargettext" ); + $wgOut->showErrorPage( "notargettitle", "notargettext" ); return; } $nu = User::newFromName( $nt->getText() ); if( is_null( $nu ) || !$nu->canReceiveEmail() ) { wfDebug( "Target is invalid user or can't receive.\n" ); - $wgOut->errorpage( "noemailtitle", "noemailtext" ); + $wgOut->showErrorPage( "noemailtitle", "noemailtext" ); return; } diff --git a/includes/SpecialLockdb.php b/includes/SpecialLockdb.php index 3c153f9388..38d715be36 100644 --- a/includes/SpecialLockdb.php +++ b/includes/SpecialLockdb.php @@ -94,7 +94,7 @@ END $fp = fopen( $wgReadOnlyFile, 'w' ); if ( false === $fp ) { - $wgOut->fileNotFoundError( $wgReadOnlyFile ); + $wgOut->showFileNotFoundError( $wgReadOnlyFile ); return; } fwrite( $fp, $this->reason ); diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 4f795c2b81..2c0720d38b 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -13,7 +13,7 @@ function wfSpecialMovepage( $par = null ) { # check rights. We don't want newbies to move pages to prevents possible attack if ( !$wgUser->isAllowed( 'move' ) or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) { - $wgOut->errorpage( "movenologin", "movenologintext" ); + $wgOut->showErrorPage( "movenologin", "movenologintext" ); return; } # We don't move protected pages @@ -60,7 +60,7 @@ class MovePageForm { $ot = Title::newFromURL( $this->oldTitle ); if( is_null( $ot ) ) { - $wgOut->errorpage( 'notargettitle', 'notargettext' ); + $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); return; } $oldTitle = $ot->getPrefixedText(); diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index ac7e0e275f..fc7efaf473 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -293,7 +293,7 @@ class SpecialPage $wgOut->setArticleRelated( false ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->setStatusCode( 404 ); - $wgOut->errorpage( 'nosuchspecialpage', 'nospecialpagetext' ); + $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' ); $retVal = false; } } diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index bccbc6e4b5..1ade3079c5 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -104,7 +104,7 @@ class PreferencesForm { global $wgUser, $wgOut; if ( $wgUser->isAnon() ) { - $wgOut->errorpage( 'prefsnologin', 'prefsnologintext' ); + $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' ); return; } if ( wfReadOnly() ) { diff --git a/includes/SpecialRevisiondelete.php b/includes/SpecialRevisiondelete.php index cf37647357..f14e07bab5 100644 --- a/includes/SpecialRevisiondelete.php +++ b/includes/SpecialRevisiondelete.php @@ -19,7 +19,7 @@ function wfSpecialRevisiondelete( $par = null ) { $page = Title::newFromUrl( $target ); if( is_null( $page ) ) { - $wgOut->errorpage( 'notargettitle', 'notargettext' ); + $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); return; } diff --git a/includes/SpecialUndelete.php b/includes/SpecialUndelete.php index d167365d19..ade8d75414 100644 --- a/includes/SpecialUndelete.php +++ b/includes/SpecialUndelete.php @@ -28,7 +28,7 @@ class PageArchive { function PageArchive( &$title ) { if( is_null( $title ) ) { - wfDebugDieBacktrace( 'Archiver() given a null title.'); + throw new MWException( 'Archiver() given a null title.'); } $this->title =& $title; } @@ -566,7 +566,7 @@ class UndeleteForm { return true; } } - $wgOut->fatalError( wfMsg( "cannotundelete" ) ); + $wgOut->showFatalError( wfMsg( "cannotundelete" ) ); return false; } } diff --git a/includes/SpecialUnlockdb.php b/includes/SpecialUnlockdb.php index 9d138082a7..a10d1ee0a5 100644 --- a/includes/SpecialUnlockdb.php +++ b/includes/SpecialUnlockdb.php @@ -84,7 +84,7 @@ END return; } if ( @! unlink( $wgReadOnlyFile ) ) { - $wgOut->fileDeleteError( $wgReadOnlyFile ); + $wgOut->showFileDeleteError( $wgReadOnlyFile ); return; } $titleObj = Title::makeTitle( NS_SPECIAL, "Unlockdb" ); diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index e61f485394..7311721d90 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -99,7 +99,7 @@ class UploadForm { # Check uploading enabled if( !$wgEnableUploads ) { - $wgOut->errorPage( 'uploaddisabled', 'uploaddisabledtext' ); + $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' ); return; } @@ -110,7 +110,7 @@ class UploadForm { return; } } else { - $wgOut->errorPage( 'uploadnologin', 'uploadnologintext' ); + $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' ); return; } @@ -132,7 +132,9 @@ class UploadForm { } if( $this->mReUpload ) { - $this->unsaveUploadedFile(); + if ( !$this->unsaveUploadedFile() ) { + return; + } $this->mainUploadForm(); } else if ( 'submit' == $this->mAction || $this->mUpload ) { $this->processUpload(); @@ -343,7 +345,7 @@ class UploadForm { } else { // Image::recordUpload() fails if the image went missing, which is // unlikely, hence the lack of a specialised message - $wgOut->fileNotFoundError( $this->mUploadSaveName ); + $wgOut->showFileNotFoundError( $this->mUploadSaveName ); } } } @@ -376,7 +378,7 @@ class UploadForm { wfRestoreWarnings(); if( ! $success ) { - $wgOut->fileRenameError( $this->mSavedFile, + $wgOut->showFileRenameError( $this->mSavedFile, "${archive}/{$this->mUploadOldVersion}" ); return false; } @@ -393,7 +395,7 @@ class UploadForm { wfRestoreWarnings(); if( ! $success ) { - $wgOut->fileCopyError( $tempName, $this->mSavedFile ); + $wgOut->showFileCopyError( $tempName, $this->mSavedFile ); return false; } else { wfDebug("$fname: wrote tempfile $tempName to ".$this->mSavedFile."\n"); @@ -424,7 +426,7 @@ class UploadForm { ? rename( $tempName, $stash ) : move_uploaded_file( $tempName, $stash ); if ( !$success ) { - $wgOut->fileCopyError( $tempName, $stash ); + $wgOut->showFileCopyError( $tempName, $stash ); return false; } @@ -460,6 +462,7 @@ class UploadForm { /** * Remove a temporarily kept file stashed by saveTempUploadedFile(). * @access private + * @return success */ function unsaveUploadedFile() { global $wgOut; @@ -467,7 +470,10 @@ class UploadForm { $success = unlink( $this->mUploadTempName ); wfRestoreWarnings(); if ( ! $success ) { - $wgOut->fileDeleteError( $this->mUploadTempName ); + $wgOut->showFileDeleteError( $this->mUploadTempName ); + return false; + } else { + return true; } } diff --git a/includes/SpecialUploadMogile.php b/includes/SpecialUploadMogile.php index a303e8ce13..51a6dd28c5 100644 --- a/includes/SpecialUploadMogile.php +++ b/includes/SpecialUploadMogile.php @@ -42,7 +42,7 @@ class UploadFormMogile extends UploadForm { if( $mfs->getPaths( $this->mSavedFile )) { $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}"; if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) { - $wgOut->fileRenameError( $this->mSavedFile, + $wgOut->showFileRenameError( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ); return false; } @@ -52,12 +52,12 @@ class UploadFormMogile extends UploadForm { if ( $this->mStashed ) { if (!$mfs->rename($tempName,$this->mSavedFile)) { - $wgOut->fileRenameError($tempName, $this->mSavedFile ); + $wgOut->showFileRenameError($tempName, $this->mSavedFile ); return false; } } else { if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) { - $wgOut->fileCopyError( $tempName, $this->mSavedFile ); + $wgOut->showFileCopyError( $tempName, $this->mSavedFile ); return false; } unlink($tempName); @@ -83,7 +83,7 @@ class UploadFormMogile extends UploadForm { $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName; $mfs = MogileFS::NewMogileFS(); if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) { - $wgOut->fileCopyError( $tempName, $stash ); + $wgOut->showFileCopyError( $tempName, $stash ); return false; } unlink($tempName); @@ -119,12 +119,16 @@ class UploadFormMogile extends UploadForm { /** * Remove a temporarily kept file stashed by saveTempUploadedFile(). * @access private + * @return success */ function unsaveUploadedFile() { global $wgOut; $mfs = MogileFS::NewMogileFS(); if ( ! $mfs->delete( $this->mUploadTempName ) ) { - $wgOut->fileDeleteError( $this->mUploadTempName ); + $wgOut->showFileDeleteError( $this->mUploadTempName ); + return false; + } else { + return true; } } } diff --git a/includes/SpecialWhatlinkshere.php b/includes/SpecialWhatlinkshere.php index 41465ddf2d..7f072bd75c 100644 --- a/includes/SpecialWhatlinkshere.php +++ b/includes/SpecialWhatlinkshere.php @@ -43,13 +43,13 @@ class WhatLinksHerePage { $targetString = isset($this->par) ? $this->par : $this->request->getVal( 'target' ); if (is_null($targetString)) { - $wgOut->errorpage( 'notargettitle', 'notargettext' ); + $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); return; } $this->target = Title::newFromURL( $targetString ); if( !$this->target ) { - $wgOut->errorpage( 'notargettitle', 'notargettext' ); + $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); return; } $this->selfTitle = Title::makeTitleSafe( NS_SPECIAL, diff --git a/includes/Title.php b/includes/Title.php index 21676c01ad..82b5539536 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -109,7 +109,7 @@ class Title { $fname = 'Title::newFromText'; if( is_object( $text ) ) { - wfDebugDieBacktrace( 'Title::newFromText given an object' ); + throw new MWException( 'Title::newFromText given an object' ); } /** diff --git a/includes/User.php b/includes/User.php index 9aed0bf795..f695d1d2c9 100644 --- a/includes/User.php +++ b/includes/User.php @@ -1192,7 +1192,7 @@ class User { * @deprecated */ function isSysop() { - wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isSysop() method\n" ); + throw new MWException( "Call to deprecated (v1.7) User::isSysop() method\n" ); #return $this->isAllowed( 'protect' ); } @@ -1201,7 +1201,7 @@ class User { * @deprecated */ function isDeveloper() { - wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isDeveloper() method\n" ); + throw new MWException( "Call to deprecated (v1.7) User::isDeveloper() method\n" ); #return $this->isAllowed( 'siteadmin' ); } @@ -1210,7 +1210,7 @@ class User { * @deprecated */ function isBureaucrat() { - wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isBureaucrat() method\n" ); + throw new MWException( "Call to deprecated (v1.7) User::isBureaucrat() method\n" ); #return $this->isAllowed( 'makesysop' ); } diff --git a/includes/WebRequest.php b/includes/WebRequest.php index 736e215fdd..4031e369af 100644 --- a/includes/WebRequest.php +++ b/includes/WebRequest.php @@ -452,7 +452,7 @@ class FauxRequest extends WebRequest { if( is_array( $data ) ) { $this->data = $data; } else { - wfDebugDieBacktrace( "FauxRequest() got bogus data" ); + throw new MWException( "FauxRequest() got bogus data" ); } $this->wasPosted = $wasPosted; } @@ -479,11 +479,11 @@ class FauxRequest extends WebRequest { } function getRequestURL() { - wfDebugDieBacktrace( 'FauxRequest::getRequestURL() not implemented' ); + throw new MWException( 'FauxRequest::getRequestURL() not implemented' ); } function appendQuery( $query ) { - wfDebugDieBacktrace( 'FauxRequest::appendQuery() not implemented' ); + throw new MWException( 'FauxRequest::appendQuery() not implemented' ); } } diff --git a/includes/Wiki.php b/includes/Wiki.php index 682b76ac65..e9cdff49db 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -51,7 +51,7 @@ class MediaWiki { } elseif( is_string( $article ) ) { $output->redirect( $article ); } else { - wfDebugDieBacktrace( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" ); + throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" ); } } wfProfileOut( 'MediaWiki::initialize' ); @@ -129,7 +129,8 @@ class MediaWiki { wfSpecialSearch(); } else if( !$title or $title->getDBkey() == '' ) { $title = Title::newFromText( wfMsgForContent( 'badtitle' ) ); - $output->errorpage( 'badtitle', 'badtitletext' ); + # Die now before we mess up $wgArticle and the skin stops working + throw new ErrorPageError( 'badtitle', 'badtitletext' ); } else if ( $title->getInterwiki() != '' ) { if( $rdfrom = $request->getVal( 'rdfrom' ) ) { $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) ); @@ -141,7 +142,7 @@ class MediaWiki { $output->redirect( $url ); } else { $title = Title::newFromText( wfMsgForContent( 'badtitle' ) ); - $output->errorpage( 'badtitle', 'badtitletext' ); + throw new ErrorPageError( 'badtitle', 'badtitletext' ); } } else if ( ( $action == 'view' ) && (!isset( $this->GET['title'] ) || $title->getPrefixedDBKey() != $this->GET['title'] ) && @@ -392,7 +393,7 @@ class MediaWiki { break; default: if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) { - $output->errorpage( 'nosuchaction', 'nosuchactiontext' ); + $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); } } wfProfileOut( 'MediaWiki::performAction' ); -- 2.20.1