=== 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.
* @return string
*/
function getPagesSection() {
- $ti = wfEscapeWikiText( $this->title->getText() );
+ $name = $this->getOutput()->getUnprefixedDisplayTitle();
# Don't show articles section if there are none.
$r = '';
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 );
* @return string
*/
function getImageSection() {
+ $name = $this->getOutput()->getUnprefixedDisplayTitle();
$r = '';
$rescnt = $this->showGallery ? $this->gallery->count() : count( $this->imgsNoGallery );
$dbcnt = $this->cat->getFileCount();
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' );
$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 ) );
* @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.
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
*
* @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 );
}
}