Arlolra has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/370189 )
Change subject: html: Add an Html::comment() method
......................................................................
html: Add an Html::comment() method
Change-Id: I1b0b9d77071eb985bbd237d30e5ba480321464f9
---
M includes/Html.php
M tests/phpunit/includes/HtmlTest.php
2 files changed, 41 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/89/370189/1
diff --git a/includes/Html.php b/includes/Html.php
index 8fe4dbe..b35ea33 100644
--- a/includes/Html.php
+++ b/includes/Html.php
@@ -238,6 +238,29 @@
}
/**
+ * @param string $contents
+ *
+ * @return string
+ */
+ public static function rawComment( $contents = '' ) {
+ return "<!--{$contents}-->";
+ }
+
+ /**
+ * @param string $contents
+ *
+ * @return string
+ */
+ public static function comment( $contents = '' ) {
+ $contents = strtr( $contents, [
+ '-' => '+',
+ '>' => '>',
+ '&' => '&',
+ ] );
+ return self::rawComment( ' ' . $contents . ' ' );
+ }
+
+ /**
* Identical to rawElement(), but has no third parameter and omits the
end
* tag (and the self-closing '/' in XML mode for empty elements).
*
diff --git a/tests/phpunit/includes/HtmlTest.php
b/tests/phpunit/includes/HtmlTest.php
index f3d4916..f2b4c99 100644
--- a/tests/phpunit/includes/HtmlTest.php
+++ b/tests/phpunit/includes/HtmlTest.php
@@ -65,6 +65,24 @@
);
}
+ /**
+ * @covers Html::comment
+ * @covers Html::rawComment
+ */
+ public function testCommentBasics() {
+ $this->assertEquals(
+ '<!-- hi -->',
+ Html::comment( 'hi' ),
+ 'Basic comment'
+ );
+
+ $this->assertEquals(
+ '<!-- ++> -->',
+ Html::comment( '-->' ),
+ 'Comment requiring escaping'
+ );
+ }
+
public function dataXmlMimeType() {
return [
// ( $mimetype, $isXmlMimeType )
--
To view, visit https://gerrit.wikimedia.org/r/370189
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1b0b9d77071eb985bbd237d30e5ba480321464f9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits