r14631 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14630‎ | r14631 | r14632 >
Date:06:40, 7 June 2006
Author:tstarling
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/BagOStuff.php (modified) (history)
  • /trunk/phase3/includes/DatabaseFunctions.php (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/Export.php (modified) (history)
  • /trunk/phase3/includes/FakeTitle.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Group.php (modified) (history)
  • /trunk/phase3/includes/HistoryBlob.php (modified) (history)
  • /trunk/phase3/includes/Hooks.php (modified) (history)
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/ImageGallery.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/LinksUpdate.php (modified) (history)
  • /trunk/phase3/includes/MagicWord.php (modified) (history)
  • /trunk/phase3/includes/MessageCache.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Parser.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/Revision.php (modified) (history)
  • /trunk/phase3/includes/Sanitizer.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SpecialContributions.php (modified) (history)
  • /trunk/phase3/includes/SpecialEmailuser.php (modified) (history)
  • /trunk/phase3/includes/SpecialLockdb.php (modified) (history)
  • /trunk/phase3/includes/SpecialMovepage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPreferences.php (modified) (history)
  • /trunk/phase3/includes/SpecialRevisiondelete.php (modified) (history)
  • /trunk/phase3/includes/SpecialUndelete.php (modified) (history)
  • /trunk/phase3/includes/SpecialUnlockdb.php (modified) (history)
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/SpecialUploadMogile.php (modified) (history)
  • /trunk/phase3/includes/SpecialWhatlinkshere.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/includes/WebRequest.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialEmailuser.php
@@ -14,13 +14,13 @@
1515 global $wgUser, $wgOut, $wgRequest, $wgEnableEmail, $wgEnableUserEmail;
1616
1717 if( !( $wgEnableEmail && $wgEnableUserEmail ) ) {
18 - $wgOut->errorpage( "nosuchspecialpage", "nospecialpagetext" );
 18+ $wgOut->showErrorPage( "nosuchspecialpage", "nospecialpagetext" );
1919 return;
2020 }
2121
2222 if( !$wgUser->canSendEmail() ) {
2323 wfDebug( "User can't send.\n" );
24 - $wgOut->errorpage( "mailnologin", "mailnologintext" );
 24+ $wgOut->showErrorPage( "mailnologin", "mailnologintext" );
2525 return;
2626 }
2727
@@ -28,21 +28,21 @@
2929 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
3030 if ( "" == $target ) {
3131 wfDebug( "Target is empty.\n" );
32 - $wgOut->errorpage( "notargettitle", "notargettext" );
 32+ $wgOut->showErrorPage( "notargettitle", "notargettext" );
3333 return;
3434 }
3535
3636 $nt = Title::newFromURL( $target );
3737 if ( is_null( $nt ) ) {
3838 wfDebug( "Target is invalid title.\n" );
39 - $wgOut->errorpage( "notargettitle", "notargettext" );
 39+ $wgOut->showErrorPage( "notargettitle", "notargettext" );
4040 return;
4141 }
4242
4343 $nu = User::newFromName( $nt->getText() );
4444 if( is_null( $nu ) || !$nu->canReceiveEmail() ) {
4545 wfDebug( "Target is invalid user or can't receive.\n" );
46 - $wgOut->errorpage( "noemailtitle", "noemailtext" );
 46+ $wgOut->showErrorPage( "noemailtitle", "noemailtext" );
4747 return;
4848 }
4949
Index: trunk/phase3/includes/Parser.php
@@ -471,7 +471,7 @@
472472 $output = call_user_func_array( $this->mTagHooks[$tagName],
473473 array( $content, $params, $this ) );
474474 } else {
475 - wfDebugDieBacktrace( "Invalid call hook $element" );
 475+ throw new MWException( "Invalid call hook $element" );
476476 }
477477 }
478478 } else {
@@ -1329,7 +1329,7 @@
13301330 $useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
13311331
13321332 if( is_null( $this->mTitle ) ) {
1333 - wfDebugDieBacktrace( 'nooo' );
 1333+ throw new MWException( 'nooo' );
13341334 }
13351335 $nottalk = !$this->mTitle->isTalkPage();
13361336
@@ -2119,7 +2119,7 @@
21202120 }
21212121 break;
21222122 default:
2123 - wfDebugDieBacktrace( "State machine error in $fname" );
 2123+ throw new MWException( "State machine error in $fname" );
21242124 }
21252125 }
21262126 if( $stack > 0 ) {
Index: trunk/phase3/includes/Revision.php
@@ -284,7 +284,7 @@
285285 $this->mTitle = null; # Load on demand if needed
286286 $this->mCurrent = false;
287287 } else {
288 - wfDebugDieBacktrace( 'Revision constructor passed invalid row format.' );
 288+ throw new MWException( 'Revision constructor passed invalid row format.' );
289289 }
290290 }
291291
@@ -606,7 +606,7 @@
607607 $data = ExternalStore::insert( $store, $data );
608608 if ( !$data ) {
609609 # This should only happen in the case of a configuration error, where the external store is not valid
610 - wfDebugDieBacktrace( "Unable to store text to external storage $store" );
 610+ throw new MWException( "Unable to store text to external storage $store" );
611611 }
612612 if ( $flags ) {
613613 $flags .= ',';
Index: trunk/phase3/includes/User.php
@@ -1192,7 +1192,7 @@
11931193 * @deprecated
11941194 */
11951195 function isSysop() {
1196 - wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isSysop() method\n" );
 1196+ throw new MWException( "Call to deprecated (v1.7) User::isSysop() method\n" );
11971197 #return $this->isAllowed( 'protect' );
11981198 }
11991199
@@ -1201,7 +1201,7 @@
12021202 * @deprecated
12031203 */
12041204 function isDeveloper() {
1205 - wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isDeveloper() method\n" );
 1205+ throw new MWException( "Call to deprecated (v1.7) User::isDeveloper() method\n" );
12061206 #return $this->isAllowed( 'siteadmin' );
12071207 }
12081208
@@ -1210,7 +1210,7 @@
12111211 * @deprecated
12121212 */
12131213 function isBureaucrat() {
1214 - wfDebugDieBacktrace( "Call to deprecated (v1.7) User::isBureaucrat() method\n" );
 1214+ throw new MWException( "Call to deprecated (v1.7) User::isBureaucrat() method\n" );
12151215 #return $this->isAllowed( 'makesysop' );
12161216 }
12171217
Index: trunk/phase3/includes/ImagePage.php
@@ -7,7 +7,7 @@
88 *
99 */
1010 if( !defined( 'MEDIAWIKI' ) )
11 - die( -1 );
 11+ die( 1 );
1212
1313 require_once( 'Image.php' );
1414
@@ -453,7 +453,7 @@
454454 $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
455455 if ( ( !is_null( $image ) )
456456 && ( '' == trim( $image ) ) ) {
457 - $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
 457+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
458458 return;
459459 }
460460
@@ -464,7 +464,7 @@
465465 if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
466466 $this->doDelete();
467467 } else {
468 - $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
 468+ $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
469469 }
470470 return;
471471 }
@@ -492,11 +492,11 @@
493493
494494 if ( !is_null( $oldimage ) ) {
495495 if ( strlen( $oldimage ) < 16 ) {
496 - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
 496+ $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
497497 return;
498498 }
499499 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
500 - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
 500+ $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
501501 return;
502502 }
503503
@@ -511,7 +511,9 @@
512512 );
513513 wfPurgeSquidServers($urlArr);
514514 }
515 - $this->doDeleteOldImage( $oldimage );
 515+ if ( !$this->doDeleteOldImage( $oldimage ) ) {
 516+ return;
 517+ }
