Merge "wpUndidRevision should be passed along during 'preview' and 'diff'"
[lhc/web/wiklou.git] / includes / Wiki.php
index 3f7e19c..6ac9341 100644 (file)
@@ -307,7 +307,8 @@ class MediaWiki {
                                $output->redirect( $article );
                        } else {
                                wfProfileOut( __METHOD__ );
-                               throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle() returned neither an object nor a URL" );
+                               throw new MWException( "Shouldn't happen: MediaWiki::initializeArticle()"
+                                       . " returned neither an object nor a URL" );
                        }
                }
 
@@ -502,12 +503,34 @@ class MediaWiki {
 
                $request = $this->context->getRequest();
 
-               if ( $request->getCookie( 'forceHTTPS' )
-                       && $request->detectProtocol() == 'http'
-                       && $request->getMethod() == 'GET'
+               // If the user has forceHTTPS set to true, or if the user
+               // is in a group requiring HTTPS, or if they have the HTTPS
+               // preference set, redirect them to HTTPS.
+               if (
+                       (
+                               $request->getCookie( 'forceHTTPS' ) ||
+                               // Avoid checking the user and groups unless it's enabled.
+                               (
+                                       $this->context->getUser()->isLoggedIn()
+                                       && $this->context->getUser()->requiresHTTPS()
+                               )
+                       ) &&
+                       $request->detectProtocol() == 'http'
                ) {
-                       $redirUrl = $request->getFullRequestURL();
-                       $redirUrl = str_replace( 'http://', 'https://', $redirUrl );
+                       $oldUrl = $request->getFullRequestURL();
+                       $redirUrl = str_replace( 'http://', 'https://', $oldUrl );
+
+                       if ( $request->wasPosted() ) {
+                               // This is weird and we'd hope it almost never happens. This
+                               // means that a POST came in via HTTP and policy requires us
+                               // redirecting to HTTPS. It's likely such a request is going
+                               // to fail due to post data being lost, but let's try anyway
+                               // and just log the instance.
+                               //
+                               // @todo @fixme See if we could issue a 307 or 308 here, need
+                               // to see how clients (automated & browser) behave when we do
+                               wfDebugLog( 'RedirectedPosts', "Redirected from HTTP to HTTPS: $oldUrl" );
+                       }
 
                        // Setup dummy Title, otherwise OutputPage::redirect will fail
                        $title = Title::newFromText( NS_MAIN, 'REDIR' );
@@ -624,27 +647,34 @@ class MediaWiki {
                        wfShellExec( "$cmd &", $retVal );
                        wfProfileOut( __METHOD__ . '-exec' );
                } else {
-                       // Fallback to running the jobs here while the user waits
-                       $group = JobQueueGroup::singleton();
-                       do {
-                               $job = $group->pop( JobQueueGroup::USE_CACHE ); // job from any queue
-                               if ( $job ) {
-                                       $output = $job->toString() . "\n";
-                                       $t = - microtime( true );
-                                       wfProfileIn( __METHOD__ . '-' . get_class( $job ) );
-                                       $success = $job->run();
-                                       wfProfileOut( __METHOD__ . '-' . get_class( $job ) );
-                                       $group->ack( $job ); // done
-                                       $t += microtime( true );
-                                       $t = round( $t * 1000 );
-                                       if ( $success === false ) {
-                                               $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n";
-                                       } else {
-                                               $output .= "Success, Time: $t ms\n";
+                       try {
+                               // Fallback to running the jobs here while the user waits
+                               $group = JobQueueGroup::singleton();
+                               do {
+                                       $job = $group->pop( JobQueueGroup::USE_CACHE ); // job from any queue
+                                       if ( $job ) {
+                                               $output = $job->toString() . "\n";
+                                               $t = - microtime( true );
+                                               wfProfileIn( __METHOD__ . '-' . get_class( $job ) );
+                                               $success = $job->run();
+                                               wfProfileOut( __METHOD__ . '-' . get_class( $job ) );
+                                               $group->ack( $job ); // done
+                                               $t += microtime( true );
+                                               $t = round( $t * 1000 );
+                                               if ( $success === false ) {
+                                                       $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n";
+                                               } else {
+                                                       $output .= "Success, Time: $t ms\n";
+                                               }
+                                               wfDebugLog( 'jobqueue', $output );
                                        }
-                                       wfDebugLog( 'jobqueue', $output );
-                               }
-                       } while ( --$n && $job );
+                               } while ( --$n && $job );
+                       } catch ( MWException $e ) {
+                               // We don't want exceptions thrown during job execution to
+                               // be reported to the user since the output is already sent.
+                               // Instead we just log them.
+                               wfDebugLog( 'exception', $e->getLogMessage() );
+                       }
                }
        }
 }