X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=bf59c9a5d205f60576bf00f12261ac535c5267e6;hb=919992eeced33aa7a9e4b4a7505464e05c14e739;hp=c57e219f8c39dd6e8d00deea9ac61d0064b03318;hpb=09110719680d7a0646a454ff1b2633a042952003;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index c57e219f8c..bf59c9a5d2 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1782,7 +1782,9 @@ class OutputPage extends ContextSource { } // Include profiling data - $this->setLimitReportData( $parserOutput->getLimitReportData() ); + if ( !$this->limitReportData ) { + $this->setLimitReportData( $parserOutput->getLimitReportData() ); + } // Link flags are ignored for now, but may in the future be // used to mark individual language links. @@ -1931,6 +1933,36 @@ class OutputPage extends ContextSource { $this->setCdnMaxage( $this->mCdnMaxage ); } + /** + * Get TTL in [$minTTL,$maxTTL] in pass it to lowerCdnMaxage() + * + * This sets and returns $minTTL if $mtime is false or null. Otherwise, + * the TTL is higher the older the $mtime timestamp is. Essentially, the + * TTL is 90% of the age of the object, subject to the min and max. + * + * @param string|integer|float|bool|null $mtime Last-Modified timestamp + * @param integer $minTTL Mimimum TTL in seconds [default: 1 minute] + * @param integer $maxTTL Maximum TTL in seconds [default: $wgSquidMaxage] + * @return integer TTL in seconds + * @since 1.28 + */ + public function adaptCdnTTL( $mtime, $minTTL = 0, $maxTTL = 0 ) { + $minTTL = $minTTL ?: IExpiringStore::TTL_MINUTE; + $maxTTL = $maxTTL ?: $this->getConfig()->get( 'SquidMaxage' ); + + if ( $mtime === null || $mtime === false ) { + return $minTTL; // entity does not exist + } + + $age = time() - wfTimestamp( TS_UNIX, $mtime ); + $adaptiveTTL = max( .9 * $age, $minTTL ); + $adaptiveTTL = min( $adaptiveTTL, $maxTTL ); + + $this->lowerCdnMaxage( (int)$adaptiveTTL ); + + return $adaptiveTTL; + } + /** * Use enableClientCache(false) to force it to send nocache headers * @@ -2166,22 +2198,26 @@ class OutputPage extends ContextSource { # We'll purge the proxy cache explicitly, but require end user agents # to revalidate against the proxy on each visit. # Surrogate-Control controls our CDN, Cache-Control downstream caches - wfDebug( __METHOD__ . ": proxy caching with ESI; {$this->mLastModified} **", 'private' ); + wfDebug( __METHOD__ . + ": proxy caching with ESI; {$this->mLastModified} **", 'private' ); # start with a shorter timeout for initial testing # header( 'Surrogate-Control: max-age=2678400+2678400, content="ESI/1.0"'); - $response->header( 'Surrogate-Control: max-age=' . $config->get( 'SquidMaxage' ) - . '+' . $this->mCdnMaxage . ', content="ESI/1.0"' ); + $response->header( + "Surrogate-Control: max-age={$config->get( 'SquidMaxage' )}" . + "+{$this->mCdnMaxage}, content=\"ESI/1.0\"" + ); $response->header( 'Cache-Control: s-maxage=0, must-revalidate, max-age=0' ); } else { # We'll purge the proxy cache for anons explicitly, but require end user agents # to revalidate against the proxy on each visit. # IMPORTANT! The CDN needs to replace the Cache-Control header with # Cache-Control: s-maxage=0, must-revalidate, max-age=0 - wfDebug( __METHOD__ . ": local proxy caching; {$this->mLastModified} **", 'private' ); + wfDebug( __METHOD__ . + ": local proxy caching; {$this->mLastModified} **", 'private' ); # start with a shorter timeout for initial testing # header( "Cache-Control: s-maxage=2678400, must-revalidate, max-age=0" ); - $response->header( 'Cache-Control: s-maxage=' . $this->mCdnMaxage - . ', must-revalidate, max-age=0' ); + $response->header( "Cache-Control: " . + "s-maxage={$this->mCdnMaxage}, must-revalidate, max-age=0" ); } } else { # We do want clients to cache if they can, but they *must* check for updates @@ -2215,6 +2251,8 @@ class OutputPage extends ContextSource { * @throws MWException */ public function output( $return = false ) { + global $wgContLang; + if ( $this->mDoNothing ) { return $return ? '' : null; } @@ -2261,7 +2299,7 @@ class OutputPage extends ContextSource { ob_start(); $response->header( 'Content-type: ' . $config->get( 'MimeType' ) . '; charset=UTF-8' ); - $response->header( 'Content-language: ' . $config->get( 'ContLang' )->getHtmlCode() ); + $response->header( 'Content-language: ' . $wgContLang->getHtmlCode() ); // Avoid Internet Explorer "compatibility view" in IE 8-10, so that // jQuery etc. can work correctly. @@ -2356,7 +2394,7 @@ class OutputPage extends ContextSource { * Output a standard error page * * showErrorPage( 'titlemsg', 'pagetextmsg' ); - * showErrorPage( 'titlemsg', 'pagetextmsg', array( 'param1', 'param2' ) ); + * showErrorPage( 'titlemsg', 'pagetextmsg', [ 'param1', 'param2' ] ); * showErrorPage( 'titlemsg', $messageObject ); * showErrorPage( $titleMessageObject, $messageObject ); * @@ -2388,10 +2426,14 @@ class OutputPage extends ContextSource { /** * Output a standard permission error page * - * @param array $errors Error message keys + * @param array $errors Error message keys or [key, param...] arrays * @param string $action Action that was denied or null if unknown */ public function showPermissionsErrorPage( array $errors, $action = null ) { + foreach ( $errors as $key => $error ) { + $errors[$key] = (array)$error; + } + // For some action (read, edit, create and upload), display a "login to do this action" // error if all of the following conditions are met: // 1. the user is not logged in @@ -2684,15 +2726,13 @@ class OutputPage extends ContextSource { $exemptStates = []; $moduleStyles = $this->getModuleStyles( /*filter*/ true ); - // Batch preload getTitleInfo for isKnownEmpty() calls below - $exemptModules = array_filter( $moduleStyles, - function ( $name ) use ( $rl, &$exemptGroups ) { - $module = $rl->getModule( $name ); - return $module && isset( $exemptGroups[ $module->getGroup() ] ); - } - ); - ResourceLoaderWikiModule::preloadTitleInfo( - $context, wfGetDB( DB_REPLICA ), $exemptModules ); + // Preload getTitleInfo for isKnownEmpty calls below and in ResourceLoaderClientHtml + // Separate user-specific batch for improved cache-hit ratio. + $userBatch = [ 'user.styles', 'user' ]; + $siteBatch = array_diff( $moduleStyles, $userBatch ); + $dbr = wfGetDB( DB_REPLICA ); + ResourceLoaderWikiModule::preloadTitleInfo( $context, $dbr, $siteBatch ); + ResourceLoaderWikiModule::preloadTitleInfo( $context, $dbr, $userBatch ); // Filter out modules handled by buildExemptModules() $moduleStyles = array_filter( $moduleStyles, @@ -2927,12 +2967,14 @@ class OutputPage extends ContextSource { } } - $chunks[] = ResourceLoader::makeInlineScript( - ResourceLoader::makeConfigSetScript( - [ 'wgPageParseReport' => $this->limitReportData ], - true - ) - ); + if ( $this->limitReportData ) { + $chunks[] = ResourceLoader::makeInlineScript( + ResourceLoader::makeConfigSetScript( + [ 'wgPageParseReport' => $this->limitReportData ], + true + ) + ); + } return self::combineWrappedStrings( $chunks ); } @@ -3050,8 +3092,8 @@ class OutputPage extends ContextSource { if ( $user->isLoggedIn() ) { $vars['wgUserId'] = $user->getId(); $vars['wgUserEditCount'] = $user->getEditCount(); - $userReg = wfTimestampOrNull( TS_UNIX, $user->getRegistration() ); - $vars['wgUserRegistration'] = $userReg !== null ? ( $userReg * 1000 ) : null; + $userReg = $user->getRegistration(); + $vars['wgUserRegistration'] = $userReg ? wfTimestamp( TS_UNIX, $userReg ) * 1000 : null; // Get the revision ID of the oldest new message on the user's talk // page. This can be used for constructing new message alerts on // the client side.