From: Brion Vibber Date: Wed, 10 Dec 2008 23:21:28 +0000 (+0000) Subject: Revert r44271 "(bug 12998) Weaken DISPLAYTITLE restictions (patch by 'rememberthedot... X-Git-Tag: 1.31.0-rc.0~44052 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=95211ac8509f68f0b794042351c652f30bbeaeb1;p=lhc%2Fweb%2Fwiklou.git Revert r44271 "(bug 12998) Weaken DISPLAYTITLE restictions (patch by 'rememberthedot@gmail.com')" Behavior seems a bit hard to predict, as far as what's going to go in the header and what in the browser window etc. Pulling it back for further testing and discussion. --- diff --git a/includes/EditPage.php b/includes/EditPage.php index a2874556de..ea4c056e27 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1083,11 +1083,11 @@ class EditPage { # Use the title defined by DISPLAYTITLE magic word when present if ( isset($this->mParserOutput) && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) { - $wgOut->setPageTitle( wfMsg( 'editing', $this->mParserOutput->getDisplayTitleH1() ) ); - $wgOut->setHTMLTitle( wfMsg( 'editing', $dt ) ); #override the HTML that setPageTitle slated for inclusion in the + $title = $dt; } else { - $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) ); + $title = $wgTitle->getPrefixedText(); } + $wgOut->setPageTitle( wfMsg( 'editing', $title ) ); } } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 121a56ad96..dcd5c309be 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -309,10 +309,7 @@ class OutputPage { } } - # "HTML title" means <title> - public function setHTMLTitle( $name ) { $this->mHTMLtitle = $name; } - - # "Page title" means <h1> + public function setHTMLTitle( $name ) {$this->mHTMLtitle = $name; } public function setPageTitle( $name ) { global $action, $wgContLang; $name = $wgContLang->convert($name, true); @@ -323,7 +320,7 @@ class OutputPage { $name .= ' - '.$taction; } } - + $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) ); } public function getHTMLTitle() { return $this->mHTMLtitle; } @@ -542,10 +539,8 @@ class OutputPage { } } // Display title - 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> - } + if( ( $dt = $parserOutput->getDisplayTitle() ) !== false ) + $this->setPageTitle( $dt ); // Hooks registered in the object global $wgParserOutputHooks; diff --git a/includes/Skin.php b/includes/Skin.php index 2ae8d27870..d02c0770fb 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1014,7 +1014,7 @@ END; function pageTitle() { global $wgOut; - $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>'; + $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>'; return $s; } diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index ca03435fe8..4a21b5625a 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -164,32 +164,17 @@ class CoreParserFunctions { * @param string $text Desired title text * @return string */ - static function displaytitle( $parser, $displayTitleH1 = '', $displayTitleTitle = '' ) { + static function displaytitle( $parser, $text = '' ) { global $wgRestrictDisplayTitle; - - $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 - } - + $text = trim( Sanitizer::decodeCharReferences( $text ) ); + if ( !$wgRestrictDisplayTitle ) { - $parser->mOutput->setDisplayTitleH1( $titleHTML ); + $parser->mOutput->setDisplayTitle( $text ); } else { - #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 ); - } + $title = Title::newFromText( $text ); + if( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) + $parser->mOutput->setDisplayTitle( $text ); } - return ''; } diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 045403dae2..35951387dd 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -29,8 +29,7 @@ class ParserOutput /** * Overridden title for display */ - private $displayTitle = false; #for use in the <title> tag - private $displayTitleH1 = false; #for use in the <h1> tag, may contain further HTML tags + private $displayTitle = false; function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(), $containsOldMagic = false, $titletext = '' ) @@ -145,15 +144,6 @@ class ParserOutput } } - /** - * 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 @@ -164,13 +154,14 @@ class ParserOutput public function setDisplayTitle( $text ) { $this->displayTitle = $text; } - - public function getDisplayTitleH1() { - return $this->displayTitleH1; - } - - public function setDisplayTitleH1( $html ) { - $this->displayTitleH1 = $html; + + /** + * Get the title to be used for display + * + * @return string + */ + public function getDisplayTitle() { + return $this->displayTitle; } /** diff --git a/skins/Modern.php b/skins/Modern.php index 18fd4a552a..1b5e078907 100644 --- a/skins/Modern.php +++ b/skins/Modern.php @@ -102,7 +102,7 @@ class ModernTemplate extends QuickTemplate { class="mediawiki <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>"> <!-- heading --> - <div id="mw_header"><h1 id="firstHeading"><?php $this->html('title') ?></h1></div> + <div id="mw_header"><h1 id="firstHeading"><?php $this->data['displaytitle']!=""?$this->html('title'):$this->text('title') ?></h1></div> <div id="mw_main"> <div id="mw_contentwrapper"> diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 1c11fc5b9d..38ec39cd55 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -115,7 +115,7 @@ class MonoBookTemplate extends QuickTemplate { <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->html('title'); ?></h1> + <h1 class="firstHeading"><?php $this->data['displaytitle']!=""?$this->html('title'):$this->text('title') ?></h1> <div id="bodyContent"> <h3 id="siteSub"><?php $this->msg('tagline') ?></h3> <div id="contentSub"><?php $this->html('subtitle') ?></div>