516518 $dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
517519 $deleted = $oldimage;
518520 } else {
@@ -524,7 +526,7 @@
525527 $targetFile = "{$dest}/{$image}";
526528 if( file_exists( $targetFile ) && ! @unlink( $targetFile ) ) {
527529 # If the deletion operation actually failed, bug out:
528 - $wgOut->fileDeleteError( $targetFile );
 530+ $wgOut->showFileDeleteError( $targetFile );
529531 return;
530532 }
531533 $dbw->delete( 'image', array( 'img_name' => $image ) );
@@ -541,7 +543,9 @@
542544 # Purge archive URLs from the squid
543545 $urlArr = Array();
544546 while ( $s = $dbw->fetchObject( $res ) ) {
545 - $this->doDeleteOldImage( $s->oi_archive_name );
 547+ if ( !$this->doDeleteOldImage( $s->oi_archive_name ) ) {
 548+ return;
 549+ }
546550 $urlArr[] = wfImageArchiveUrl( $s->oi_archive_name );
547551 }
548552
@@ -581,6 +585,9 @@
582586 $wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
583587 }
584588
 589+ /**
 590+ * @return success
 591+ */
585592 function doDeleteOldImage( $oldimage )
586593 {
587594 global $wgOut;
@@ -598,11 +605,13 @@
599606 $targetFile = "{$archive}/{$oldimage}";
600607 if( $oldimage != '' && file_exists( $targetFile ) && !@unlink( $targetFile ) ) {
601608 # If we actually have a file and can't delete it, throw an error.
602 - $wgOut->fileDeleteError( "{$archive}/{$oldimage}" );
 609+ $wgOut->showFileDeleteError( "{$archive}/{$oldimage}" );
 610+ return false;
603611 } else {
604612 # Log the deletion
605613 $log = new LogPage( 'delete' );
606614 $log->addEntry( 'delete', $this->mTitle, wfMsg('deletedrevision',$oldimage) );
 615+ return true;
607616 }
608617 }
609618
@@ -611,11 +620,11 @@
612621
613622 $oldimage = $wgRequest->getText( 'oldimage' );
614623 if ( strlen( $oldimage ) < 16 ) {
615 - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
 624+ $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
616625 return;
617626 }
618627 if ( strstr( $oldimage, "/" ) || strstr( $oldimage, "\\" ) ) {
619 - $wgOut->unexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
 628+ $wgOut->showUnexpectedValueError( 'oldimage', htmlspecialchars($oldimage) );
620629 return;
621630 }
622631
@@ -624,7 +633,7 @@
625634 return;
626635 }
627636 if( $wgUser->isAnon() ) {
628 - $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
 637+ $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
629638 return;
630639 }
631640 if ( ! $this->mTitle->userCanEdit() ) {
@@ -635,7 +644,7 @@
636645 return $this->blockedIPpage();
637646 }
638647 if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
639 - $wgOut->errorpage( 'internalerror', 'sessionfailure' );
 648+ $wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
