Merge "Avoid double-rendering on late exceptions"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 29 Mar 2016 22:31:00 +0000 (22:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 29 Mar 2016 22:31:00 +0000 (22:31 +0000)
1  2 
includes/OutputPage.php

diff --combined includes/OutputPage.php
@@@ -460,7 -460,7 +460,7 @@@ class OutputPage extends ContextSource 
         * @param string $script Raw HTML
         */
        function addScript( $script ) {
 -              $this->mScripts .= $script . "\n";
 +              $this->mScripts .= $script;
        }
  
        /**
         * @param string $script JavaScript text, no "<script>" tags
         */
        public function addInlineScript( $script ) {
 -              $this->mScripts .= Html::inlineScript( "\n$script\n" ) . "\n";
 +              $this->mScripts .= Html::inlineScript( $script );
        }
  
        /**
                        // adding of CSS or Javascript by extensions.
                        Hooks::run( 'BeforePageDisplay', [ &$this, &$sk ] );
  
-                       $sk->outputPage();
+                       try {
+                               $sk->outputPage();
+                       } catch ( Exception $e ) {
+                               ob_end_clean(); // bug T129657
+                               throw $e;
+                       }
                }
  
-               // This hook allows last minute changes to final overall output by modifying output buffer
-               Hooks::run( 'AfterFinalPageOutput', [ $this ] );
+               try {
+                       // This hook allows last minute changes to final overall output by modifying output buffer
+                       Hooks::run( 'AfterFinalPageOutput', [ $this ] );
+               } catch ( Exception $e ) {
+                       ob_end_clean(); // bug T129657
+                       throw $e;
+               }
  
                $this->sendCacheControl();
  
         * @return string HTML fragment
         */
        function getHeadScripts() {
 -              return $this->getInlineHeadScripts() . "\n" . $this->getExternalHeadScripts();
 +              return $this->getInlineHeadScripts() . $this->getExternalHeadScripts();
        }
  
        /**
                        'wgMonthNames' => $lang->getMonthNamesArray(),
                        'wgMonthNamesShort' => $lang->getMonthAbbreviationsArray(),
                        'wgRelevantPageName' => $relevantTitle->getPrefixedDBkey(),
 -                      'wgRelevantArticleId' => $relevantTitle->getArticleId(),
 +                      'wgRelevantArticleId' => $relevantTitle->getArticleID(),
 +                      'wgRequestId' => WebRequest::getRequestId(),
                ];
  
                if ( $user->isLoggedIn() ) {
                        # If wanted, and the interface is right-to-left, flip the CSS
                        $style_css = CSSJanus::transform( $style_css, true, false );
                }
 -              $this->mInlineStyles .= Html::inlineStyle( $style_css ) . "\n";
 +              $this->mInlineStyles .= Html::inlineStyle( $style_css );
        }
  
        /**
                        if ( $this->getLanguage()->getDir() !== $wgContLang->getDir() ) {
                                $previewedCSS = CSSJanus::transform( $previewedCSS, true, false );
                        }
 -                      $otherTags[] = Html::inlineStyle( $previewedCSS ) . "\n";
 +                      $otherTags[] = Html::inlineStyle( $previewedCSS );
                } else {
                        // Load the user styles normally
                        $moduleStyles[] = 'user';
                        ResourceLoaderModule::TYPE_STYLES
                );
                // Add normal styles added through addStyle()/addInlineStyle() here
 -              $links[] = implode( "\n", $this->buildCssLinksArray() ) . $this->mInlineStyles;
 +              $links[] = implode( '', $this->buildCssLinksArray() ) . $this->mInlineStyles;
                // Add marker tag to mark the place where the client-side
                // loader should inject dynamic styles
                // We use a <meta> tag with a made-up name for this because that's valid HTML