X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FOutputPage.php;h=50629ba1543c95d10428039c80afa560ac9ded7f;hp=45cf1121805b1ce239c4f5aa217d244a75ca5783;hb=0e15a6068a5a07fc109b5898ae51fdb8decafaf0;hpb=6d9704caefde82e494a8eeffe7abee5978f9f7b1 diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 45cf112180..50629ba154 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -295,9 +295,6 @@ class OutputPage extends ContextSource { */ private $copyrightUrl; - /** @var array Profiling data */ - private $limitReportData = []; - /** * Constructor for OutputPage. This should not be called directly. * Instead a new RequestContext should be created and it will implicitly create @@ -1214,8 +1211,8 @@ class OutputPage extends ContextSource { /** * Add new language links * - * @param array $newLinkArray Associative array mapping language code to the page - * name + * @param string[] $newLinkArray Array of interwiki-prefixed (non DB key) titles + * (e.g. 'fr:Test page') */ public function addLanguageLinks( array $newLinkArray ) { $this->mLanguageLinks += $newLinkArray; @@ -1224,8 +1221,8 @@ class OutputPage extends ContextSource { /** * Reset the language links and add new language links * - * @param array $newLinkArray Associative array mapping language code to the page - * name + * @param string[] $newLinkArray Array of interwiki-prefixed (non DB key) titles + * (e.g. 'fr:Test page') */ public function setLanguageLinks( array $newLinkArray ) { $this->mLanguageLinks = $newLinkArray; @@ -1234,7 +1231,7 @@ class OutputPage extends ContextSource { /** * Get the list of language links * - * @return array Array of Interwiki Prefixed (non DB key) Titles (e.g. 'fr:Test page') + * @return string[] Array of interwiki-prefixed (non DB key) titles (e.g. 'fr:Test page') */ public function getLanguageLinks() { return $this->mLanguageLinks; @@ -1713,7 +1710,6 @@ class OutputPage extends ContextSource { $popts->setTidy( $oldTidy ); $this->addParserOutput( $parserOutput ); - } /** @@ -1776,16 +1772,11 @@ class OutputPage extends ContextSource { } } - // Enable OOUI if requested via ParserOutput + // enable OOUI if requested via ParserOutput if ( $parserOutput->getEnableOOUI() ) { $this->enableOOUI(); } - // Include profiling data - 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. $linkFlags = []; @@ -1933,6 +1924,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 * @@ -2168,22 +2189,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 @@ -2692,15 +2717,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, @@ -2779,8 +2802,8 @@ class OutputPage extends ContextSource { // The spec recommends defining XHTML5's charset using the XML declaration // instead of meta. // Our XML declaration is output by Html::htmlHeader. - // http://www.whatwg.org/html/semantics.html#attr-meta-http-equiv-content-type - // http://www.whatwg.org/html/semantics.html#charset + // https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-content-type + // https://html.spec.whatwg.org/multipage/semantics.html#charset $pieces[] = Html::element( 'meta', [ 'charset' => 'UTF-8' ] ); } @@ -2935,15 +2958,6 @@ class OutputPage extends ContextSource { } } - if ( $this->limitReportData ) { - $chunks[] = ResourceLoader::makeInlineScript( - ResourceLoader::makeConfigSetScript( - [ 'wgPageParseReport' => $this->limitReportData ], - true - ) - ); - } - return self::combineWrappedStrings( $chunks ); } @@ -3664,7 +3678,7 @@ class OutputPage extends ContextSource { public static function transformCssMedia( $media ) { global $wgRequest; - // http://www.w3.org/TR/css3-mediaqueries/#syntax + // https://www.w3.org/TR/css3-mediaqueries/#syntax $screenMediaQueryRegex = '/^(?:only\s+)?screen\b/i'; // Switch in on-screen display for media testing @@ -3845,12 +3859,4 @@ class OutputPage extends ContextSource { 'mediawiki.widgets.styles', ] ); } - - /** - * @param array $data Data from ParserOutput::getLimitReportData() - * @since 1.28 - */ - public function setLimitReportData( array $data ) { - $this->limitReportData = $data; - } }