From 880d68b28c367a047f7002ed1a82e718ace9dd9e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 31 Dec 2008 16:49:38 +0000 Subject: [PATCH] Pull back r45181 "(Bug 12998) Weaken DISPLAYTITLE restictions (patch by rememberthedot@gmail.com)" for now. Escaping issues per comment http://www.mediawiki.org/wiki/Special:Code/MediaWiki/45181#c1046 --- includes/EditPage.php | 10 ++++----- includes/OutputPage.php | 13 ++++-------- includes/parser/CoreParserFunctions.php | 21 +++++++------------ includes/parser/ParserOutput.php | 27 +++++++++---------------- skins/Modern.php | 2 +- skins/MonoBook.php | 3 +-- 6 files changed, 26 insertions(+), 50 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index ed1806ff0f..1259eecae1 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1085,14 +1085,12 @@ class EditPage { } else { # Use the title defined by DISPLAYTITLE magic word when present if ( isset( $this->mParserOutput ) - && ( $displayTitle = $this->mParserOutput->getDisplayTitle() ) !== false ) - { - $wgOut->setPageTitle( wfMsg( 'editing', $this->mParserOutput->getDisplayTitleH1() ) ); - # Override the HTML that setPageTitle slated for inclusion in the - $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'editing', $displayTitle ) ) ); + && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) { + $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 bdc8a944c5..ab974785db 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/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 7a507e7c21..a3b5189a31 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -168,24 +168,17 @@ class CoreParserFunctions { * @param string $text Desired title text * @return string */ - static function displaytitle( $parser, $displayTitleH1 = '' ) { + 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 - + $text = trim( Sanitizer::decodeCharReferences( $text ) ); + if ( !$wgRestrictDisplayTitle ) { - $parser->mOutput->setDisplayTitleH1( $titleHTML ); - $parser->mOutput->setDisplayTitle( $titleText ); + $parser->mOutput->setDisplayTitle( $text ); } else { - # Only requested titles that normalize to the actual title are allowed through - $title = Title::newFromText( $titleText ); - if ( $title != null && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) { - $parser->mOutput->setDisplayTitleH1( $titleHTML ); - $parser->mOutput->setDisplayTitle( $titleText ); #put the stripped contents of <h1> into <title> - } + $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 400d7fe650..cb24bafaef 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 987673ac68..5d6a5b1a97 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> @@ -371,4 +371,3 @@ class MonoBookTemplate extends QuickTemplate { } // end of class - -- 2.20.1