X-Git-Url: https://git.cyclocoop.org/admin/?a=blobdiff_plain;f=includes%2Fexception%2FMWException.php;h=cb7ff19b35812ca45526c3682c6717facc283778;hb=115ebbe89d25522b5a967b87977fc7ecf3188a95;hp=7f70c4fbaf3ea2111a28431b90e3360ba7cef0f5;hpb=4d1e6f80db5b420e5a745f2b48d1516b04b1a185;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/exception/MWException.php b/includes/exception/MWException.php index 7f70c4fbaf..cb7ff19b35 100644 --- a/includes/exception/MWException.php +++ b/includes/exception/MWException.php @@ -69,23 +69,22 @@ class MWException extends Exception { * @param string $key Message name * @param string $fallback Default message if the message cache can't be * called by the exception - * The function also has other parameters that are arguments for the message + * @param mixed ...$params To pass to wfMessage() * @return string Message with arguments replaced */ - public function msg( $key, $fallback /*[, params...] */ ) { + public function msg( $key, $fallback, ...$params ) { global $wgSitename; - $args = array_slice( func_get_args(), 2 ); // FIXME: Keep logic in sync with MWExceptionRenderer::msg. $res = false; if ( $this->useMessageCache() ) { try { - $res = wfMessage( $key, $args )->text(); + $res = wfMessage( $key, $params )->text(); } catch ( Exception $e ) { } } if ( $res === false ) { - $res = wfMsgReplaceArgs( $fallback, $args ); + $res = wfMsgReplaceArgs( $fallback, $params ); // If an exception happens inside message rendering, // {{SITENAME}} sometimes won't be replaced. $res = strtr( $res, [ @@ -209,12 +208,7 @@ class MWException extends Exception { wfHttpError( 500, 'Internal Server Error', $this->getText() ); } elseif ( self::isCommandLine() ) { $message = $this->getText(); - // T17602: STDERR may not be available - if ( !defined( 'MW_PHPUNIT_TEST' ) && defined( 'STDERR' ) ) { - fwrite( STDERR, $message ); - } else { - echo $message; - } + $this->writeToCommandLine( $message ); } else { self::statusHeader( 500 ); self::header( "Content-Type: $wgMimeType; charset=utf-8" ); @@ -223,6 +217,21 @@ class MWException extends Exception { } } + /** + * Write a message to stderr falling back to stdout if stderr unavailable + * + * @param string $message + * @suppress SecurityCheck-XSS + */ + private function writeToCommandLine( $message ) { + // T17602: STDERR may not be available + if ( !defined( 'MW_PHPUNIT_TEST' ) && defined( 'STDERR' ) ) { + fwrite( STDERR, $message ); + } else { + echo $message; + } + } + /** * Check whether we are in command line mode or not to report the exception * in the correct format.