X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=cde92e8c176a129c36289b8200cbae04bbe6db59;hb=cc2d3607ac7e434f150d66b156643219aee8808a;hp=99a4c2b895353acb42fb6d8f95245814f640562a;hpb=3b5c100426f06f9dbd11571e725ffa1eb00e2cb6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 99a4c2b895..cde92e8c17 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -85,6 +85,9 @@ class OutputPage extends ContextSource { /** @var bool Stores "article flag" toggle. */ private $mIsArticleRelated = true; + /** @var bool Is the content subject to copyright */ + private $mHasCopyright = false; + /** * @var bool We have to set isPrintable(). Some pages should * never be printed (ex: redirections). @@ -320,6 +323,11 @@ class OutputPage extends ContextSource { */ private $CSPNonce; + /** + * @var array A cache of the names of the cookies that will influence the cache + */ + private static $cacheVaryCookies = null; + /** * Constructor for OutputPage. This should not be called directly. * Instead a new RequestContext should be created and it will implicitly create @@ -1261,6 +1269,28 @@ class OutputPage extends ContextSource { return $this->mIsArticleRelated; } + /** + * Set whether the standard copyright should be shown for the current page. + * + * @param bool $hasCopyright + */ + public function setCopyright( $hasCopyright ) { + $this->mHasCopyright = $hasCopyright; + } + + /** + * Return whether the standard copyright should be shown for the current page. + * By default, it is true for all articles but other pages + * can signal it by using setCopyright( true ). + * + * Used by SkinTemplate to decided whether to show the copyright. + * + * @return bool + */ + public function showsCopyright() { + return $this->isArticle() || $this->mHasCopyright; + } + /** * Add new language links * @@ -1723,13 +1753,71 @@ class OutputPage extends ContextSource { * @param bool $linestart Is this the start of a line? * @param bool $interface Is this text in the user interface language? * @throws MWException + * @deprecated since 1.32 due to untidy output; use + * addWikiTextAsInterface() if $interface is default value or true, + * or else addWikiTextAsContent() if $interface is false. */ public function addWikiText( $text, $linestart = true, $interface = true ) { - $title = $this->getTitle(); // Work around E_STRICT + $title = $this->getTitle(); + if ( !$title ) { + throw new MWException( 'Title is null' ); + } + $this->addWikiTextTitleInternal( $text, $title, $linestart, /*tidy*/false, $interface ); + } + + /** + * Convert wikitext *in the user interface language* to HTML and + * add it to the buffer. The result will not be + * language-converted, as user interface messages are already + * localized into a specific variant. Assumes that the current + * page title will be used if optional $title is not + * provided. Output will be tidy. + * + * @param string $text Wikitext in the user interface language + * @param bool $linestart Is this the start of a line? (Defaults to true) + * @param Title|null $title Optional title to use; default of `null` + * means use current page title. + * @throws MWException if $title is not provided and OutputPage::getTitle() + * is null + * @since 1.32 + */ + public function addWikiTextAsInterface( + $text, $linestart = true, Title $title = null + ) { + if ( $title === null ) { + $title = $this->getTitle(); + } + if ( !$title ) { + throw new MWException( 'Title is null' ); + } + $this->addWikiTextTitleInternal( $text, $title, $linestart, /*tidy*/true, /*interface*/true ); + } + + /** + * Convert wikitext *in the page content language* to HTML and add + * it to the buffer. The result with be language-converted to the + * user's preferred variant. Assumes that the current page title + * will be used if optional $title is not provided. Output will be + * tidy. + * + * @param string $text Wikitext in the page content language + * @param bool $linestart Is this the start of a line? (Defaults to true) + * @param Title|null $title Optional title to use; default of `null` + * means use current page title. + * @throws MWException if $title is not provided and OutputPage::getTitle() + * is null + * @since 1.32 + */ + public function addWikiTextAsContent( + $text, $linestart = true, Title $title = null + ) { + if ( $title === null ) { + $title = $this->getTitle(); + } if ( !$title ) { throw new MWException( 'Title is null' ); } - $this->addWikiTextTitle( $text, $title, $linestart, /*tidy*/false, $interface ); + $this->addWikiTextTitleInternal( $text, $title, $linestart, /*tidy*/true, /*interface*/false ); } /** @@ -1738,45 +1826,88 @@ class OutputPage extends ContextSource { * @param string $text Wikitext * @param Title $title * @param bool $linestart Is this the start of a line? + * @deprecated since 1.32 due to untidy output; use + * addWikiTextAsInterface() */ public function addWikiTextWithTitle( $text, Title $title, $linestart = true ) { - $this->addWikiTextTitle( $text, $title, $linestart ); + wfDeprecated( __METHOD__, '1.32' ); + $this->addWikiTextTitleInternal( $text, $title, $linestart, /*tidy*/false, /*interface*/false ); } /** - * Add wikitext with a custom Title object and tidy enabled. + * Add wikitext *in content language* with a custom Title object. + * Output will be tidy. * - * @param string $text Wikitext + * @param string $text Wikitext in content language * @param Title $title * @param bool $linestart Is this the start of a line? + * @deprecated since 1.32 to rename methods consistently; use + * addWikiTextAsContent() */ function addWikiTextTitleTidy( $text, Title $title, $linestart = true ) { - $this->addWikiTextTitle( $text, $title, $linestart, true ); + wfDeprecated( __METHOD__, '1.32' ); + $this->addWikiTextTitleInternal( $text, $title, $linestart, /*tidy*/true, /*interface*/false ); } /** - * Add wikitext with tidy enabled + * Add wikitext *in content language*. Output will be tidy. * - * @param string $text Wikitext + * @param string $text Wikitext in content language * @param bool $linestart Is this the start of a line? + * @deprecated since 1.32 to rename methods consistently; use + * addWikiTextAsContent() */ public function addWikiTextTidy( $text, $linestart = true ) { + wfDeprecated( __METHOD__, '1.32' ); $title = $this->getTitle(); - $this->addWikiTextTitleTidy( $text, $title, $linestart ); + if ( !$title ) { + throw new MWException( 'Title is null' ); + } + $this->addWikiTextTitleInternal( $text, $title, $linestart, /*tidy*/true, /*interface*/false ); } /** - * Add wikitext with a custom Title object + * Add wikitext with a custom Title object. + * Output is unwrapped. * * @param string $text Wikitext * @param Title $title * @param bool $linestart Is this the start of a line? - * @param bool $tidy Whether to use tidy + * @param bool $tidy Whether to use tidy. + * Setting this to false (or omitting it) is deprecated + * since 1.32; all wikitext should be tidied. + * For backwards-compatibility with prior MW releases, + * you may wish to invoke this method but set $tidy=true; + * this will result in equivalent output to the non-deprecated + * addWikiTextAsContent()/addWikiTextAsInterface() methods. * @param bool $interface Whether it is an interface message * (for example disables conversion) + * @deprecated since 1.32, use addWikiTextAsContent() or + * addWikiTextAsInterface() (depending on $interface) */ public function addWikiTextTitle( $text, Title $title, $linestart, $tidy = false, $interface = false + ) { + wfDeprecated( __METHOD__, '1.32' ); + return $this->addWikiTextTitleInternal( $text, $title, $linestart, $tidy, $interface ); + } + + /** + * Add wikitext with a custom Title object. + * Output is unwrapped. + * + * @param string $text Wikitext + * @param Title $title + * @param bool $linestart Is this the start of a line? + * @param bool $tidy Whether to use tidy. + * Setting this to false (or omitting it) is deprecated + * since 1.32; all wikitext should be tidied. + * @param bool $interface Whether it is an interface message + * (for example disables conversion) + * @private + */ + private function addWikiTextTitleInternal( + $text, Title $title, $linestart, $tidy, $interface ) { global $wgParser; @@ -1793,6 +1924,7 @@ class OutputPage extends ContextSource { $this->addParserOutput( $parserOutput, [ 'enableSectionEditLinks' => false, + 'wrapperDivClass' => '', ] ); } @@ -1973,6 +2105,9 @@ class OutputPage extends ContextSource { /** * Parse wikitext, strip paragraphs, and return the HTML. * + * @todo This doesn't work as expected at all. If $interface is false, there's always a + * wrapping
, so stripOuterParagraph() does nothing. + * * @param string $text * @param bool $linestart Is this the start of a line? * @param bool $interface Use interface language (instead of content language) while parsing @@ -2017,8 +2152,6 @@ class OutputPage extends ContextSource { * @param string|int|float|bool|null $mtime Last-Modified timestamp * @param int $minTTL Minimum TTL in seconds [default: 1 minute] * @param int $maxTTL Maximum TTL in seconds [default: $wgSquidMaxage] - * @return int TTL in seconds passed to lowerCdnMaxage() (may not be the same as the new - * s-maxage) * @since 1.28 */ public function adaptCdnTTL( $mtime, $minTTL = 0, $maxTTL = 0 ) { @@ -2029,13 +2162,11 @@ class OutputPage extends ContextSource { return $minTTL; // entity does not exist } - $age = time() - wfTimestamp( TS_UNIX, $mtime ); + $age = MWTimestamp::time() - wfTimestamp( TS_UNIX, $mtime ); $adaptiveTTL = max( 0.9 * $age, $minTTL ); $adaptiveTTL = min( $adaptiveTTL, $maxTTL ); $this->lowerCdnMaxage( (int)$adaptiveTTL ); - - return $adaptiveTTL; } /** @@ -2055,19 +2186,18 @@ class OutputPage extends ContextSource { * @return array */ function getCacheVaryCookies() { - static $cookies; - if ( $cookies === null ) { + if ( self::$cacheVaryCookies === null ) { $config = $this->getConfig(); - $cookies = array_merge( + self::$cacheVaryCookies = array_values( array_unique( array_merge( SessionManager::singleton()->getVaryCookies(), [ 'forceHTTPS', ], $config->get( 'CacheVaryCookies' ) - ); - Hooks::run( 'GetCacheVaryCookies', [ $this, &$cookies ] ); + ) ) ); + Hooks::run( 'GetCacheVaryCookies', [ $this, &self::$cacheVaryCookies ] ); } - return $cookies; + return self::$cacheVaryCookies; } /** @@ -2151,8 +2281,12 @@ class OutputPage extends ContextSource { * Get a complete Key header * * @return string + * @deprecated in 1.32; the IETF spec for this header expired w/o becoming + * a standard. */ public function getKeyHeader() { + wfDeprecated( '$wgUseKeyHeader', '1.32' ); + $cvCookies = $this->getCacheVaryCookies(); $cookiesOption = []; @@ -2200,6 +2334,16 @@ class OutputPage extends ContextSource { continue; } + // XXX Note that this code is not strictly correct: we + // do a case-insensitive match in + // LanguageConverter::getHeaderVariant() while the + // (abandoned, draft) spec for the `Key` header only + // allows case-sensitive matches. To match the logic + // in LanguageConverter::getHeaderVariant() we should + // also be looking at fallback variants and deprecated + // mediawiki-internal codes, as well as BCP 47 + // normalized forms. + $aloption[] = "substr=$variant"; // IE and some other browsers use BCP 47 standards in their Accept-Language header, @@ -3995,4 +4139,5 @@ class OutputPage extends ContextSource { } return $this->CSPNonce; } + }