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 );
}
* @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 '<' . $this->key . '>';
+ }
}
/**
}
}
+
+/**
+ * Variant of the Message class.
+ *
+ * Rather than treating the message key as a lookup
+ * value (which is passed to the MessageCache and
+ * translated as necessary), a RawMessage key is
+ * treated as the actual message.
+ *
+ * All other functionality (parsing, escaping, etc.)
+ * is preserved.
+ *
+ * @since 1.21
+ */
+class RawMessage extends Message {
+ /**
+ * Call the parent constructor, then store the key as
+ * the message.
+ *
+ * @param $key Message to use
+ * @param $params Parameters for the message
+ * @see Message::__construct
+ */
+ public function __construct( $key, $params = array() ) {
+ parent::__construct( $key, $params );
+ // The key is the message.
+ $this->message = $key;
+ }
+
+ /**
+ * Fetch the message (in this case, the key).
+ *
+ * @return string
+ */
+ public function fetchMessage() {
+ // Just in case the message is unset somewhere.
+ if( !isset( $this->message ) ) {
+ $this->message = $this->key;
+ }
+ return $this->message;
+ }
+}