Merge "Add fastcgi_finish_request where appropriate"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 3 Jan 2014 16:06:47 +0000 (16:06 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 3 Jan 2014 16:06:47 +0000 (16:06 +0000)
1  2 
api.php
includes/Wiki.php

diff --combined api.php
+++ b/api.php
@@@ -69,18 -69,20 +69,23 @@@ $wgTitle = Title::makeTitle( NS_MAIN, '
   */
  $processor = new ApiMain( RequestContext::getMain(), $wgEnableWriteAPI );
  
 +// Last chance hook before executing the API
 +wfRunHooks( 'ApiBeforeMain', array( &$processor ) );
 +
  // Process data & print results
  $processor->execute();
  
+ if ( function_exists( 'fastcgi_finish_request' ) ) {
+       fastcgi_finish_request();
+ }
  // Execute any deferred updates
  DeferredUpdates::doUpdates();
  
  // Log what the user did, for book-keeping purposes.
  $endtime = microtime( true );
  wfProfileOut( 'api.php' );
  wfLogProfilingData();
  
  // Log the request
diff --combined includes/Wiki.php
@@@ -95,8 -95,8 +95,8 @@@ class MediaWiki 
                        // Check variant links so that interwiki links don't have to worry
                        // about the possible different language variants
                        if ( count( $wgContLang->getVariants() ) > 1
 -                              && !is_null( $ret ) && $ret->getArticleID() == 0 )
 -                      {
 +                              && !is_null( $ret ) && $ret->getArticleID() == 0
 +                      {
                                $wgContLang->findVariantLink( $title, $ret );
                        }
                }
                        $ret = Title::newMainPage();
                }
  
 -              if ( $ret === null || ( $ret->getDBkey() == '' && $ret->getInterwiki() == '' ) ) {
 +              if ( $ret === null || ( $ret->getDBkey() == '' && !$ret->isExternal() ) ) {
                        $ret = SpecialPage::getTitleFor( 'Badtitle' );
                }
  
                wfRunHooks( 'BeforeInitialize', array( &$title, &$unused, &$output, &$user, $request, $this ) );
  
                // Invalid titles. Bug 21776: The interwikis must redirect even if the page name is empty.
 -              if ( is_null( $title ) || ( $title->getDBkey() == '' && $title->getInterwiki() == '' ) ||
 -                      $title->isSpecial( 'Badtitle' ) )
 -              {
 +              if ( is_null( $title ) || ( $title->getDBkey() == '' && !$title->isExternal() )
 +                      || $title->isSpecial( 'Badtitle' )
 +              {
                        $this->context->setTitle( SpecialPage::getTitleFor( 'Badtitle' ) );
                        wfProfileOut( __METHOD__ );
                        throw new BadTitleError();
                $pageView = false; // was an article or special page viewed?
  
                // Interwiki redirects
 -              if ( $title->getInterwiki() != '' ) {
 +              if ( $title->isExternal() ) {
                        $rdfrom = $request->getVal( 'rdfrom' );
                        if ( $rdfrom ) {
                                $url = $title->getFullURL( array( 'rdfrom' => $rdfrom ) );
                        }
                        // Check for a redirect loop
                        if ( !preg_match( '/^' . preg_quote( $wgServer, '/' ) . '/', $url )
 -                              && $title->isLocal() )
 -                      {
 +                              && $title->isLocal()
 +                      {
                                // 301 so google et al report the target as the actual url.
                                $output->redirect( $url, 301 );
                        } else {
                        }
                // Redirect loops, no title in URL, $wgUsePathInfo URLs, and URLs with a variant
                } elseif ( $request->getVal( 'action', 'view' ) == 'view' && !$request->wasPosted()
 -                      && ( $request->getVal( 'title' ) === null ||
 -                              $title->getPrefixedDBkey() != $request->getVal( 'title' ) )
 +                      && ( $request->getVal( 'title' ) === null
 +                              || $title->getPrefixedDBkey() != $request->getVal( 'title' ) )
                        && !count( $request->getValueNames( array( 'action', 'title' ) ) )
 -                      && wfRunHooks( 'TestCanonicalRedirect', array( $request, $title, $output ) ) )
 -              {
 +                      && wfRunHooks( 'TestCanonicalRedirect', array( $request, $title, $output ) )
 +              {
                        if ( $title->isSpecialPage() ) {
                                list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
                                if ( $name ) {
                $action = $request->getVal( 'action', 'view' );
                $file = ( $title->getNamespace() == NS_FILE ) ? $article->getFile() : null;
                if ( ( $action == 'view' || $action == 'render' ) // ... for actions that show content
 -                      && !$request->getVal( 'oldid' ) && // ... and are not old revisions
 -                      !$request->getVal( 'diff' ) && // ... and not when showing diff
 -                      $request->getVal( 'redirect' ) != 'no' && // ... unless explicitly told not to
 +                      && !$request->getVal( 'oldid' ) // ... and are not old revisions
 +                      && !$request->getVal( 'diff' ) // ... and not when showing diff
 +                      && $request->getVal( 'redirect' ) != 'no' // ... unless explicitly told not to
                        // ... and the article is not a non-redirect image page with associated file
 -                      !( is_object( $file ) && $file->exists() && !$file->getRedirected() ) )
 -              {
 +                      && !( is_object( $file ) && $file->exists() && !$file->getRedirected() )
 +              {
                        // Give extensions a change to ignore/handle redirects as needed
                        $ignoreRedirect = $target = false;
  
                $user = $this->context->getUser();
  
                if ( !wfRunHooks( 'MediaWikiPerformAction',
 -                      array( $output, $page, $title, $user, $request, $this ) ) )
 -              {
 +                              array( $output, $page, $title, $user, $request, $this ) )
 +              {
                        wfProfileOut( __METHOD__ );
                        return;
                }
                try {
                        $this->checkMaxLag();
                        $this->main();
+                       if ( function_exists( 'fastcgi_finish_request' ) ) {
+                               fastcgi_finish_request();
+                       }
                        $this->restInPeace();
                } catch ( Exception $e ) {
                        MWExceptionHandler::handle( $e );