testPngNativetZtxt requires zlib extension
[lhc/web/wiklou.git] / includes / Message.php
index 976f144..96747c9 100644 (file)
@@ -457,11 +457,11 @@ class Message {
                        if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) {
                                $string = $m[1];
                        }
-               } elseif( $this->format === 'block-parse' ){
+               } elseif( $this->format === 'block-parse' ) {
                        $string = $this->parseText( $string );
-               } elseif( $this->format === 'text' ){
+               } elseif( $this->format === 'text' ) {
                        $string = $this->transformText( $string );
-               } elseif( $this->format === 'escaped' ){
+               } elseif( $this->format === 'escaped' ) {
                        $string = $this->transformText( $string );
                        $string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8', false );
                }
@@ -480,7 +480,24 @@ class Message {
         * @return String
         */
        public function __toString() {
-               return $this->toString();
+               // PHP doesn't allow __toString to throw exceptions and will
+               // trigger a fatal error if it does. So, catch any exceptions.
+
+               try {
+                       return $this->toString();
+               } catch ( Exception $ex ) {
+                       try {
+                               trigger_error( "Exception caught in " . __METHOD__ . " (message " . $this->key . "): "
+                                       . $ex, E_USER_WARNING );
+                       } catch ( Exception $ex ) {
+                               // Doh! Cause a fatal error after all?
+                       }
+
+                       if ( $this->format === 'plain' ) {
+                               return '<' . $this->key . '>';
+                       }
+                       return '&lt;' . $this->key . '&gt;';
+               }
        }
 
        /**