return $this;
}
+ /**
+ * Add parameters that are plaintext and will be passed through without
+ * the content being evaluated. Plaintext parameters are not valid as
+ * arguments to parser functions. This differs from self::rawParams in
+ * that the Message class handles escaping to match the output format.
+ *
+ * @since 1.25
+ *
+ * @param string|string[] $param,... plaintext parameters, or a single argument that is
+ * an array of plaintext parameters.
+ *
+ * @return Message $this
+ */
+ public function plaintextParams( /*...*/ ) {
+ $params = func_get_args();
+ if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+ $params = $params[0];
+ }
+ foreach ( $params as $param ) {
+ $this->parameters[] = self::plaintextParam( $param );
+ }
+ return $this;
+ }
+
/**
* Set the language and the title from a context object
*
return array( 'bitrate' => $bitrate );
}
+ /**
+ * @since 1.25
+ *
+ * @param string $plaintext
+ *
+ * @return string[] Array with a single "plaintext" key.
+ */
+ public static function plaintextParam( $plaintext ) {
+ return array( 'plaintext' => $plaintext );
+ }
+
/**
* Substitutes any parameters into the message text.
*
return array( 'before', $this->language->formatSize( $param['size'] ) );
} elseif ( isset( $param['bitrate'] ) ) {
return array( 'before', $this->language->formatBitrate( $param['bitrate'] ) );
+ } elseif ( isset( $param['plaintext'] ) ) {
+ return array( 'after', $this->formatPlaintext( $param['plaintext'] ) );
} else {
$warning = 'Invalid parameter for message "' . $this->getKey() . '": ' .
htmlspecialchars( serialize( $param ) );
return $this->message;
}
+ /**
+ * Formats a message parameter wrapped with 'plaintext'. Ensures that
+ * the entire string is displayed unchanged when displayed in the output
+ * format.
+ *
+ * @since 1.25
+ *
+ * @param string $plaintext String to ensure plaintext output of
+ *
+ * @return string Input plaintext encoded for output to $this->format
+ */
+ protected function formatPlaintext( $plaintext ) {
+ switch ( $this->format ) {
+ case 'text':
+ case 'plain':
+ return $plaintext;
+
+ case 'parse':
+ case 'block-parse':
+ case 'escaped':
+ default:
+ return htmlspecialchars( $plaintext, ENT_QUOTES );
+
+ }
+ }
}
/**
);
}
+ public function messagePlaintextParamsProvider() {
+ return array(
+ array(
+ 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
+ 'plain',
+ ),
+
+ array(
+ // expect
+ 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
+ // format
+ 'text',
+ ),
+ array(
+ 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
+ 'escaped',
+ ),
+
+ array(
+ 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
+ 'parse',
+ ),
+
+ array(
+ "<p>one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;\n</p>",
+ 'parseAsBlock',
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider messagePlaintextParamsProvider
+ * @covers Message::plaintextParams
+ */
+ public function testMessagePlaintextParams( $expect, $format ) {
+ $lang = Language::factory( 'en' );
+
+ $msg = new RawMessage( '$1 $2' );
+ $params = array(
+ 'one $2',
+ '<div>foo</div> [[Bar]] {{Baz}} <',
+ );
+ $this->assertEquals(
+ $expect,
+ $msg->inLanguage( $lang )->plaintextParams( $params )->$format(),
+ "Fail formatting for $format"
+ );
+ }
+
/**
* @covers Message::inContentLanguage
*/