640649 return;
641650 }
642651 $name = substr( $oldimage, 15 );
@@ -645,7 +654,7 @@
646655 $curfile = "{$dest}/{$name}";
647656
648657 if ( ! is_file( $curfile ) ) {
649 - $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
 658+ $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
650659 return;
651660 }
652661 $oldver = wfTimestampNow() . "!{$name}";
@@ -654,11 +663,12 @@
655664 $size = $dbr->selectField( 'oldimage', 'oi_size', array( 'oi_archive_name' => $oldimage ) );
656665
657666 if ( ! rename( $curfile, "${archive}/{$oldver}" ) ) {
658 - $wgOut->fileRenameError( $curfile, "${archive}/{$oldver}" );
 667+ $wgOut->showFileRenameError( $curfile, "${archive}/{$oldver}" );
659668 return;
660669 }
661670 if ( ! copy( "{$archive}/{$oldimage}", $curfile ) ) {
662 - $wgOut->fileCopyError( "${archive}/{$oldimage}", $curfile );
 671+ $wgOut->showFileCopyError( "${archive}/{$oldimage}", $curfile );
 672+ return;
663673 }
664674
665675 # Record upload and update metadata cache
Index: trunk/phase3/includes/Export.php
@@ -634,7 +634,7 @@
635635 $ns = intval( $key );
636636 $this->namespaces[$ns] = true;
637637 } else {
638 - wfDie( "Unrecognized namespace key '$key'\n" );
 638+ throw new MWException( "Unrecognized namespace key '$key'\n" );
639639 }
640640 }
641641 }
Index: trunk/phase3/includes/LinksUpdate.php
@@ -44,7 +44,7 @@
4545 $this->mDb =& wfGetDB( DB_MASTER );
4646
4747 if ( !is_object( $title ) ) {
48 - wfDebugDieBacktrace( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
 48+ throw new MWException( "The calling convention to LinksUpdate::LinksUpdate() has changed. " .
4949 "Please see Article::editUpdates() for an invocation example.\n" );
5050 }
5151 $this->mTitle = $title;
Index: trunk/phase3/includes/MessageCache.php
@@ -291,7 +291,7 @@
292292 $fname = 'MessageCache::loadFromDB';
293293 $dbr =& wfGetDB( DB_SLAVE );
294294 if ( !$dbr ) {
295 - wfDebugDieBacktrace( 'Invalid database object' );
 295+ throw new MWException( 'Invalid database object' );
296296 }
297297 $conditions = array( 'page_is_redirect' => 0,
298298 'page_namespace' => NS_MEDIAWIKI);
Index: trunk/phase3/includes/SpecialWhatlinkshere.php
@@ -43,13 +43,13 @@
4444 $targetString = isset($this->par) ? $this->par : $this->request->getVal( 'target' );
4545
4646 if (is_null($targetString)) {
47 - $wgOut->errorpage( 'notargettitle', 'notargettext' );
 47+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
4848 return;
4949 }
5050
5151 $this->target = Title::newFromURL( $targetString );
5252 if( !$this->target ) {
53 - $wgOut->errorpage( 'notargettitle', 'notargettext' );
 53+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
5454 return;
5555 }
5656 $this->selfTitle = Title::makeTitleSafe( NS_SPECIAL,
Index: trunk/phase3/includes/Article.php
@@ -1464,7 +1464,7 @@
14651465 $wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
14661466 }
14671467 else {
1468 - $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
 1468+ $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
14691469 }
14701470 }
14711471
@@ -1477,7 +1477,7 @@
14781478 global $wgUser, $wgOut;
14791479
14801480 if ( $wgUser->isAnon() ) {
1481 - $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
 1481+ $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
14821482 return;
14831483 }
14841484 if ( wfReadOnly() ) {
@@ -1525,7 +1525,7 @@
15261526 global $wgUser, $wgOut;
15271527
15281528 if ( $wgUser->isAnon() ) {
1529 - $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
 1529+ $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
15301530 return;
15311531 }
15321532 if ( wfReadOnly() ) {
@@ -1658,7 +1658,7 @@
16591659 */
16601660 function flattenRestrictions( $limit ) {
16611661 if( !is_array( $limit ) ) {
1662 - wfDebugDieBacktrace( 'Article::flattenRestrictions given non-array restriction set' );
 1662+ throw new MWException( 'Article::flattenRestrictions given non-array restriction set' );
16631663 }
16641664 $bits = array();
16651665 ksort( $limit );
@@ -1705,7 +1705,7 @@
17061706 $conds = $this->mTitle->pageCond();
17071707 $latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
17081708 if ( $latest === false ) {
1709 - $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
 1709+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
17101710 return;
17111711 }
17121712
@@ -1899,7 +1899,7 @@
19001900 $wgOut->returnToMain( false );
19011901 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
19021902 } else {
1903 - $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
 1903+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
19041904 }
19051905 }
19061906 }
@@ -2522,7 +2522,7 @@
25232523 $fname = 'Article::info';
25242524
25252525 if ( !$wgAllowPageInfo ) {
2526 - $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
 2526+ $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
25272527 return;
25282528 }
25292529
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -642,7 +642,7 @@
643643 */
644644 function wfDie( $msg='' ) {
645645 echo $msg;
646 - die( -1 );
 646+ die( 1 );
647647 }
648648
649649 /**
@@ -665,7 +665,7 @@
666666 }
667667 echo $msg;
668668 echo wfReportTime()."\n";
669 - die( -1 );
 669+ die( 1 );
670670 }
671671
672672 /**
@@ -1364,7 +1364,7 @@
13651365 case TS_ORACLE:
13661366 return gmdate( 'd-M-y h.i.s A', $uts) . ' +00:00';
13671367 default:
1368 - wfDebugDieBacktrace( 'wfTimestamp() called with illegal output type.');
 1368+ throw new MWException( 'wfTimestamp() called with illegal output type.');
13691369 }
13701370 }
13711371
@@ -1605,7 +1605,7 @@
16061606 */
16071607 function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) {
16081608 if ( is_null( $changed ) ) {
1609 - wfDebugDieBacktrace('GlobalFunctions::wfAppendToArrayIfNotDefault got null');
 1609+ throw new MWException('GlobalFunctions::wfAppendToArrayIfNotDefault got null');
16101610 }
16111611 if ( $default[$key] !== $value ) {
16121612 $changed[$key] = $value;
@@ -1726,7 +1726,7 @@
17271727 $php_ver = PHP_VERSION;
17281728
17291729 if ( version_compare( $php_ver, (string)$req_ver, '<' ) )
1730 - wfDebugDieBacktrace( "PHP $req_ver required--this is only $php_ver" );
 1730+ throw new MWException( "PHP $req_ver required--this is only $php_ver" );
17311731 }
17321732
17331733 /**
@@ -1746,7 +1746,7 @@
17471747 global $wgVersion;
17481748
17491749 if ( version_compare( $wgVersion, (string)$req_ver, '<' ) )
1750 - wfDebugDieBacktrace( "MediaWiki $req_ver required--this is only $wgVersion" );
 1750+ throw new MWException( "MediaWiki $req_ver required--this is only $wgVersion" );
17511751 }
17521752
17531753 /**
Index: trunk/phase3/includes/Group.php
@@ -90,7 +90,7 @@
9191 /** Initialise a new row in the database */
9292 function addToDatabase() {
9393 if ( Group::getStaticGroups() ) {
94 - wfDebugDieBacktrace( "Can't modify groups in static mode" );
 94+ throw new MWException( "Can't modify groups in static mode" );
9595 }
9696
9797 $fname = 'Group::addToDatabase';
@@ -110,7 +110,7 @@
111111 global $wgMemc;
112112
113113 if ( Group::getStaticGroups() ) {
114 - wfDebugDieBacktrace( "Can't modify groups in static mode" );
 114+ throw new MWException( "Can't modify groups in static mode" );
115115 }
116116 if($this->id == 0) { return; }
117117
@@ -136,7 +136,7 @@
137137 global $wgMemc;
138138
139139 if ( Group::getStaticGroups() ) {
140 - wfDebugDieBacktrace( "Can't modify groups in static mode" );
 140+ throw new MWException( "Can't modify groups in static mode" );
141141 }
142142 if($this->id == 0) { return; }
143143
Index: trunk/phase3/includes/DatabaseFunctions.php
@@ -18,7 +18,7 @@
1919 global $wgOut;
2020 if ( !is_numeric( $db ) ) {
2121 # Someone has tried to call this the old way
22 - $wgOut->fatalError( wfMsgNoDB( 'wrong_wfQuery_params', $db, $sql ) );
 22+ throw new FatalError( wfMsgNoDB( 'wrong_wfQuery_params', $db, $sql ) );
2323 }
2424 $c =& wfGetDB( $db );
2525 if ( $c !== false ) {
Index: trunk/phase3/includes/SpecialContributions.php
@@ -157,13 +157,13 @@
158158
159159 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
160160 if (!strlen($target)) {
161 - $wgOut->errorpage('notargettitle', 'notargettext');
 161+ $wgOut->showErrorPage('notargettitle', 'notargettext');
162162 return;
163163 }
164164
165165 $nt = Title::newFromURL( $target );
166166 if (!$nt) {
167 - $wgOut->errorpage( 'notargettitle', 'notargettext' );
 167+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
168168 return;
169169 }
170170
Index: trunk/phase3/includes/Sanitizer.php
@@ -742,7 +742,7 @@
743743 # For 'reduced' form, return explicitly the attribute name here.
744744 return $set[1];
745745 } else {
746 - wfDebugDieBacktrace( "Tag conditions not met. This should never happen and is a bug." );
 746+ throw new MWException( "Tag conditions not met. This should never happen and is a bug." );
747747 }
748748 }
749749
Index: trunk/phase3/includes/SpecialUploadMogile.php
@@ -42,7 +42,7 @@
4343 if( $mfs->getPaths( $this->mSavedFile )) {
4444 $this->mUploadOldVersion = gmdate( 'YmdHis' ) . "!{$saveName}";
4545 if( !$mfs->rename( $this->mSavedFile, "archive!{$this->mUploadOldVersion}" ) ) {
46 - $wgOut->fileRenameError( $this->mSavedFile,
 46+ $wgOut->showFileRenameError( $this->mSavedFile,
4747 "archive!{$this->mUploadOldVersion}" );
4848 return false;
4949 }
@@ -52,12 +52,12 @@
5353
5454 if ( $this->mStashed ) {
5555 if (!$mfs->rename($tempName,$this->mSavedFile)) {
56 - $wgOut->fileRenameError($tempName, $this->mSavedFile );
 56+ $wgOut->showFileRenameError($tempName, $this->mSavedFile );
5757 return false;
5858 }
5959 } else {
6060 if ( !$mfs->saveFile($this->mSavedFile,'normal',$tempName )) {
61 - $wgOut->fileCopyError( $tempName, $this->mSavedFile );
 61+ $wgOut->showFileCopyError( $tempName, $this->mSavedFile );
6262 return false;
6363 }
6464 unlink($tempName);
@@ -83,7 +83,7 @@
8484 $stash = 'stash!' . gmdate( "YmdHis" ) . '!' . $saveName;
8585 $mfs = MogileFS::NewMogileFS();
8686 if ( !$mfs->saveFile( $stash, 'normal', $tempName ) ) {
87 - $wgOut->fileCopyError( $tempName, $stash );
 87+ $wgOut->showFileCopyError( $tempName, $stash );
8888 return false;
8989 }
9090 unlink($tempName);
@@ -119,12 +119,16 @@
120120 /**
121121 * Remove a temporarily kept file stashed by saveTempUploadedFile().
122122 * @access private
 123+ * @return success
123124 */
124125 function unsaveUploadedFile() {
125126 global $wgOut;
126127 $mfs = MogileFS::NewMogileFS();
127128 if ( ! $mfs->delete( $this->mUploadTempName ) ) {
128 - $wgOut->fileDeleteError( $this->mUploadTempName );
 129+ $wgOut->showFileDeleteError( $this->mUploadTempName );
 130+ return false;
 131+ } else {
 132+ return true;
129133 }
130134 }
131135 }
Index: trunk/phase3/includes/MagicWord.php
@@ -192,7 +192,7 @@
193193 global $wgMagicWords;
194194
195195 if ( !is_array( $wgMagicWords ) ) {
196 - wfDebugDieBacktrace( "Incorrect initialisation order, \$wgMagicWords does not exist\n" );
 196+ throw new MWException( "Incorrect initialisation order, \$wgMagicWords does not exist\n" );
197197 }
198198 if (!array_key_exists( $id, $wgMagicWords ) ) {
199199 $mw = new MagicWord();
Index: trunk/phase3/includes/SpecialPage.php
@@ -293,7 +293,7 @@
294294 $wgOut->setArticleRelated( false );
295295 $wgOut->setRobotpolicy( 'noindex,nofollow' );
296296 $wgOut->setStatusCode( 404 );
297 - $wgOut->errorpage( 'nosuchspecialpage', 'nospecialpagetext' );
 297+ $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
298298 $retVal = false;
299299 }
300300 }
Index: trunk/phase3/includes/SpecialLockdb.php
@@ -94,7 +94,7 @@
9595 $fp = fopen( $wgReadOnlyFile, 'w' );
9696
9797 if ( false === $fp ) {
98 - $wgOut->fileNotFoundError( $wgReadOnlyFile );
 98+ $wgOut->showFileNotFoundError( $wgReadOnlyFile );
9999 return;
100100 }
101101 fwrite( $fp, $this->reason );
Index: trunk/phase3/includes/HistoryBlob.php
@@ -59,7 +59,7 @@
6060
6161 function ConcatenatedGzipHistoryBlob() {
6262 if ( !function_exists( 'gzdeflate' ) ) {
63 - wfDie( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
 63+ throw new MWException( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
6464 }
6565 }
6666
Index: trunk/phase3/includes/Wiki.php
@@ -51,7 +51,7 @@
5252 } elseif( is_string( $article ) ) {
5353 $output->redirect( $article );
5454 } else {
55 - wfDebugDieBacktrace( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
 55+ throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
5656 }
5757 }
5858 wfProfileOut( 'MediaWiki::initialize' );
@@ -129,7 +129,8 @@
130130 wfSpecialSearch();
131131 } else if( !$title or $title->getDBkey() == '' ) {
132132 $title = Title::newFromText( wfMsgForContent( 'badtitle' ) );
133 - $output->errorpage( 'badtitle', 'badtitletext' );
 133+ # Die now before we mess up $wgArticle and the skin stops working
 134+ throw new ErrorPageError( 'badtitle', 'badtitletext' );
134135 } else if ( $title->getInterwiki() != '' ) {
135136 if( $rdfrom = $request->getVal( 'rdfrom' ) ) {
136137 $url = $title->getFullURL( 'rdfrom=' . urlencode( $rdfrom ) );
@@ -141,7 +142,7 @@
142143 $output->redirect( $url );
143144 } else {
144145 $title = Title::newFromText( wfMsgForContent( 'badtitle' ) );
145 - $output->errorpage( 'badtitle', 'badtitletext' );
 146+ throw new ErrorPageError( 'badtitle', 'badtitletext' );
146147 }
147148 } else if ( ( $action == 'view' ) &&
148149 (!isset( $this->GET['title'] ) || $title->getPrefixedDBKey() != $this->GET['title'] ) &&
@@ -392,7 +393,7 @@
393394 break;
394395 default:
395396 if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
396 - $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
 397+ $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
397398 }
398399 }
399400 wfProfileOut( 'MediaWiki::performAction' );
Index: trunk/phase3/includes/SpecialMovepage.php
@@ -13,7 +13,7 @@
1414
1515 # check rights. We don't want newbies to move pages to prevents possible attack
1616 if ( !$wgUser->isAllowed( 'move' ) or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
17 - $wgOut->errorpage( "movenologin", "movenologintext" );
 17+ $wgOut->showErrorPage( "movenologin", "movenologintext" );
1818 return;
1919 }
2020 # We don't move protected pages
@@ -60,7 +60,7 @@
6161
6262 $ot = Title::newFromURL( $this->oldTitle );
6363 if( is_null( $ot ) ) {
64 - $wgOut->errorpage( 'notargettitle', 'notargettext' );
 64+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
6565 return;
6666 }
6767 $oldTitle = $ot->getPrefixedText();
Index: trunk/phase3/includes/SpecialRevisiondelete.php
@@ -19,7 +19,7 @@
2020 $page = Title::newFromUrl( $target );
2121
2222 if( is_null( $page ) ) {
23 - $wgOut->errorpage( 'notargettitle', 'notargettext' );
 23+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
2424 return;
2525 }
2626
Index: trunk/phase3/includes/OutputPage.php
@@ -1,6 +1,6 @@
22 <?php
33 if ( ! defined( 'MEDIAWIKI' ) )
4 - die( -1 );
 4+ die( 1 );
55 /**
66 * @package MediaWiki
77 */
@@ -666,7 +666,7 @@
667667 /**
668668 * Note: these arguments are keys into wfMsg(), not text!
669669 */
670 - function errorpage( $title, $msg ) {
 670+ function showErrorPage( $title, $msg ) {
671671 global $wgTitle;
672672
673673 $this->mDebugtext .= 'Original title: ' .
@@ -681,11 +681,13 @@
682682 $this->mBodytext = '';
683683 $this->addWikiText( wfMsg( $msg ) );
684684 $this->returnToMain( false );
 685+ }
685686
686 - $this->output();
687 - wfErrorExit();
 687+ /** @obsolete */
 688+ function errorpage( $title, $msg ) {
 689+ throw new ErrorPageError( $title, $msg );
688690 }
689 -
 691+
690692 /**
691693 * Display an error page indicating that a given version of MediaWiki is
692694 * required to use it
@@ -779,34 +781,9 @@
780782 $this->returnToMain();
781783 }
782784
 785+ /** @obsolete */
783786 function databaseError( $fname, $sql, $error, $errno ) {
784 - global $wgUser, $wgCommandLineMode, $wgShowSQLErrors;
785 -
786 - $this->setPageTitle( wfMsgNoDB( 'databaseerror' ) );
787 - $this->setRobotpolicy( 'noindex,nofollow' );
788 - $this->setArticleRelated( false );
789 - $this->enableClientCache( false );
790 - $this->mRedirect = '';
791 -
792 - if( !$wgShowSQLErrors ) {
793 - $sql = wfMsg( 'sqlhidden' );
794 - }
795 -
796 - if ( $wgCommandLineMode ) {
797 - $msg = wfMsgNoDB( 'dberrortextcl', htmlspecialchars( $sql ),
798 - htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
799 - } else {
800 - $msg = wfMsgNoDB( 'dberrortext', htmlspecialchars( $sql ),
801 - htmlspecialchars( $fname ), $errno, htmlspecialchars( $error ) );
802 - }
803 -
804 - if ( $wgCommandLineMode || !is_object( $wgUser )) {
805 - print $msg."\n";
806 - wfErrorExit();
807 - }
808 - $this->mBodytext = $msg;
809 - $this->output();
810 - wfErrorExit();
 787+ throw new MWException( "OutputPage::databaseError is obsolete\n" );
811788 }
812789
813790 function readOnlyPage( $source = null, $protected = false ) {
@@ -857,36 +834,63 @@
858835 $this->returnToMain( false );
859836 }
860837
861 - function fatalError( $message ) {
 838+ /** @obsolete */
 839+ function fatalError( $message ) {
 840+ throw new FatalError( $message );
 841+ }
 842+
 843+ /** @obsolete */
 844+ function unexpectedValueError( $name, $val ) {
 845+ throw new FatalError( wfMsg( 'unexpected', $name, $val ) );
 846+ }
 847+
 848+ /** @obsolete */
 849+ function fileCopyError( $old, $new ) {
 850+ throw new FatalError( wfMsg( 'filecopyerror', $old, $new ) );
 851+ }
 852+
 853+ /** @obsolete */
 854+ function fileRenameError( $old, $new ) {
 855+ throw new FatalError( wfMsg( 'filerenameerror', $old, $new ) );
 856+ }
 857+
 858+ /** @obsolete */
 859+ function fileDeleteError( $name ) {
 860+ throw new FatalError( wfMsg( 'filedeleteerror', $name ) );
 861+ }
 862+
 863+ /** @obsolete */
 864+ function fileNotFoundError( $name ) {
 865+ throw new FatalError( wfMsg( 'filenotfound', $name ) );
 866+ }
 867+
 868+ function showFatalError( $message ) {
862869 $this->setPageTitle( wfMsg( "internalerror" ) );
863870 $this->setRobotpolicy( "noindex,nofollow" );
864871 $this->setArticleRelated( false );
865872 $this->enableClientCache( false );
866873 $this->mRedirect = '';
867 -
868874 $this->mBodytext = $message;
869 - $this->output();
870 - wfErrorExit();
871875 }
872876
873 - function unexpectedValueError( $name, $val ) {
874 - $this->fatalError( wfMsg( 'unexpected', $name, $val ) );
 877+ function showUnexpectedValueError( $name, $val ) {
 878+ $this->showFatalError( wfMsg( 'unexpected', $name, $val ) );
875879 }
876880
877 - function fileCopyError( $old, $new ) {
878 - $this->fatalError( wfMsg( 'filecopyerror', $old, $new ) );
 881+ function showFileCopyError( $old, $new ) {
 882+ $this->showFatalError( wfMsg( 'filecopyerror', $old, $new ) );
879883 }
880884
881 - function fileRenameError( $old, $new ) {
882 - $this->fatalError( wfMsg( 'filerenameerror', $old, $new ) );
 885+ function showFileRenameError( $old, $new ) {
 886+ $this->showFatalError( wfMsg( 'filerenameerror', $old, $new ) );
883887 }
884888
885 - function fileDeleteError( $name ) {
886 - $this->fatalError( wfMsg( 'filedeleteerror', $name ) );
 889+ function showFileDeleteError( $name ) {
 890+ $this->showFatalError( wfMsg( 'filedeleteerror', $name ) );
887891 }
888892
889 - function fileNotFoundError( $name ) {
890 - $this->fatalError( wfMsg( 'filenotfound', $name ) );
 893+ function showFileNotFoundError( $name ) {
 894+ $this->showFatalError( wfMsg( 'filenotfound', $name ) );
891895 }
892896
893897 /**
Index: trunk/phase3/includes/Setup.php
@@ -19,7 +19,7 @@
2020 // Check to see if we are at the file scope
2121 if ( !isset( $wgVersion ) ) {
2222 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
23 - die( -1 );
 23+ die( 1 );
2424 }
2525
2626 if( !isset( $wgProfiling ) )
Index: trunk/phase3/includes/SpecialUndelete.php
@@ -28,7 +28,7 @@
2929
3030 function PageArchive( &$title ) {
3131 if( is_null( $title ) ) {
32 - wfDebugDieBacktrace( 'Archiver() given a null title.');
 32+ throw new MWException( 'Archiver() given a null title.');
3333 }
3434 $this->title =& $title;
3535 }
@@ -566,7 +566,7 @@
567567 return true;
568568 }
569569 }
570 - $wgOut->fatalError( wfMsg( "cannotundelete" ) );
 570+ $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
571571 return false;
572572 }
573573 }
Index: trunk/phase3/includes/FakeTitle.php
@@ -4,7 +4,7 @@
55 * Fake title class that triggers an error if any members are called
66 */
77 class FakeTitle {
8 - function error() { wfDebugDieBacktrace( "Attempt to call member function of FakeTitle\n" ); }
 8+ function error() { throw new MWException( "Attempt to call member function of FakeTitle\n" ); }
99
1010 // PHP 5.1 method overload
1111 function __call( $name, $args ) { $this->error(); }
Index: trunk/phase3/includes/SpecialUpload.php
@@ -99,7 +99,7 @@
100100
101101 # Check uploading enabled
102102 if( !$wgEnableUploads ) {
103 - $wgOut->errorPage( 'uploaddisabled', 'uploaddisabledtext' );
 103+ $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
104104 return;
105105 }
106106
@@ -110,7 +110,7 @@
111111 return;
112112 }
113113 } else {
114 - $wgOut->errorPage( 'uploadnologin', 'uploadnologintext' );
 114+ $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
115115 return;
116116 }
117117
@@ -132,7 +132,9 @@
133133 }
134134
135135 if( $this->mReUpload ) {
136 - $this->unsaveUploadedFile();
 136+ if ( !$this->unsaveUploadedFile() ) {
 137+ return;
 138+ }
137139 $this->mainUploadForm();
138140 } else if ( 'submit' == $this->mAction || $this->mUpload ) {
139141 $this->processUpload();
@@ -343,7 +345,7 @@
344346 } else {
345347 // Image::recordUpload() fails if the image went missing, which is
346348 // unlikely, hence the lack of a specialised message
347 - $wgOut->fileNotFoundError( $this->mUploadSaveName );
 349+ $wgOut->showFileNotFoundError( $this->mUploadSaveName );
348350 }
349351 }
350352 }
@@ -376,7 +378,7 @@
377379 wfRestoreWarnings();
378380
379381 if( ! $success ) {
380 - $wgOut->fileRenameError( $this->mSavedFile,
 382+ $wgOut->showFileRenameError( $this->mSavedFile,
381383 "${archive}/{$this->mUploadOldVersion}" );
382384 return false;
383385 }
@@ -393,7 +395,7 @@
394396 wfRestoreWarnings();
395397
396398 if( ! $success ) {
397 - $wgOut->fileCopyError( $tempName, $this->mSavedFile );
 399+ $wgOut->showFileCopyError( $tempName, $this->mSavedFile );
398400 return false;
399401 } else {
400402 wfDebug("$fname: wrote tempfile $tempName to ".$this->mSavedFile."\n");
@@ -424,7 +426,7 @@
425427 ? rename( $tempName, $stash )
426428 : move_uploaded_file( $tempName, $stash );
427429 if ( !$success ) {
428 - $wgOut->fileCopyError( $tempName, $stash );
 430+ $wgOut->showFileCopyError( $tempName, $stash );
429431 return false;
430432 }
431433
@@ -460,6 +462,7 @@
461463 /**
462464 * Remove a temporarily kept file stashed by saveTempUploadedFile().
463465 * @access private
 466+ * @return success
464467 */
465468 function unsaveUploadedFile() {
466469 global $wgOut;
@@ -467,7 +470,10 @@
468471 $success = unlink( $this->mUploadTempName );
469472 wfRestoreWarnings();
470473 if ( ! $success ) {
471 - $wgOut->fileDeleteError( $this->mUploadTempName );
 474+ $wgOut->showFileDeleteError( $this->mUploadTempName );
 475+ return false;
 476+ } else {
 477+ return true;
472478 }
473479 }
474480
Index: trunk/phase3/includes/WebRequest.php
@@ -452,7 +452,7 @@
453453 if( is_array( $data ) ) {
454454 $this->data = $data;
455455 } else {
456 - wfDebugDieBacktrace( "FauxRequest() got bogus data" );
 456+ throw new MWException( "FauxRequest() got bogus data" );
457457 }
458458 $this->wasPosted = $wasPosted;
459459 }
@@ -479,11 +479,11 @@
480480 }
481481
482482 function getRequestURL() {
483 - wfDebugDieBacktrace( 'FauxRequest::getRequestURL() not implemented' );
 483+ throw new MWException( 'FauxRequest::getRequestURL() not implemented' );
484484 }
485485
486486 function appendQuery( $query ) {
487 - wfDebugDieBacktrace( 'FauxRequest::appendQuery() not implemented' );
 487+ throw new MWException( 'FauxRequest::appendQuery() not implemented' );
488488 }
489489
490490 }
Index: trunk/phase3/includes/Exception.php
@@ -1,172 +1,193 @@
2 -<?php
3 -
4 -class MWException extends Exception
5 -{
6 - function useOutputPage() {
7 - return !empty( $GLOBALS['wgFullyInitialised'] );
8 - }
9 -
10 - function useMessageCache() {
11 - global $wgLang;
12 - return is_object( $wgLang );
13 - }
14 -
15 - function msg( $key, $fallback /*[, params...] */ ) {
16 - $args = array_slice( func_get_args(), 2 );
17 - if ( $this->useMessageCache() ) {
18 - return wfMsgReal( $key, $args );
19 - } else {
20 - return wfMsgReplaceArgs( $fallback, $args );
21 - }
22 - }
23 -
24 - function getHTML() {
25 - return '<p>' . htmlspecialchars( $this->getMessage() ) .
26 - '</p><p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
27 - "</p>\n";
28 - }
29 -
30 - function getText() {
31 - return $this->getMessage() .
32 - "\nBacktrace:\n" . $this->getTraceAsString() . "\n";
33 - }
34 -
35 - function getPageTitle() {
36 - if ( $this->useMessageCache() ) {
37 - return wfMsg( 'internalerror' );
38 - } else {
39 - global $wgSitename;
40 - return "$wgSitename error";
41 - }
42 - }
43 -
44 - function reportHTML() {
45 - global $wgOut;
46 - if ( $this->useOutputPage() ) {
47 - $wgOut->setPageTitle( $this->getPageTitle() );
48 - $wgOut->setRobotpolicy( "noindex,nofollow" );
49 - $wgOut->setArticleRelated( false );
50 - $wgOut->enableClientCache( false );
51 - $wgOut->redirect( '' );
52 - $wgOut->clearHTML();
53 - $wgOut->addHTML( $this->getHTML() );
54 - $wgOut->output();
55 - } else {
56 - echo $this->htmlHeader();
57 - echo $this->getHTML();
58 - echo $this->htmlFooter();
59 - }
60 - }
61 -
62 - function reportText() {
63 - echo $this->getText();
64 - }
65 -
66 - function report() {
67 - global $wgCommandLineMode;
68 - if ( $wgCommandLineMode ) {
69 - $this->reportText();
70 - } else {
71 - $this->reportHTML();
72 - }
73 - }
74 -
75 - function htmlHeader() {
76 - global $wgLogo, $wgSitename, $wgOutputEncoding;
77 -
78 - if ( !headers_sent() ) {
79 - header( 'HTTP/1.0 500 Internal Server Error' );
80 - header( 'Content-type: text/html; charset='.$wgOutputEncoding );
81 - /* Don't cache error pages! They cause no end of trouble... */
82 - header( 'Cache-control: none' );
83 - header( 'Pragma: nocache' );
84 - }
85 - $title = $this->getPageTitle();
86 - echo "<html>
87 - <head>
88 - <title>$title</title>
89 - </head>
90 - <body>
91 - <h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1>
92 - ";
93 - }
94 -
95 - function htmlFooter() {
96 - echo "</body></html>";
97 - }
98 -}
99 -
100 -/**
101 - * Exception class which takes an HTML error message, and does not
102 - * produce a backtrace. Replacement for OutputPage::fatalError().
103 - */
104 -class FatalError extends MWException {
105 - function getHTML() {
106 - return $this->getMessage();
107 - }
108 -
109 - function getText() {
110 - return $this->getMessage();
111 - }
112 -}
113 -
114 -/**
115 - * Install an exception handler for MediaWiki exception types.
116 - */
117 -function wfInstallExceptionHandler() {
118 - set_exception_handler( 'wfExceptionHandler' );
119 -}
120 -
121 -/**
122 - * Report an exception to the user
123 - */
124 -function wfReportException( Exception $e ) {
125 - if ( is_a( $e, 'MWException' ) ) {
126 - try {
127 - $e->report();
128 - } catch ( Exception $e2 ) {
129 - // Exception occurred from within exception handler
130 - // Show a simpler error message for the original exception,
131 - // don't try to invoke report()
132 - $message = "MediaWiki internal error.\n\n" .
133 - "Original exception: " . $e->__toString() .
134 - "\n\nException caught inside exception handler: " .
135 - $e2->__toString() . "\n";
136 -
137 - if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) {
138 - echo $message;
139 - } else {
140 - echo nl2br( htmlspecialchars( $message ) ). "\n";
141 - }
142 - }
143 - } else {
144 - echo $e->__toString();
145 - }
146 -}
147 -
148 -/**
149 - * Exception handler which simulates the appropriate catch() handling:
150 - *
151 - * try {
152 - * ...
153 - * } catch ( MWException $e ) {
154 - *
155 - * $e->report();
156 - * } catch ( Exception $e ) {
157 - * echo $e->__toString();
158 - * }
159 - */
160 -function wfExceptionHandler( $e ) {
161 - wfReportException( $e );
162 -
163 - // Final cleanup, similar to wfErrorExit()
164 - try {
165 - wfProfileClose();
166 - logProfilingData();
167 - } catch ( Exception $e ) {}
168 -
169 - // Exit value should be nonzero for the benefit of shell jobs
170 - exit( 1 );
171 -}
172 -
173 -?>
 2+<?php
 3+
 4+class MWException extends Exception
 5+{
 6+ function useOutputPage() {
 7+ return !empty( $GLOBALS['wgFullyInitialised'] );
 8+ }
 9+
 10+ function useMessageCache() {
 11+ global $wgLang;
 12+ return is_object( $wgLang );
 13+ }
 14+
 15+ function msg( $key, $fallback /*[, params...] */ ) {
 16+ $args = array_slice( func_get_args(), 2 );
 17+ if ( $this->useMessageCache() ) {
 18+ return wfMsgReal( $key, $args );
 19+ } else {
 20+ return wfMsgReplaceArgs( $fallback, $args );
 21+ }
 22+ }
 23+
 24+ function getHTML() {
 25+ return '<p>' . htmlspecialchars( $this->getMessage() ) .
 26+ '</p><p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
 27+ "</p>\n";
 28+ }
 29+
 30+ function getText() {
 31+ return $this->getMessage() .
 32+ "\nBacktrace:\n" . $this->getTraceAsString() . "\n";
 33+ }
 34+
 35+ function getPageTitle() {
 36+ if ( $this->useMessageCache() ) {
 37+ return wfMsg( 'internalerror' );
 38+ } else {
 39+ global $wgSitename;
 40+ return "$wgSitename error";
 41+ }
 42+ }
 43+
 44+ function reportHTML() {
 45+ global $wgOut;
 46+ if ( $this->useOutputPage() ) {
 47+ $wgOut->setPageTitle( $this->getPageTitle() );
 48+ $wgOut->setRobotpolicy( "noindex,nofollow" );
 49+ $wgOut->setArticleRelated( false );
 50+ $wgOut->enableClientCache( false );
 51+ $wgOut->redirect( '' );
 52+ $wgOut->clearHTML();
 53+ $wgOut->addHTML( $this->getHTML() );
 54+ $wgOut->output();
 55+ } else {
 56+ echo $this->htmlHeader();
 57+ echo $this->getHTML();
 58+ echo $this->htmlFooter();
 59+ }
 60+ }
 61+
 62+ function reportText() {
 63+ echo $this->getText();
 64+ }
 65+
 66+ function report() {
 67+ global $wgCommandLineMode;
 68+ if ( $wgCommandLineMode ) {
 69+ $this->reportText();
 70+ } else {
 71+ $this->reportHTML();
 72+ }
 73+ }
 74+
 75+ function htmlHeader() {
 76+ global $wgLogo, $wgSitename, $wgOutputEncoding;
 77+
 78+ if ( !headers_sent() ) {
 79+ header( 'HTTP/1.0 500 Internal Server Error' );
 80+ header( 'Content-type: text/html; charset='.$wgOutputEncoding );
 81+ /* Don't cache error pages! They cause no end of trouble... */
 82+ header( 'Cache-control: none' );
 83+ header( 'Pragma: nocache' );
 84+ }
 85+ $title = $this->getPageTitle();
 86+ echo "<html>
 87+ <head>
 88+ <title>$title</title>
 89+ </head>
 90+ <body>
 91+ <h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1>
 92+ ";
 93+ }
 94+
 95+ function htmlFooter() {
 96+ echo "</body></html>";
 97+ }
 98+}
 99+
 100+/**
 101+ * Exception class which takes an HTML error message, and does not
 102+ * produce a backtrace. Replacement for OutputPage::fatalError().
 103+ */
 104+class FatalError extends MWException {
 105+ function getHTML() {
 106+ return $this->getMessage();
 107+ }
 108+
 109+ function getText() {
 110+ return $this->getMessage();
 111+ }
 112+}
 113+
 114+class ErrorPageError extends MWException {
 115+ public $title, $msg;
 116+
 117+ /**
 118+ * Note: these arguments are keys into wfMsg(), not text!
 119+ */
 120+ function __construct( $title, $msg ) {
 121+ $this->title = $title;
 122+ $this->msg = $msg;
 123+ parent::__construct( wfMsg( $msg ) );
 124+ }
 125+
 126+ function report() {
 127+ global $wgOut;
 128+ $wgOut->showErrorPage( $this->title, $this->msg );
 129+ $wgOut->output();
 130+ }
 131+}
 132+
 133+/**
 134+ * Install an exception handler for MediaWiki exception types.
 135+ */
 136+function wfInstallExceptionHandler() {
 137+ set_exception_handler( 'wfExceptionHandler' );
 138+}
 139+
 140+/**
 141+ * Report an exception to the user
 142+ */
 143+function wfReportException( Exception $e ) {
 144+ if ( is_a( $e, 'MWException' ) ) {
 145+ try {
 146+ $e->report();
 147+ } catch ( Exception $e2 ) {
 148+ // Exception occurred from within exception handler
 149+ // Show a simpler error message for the original exception,
 150+ // don't try to invoke report()
 151+ $message = "MediaWiki internal error.\n\n" .
 152+ "Original exception: " . $e->__toString() .
 153+ "\n\nException caught inside exception handler: " .
 154+ $e2->__toString() . "\n";
 155+
 156+ if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) {
 157+ echo $message;
 158+ } else {
 159+ echo nl2br( htmlspecialchars( $message ) ). "\n";
 160+ }
 161+ }
 162+ } else {
 163+ echo $e->__toString();
 164+ }
 165+}
 166+
 167+/**
 168+ * Exception handler which simulates the appropriate catch() handling:
 169+ *
 170+ * try {
 171+ * ...
 172+ * } catch ( MWException $e ) {
 173+ * $e->report();
 174+ * } catch ( Exception $e ) {
 175+ * echo $e->__toString();
 176+ * }
 177+ */
 178+function wfExceptionHandler( $e ) {
 179+ global $wgFullyInitialised;
 180+ wfReportException( $e );
 181+
 182+ // Final cleanup, similar to wfErrorExit()
 183+ if ( $wgFullyInitialised ) {
 184+ try {
 185+ wfProfileClose();
 186+ logProfilingData(); // uses $wgRequest, hence the $wgFullyInitialised condition
 187+ } catch ( Exception $e ) {}
 188+ }
 189+
 190+ // Exit value should be nonzero for the benefit of shell jobs
 191+ exit( 1 );
 192+}
 193+
 194+?>
Property changes on: trunk/phase3/includes/Exception.php
___________________________________________________________________
Added: svn:eol-style
174195 + native
Index: trunk/phase3/includes/SpecialUnlockdb.php
@@ -84,7 +84,7 @@
8585 return;
8686 }
8787 if ( @! unlink( $wgReadOnlyFile ) ) {
88 - $wgOut->fileDeleteError( $wgReadOnlyFile );
 88+ $wgOut->showFileDeleteError( $wgReadOnlyFile );
8989 return;
9090 }
9191 $titleObj = Title::makeTitle( NS_SPECIAL, "Unlockdb" );
Index: trunk/phase3/includes/Skin.php
@@ -1,6 +1,6 @@
22 <?php
33 if ( ! defined( 'MEDIAWIKI' ) )
4 - die( -1 );
 4+ die( 1 );
55
66 /**
77 *
Index: trunk/phase3/includes/ProtectionForm.php
@@ -65,7 +65,7 @@
6666 if( is_null( $this->mTitle ) ||
6767 !$this->mTitle->exists() ||
6868 $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
69 - $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
 69+ $wgOut->showFatalError( wfMsg( 'badarticleerror' ) );
7070 return;
7171 }
7272
@@ -98,13 +98,12 @@
9999
100100 $token = $wgRequest->getVal( 'wpEditToken' );
101101 if( !$wgUser->matchEditToken( $token ) ) {
102 - $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
103 - return false;
 102+ throw new FatalError( wfMsg( 'sessionfailure' ) );
104103 }
105104
106105 $ok = $this->mArticle->updateRestrictions( $this->mRestrictions, $this->mReason );
107106 if( !$ok ) {
108 - $wgOut->fatalError( "Unknown error at restriction save time." );
 107+ throw new FatalError( "Unknown error at restriction save time." );
109108 }
110109 return $ok;
111110 }
Index: trunk/phase3/includes/Hooks.php
@@ -34,7 +34,7 @@
3535 $fname = 'wfRunHooks';
3636
3737 if (!is_array($wgHooks)) {
38 - wfDebugDieBacktrace("Global hooks array is not an array!\n");
 38+ throw new MWException("Global hooks array is not an array!\n");
3939 return false;
4040 }
4141
@@ -43,7 +43,7 @@
4444 }
4545
4646 if (!is_array($wgHooks[$event])) {
47 - wfDebugDieBacktrace("Hooks array for event '$event' is not an array!\n");
 47+ throw new MWException("Hooks array for event '$event' is not an array!\n");
4848 return false;
4949 }
5050
@@ -62,7 +62,7 @@
6363
6464 if (is_array($hook)) {
6565 if (count($hook) < 1) {
66 - wfDebugDieBacktrace("Empty array in hooks for " . $event . "\n");
 66+ throw new MWException("Empty array in hooks for " . $event . "\n");
6767 } else if (is_object($hook[0])) {
6868 $object =& $wgHooks[$event][$index][0];
6969 if (count($hook) < 2) {
@@ -82,7 +82,7 @@
8383 }
8484 } else {
8585 var_dump( $wgHooks );
86 - wfDebugDieBacktrace("Unknown datatype in hooks for " . $event . "\n");
 86+ throw new MWException("Unknown datatype in hooks for " . $event . "\n");
8787 }
8888 } else if (is_string($hook)) { # functions look like strings, too
8989 $func = $hook;
@@ -90,7 +90,7 @@
9191 $object =& $wgHooks[$event][$index];
9292 $method = "on" . $event;
9393 } else {
94 - wfDebugDieBacktrace("Unknown datatype in hooks for " . $event . "\n");
 94+ throw new MWException("Unknown datatype in hooks for " . $event . "\n");
9595 }
9696
9797 /* We put the first data element on, if needed. */
@@ -119,7 +119,7 @@
120120
121121 if (is_string($retval)) {
122122 global $wgOut;
123 - $wgOut->fatalError($retval);
 123+ $wgOut->showFatalError($retval);
124124 return false;
125125 } else if (!$retval) {
126126 return false;
Index: trunk/phase3/includes/ImageGallery.php
@@ -1,6 +1,6 @@
22 <?php
33 if ( ! defined( 'MEDIAWIKI' ) )
4 - die( -1 );
 4+ die( 1 );
55
66 /**
77 * @package MediaWiki
Index: trunk/phase3/includes/SpecialPreferences.php
@@ -104,7 +104,7 @@
105105 global $wgUser, $wgOut;
106106
107107 if ( $wgUser->isAnon() ) {
108 - $wgOut->errorpage( 'prefsnologin', 'prefsnologintext' );
 108+ $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
109109 return;
110110 }
111111 if ( wfReadOnly() ) {
Index: trunk/phase3/includes/BagOStuff.php
@@ -35,7 +35,7 @@
3636 * @package MediaWiki
3737 * @abstract
3838 */
39 -class BagOStuff {
 39+abstract class BagOStuff {
4040 var $debugmode;
4141
4242 function BagOStuff() {
@@ -212,7 +212,7 @@
213213 * @abstract
214214 * @package MediaWiki
215215 */
216 -class SqlBagOStuff extends BagOStuff {
 216+abstract class SqlBagOStuff extends BagOStuff {
217217 var $table;
218218 var $lastexpireall = 0;
219219
@@ -292,16 +292,9 @@
293293 function _blobencode($str) {
294294 return $str;
295295 }
296 - function _doinsert($table, $vals) {
297 - wfDie( 'abstract function SqlBagOStuff::_doinsert() must be defined' );
298 - }
299 - function _doquery($sql) {
300 - wfDie( 'abstract function SqlBagOStuff::_doquery() must be defined' );
301 - }
302296
303 - function _fetchrow($res) {
304 - wfDie( 'abstract function SqlBagOStuff::_fetchrow() must be defined' );
305 - }
 297+ abstract function _doinsert($table, $vals);
 298+ abstract function _doquery($sql);
306299
307300 function _freeresult($result) {
308301 /* stub */
@@ -313,14 +306,9 @@
314307 return 'unknown error';
315308 }
316309
317 - function _maxdatetime() {
318 - wfDie( 'abstract function SqlBagOStuff::_maxdatetime() must be defined' );
319 - }
 310+ abstract function _maxdatetime();
 311+ abstract function _fromunixtime($ts);
320312
321 - function _fromunixtime() {
322 - wfDie( 'abstract function SqlBagOStuff::_fromunixtime() must be defined' );
323 - }
324 -
325313 function garbageCollect() {
326314 /* Ignore 99% of requests */
327315 if ( !mt_rand( 0, 100 ) ) {
@@ -427,7 +415,7 @@
428416 /* This is actually a hack, we should be able
429417 to use Language classes here... or not */
430418 if (!$dbw)
431 - wfDie("Could not connect to database");
 419+ throw new MWException("Could not connect to database");
432420 $this->table = $dbw->tableName( $this->table );
433421 $this->tableInitialised = true;
434422 }
Index: trunk/phase3/includes/Title.php
@@ -109,7 +109,7 @@
110110 $fname = 'Title::newFromText';
111111
112112 if( is_object( $text ) ) {
113 - wfDebugDieBacktrace( 'Title::newFromText given an object' );
 113+ throw new MWException( 'Title::newFromText given an object' );
114114 }
115115
116116 /**
Index: trunk/phase3/includes/Image.php
@@ -75,7 +75,7 @@
7676
7777 function Image( $title ) {
7878 if( !is_object( $title ) ) {
79 - wfDebugDieBacktrace( 'Image constructor given bogus title.' );
 79+ throw new MWException( 'Image constructor given bogus title.' );
8080 }
8181 $this->title =& $title;
8282 $this->name = $title->getDBkey();
@@ -994,7 +994,7 @@
995995 unlink( $thumbPath );
996996 } else {
997997 // This should have been dealt with already
998 - wfDebugDieBacktrace( "Directory where image should be: $thumbPath" );
 998+ throw new MWException( "Directory where image should be: $thumbPath" );
999999 }
10001000 }
10011001 // Rename the old image into the new location
@@ -1270,16 +1270,24 @@
12711271 }
12721272 # img_name must be unique
12731273 if ( !$db->indexUnique( 'image', 'img_name' ) && !$db->indexExists('image','PRIMARY') ) {
1274 - wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' );
 1274+ throw new MWException( 'Database schema not up to date, please run maintenance/archives/patch-image_name_unique.sql' );
12751275 }
12761276
1277 - #new fields must exist
 1277+ # new fields must exist
 1278+ #
 1279+ # Not really, there's hundreds of checks like this that we could do and they're all pointless, because
 1280+ # if the fields are missing, the database will loudly report a query error, the first time you try to do
 1281+ # something. The only reason I put the above schema check in was because the absence of that particular
 1282+ # index would lead to an annoying subtle bug. No error message, just some very odd behaviour on duplicate
 1283+ # uploads. -- TS
 1284+ /*
12781285 if ( !$db->fieldExists( 'image', 'img_media_type' )
12791286 || !$db->fieldExists( 'image', 'img_metadata' )
12801287 || !$db->fieldExists( 'image', 'img_width' ) ) {
12811288
1282 - wfDebugDieBacktrace( 'Database schema not up to date, please run maintenance/update.php' );
1283 - }
 1289+ throw new MWException( 'Database schema not up to date, please run maintenance/update.php' );
 1290+ }
 1291+ */
12841292 }
12851293
12861294 /**
Index: trunk/phase3/includes/Linker.php
@@ -194,7 +194,7 @@
195195
196196 # Fail gracefully
197197 if ( ! is_object($nt) ) {
198 - # wfDebugDieBacktrace();
 198+ # throw new MWException();
199199 wfProfileOut( $fname );
200200 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
201201 }
@@ -343,7 +343,7 @@
344344 function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
345345 # Fail gracefully
346346 if ( ! isset($nt) ) {
347 - # wfDebugDieBacktrace();
 347+ # throw new MWException();
348348 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
349349 }
350350
@@ -658,7 +658,7 @@
659659 function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
660660 # Fail gracefully
661661 if ( ! isset($nt) ) {
662 - # wfDebugDieBacktrace();
 662+ # throw new MWException();
663663 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
664664 }
665665

Follow-up revisions

RevisionCommit summaryAuthorDate
r14632Unbreak the wiki when the base BagOStuff class is used for faux cache objects...brion07:50, 7 June 2006
r79752More ancient deprecated functions:...happy-melon20:40, 6 January 2011

Status & tagging log