# Use the title defined by DISPLAYTITLE magic word when present
if ( isset($this->mParserOutput)
&& ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
- $title = $dt;
+ $wgOut->setPageTitle( wfMsg( 'editing', $this->mParserOutput->getDisplayTitleH1() ) );
+ $wgOut->setHTMLTitle( wfMsg( 'editing', $dt ) ); #override the HTML that setPageTitle slated for inclusion in the <title>
} else {
- $title = $wgTitle->getPrefixedText();
+ $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) );
}
- $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
}
}
}
}
- public function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; }
+ # "HTML title" means <title>
+ public function setHTMLTitle( $name ) { $this->mHTMLtitle = $name; }
+
+ # "Page title" means <h1>
public function setPageTitle( $name ) {
global $action, $wgContLang;
$name = $wgContLang->convert($name, true);
$name .= ' - '.$taction;
}
}
-
+
$this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
}
public function getHTMLTitle() { return $this->mHTMLtitle; }
}
}
// Display title
- if( ( $dt = $parserOutput->getDisplayTitle() ) !== false )
- $this->setPageTitle( $dt );
+ if( ( $displayTitleText = $parserOutput->getDisplayTitle() ) !== false ) {
+ $this->setPageTitle( $parserOutput->getDisplayTitleH1() );
+ $this->setHTMLTitle( wfMsg( 'pagetitle', $displayTitleText ) ); #override the HTML that setPageTitle slated for inclusion in the <title>
+ }
// Hooks registered in the object
global $wgParserOutputHooks;
function pageTitle() {
global $wgOut;
- $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
+ $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
return $s;
}
* @param string $text Desired title text
* @return string
*/
- static function displaytitle( $parser, $text = '' ) {
+ static function displaytitle( $parser, $displayTitleH1 = '', $displayTitleTitle = '' ) {
global $wgRestrictDisplayTitle;
- $text = trim( Sanitizer::decodeCharReferences( $text ) );
-
+
+ $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
+ }
+
if ( !$wgRestrictDisplayTitle ) {
- $parser->mOutput->setDisplayTitle( $text );
+ $parser->mOutput->setDisplayTitleH1( $titleHTML );
} else {
- $title = Title::newFromText( $text );
- if( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) )
- $parser->mOutput->setDisplayTitle( $text );
+ #only titles that normalize to the same title are allowed in the <h1> tag
+ $title = Title::newFromText( $titleText );
+
+ if ( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) {
+ $parser->mOutput->setDisplayTitleH1( $titleHTML );
+ } else {
+ $parser->mOutput->setDisplayTitleH1( $parser->mTitle );
+ }
}
+
return '';
}
/**
* Overridden title for display
*/
- private $displayTitle = false;
+ private $displayTitle = false; #for use in the <title> tag
+ private $displayTitleH1 = false; #for use in the <h1> tag, may contain further HTML tags
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
$containsOldMagic = false, $titletext = '' )
}
}
+ /**
+ * Get the title to be used for display
+ *
+ * @return string
+ */
+ public function getDisplayTitle() {
+ return $this->displayTitle;
+ }
+
/**
* Override the title to be used for display
* -- this is assumed to have been validated
public function setDisplayTitle( $text ) {
$this->displayTitle = $text;
}
-
- /**
- * Get the title to be used for display
- *
- * @return string
- */
- public function getDisplayTitle() {
- return $this->displayTitle;
+
+ public function getDisplayTitleH1() {
+ return $this->displayTitleH1;
+ }
+
+ public function setDisplayTitleH1( $html ) {
+ $this->displayTitleH1 = $html;
}
/**
class="mediawiki <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
<!-- heading -->
- <div id="mw_header"><h1 id="firstHeading"><?php $this->data['displaytitle']!=""?$this->html('title'):$this->text('title') ?></h1></div>
+ <div id="mw_header"><h1 id="firstHeading"><?php $this->html('title') ?></h1></div>
<div id="mw_main">
<div id="mw_contentwrapper">
<div id="content">
<a name="top" id="top"></a>
<?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
- <h1 class="firstHeading"><?php $this->data['displaytitle']!=""?$this->html('title'):$this->text('title') ?></h1>
+ <h1 class="firstHeading"><?php $this->html('title'); ?></h1>
<div id="bodyContent">
<h3 id="siteSub"><?php $this->msg('tagline') ?></h3>
<div id="contentSub"><?php $this->html('subtitle') ?></div>