A little refactoring of the input splitting/expansion:
[lhc/web/wiklou.git] / includes / Wiki.php
index 72a6a61..2a60262 100644 (file)
@@ -57,18 +57,10 @@ class MediaWiki {
        }
 
        function checkMaxLag( $maxLag ) {
-               global $wgLoadBalancer, $wgShowHostnames;
+               global $wgLoadBalancer;
                list( $host, $lag ) = $wgLoadBalancer->getMaxLag();
                if ( $lag > $maxLag ) {
-                       header( 'HTTP/1.1 503 Service Unavailable' );
-                       header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) );
-                       header( 'X-Database-Lag: ' . intval( $lag ) );
-                       header( 'Content-Type: text/plain' );
-                       if( $wgShowHostnames ) {
-                               echo "Waiting for $host: $lag seconds lagged\n";
-                       } else {
-                               echo "Waiting for a database server: $lag seconds lagged\n";
-                       }
+                       wfMaxlagError( $host, $lag, $maxLag );
                        return false;
                } else {
                        return true;
@@ -228,6 +220,10 @@ class MediaWiki {
 
                switch( $title->getNamespace() ) {
                case NS_IMAGE:
+                       $file = wfFindFile( $title );
+                       if( $file && $file->getRedirected() ) {
+                               return new Article( $title );
+                       }
                        return new ImagePage( $title );
                case NS_CATEGORY:
                        return new CategoryPage( $title );
@@ -252,7 +248,7 @@ class MediaWiki {
                $article = $this->articleFromTitle( $title );
 
                // Namespace might change when using redirects
-               if( $action == 'view' && !$request->getVal( 'oldid' ) &&
+               if( ( $action == 'view' || $action == 'render' ) && !$request->getVal( 'oldid' ) &&
                                                $request->getVal( 'redirect' ) != 'no' ) {
 
                        $dbr = wfGetDB(DB_SLAVE);
@@ -297,7 +293,7 @@ class MediaWiki {
                $this->doJobs();
                $loadBalancer->saveMasterPos();
                # Now commit any transactions, so that unreported errors after output() don't roll back the whole thing
-               $loadBalancer->commitAll();
+               $loadBalancer->commitMasterChanges();
                $output->output();
                wfProfileOut( 'MediaWiki::finalCleanup' );
        }
@@ -309,6 +305,12 @@ class MediaWiki {
         */
        function doUpdates ( &$updates ) {
                wfProfileIn( 'MediaWiki::doUpdates' );
+               /* No need to get master connections in case of empty updates array */
+               if (!$updates) {
+                       wfProfileOut('MediaWiki::doUpdates');
+                       return;
+               }
+               
                $dbw = wfGetDB( DB_MASTER );
                foreach( $updates as $up ) {
                        $up->doUpdate();
@@ -360,7 +362,6 @@ class MediaWiki {
         */
        function restInPeace ( &$loadBalancer ) {
                wfLogProfilingData();
-               $loadBalancer->closeAll();
                wfDebug( "Request ended normally\n" );
        }
 
@@ -371,6 +372,11 @@ class MediaWiki {
 
                wfProfileIn( 'MediaWiki::performAction' );
 
+               if ( !wfRunHooks('MediaWikiPerformAction', array($output, $article, $title, $user, $request)) ) {
+                       wfProfileOut( 'MediaWiki::performAction' );
+                       return;
+               }
+
                $action = $this->getVal('Action');
                if( in_array( $action, $this->getVal('DisabledActions',array()) ) ) {
                        /* No such action; this will switch to the default case */