Manual:HtmlArmor.php
Appearance
| MediaWiki バージョン: | ≧ 1.28 Gerrit change 284750 |
| MediaWiki ファイル: includes/libs/HtmlArmor/HtmlArmor.php | |
|---|---|
| ソース コード: | master • 1.45.1 • 1.44.3 • 1.43.6 |
| クラス: | Wikimedia\HtmlArmor\HtmlArmor |
HtmlArmor is a small utility class for situations where you want to accept a parameter of text that is normally escaped, but in some cases needs to accept raw HTML.
使用法
/**
* @param string|HtmlArmor $text
* @return string
*/
function fooBar( $text ) {
$html = HtmlArmor::getHtml( $text );
return "<stuff>$html</stuff>";
}
In the above example, the $text parameter can either be a to-be-escaped string, or an HtmlArmor object that should remain the same.
The HtmlArmor::getHtml() function will take care of the escaping for you, providing you with content you know that is safe HTML.
fooBar( "this will be <b>escaped!</b>" );
// <stuff>this will be <b>escaped!</b></stuff>
fooBar( new HtmlArmor( "this will <i>not</i> be <b>escaped!</b>" ) );
// <stuff>this will <i>not</i> be <b>escaped!</b></stuff>"