+ /**
+ * Wrap the body text with language information and identifiable element
+ *
+ * @param Title $title
+ * @return string html
+ */
+ protected function wrapHTML( $title, $html ) {
+ # An ID that includes the actual body text; without categories, contentSub, ...
+ $realBodyAttribs = [ 'id' => 'mw-content-text' ];
+
+ # Add a mw-content-ltr/rtl class to be able to style based on text direction
+ # when the content is different from the UI language, i.e.:
+ # not for special pages or file pages AND only when viewing
+ if ( !in_array( $title->getNamespace(), [ NS_SPECIAL, NS_FILE ] ) &&
+ Action::getActionName( $this ) === 'view' ) {
+ $pageLang = $title->getPageViewLanguage();
+ $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
+ $realBodyAttribs['dir'] = $pageLang->getDir();
+ $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
+ }
+
+ return Html::rawElement( 'div', $realBodyAttribs, $html );
+ }
+