$wgOut->returnToMain( false, $rcTitle->getPrefixedText() );
}
else {
- $wgOut->errorpage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+ $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
}
}
global $wgUser, $wgOut;
if ( $wgUser->isAnon() ) {
- $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
+ $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
return;
}
if ( wfReadOnly() ) {
global $wgUser, $wgOut;
if ( $wgUser->isAnon() ) {
- $wgOut->errorpage( 'watchnologin', 'watchnologintext' );
+ $wgOut->showErrorPage( 'watchnologin', 'watchnologintext' );
return;
}
if ( wfReadOnly() ) {
*/
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 );
$conds = $this->mTitle->pageCond();
$latest = $dbw->selectField( 'page', 'page_latest', $conds, $fname );
if ( $latest === false ) {
- $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
return;
}
$wgOut->returnToMain( false );
wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
} else {
- $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
}
}
}
$fname = 'Article::info';
if ( !$wgAllowPageInfo ) {
- $wgOut->errorpage( 'nosuchaction', 'nosuchactiontext' );
+ $wgOut->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
return;
}
* @package MediaWiki
* @abstract
*/
-class BagOStuff {
+abstract class BagOStuff {
var $debugmode;
function BagOStuff() {
* @abstract
* @package MediaWiki
*/
-class SqlBagOStuff extends BagOStuff {
+abstract class SqlBagOStuff extends BagOStuff {
var $table;
var $lastexpireall = 0;
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 */
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 */
/* 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;
}
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 ) {
-<?php\r
-\r
-class MWException extends Exception\r
-{\r
- function useOutputPage() {\r
- return !empty( $GLOBALS['wgFullyInitialised'] );\r
- }\r
-\r
- function useMessageCache() {\r
- global $wgLang;\r
- return is_object( $wgLang );\r
- }\r
-\r
- function msg( $key, $fallback /*[, params...] */ ) {\r
- $args = array_slice( func_get_args(), 2 );\r
- if ( $this->useMessageCache() ) {\r
- return wfMsgReal( $key, $args );\r
- } else {\r
- return wfMsgReplaceArgs( $fallback, $args );\r
- }\r
- }\r
- \r
- function getHTML() {\r
- return '<p>' . htmlspecialchars( $this->getMessage() ) . \r
- '</p><p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .\r
- "</p>\n";\r
- }\r
-\r
- function getText() {\r
- return $this->getMessage() . \r
- "\nBacktrace:\n" . $this->getTraceAsString() . "\n";\r
- }\r
- \r
- function getPageTitle() {\r
- if ( $this->useMessageCache() ) {\r
- return wfMsg( 'internalerror' );\r
- } else {\r
- global $wgSitename;\r
- return "$wgSitename error";\r
- }\r
- }\r
- \r
- function reportHTML() {\r
- global $wgOut;\r
- if ( $this->useOutputPage() ) {\r
- $wgOut->setPageTitle( $this->getPageTitle() );\r
- $wgOut->setRobotpolicy( "noindex,nofollow" );\r
- $wgOut->setArticleRelated( false );\r
- $wgOut->enableClientCache( false );\r
- $wgOut->redirect( '' );\r
- $wgOut->clearHTML();\r
- $wgOut->addHTML( $this->getHTML() );\r
- $wgOut->output();\r
- } else {\r
- echo $this->htmlHeader();\r
- echo $this->getHTML();\r
- echo $this->htmlFooter();\r
- }\r
- }\r
- \r
- function reportText() {\r
- echo $this->getText();\r
- }\r
-\r
- function report() {\r
- global $wgCommandLineMode;\r
- if ( $wgCommandLineMode ) {\r
- $this->reportText();\r
- } else {\r
- $this->reportHTML();\r
- }\r
- }\r
-\r
- function htmlHeader() {\r
- global $wgLogo, $wgSitename, $wgOutputEncoding;\r
-\r
- if ( !headers_sent() ) {\r
- header( 'HTTP/1.0 500 Internal Server Error' );\r
- header( 'Content-type: text/html; charset='.$wgOutputEncoding );\r
- /* Don't cache error pages! They cause no end of trouble... */\r
- header( 'Cache-control: none' );\r
- header( 'Pragma: nocache' );\r
- }\r
- $title = $this->getPageTitle();\r
- echo "<html>\r
- <head>\r
- <title>$title</title>\r
- </head>\r
- <body>\r
- <h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1>\r
- ";\r
- }\r
-\r
- function htmlFooter() {\r
- echo "</body></html>";\r
- } \r
-}\r
-\r
-/**\r
- * Exception class which takes an HTML error message, and does not \r
- * produce a backtrace. Replacement for OutputPage::fatalError().\r
- */\r
-class FatalError extends MWException {\r
- function getHTML() {\r
- return $this->getMessage();\r
- }\r
-\r
- function getText() {\r
- return $this->getMessage();\r
- }\r
-}\r
-\r
-/**\r
- * Install an exception handler for MediaWiki exception types.\r
- */\r
-function wfInstallExceptionHandler() {\r
- set_exception_handler( 'wfExceptionHandler' );\r
-}\r
-\r
-/**\r
- * Report an exception to the user\r
- */\r
-function wfReportException( Exception $e ) {\r
- if ( is_a( $e, 'MWException' ) ) {\r
- try {\r
- $e->report();\r
- } catch ( Exception $e2 ) {\r
- // Exception occurred from within exception handler\r
- // Show a simpler error message for the original exception, \r
- // don't try to invoke report()\r
- $message = "MediaWiki internal error.\n\n" .\r
- "Original exception: " . $e->__toString() . \r
- "\n\nException caught inside exception handler: " . \r
- $e2->__toString() . "\n";\r
-\r
- if ( !empty( $GLOBALS['wgCommandLineMode'] ) ) {\r
- echo $message;\r
- } else {\r
- echo nl2br( htmlspecialchars( $message ) ). "\n";\r
- }\r
- }\r
- } else {\r
- echo $e->__toString();\r
- }\r
-}\r
-\r
-/**\r
- * Exception handler which simulates the appropriate catch() handling:\r
- * \r
- * try {\r
- * ...\r
- * } catch ( MWException $e ) {\r
- * \r
- * $e->report();\r
- * } catch ( Exception $e ) {\r
- * echo $e->__toString();\r
- * }\r
- */\r
-function wfExceptionHandler( $e ) {\r
- wfReportException( $e );\r
- \r
- // Final cleanup, similar to wfErrorExit()\r
- try {\r
- wfProfileClose();\r
- logProfilingData();\r
- } catch ( Exception $e ) {}\r
-\r
- // Exit value should be nonzero for the benefit of shell jobs\r
- exit( 1 );\r
-}\r
-\r
-?>\r
+<?php
+
+class MWException extends Exception
+{
+ function useOutputPage() {
+ return !empty( $GLOBALS['wgFullyInitialised'] );
+ }
+
+ function useMessageCache() {
+ global $wgLang;
+ return is_object( $wgLang );
+ }
+
+ function msg( $key, $fallback /*[, params...] */ ) {
+ $args = array_slice( func_get_args(), 2 );
+ if ( $this->useMessageCache() ) {
+ return wfMsgReal( $key, $args );
+ } else {
+ return wfMsgReplaceArgs( $fallback, $args );
+ }
+ }
+
+ function getHTML() {
+ return '<p>' . htmlspecialchars( $this->getMessage() ) .
+ '</p><p>Backtrace:</p><p>' . nl2br( htmlspecialchars( $this->getTraceAsString() ) ) .
+ "</p>\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 "<html>
+ <head>
+ <title>$title</title>
+ </head>
+ <body>
+ <h1><img src='$wgLogo' style='float:left;margin-right:1em' alt=''>$title</h1>
+ ";
+ }
+
+ function htmlFooter() {
+ echo "</body></html>";
+ }
+}
+
+/**
+ * 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 );
+}
+
+?>
$ns = intval( $key );
$this->namespaces[$ns] = true;
} else {
- wfDie( "Unrecognized namespace key '$key'\n" );
+ throw new MWException( "Unrecognized namespace key '$key'\n" );
}
}
}
* 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(); }
*/
function wfDie( $msg='' ) {
echo $msg;
- die( -1 );
+ die( 1 );
}
/**
}
echo $msg;
echo wfReportTime()."\n";
- die( -1 );
+ die( 1 );
}
/**
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.');
}
}
*/
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;
$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" );
}
/**
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" );
}
/**
/** 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';
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; }
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; }
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" );
}
}
$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;
}
}
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;
}
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) {
}
} 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;
$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. */
if (is_string($retval)) {
global $wgOut;
- $wgOut->fatalError($retval);
+ $wgOut->showFatalError($retval);
return false;
} else if (!$retval) {
return false;
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();
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
}
# 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' );
+ }
+ */
}
/**
<?php
if ( ! defined( 'MEDIAWIKI' ) )
- die( -1 );
+ die( 1 );
/**
* @package MediaWiki
*
*/
if( !defined( 'MEDIAWIKI' ) )
- die( -1 );
+ die( 1 );
require_once( 'Image.php' );
$wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
if ( ( !is_null( $image ) )
&& ( '' == trim( $image ) ) ) {
- $wgOut->fatalError( wfMsg( 'cannotdelete' ) );
+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
return;
}
if( $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
$this->doDelete();
} else {
- $wgOut->fatalError( wfMsg( 'sessionfailure' ) );
+ $wgOut->showFatalError( wfMsg( 'sessionfailure' ) );
}
return;
}
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;
}
);
wfPurgeSquidServers($urlArr);
}
- $this->doDeleteOldImage( $oldimage );
+ if ( !$this->doDeleteOldImage( $oldimage ) ) {
+ return;
+ }
$dbw->delete( 'oldimage', array( 'oi_archive_name' => $oldimage ) );
$deleted = $oldimage;
} else {
$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 ) );
# 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 );
}
$wgOut->returnToMain( false, $this->mTitle->getPrefixedText() );
}
+ /**
+ * @return success
+ */
function doDeleteOldImage( $oldimage )
{
global $wgOut;
$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;
}
}
$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;
}
return;
}
if( $wgUser->isAnon() ) {
- $wgOut->errorpage( 'uploadnologin', 'uploadnologintext' );
+ $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
return;
}
if ( ! $this->mTitle->userCanEdit() ) {
return $this->blockedIPpage();
}
if( !$wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ), $oldimage ) ) {
- $wgOut->errorpage( 'internalerror', 'sessionfailure' );
+ $wgOut->showErrorPage( 'internalerror', 'sessionfailure' );
return;
}
$name = substr( $oldimage, 15 );
$curfile = "{$dest}/{$name}";
if ( ! is_file( $curfile ) ) {
- $wgOut->fileNotFoundError( htmlspecialchars( $curfile ) );
+ $wgOut->showFileNotFoundError( htmlspecialchars( $curfile ) );
return;
}
$oldver = wfTimestampNow() . "!{$name}";
$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
# Fail gracefully
if ( ! is_object($nt) ) {
- # wfDebugDieBacktrace();
+ # throw new MWException();
wfProfileOut( $fname );
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
}
function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
# Fail gracefully
if ( ! isset($nt) ) {
- # wfDebugDieBacktrace();
+ # throw new MWException();
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
}
function makeBrokenImageLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
# Fail gracefully
if ( ! isset($nt) ) {
- # wfDebugDieBacktrace();
+ # throw new MWException();
return "<!-- ERROR -->{$prefix}{$text}{$trail}";
}
$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;
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();
$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);
<?php
if ( ! defined( 'MEDIAWIKI' ) )
- die( -1 );
+ die( 1 );
/**
* @package MediaWiki
*/
/**
* Note: these arguments are keys into wfMsg(), not text!
*/
- function errorpage( $title, $msg ) {
+ function showErrorPage( $title, $msg ) {
global $wgTitle;
$this->mDebugtext .= 'Original title: ' .
$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
$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 ) {
$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 ) );
}
/**
$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 {
$useLinkPrefixExtension = $wgContLang->linkPrefixExtension();
if( is_null( $this->mTitle ) ) {
- wfDebugDieBacktrace( 'nooo' );
+ throw new MWException( 'nooo' );
}
$nottalk = !$this->mTitle->isTalkPage();
}
break;
default:
- wfDebugDieBacktrace( "State machine error in $fname" );
+ throw new MWException( "State machine error in $fname" );
}
}
if( $stack > 0 ) {
if( is_null( $this->mTitle ) ||
!$this->mTitle->exists() ||
$this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
- $wgOut->fatalError( wfMsg( 'badarticleerror' ) );
+ $wgOut->showFatalError( wfMsg( 'badarticleerror' ) );
return;
}
$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;
}
$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.' );
}
}
$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 .= ',';
# 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." );
}
}
// 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 ) )
<?php
if ( ! defined( 'MEDIAWIKI' ) )
- die( -1 );
+ die( 1 );
/**
*
$target = isset($par) ? $par : $wgRequest->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;
}
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;
}
$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;
}
$fp = fopen( $wgReadOnlyFile, 'w' );
if ( false === $fp ) {
- $wgOut->fileNotFoundError( $wgReadOnlyFile );
+ $wgOut->showFileNotFoundError( $wgReadOnlyFile );
return;
}
fwrite( $fp, $this->reason );
# 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
$ot = Title::newFromURL( $this->oldTitle );
if( is_null( $ot ) ) {
- $wgOut->errorpage( 'notargettitle', 'notargettext' );
+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
return;
}
$oldTitle = $ot->getPrefixedText();
$wgOut->setArticleRelated( false );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
$wgOut->setStatusCode( 404 );
- $wgOut->errorpage( 'nosuchspecialpage', 'nospecialpagetext' );
+ $wgOut->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
$retVal = false;
}
}
global $wgUser, $wgOut;
if ( $wgUser->isAnon() ) {
- $wgOut->errorpage( 'prefsnologin', 'prefsnologintext' );
+ $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext' );
return;
}
if ( wfReadOnly() ) {
$page = Title::newFromUrl( $target );
if( is_null( $page ) ) {
- $wgOut->errorpage( 'notargettitle', 'notargettext' );
+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
return;
}
function PageArchive( &$title ) {
if( is_null( $title ) ) {
- wfDebugDieBacktrace( 'Archiver() given a null title.');
+ throw new MWException( 'Archiver() given a null title.');
}
$this->title =& $title;
}
return true;
}
}
- $wgOut->fatalError( wfMsg( "cannotundelete" ) );
+ $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
return false;
}
}
return;
}
if ( @! unlink( $wgReadOnlyFile ) ) {
- $wgOut->fileDeleteError( $wgReadOnlyFile );
+ $wgOut->showFileDeleteError( $wgReadOnlyFile );
return;
}
$titleObj = Title::makeTitle( NS_SPECIAL, "Unlockdb" );
# Check uploading enabled
if( !$wgEnableUploads ) {
- $wgOut->errorPage( 'uploaddisabled', 'uploaddisabledtext' );
+ $wgOut->showErrorPage( 'uploaddisabled', 'uploaddisabledtext' );
return;
}
return;
}
} else {
- $wgOut->errorPage( 'uploadnologin', 'uploadnologintext' );
+ $wgOut->showErrorPage( 'uploadnologin', 'uploadnologintext' );
return;
}
}
if( $this->mReUpload ) {
- $this->unsaveUploadedFile();
+ if ( !$this->unsaveUploadedFile() ) {
+ return;
+ }
$this->mainUploadForm();
} else if ( 'submit' == $this->mAction || $this->mUpload ) {
$this->processUpload();
} 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 );
}
}
}
wfRestoreWarnings();
if( ! $success ) {
- $wgOut->fileRenameError( $this->mSavedFile,
+ $wgOut->showFileRenameError( $this->mSavedFile,
"${archive}/{$this->mUploadOldVersion}" );
return false;
}
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");
? rename( $tempName, $stash )
: move_uploaded_file( $tempName, $stash );
if ( !$success ) {
- $wgOut->fileCopyError( $tempName, $stash );
+ $wgOut->showFileCopyError( $tempName, $stash );
return false;
}
/**
* Remove a temporarily kept file stashed by saveTempUploadedFile().
* @access private
+ * @return success
*/
function unsaveUploadedFile() {
global $wgOut;
$success = unlink( $this->mUploadTempName );
wfRestoreWarnings();
if ( ! $success ) {
- $wgOut->fileDeleteError( $this->mUploadTempName );
+ $wgOut->showFileDeleteError( $this->mUploadTempName );
+ return false;
+ } else {
+ return true;
}
}
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;
}
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);
$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);
/**
* 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;
}
}
}
$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,
$fname = 'Title::newFromText';
if( is_object( $text ) ) {
- wfDebugDieBacktrace( 'Title::newFromText given an object' );
+ throw new MWException( 'Title::newFromText given an object' );
}
/**
* @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' );
}
* @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' );
}
* @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' );
}
if( is_array( $data ) ) {
$this->data = $data;
} else {
- wfDebugDieBacktrace( "FauxRequest() got bogus data" );
+ throw new MWException( "FauxRequest() got bogus data" );
}
$this->wasPosted = $wasPosted;
}
}
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' );
}
}
} 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' );
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 ) );
$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'] ) &&
break;
default:
if( wfRunHooks( 'UnknownAction', array( $action, $article ) ) ) {
- $output->errorpage( 'nosuchaction', 'nosuchactiontext' );
+ $output->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
}
}
wfProfileOut( 'MediaWiki::performAction' );