Merge "Improve page display title handling for category pages"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 12 Sep 2018 07:25:46 +0000 (07:25 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 12 Sep 2018 07:25:46 +0000 (07:25 +0000)
RELEASE-NOTES-1.32
includes/CategoryViewer.php
includes/EditPage.php
includes/OutputPage.php
includes/page/Article.php

index 2f5d66f..041b3d7 100644 (file)
@@ -114,6 +114,7 @@ production.
 === Bug fixes in 1.32 ===
 * SpecialPage::execute() will now only call checkLoginSecurityLevel() if
   getLoginSecurityLevel() returns non-false.
+* (T43720, T46197) Improved page display title handling for category pages
 
 === Action API changes in 1.32 ===
 * Added templated parameters.
index 46a1473..a07e1b4 100644 (file)
@@ -424,7 +424,7 @@ class CategoryViewer extends ContextSource {
         * @return string
         */
        function getPagesSection() {
-               $ti = wfEscapeWikiText( $this->title->getText() );
+               $name = $this->getOutput()->getUnprefixedDisplayTitle();
                # Don't show articles section if there are none.
                $r = '';
 
@@ -440,7 +440,7 @@ class CategoryViewer extends ContextSource {
 
                if ( $rescnt > 0 ) {
                        $r = "<div id=\"mw-pages\">\n";
-                       $r .= '<h2>' . $this->msg( 'category_header', $ti )->parse() . "</h2>\n";
+                       $r .= '<h2>' . $this->msg( 'category_header' )->rawParams( $name )->parse() . "</h2>\n";
                        $r .= $countmsg;
                        $r .= $this->getSectionPagingLinks( 'page' );
                        $r .= $this->formatList( $this->articles, $this->articles_start_char );
@@ -454,6 +454,7 @@ class CategoryViewer extends ContextSource {
         * @return string
         */
        function getImageSection() {
+               $name = $this->getOutput()->getUnprefixedDisplayTitle();
                $r = '';
                $rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
                $dbcnt = $this->cat->getFileCount();
@@ -463,10 +464,7 @@ class CategoryViewer extends ContextSource {
                if ( $rescnt > 0 ) {
                        $r .= "<div id=\"mw-category-media\">\n";
                        $r .= '<h2>' .
-                               $this->msg(
-                                       'category-media-header',
-                                       wfEscapeWikiText( $this->title->getText() )
-                               )->text() .
+                               $this->msg( 'category-media-header' )->rawParams( $name )->parse() .
                                "</h2>\n";
                        $r .= $countmsg;
                        $r .= $this->getSectionPagingLinks( 'file' );
index d8903c3..64b2f01 100644 (file)
@@ -2490,6 +2490,8 @@ ERROR;
                $displayTitle = isset( $this->mParserOutput ) ? $this->mParserOutput->getDisplayTitle() : false;
                if ( $displayTitle === false ) {
                        $displayTitle = $contextTitle->getPrefixedText();
+               } else {
+                       $out->setDisplayTitle( $displayTitle );
                }
                $out->setPageTitle( $this->context->msg( $msg, $displayTitle ) );
 
index 4f12e0c..99a4c2b 100644 (file)
@@ -58,6 +58,15 @@ class OutputPage extends ContextSource {
         * @var string The contents of <h1> */
        private $mPageTitle = '';
 
+       /**
+        * @var string The displayed title of the page. Different from page title
+        * if overridden by display title magic word or hooks. Can contain safe
+        * HTML. Different from page title which may contain messages such as
+        * "Editing X" which is displayed in h1. This can be used for other places
+        * where the page name is referred on the page.
+        */
+       private $displayTitle;
+
        /**
         * @var string Contains all of the "<body>" content. Should be private we
         *   got set/get accessors and the append() method.
@@ -964,6 +973,48 @@ class OutputPage extends ContextSource {
                return $this->mPageTitle;
        }
 
+       /**
+        * Same as page title but only contains name of the page, not any other text.
+        *
+        * @since 1.32
+        * @param string $html Page title text.
+        * @see OutputPage::setPageTitle
+        */
+       public function setDisplayTitle( $html ) {
+               $this->displayTitle = $html;
+       }
+
+       /**
+        * Returns page display title.
+        *
+        * Performs some normalization, but this not as strict the magic word.
+        *
+        * @since 1.32
+        * @return string HTML
+        */
+       public function getDisplayTitle() {
+               $html = $this->displayTitle;
+               if ( $html === null ) {
+                       $html = $this->getTitle()->getPrefixedText();
+               }
+
+               return Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags( $html ) );
+       }
+
+       /**
+        * Returns page display title without namespace prefix if possible.
+        *
+        * @since 1.32
+        * @return string HTML
+        */
+       public function getUnprefixedDisplayTitle() {
+               $text = $this->getDisplayTitle();
+               $nsPrefix = $this->getTitle()->getNsText() . ':';
+               $prefix = preg_quote( $nsPrefix, '/' );
+
+               return preg_replace( "/^$prefix/i", '', $text );
+       }
+
        /**
         * Set the Title object to use
         *
index 464bb60..7404f83 100644 (file)
@@ -878,10 +878,13 @@ class Article implements Page {
         * @param ParserOutput $pOutput
         */
        public function adjustDisplayTitle( ParserOutput $pOutput ) {
+               $out = $this->getContext()->getOutput();
+
                # Adjust the title if it was set by displaytitle, -{T|}- or language conversion
                $titleText = $pOutput->getTitleText();
                if ( strval( $titleText ) !== '' ) {
-                       $this->getContext()->getOutput()->setPageTitle( $titleText );
+                       $out->setPageTitle( $titleText );
+                       $out->setDisplayTitle( $titleText );
                }
        }