From 7a56bf81683e5ce5e2b5adeed0937ab114370d8b Mon Sep 17 00:00:00 2001 From: addshore Date: Mon, 24 Feb 2014 21:21:09 +0100 Subject: [PATCH] Add scope to Exception class methods Change-Id: I0097aa9a6d9c178c85706b90484f7a68d3ddbc8b --- includes/exception/BadTitleError.php | 4 +-- includes/exception/ErrorPageError.php | 4 +-- includes/exception/FatalError.php | 4 +-- includes/exception/MWException.php | 26 +++++++++---------- includes/exception/PermissionsError.php | 4 +-- .../exception/MWExceptionHandlerTest.php | 2 +- .../includes/exception/MWExceptionTest.php | 14 +++++----- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/includes/exception/BadTitleError.php b/includes/exception/BadTitleError.php index b3d842d78b..2da37752f0 100644 --- a/includes/exception/BadTitleError.php +++ b/includes/exception/BadTitleError.php @@ -31,7 +31,7 @@ class BadTitleError extends ErrorPageError { * @param string|Message $msg A message key (default: 'badtitletext') * @param array $params parameter to wfMessage() */ - function __construct( $msg = 'badtitletext', $params = array() ) { + public function __construct( $msg = 'badtitletext', $params = array() ) { parent::__construct( 'badtitle', $msg, $params ); } @@ -39,7 +39,7 @@ class BadTitleError extends ErrorPageError { * Just like ErrorPageError::report() but additionally set * a 400 HTTP status code (bug 33646). */ - function report() { + public function report() { global $wgOut; // bug 33646: a badtitle error page need to return an error code diff --git a/includes/exception/ErrorPageError.php b/includes/exception/ErrorPageError.php index 439d8e445e..7cd198b180 100644 --- a/includes/exception/ErrorPageError.php +++ b/includes/exception/ErrorPageError.php @@ -34,7 +34,7 @@ class ErrorPageError extends MWException { * @param string|Message $msg Message key (string) for error text, or a Message object * @param array $params with parameters to wfMessage() */ - function __construct( $title, $msg, $params = array() ) { + public function __construct( $title, $msg, $params = array() ) { $this->title = $title; $this->msg = $msg; $this->params = $params; @@ -52,7 +52,7 @@ class ErrorPageError extends MWException { parent::__construct( $enMsg->text() ); } - function report() { + public function report() { global $wgOut; $wgOut->showErrorPage( $this->title, $this->msg, $this->params ); diff --git a/includes/exception/FatalError.php b/includes/exception/FatalError.php index 8953219f14..a7d672fa2e 100644 --- a/includes/exception/FatalError.php +++ b/includes/exception/FatalError.php @@ -30,14 +30,14 @@ class FatalError extends MWException { /** * @return string */ - function getHTML() { + public function getHTML() { return $this->getMessage(); } /** * @return string */ - function getText() { + public function getText() { return $this->getMessage(); } } diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 80b6ac5c4b..f344938812 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -29,7 +29,7 @@ class MWException extends Exception { * * @return bool */ - function useOutputPage() { + public function useOutputPage() { return $this->useMessageCache() && !empty( $GLOBALS['wgFullyInitialised'] ) && !empty( $GLOBALS['wgOut'] ) && @@ -42,7 +42,7 @@ class MWException extends Exception { * @since 1.23 * @return boolean */ - function isLoggable() { + public function isLoggable() { return true; } @@ -51,7 +51,7 @@ class MWException extends Exception { * * @return bool */ - function useMessageCache() { + public function useMessageCache() { global $wgLang; foreach ( $this->getTrace() as $frame ) { @@ -70,7 +70,7 @@ class MWException extends Exception { * @param array $args arguments to pass to the callback functions * @return string|null string to output or null if any hook has been called */ - function runHooks( $name, $args = array() ) { + public function runHooks( $name, $args = array() ) { global $wgExceptionHooks; if ( !isset( $wgExceptionHooks ) || !is_array( $wgExceptionHooks ) ) { @@ -113,7 +113,7 @@ class MWException extends Exception { * The function also has other parameters that are arguments for the message * @return string message with arguments replaced */ - function msg( $key, $fallback /*[, params...] */ ) { + public function msg( $key, $fallback /*[, params...] */ ) { $args = array_slice( func_get_args(), 2 ); if ( $this->useMessageCache() ) { @@ -130,7 +130,7 @@ class MWException extends Exception { * * @return string html to output */ - function getHTML() { + public function getHTML() { global $wgShowExceptionDetails; if ( $wgShowExceptionDetails ) { @@ -155,7 +155,7 @@ class MWException extends Exception { * * @return string */ - function getText() { + public function getText() { global $wgShowExceptionDetails; if ( $wgShowExceptionDetails ) { @@ -172,7 +172,7 @@ class MWException extends Exception { * * @return string */ - function getPageTitle() { + public function getPageTitle() { global $wgSitename; return $this->msg( 'pagetitle', "$1 - $wgSitename", $this->msg( 'internalerror', 'Internal error' ) ); } @@ -184,7 +184,7 @@ class MWException extends Exception { * @deprecated since 1.22 Use MWExceptionHandler::getLogId instead. * @return string */ - function getLogId() { + public function getLogId() { wfDeprecated( __METHOD__, '1.22' ); return MWExceptionHandler::getLogId( $this ); } @@ -197,7 +197,7 @@ class MWException extends Exception { * @deprecated since 1.22 Use MWExceptionHandler::getLogMessage instead. * @return string */ - function getLogMessage() { + public function getLogMessage() { wfDeprecated( __METHOD__, '1.22' ); return MWExceptionHandler::getLogMessage( $this ); } @@ -205,7 +205,7 @@ class MWException extends Exception { /** * Output the exception report using HTML. */ - function reportHTML() { + public function reportHTML() { global $wgOut; if ( $this->useOutputPage() ) { $wgOut->prepareErrorPage( $this->getPageTitle() ); @@ -241,7 +241,7 @@ class MWException extends Exception { * Output a report about the exception and takes care of formatting. * It will be either HTML or plain text based on isCommandLine(). */ - function report() { + public function report() { global $wgMimeType; MWExceptionHandler::logException( $this ); @@ -267,7 +267,7 @@ class MWException extends Exception { * * @return bool */ - static function isCommandLine() { + public static function isCommandLine() { return !empty( $GLOBALS['wgCommandLineMode'] ); } } diff --git a/includes/exception/PermissionsError.php b/includes/exception/PermissionsError.php index 987c894d56..bfba7b2742 100644 --- a/includes/exception/PermissionsError.php +++ b/includes/exception/PermissionsError.php @@ -28,7 +28,7 @@ class PermissionsError extends ErrorPageError { public $permission, $errors; - function __construct( $permission, $errors = array() ) { + public function __construct( $permission, $errors = array() ) { global $wgLang; $this->permission = $permission; @@ -49,7 +49,7 @@ class PermissionsError extends ErrorPageError { $this->errors = $errors; } - function report() { + public function report() { global $wgOut; $wgOut->showPermissionsErrorPage( $this->errors, $this->permission ); diff --git a/tests/phpunit/includes/exception/MWExceptionHandlerTest.php b/tests/phpunit/includes/exception/MWExceptionHandlerTest.php index 67faf8db82..838e4f076b 100644 --- a/tests/phpunit/includes/exception/MWExceptionHandlerTest.php +++ b/tests/phpunit/includes/exception/MWExceptionHandlerTest.php @@ -11,7 +11,7 @@ class MWExceptionHandlerTest extends MediaWikiTestCase { /** * @covers MWExceptionHandler::getRedactedTrace */ - function testGetRedactedTrace() { + public function testGetRedactedTrace() { $refvar = 'value'; try { $array = array( 'a', 'b' ); diff --git a/tests/phpunit/includes/exception/MWExceptionTest.php b/tests/phpunit/includes/exception/MWExceptionTest.php index 5f001c7ea6..f1ddc17e4c 100644 --- a/tests/phpunit/includes/exception/MWExceptionTest.php +++ b/tests/phpunit/includes/exception/MWExceptionTest.php @@ -11,7 +11,7 @@ class MWExceptionTest extends MediaWikiTestCase { /** * @expectedException MWException */ - function testMwexceptionThrowing() { + public function testMwexceptionThrowing() { throw new MWException(); } @@ -21,7 +21,7 @@ class MWExceptionTest extends MediaWikiTestCase { * @covers MWExceptionHandler::jsonSerializeException * @dataProvider provideExceptionClasses */ - function testJsonSerializeExceptions( $exception_class ) { + public function testJsonSerializeExceptions( $exception_class ) { $json = MWExceptionHandler::jsonSerializeException( new $exception_class() ); @@ -29,7 +29,7 @@ class MWExceptionTest extends MediaWikiTestCase { "The $exception_class exception should be JSON serializable, got false." ); } - function provideExceptionClasses() { + public function provideExceptionClasses() { return array( array( 'Exception' ), array( 'MWException' ), @@ -46,7 +46,7 @@ class MWExceptionTest extends MediaWikiTestCase { * @param $key String Name of the key to validate in the serialized JSON * @dataProvider provideJsonSerializedKeys */ - function testJsonserializeexceptionKeys( $expectedKeyType, $exClass, $key ) { + public function testJsonserializeexceptionKeys( $expectedKeyType, $exClass, $key ) { # Make sure we log a backtrace: $this->setMwGlobals( array( 'wgLogExceptionBacktrace' => true ) ); @@ -66,7 +66,7 @@ class MWExceptionTest extends MediaWikiTestCase { /** * Returns test cases: exception class, key name, gettype() */ - function provideJsonSerializedKeys() { + public function provideJsonSerializedKeys() { $testCases = array(); foreach ( array( 'Exception', 'MWException' ) as $exClass ) { $exTests = array( @@ -89,7 +89,7 @@ class MWExceptionTest extends MediaWikiTestCase { * * @covers MWExceptionHandler::jsonSerializeException */ - function testJsonserializeexceptionBacktracingEnabled() { + public function testJsonserializeexceptionBacktracingEnabled() { $this->setMwGlobals( array( 'wgLogExceptionBacktrace' => true ) ); $json = json_decode( MWExceptionHandler::jsonSerializeException( new Exception() ) @@ -103,7 +103,7 @@ class MWExceptionTest extends MediaWikiTestCase { * * @covers MWExceptionHandler::jsonSerializeException */ - function testJsonserializeexceptionBacktracingDisabled() { + public function testJsonserializeexceptionBacktracingDisabled() { $this->setMwGlobals( array( 'wgLogExceptionBacktrace' => false ) ); $json = json_decode( MWExceptionHandler::jsonSerializeException( new Exception() ) -- 2.20.1