Merge "pass codesniffer on tests/"
[lhc/web/wiklou.git] / includes / Wiki.php
index e6ccbe5..21a7d9a 100644 (file)
@@ -126,7 +126,7 @@ class MediaWiki {
         * @return Title
         */
        public function getTitle() {
-               if( $this->context->getTitle() === null ){
+               if( $this->context->getTitle() === null ) {
                        $this->context->setTitle( $this->parseTitle() );
                }
                return $this->context->getTitle();
@@ -178,7 +178,7 @@ class MediaWiki {
                wfProfileIn( __METHOD__ );
 
                $request = $this->context->getRequest();
-               $title = $this->context->getTitle();
+               $requestTitle = $title = $this->context->getTitle();
                $output = $this->context->getOutput();
                $user = $this->context->getUser();
 
@@ -302,7 +302,7 @@ class MediaWiki {
                                global $wgArticle;
                                $wgArticle = new DeprecatedGlobal( 'wgArticle', $article, '1.18' );
 
-                               $this->performAction( $article );
+                               $this->performAction( $article, $requestTitle );
                        } elseif ( is_string( $article ) ) {
                                $output->redirect( $article );
                        } else {
@@ -331,8 +331,18 @@ class MediaWiki {
                wfProfileIn( __METHOD__ );
 
                $title = $this->context->getTitle();
-               $article = Article::newFromTitle( $title, $this->context );
-               $this->context->setWikiPage( $article->getPage() );
+               if ( $this->context->canUseWikiPage() ) {
+                       // Try to use request context wiki page, as there
+                       // is already data from db saved in per process
+                       // cache there from this->getAction() call.
+                       $page = $this->context->getWikiPage();
+                       $article = Article::newFromWikiPage( $page, $this->context );
+               } else {
+                       // This case should not happen, but just in case.
+                       $article = Article::newFromTitle( $title, $this->context );
+                       $this->context->setWikiPage( $article->getPage() );
+               }
+
                // NS_MEDIAWIKI has no redirects.
                // It is also used for CSS/JS, so performance matters here...
                if ( $title->getNamespace() == NS_MEDIAWIKI ) {
@@ -396,8 +406,9 @@ class MediaWiki {
         * Perform one of the "standard" actions
         *
         * @param $page Page
+        * @param $requestTitle The original title, before any redirects were applied
         */
-       private function performAction( Page $page ) {
+       private function performAction( Page $page, Title $requestTitle ) {
                global $wgUseSquid, $wgSquidMaxage;
 
                wfProfileIn( __METHOD__ );
@@ -420,7 +431,7 @@ class MediaWiki {
                if ( $action instanceof Action ) {
                        # Let Squid cache things if we can purge them.
                        if ( $wgUseSquid &&
-                               in_array( $request->getFullRequestURL(), $title->getSquidURLs() )
+                               in_array( $request->getFullRequestURL(), $requestTitle->getSquidURLs() )
                        ) {
                                $output->setSquidMaxage( $wgSquidMaxage );
                        }
@@ -496,7 +507,7 @@ class MediaWiki {
                        && $request->getMethod() == 'GET'
                ) {
                        $redirUrl = $request->getFullRequestURL();
-                       $redirUrl = str_replace( 'http://' , 'https://' , $redirUrl );
+                       $redirUrl = str_replace( 'http://', 'https://', $redirUrl );
 
                        // Setup dummy Title, otherwise OutputPage::redirect will fail
                        $title = Title::newFromText( NS_MAIN, 'REDIR' );
@@ -573,9 +584,6 @@ class MediaWiki {
                // Execute a job from the queue
                $this->doJobs();
 
-               // Log message usage, if $wgAdaptiveMessageCache is set to true
-               MessageCache::logMessages();
-
                // Log profiling data, e.g. in the database or UDP
                wfLogProfilingData();
 
@@ -596,28 +604,34 @@ class MediaWiki {
                if ( $wgJobRunRate <= 0 || wfReadOnly() ) {
                        return;
                }
+
                if ( $wgJobRunRate < 1 ) {
                        $max = mt_getrandmax();
                        if ( mt_rand( 0, $max ) > $max * $wgJobRunRate ) {
-                               return;
+                               return; // the higher $wgJobRunRate, the less likely we return here
                        }
                        $n = 1;
                } else {
                        $n = intval( $wgJobRunRate );
                }
 
-               while ( $n-- && false != ( $job = Job::pop() ) ) {
-                       $output = $job->toString() . "\n";
-                       $t = - microtime( true );
-                       $success = $job->run();
-                       $t += microtime( true );
-                       $t = round( $t * 1000 );
-                       if ( !$success ) {
-                               $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n";
-                       } else {
-                               $output .= "Success, Time: $t ms\n";
+               $group = JobQueueGroup::singleton();
+               do {
+                       $job = $group->pop( JobQueueGroup::USE_CACHE ); // job from any queue
+                       if ( $job ) {
+                               $output = $job->toString() . "\n";
+                               $t = - microtime( true );
+                               $success = $job->run();
+                               $group->ack( $job ); // done
+                               $t += microtime( true );
+                               $t = round( $t * 1000 );
+                               if ( !$success ) {
+                                       $output .= "Error: " . $job->getLastError() . ", Time: $t ms\n";
+                               } else {
+                                       $output .= "Success, Time: $t ms\n";
+                               }
+                               wfDebugLog( 'jobqueue', $output );
                        }
-                       wfDebugLog( 'jobqueue', $output );
-               }
+               } while ( --$n && $job );
        }
 }