$this->addWikiTextTitleInternal( $text, $title, $linestart, /*tidy*/true, /*interface*/true );
}
+ /**
+ * Convert wikitext *in the user interface language* to HTML and
+ * add it to the buffer with a `<div class="$wrapperClass">`
+ * wrapper. The result will not be language-converted, as user
+ * interface messages as already localized into a specific
+ * variant. The $text will be parsed in start-of-line context.
+ * Output will be tidy.
+ *
+ * @param string $wrapperClass The class attribute value for the <div>
+ * wrapper in the output HTML
+ * @param string $text Wikitext in the user interface language
+ * @since 1.32
+ */
+ public function wrapWikiTextAsInterface(
+ $wrapperClass, $text
+ ) {
+ $this->addWikiTextTitleInternal(
+ $text, $this->getTitle(),
+ /*linestart*/true, /*tidy*/true, /*interface*/true,
+ $wrapperClass
+ );
+ }
+
/**
* Convert wikitext *in the page content language* to HTML and add
* it to the buffer. The result with be language-converted to the
* since 1.32; all wikitext should be tidied.
* @param bool $interface Whether it is an interface message
* (for example disables conversion)
+ * @param string $wrapperClass if not empty, wraps the output in
+ * a `<div class="$wrapperClass">`
* @private
*/
private function addWikiTextTitleInternal(
- $text, Title $title, $linestart, $tidy, $interface
+ $text, Title $title, $linestart, $tidy, $interface, $wrapperClass = null
) {
global $wgParser;
$this->addParserOutput( $parserOutput, [
'enableSectionEditLinks' => false,
- 'wrapperDivClass' => '',
+ 'wrapperDivClass' => $wrapperClass ?? '',
] );
}
* @dataProvider provideAddWikiText
* @covers OutputPage::addWikiText
* @covers OutputPage::addWikiTextAsInterface
+ * @covers OutputPage::wrapWikiTextAsInterface
* @covers OutputPage::addWikiTextAsContent
* @covers OutputPage::addWikiTextWithTitle
* @covers OutputPage::addWikiTextTitle
'<div class="mw-editintro">' . "Some page\n</div>"
],
],
+ 'wrapWikiTextAsInterface' => [
+ 'Simple' => [
+ [ 'wrapperClass', 'text' ],
+ "<div class=\"wrapperClass\"><p>text\n</p></div>"
+ ], 'Spurious </div>' => [
+ [ 'wrapperClass', 'text</div><div>more' ],
+ "<div class=\"wrapperClass\"><p>text</p><div>more\n</div></div>"
+ ], 'Extra newlines would break <p> wrappers' => [
+ [ 'two classes', "1\n\n2\n\n3" ],
+ "<div class=\"two classes\"><p>1\n</p><p>2\n</p><p>3\n</p></div>"
+ ], 'Other unclosed tags' => [
+ [ 'error', 'a<b>c<i>d' ],
+ "<div class=\"error\"><p>a<b>c<i>d\n</i></b></p></div>"
+ ],
+ ],
];
// Test all the others on addWikiTextTitle as well