Merge "Work around T87871 to avoid double-loading OOjs UI PHP styles"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 11 Feb 2016 03:51:16 +0000 (03:51 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 11 Feb 2016 03:51:16 +0000 (03:51 +0000)
1  2 
includes/OutputPage.php

diff --combined includes/OutputPage.php
@@@ -21,7 -21,6 +21,7 @@@
   */
  
  use MediaWiki\Logger\LoggerFactory;
 +use MediaWiki\Session\SessionManager;
  use WrappedString\WrappedString;
  
  /**
@@@ -1573,42 -1572,11 +1573,42 @@@ class OutputPage extends ContextSource 
         * @return ParserOptions
         */
        public function parserOptions( $options = null ) {
 +              if ( $options !== null && !empty( $options->isBogus ) ) {
 +                      // Someone is trying to set a bogus pre-$wgUser PO. Check if it has
 +                      // been changed somehow, and keep it if so.
 +                      $anonPO = ParserOptions::newFromAnon();
 +                      $anonPO->setEditSection( false );
 +                      if ( !$options->matches( $anonPO ) ) {
 +                              wfLogWarning( __METHOD__ . ': Setting a changed bogus ParserOptions: ' . wfGetAllCallers( 5 ) );
 +                              $options->isBogus = false;
 +                      }
 +              }
 +
                if ( !$this->mParserOptions ) {
 +                      if ( !$this->getContext()->getUser()->isSafeToLoad() ) {
 +                              // $wgUser isn't unstubbable yet, so don't try to get a
 +                              // ParserOptions for it. And don't cache this ParserOptions
 +                              // either.
 +                              $po = ParserOptions::newFromAnon();
 +                              $po->setEditSection( false );
 +                              $po->isBogus = true;
 +                              if ( $options !== null ) {
 +                                      $this->mParserOptions = empty( $options->isBogus ) ? $options : null;
 +                              }
 +                              return $po;
 +                      }
 +
                        $this->mParserOptions = ParserOptions::newFromContext( $this->getContext() );
                        $this->mParserOptions->setEditSection( false );
                }
 -              return wfSetVar( $this->mParserOptions, $options );
 +
 +              if ( $options !== null && !empty( $options->isBogus ) ) {
 +                      // They're trying to restore the bogus pre-$wgUser PO. Do the right
 +                      // thing.
 +                      return wfSetVar( $this->mParserOptions, null, true );
 +              } else {
 +                      return wfSetVar( $this->mParserOptions, $options );
 +              }
        }
  
        /**
                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' )
                        );
         * @return string
         */
        public function getVaryHeader() {
 +              foreach ( SessionManager::singleton()->getVaryHeaders() as $header => $options ) {
 +                      $this->addVaryHeader( $header, $options );
 +              }
                return 'Vary: ' . join( ', ', array_keys( $this->mVaryHeader ) );
        }
  
                }
                $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;
  
                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
                        'oojs-ui.styles.textures',
                        'mediawiki.widgets.styles',
                ) );
+               // Used by 'skipFunction' of the four 'oojs-ui.styles.*' modules. Please don't treat this as a
+               // public API or you'll be severely disappointed when T87871 is fixed and it disappears.
+               $this->addMeta( 'X-OOUI-PHP', '1' );
        }
  }