X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=99a4c2b895353acb42fb6d8f95245814f640562a;hb=62c36e82cf424f6ef51b524b2da41ff798111d83;hp=4f12e0cfd0f1e961e7088a923ebd0dde97559678;hpb=a3357744c34d6f5b8e39114e64c6937800698069;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 4f12e0cfd0..99a4c2b895 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -58,6 +58,15 @@ class OutputPage extends ContextSource { * @var string The contents of

*/ 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 "" 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 *