X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=2bfccda265327c30f6c90671c088a2893bf32a75;hb=300b91a1eccecb5f9c4e36126222edfddb33474b;hp=3675e8a4ee66b3bc7cf4c245cb212572aa813493;hpb=b83157af8f5579e214377aa9868d03780fbc70eb;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 3675e8a4ee..2bfccda265 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 * @@ -1715,7 +1766,8 @@ class OutputPage extends ContextSource { } /** - * Add wikitext with a custom Title object + * Add wikitext with a custom Title object. + * Output is unwrapped. * * @param string $text Wikitext * @param Title $title @@ -1742,6 +1794,7 @@ class OutputPage extends ContextSource { $this->addParserOutput( $parserOutput, [ 'enableSectionEditLinks' => false, + 'wrapperDivClass' => '', ] ); } @@ -2754,6 +2807,18 @@ class OutputPage extends ContextSource { foreach ( $this->contentOverrideCallbacks as $callback ) { $content = $callback( $title ); if ( $content !== null ) { + $text = ContentHandler::getContentText( $content ); + if ( strpos( $text, '' ) !== false ) { + // Proactively replace this so that we can display a message + // to the user, instead of letting it go to Html::inlineScript(), + // where it would be considered a server-side issue. + $titleFormatted = $title->getPrefixedText(); + $content = new JavaScriptContent( + Xml::encodeJsCall( 'mw.log.error', [ + "Cannot preview $titleFormatted due to script-closing tag." + ] ) + ); + } return $content; } }