(Bug 12998) Weaken DISPLAYTITLE restictions (patch by rememberthedot@gmail.com)
authorAaron Schulz <aaron@users.mediawiki.org>
Tue, 30 Dec 2008 12:22:15 +0000 (12:22 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Tue, 30 Dec 2008 12:22:15 +0000 (12:22 +0000)
includes/EditPage.php
includes/OutputPage.php
includes/Skin.php
includes/parser/CoreParserFunctions.php
includes/parser/ParserOutput.php
skins/Modern.php
skins/MonoBook.php

index 1259eec..ed1806f 100644 (file)
@@ -1085,12 +1085,14 @@ class EditPage {
                } else {
                        # Use the title defined by DISPLAYTITLE magic word when present
                        if ( isset( $this->mParserOutput )
-                        && ( $dt = $this->mParserOutput->getDisplayTitle() ) !== false ) {
-                               $title = $dt;
+                               && ( $displayTitle = $this->mParserOutput->getDisplayTitle() ) !== false )
+                       {
+                               $wgOut->setPageTitle( wfMsg( 'editing', $this->mParserOutput->getDisplayTitleH1() ) );
+                               # Override the HTML that setPageTitle slated for inclusion in the <title>
+                               $wgOut->setHTMLTitle( wfMsg( 'pagetitle', wfMsg( 'editing', $displayTitle ) ) );
                        } else {
-                               $title = $wgTitle->getPrefixedText();
+                               $wgOut->setPageTitle( wfMsg( 'editing', $wgTitle->getPrefixedText() ) );
                        }
-                       $wgOut->setPageTitle( wfMsg( 'editing', $title ) );
                }
        }
 
index ab97478..bdc8a94 100644 (file)
@@ -309,7 +309,10 @@ class OutputPage {
                }
        }
 
-       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);
@@ -320,7 +323,7 @@ class OutputPage {
                                $name .= ' - '.$taction;
                        }
                }
-
+               
                $this->setHTMLTitle( wfMsg( 'pagetitle', $name ) );
        }
        public function getHTMLTitle() { return $this->mHTMLtitle; }
@@ -539,8 +542,10 @@ class OutputPage {
                        }
                }
                // 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;
index 0c221fe..425aa83 100644 (file)
@@ -1018,7 +1018,7 @@ END;
 
        function pageTitle() {
                global $wgOut;
-               $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
+               $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
                return $s;
        }
 
index a3b5189..7a507e7 100644 (file)
@@ -168,17 +168,24 @@ class CoreParserFunctions {
         * @param string $text Desired title text
         * @return string
         */
-       static function displaytitle( $parser, $text = '' ) {
+       static function displaytitle( $parser, $displayTitleH1 = '' ) {
                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
+               
                if ( !$wgRestrictDisplayTitle ) {
-                       $parser->mOutput->setDisplayTitle( $text );
+                       $parser->mOutput->setDisplayTitleH1( $titleHTML );
+                       $parser->mOutput->setDisplayTitle( $titleText );
                } else {
-                       $title = Title::newFromText( $text );
-                       if( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) )
-                               $parser->mOutput->setDisplayTitle( $text );
+                       # 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>
+                       }
                }
+               
                return '';
        }
 
index 3595138..045403d 100644 (file)
@@ -29,7 +29,8 @@ class ParserOutput
        /**
         * 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 = '' )
@@ -144,6 +145,15 @@ 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
@@ -154,14 +164,13 @@ class ParserOutput
        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;
        }
 
        /**
index cb24baf..400d7fe 100644 (file)
@@ -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->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">
index 5d6a5b1..987673a 100644 (file)
@@ -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->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>
@@ -371,3 +371,4 @@ class MonoBookTemplate extends QuickTemplate {
 } // end of class
 
 
+