X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FOutputPage.php;h=3adef5b2515411ddffd857a068beb02a24982ac1;hb=2c085ac5a3c8020958d52554e13317feef30ffaf;hp=97165b46130401a79695f4333d9fbaaa030da419;hpb=174f34a86de3162bc673fd3bc6bed815cccf0edc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 97165b4613..3adef5b251 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -21,6 +21,7 @@ */ use MediaWiki\Logger\LoggerFactory; +use MediaWiki\Session\SessionManager; use WrappedString\WrappedString; /** @@ -1977,11 +1978,9 @@ class OutputPage extends ContextSource { if ( $cookies === null ) { $config = $this->getConfig(); $cookies = array_merge( + SessionManager::singleton()->getVaryCookies(), array( - $config->get( 'CookiePrefix' ) . 'Token', - $config->get( 'CookiePrefix' ) . 'LoggedOut', - "forceHTTPS", - session_name() + 'forceHTTPS', ), $config->get( 'CacheVaryCookies' ) ); @@ -2033,6 +2032,9 @@ class OutputPage extends ContextSource { * @return string */ public function getVaryHeader() { + foreach ( SessionManager::singleton()->getVaryHeaders() as $header => $options ) { + $this->addVaryHeader( $header, $options ); + } return 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) ); } @@ -2050,6 +2052,10 @@ class OutputPage extends ContextSource { } $this->addVaryHeader( 'Cookie', $cookiesOption ); + foreach ( SessionManager::singleton()->getVaryHeaders() as $header => $options ) { + $this->addVaryHeader( $header, $options ); + } + $headers = array(); foreach ( $this->mVaryHeader as $header => $option ) { $newheader = $header; @@ -2173,8 +2179,8 @@ class OutputPage extends ContextSource { if ( $this->mEnableClientCache ) { if ( - $config->get( 'UseSquid' ) && session_id() == '' && !$this->isPrintable() && - $this->mCdnMaxage != 0 && !$this->haveCacheVaryCookies() + $config->get( 'UseSquid' ) && !SessionManager::getGlobalSession()->isPersistent() && + !$this->isPrintable() && $this->mCdnMaxage != 0 && !$this->haveCacheVaryCookies() ) { if ( $config->get( 'UseESI' ) ) { # We'll purge the proxy cache explicitly, but require end user agents @@ -3809,6 +3815,58 @@ class OutputPage extends ContextSource { return $link; } + /** + * Transform path to web-accessible static resource. + * + * This is used to add a validation hash as query string. + * This aids various behaviors: + * + * - Put long Cache-Control max-age headers on responses for improved + * cache performance. + * - Get the correct version of a file as expected by the current page. + * - Instantly get the updated version of a file after deployment. + * + * Avoid using this for urls included in HTML as otherwise clients may get different + * versions of a resource when navigating the site depending on when the page was cached. + * If changes to the url propagate, this is not a problem (e.g. if the url is in + * an external stylesheet). + * + * @since 1.27 + * @param Config $config + * @param string $path Path-absolute URL to file (from document root, must start with "/") + * @return string URL + */ + public static function transformResourcePath( Config $config, $path ) { + global $IP; + $remotePath = $config->get( 'ResourceBasePath' ); + if ( strpos( $path, $remotePath ) !== 0 ) { + // Path is outside wgResourceBasePath, ignore. + return $path; + } + $path = RelPath\getRelativePath( $path, $remotePath ); + return self::transformFilePath( $remotePath, $IP, $path ); + } + + /** + * Utility method for transformResourceFilePath(). + * + * Caller is responsible for ensuring the file exists. Emits a PHP warning otherwise. + * + * @since 1.27 + * @param string $remotePath URL path that points to $localPath + * @param string $localPath File directory exposed at $remotePath + * @param string $file Path to target file relative to $localPath + * @return string URL + */ + public static function transformFilePath( $remotePath, $localPath, $file ) { + $hash = md5_file( "$localPath/$file" ); + if ( $hash === false ) { + wfLogWarning( __METHOD__ . ": Failed to hash $localPath/$file" ); + $hash = ''; + } + return "$remotePath/$file?" . substr( $hash, 0, 5 ); + } + /** * Transform "media" attribute based on request parameters * @@ -3993,7 +4051,7 @@ class OutputPage extends ContextSource { $this->getLanguage()->getDir() ); $this->addModuleStyles( array( - 'oojs-ui.styles', + 'oojs-ui-core.styles', 'oojs-ui.styles.icons', 'oojs-ui.styles.indicators', 'oojs-ui.styles.textures',