Various fixes to make phan-taint-check happier
[lhc/web/wiklou.git] / includes / exception / MWException.php
index 652a87d..502cee8 100644 (file)
@@ -76,6 +76,7 @@ class MWException extends Exception {
                global $wgSitename;
                $args = array_slice( func_get_args(), 2 );
 
+               // FIXME: Keep logic in sync with MWExceptionRenderer::msg.
                $res = false;
                if ( $this->useMessageCache() ) {
                        try {
@@ -87,7 +88,9 @@ class MWException extends Exception {
                        $res = wfMsgReplaceArgs( $fallback, $args );
                        // If an exception happens inside message rendering,
                        // {{SITENAME}} sometimes won't be replaced.
-                       $res = preg_replace( '/\{\{SITENAME\}\}/', $wgSitename, $res );
+                       $res = strtr( $res, [
+                               '{{SITENAME}}' => $wgSitename,
+                       ] );
                }
                return $res;
        }
@@ -118,7 +121,7 @@ class MWException extends Exception {
                                        "Fatal exception of type $1",
                                        $type,
                                        $logId,
-                                       MWExceptionHandler::getURL( $this )
+                                       MWExceptionHandler::getURL()
                                )
                        ) ) .
                        "<!-- Set \$wgShowExceptionDetails = true; " .
@@ -206,12 +209,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" );
@@ -220,6 +218,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.