X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/libs/HtmlArmor.php diff --git a/includes/libs/HtmlArmor.php b/includes/libs/HtmlArmor.php new file mode 100644 index 00000000..1c141ab0 --- /dev/null +++ b/includes/libs/HtmlArmor.php @@ -0,0 +1,57 @@ + + */ + +/** + * Marks HTML that shouldn't be escaped + * + * @since 1.28 + */ +class HtmlArmor { + + /** + * @var string|null + */ + private $value; + + /** + * @param string|null $value + */ + public function __construct( $value ) { + $this->value = $value; + } + + /** + * Provide a string or HtmlArmor object + * and get safe HTML back + * + * @param string|HtmlArmor $input + * @return string|null safe for usage in HTML, or null + * if the HtmlArmor instance was wrapping null. + */ + public static function getHtml( $input ) { + if ( $input instanceof HtmlArmor ) { + return $input->value; + } else { + return htmlspecialchars( $input, ENT_QUOTES ); + } + } +}