+
+ $titleHTML = Sanitizer::removeHTMLtags( $displayTitleH1 ); #escape the bad tags
+ $titleText = trim( Sanitizer::stripAllTags( $titleHTML ) ); #remove the good tags, leaving the bad tags escaped, and trim it to make sure it comes out pretty
+
+ #the user can put any sanitized text into the page title used in the <title> attribute, since it is not copy-pasteable like the <h1> tag
+ if ($displayTitleTitle == '') {
+ $parser->mOutput->setDisplayTitle( $titleText ); #use the stripped contents of <h1>
+ } else {
+ $parser->mOutput->setDisplayTitle( $displayTitleTitle ); #use what the user explicitly requested, MediaWiki escapes this automatically before it is served out
+ }
+