Revert "MediaWiki.php: Redirect non-standard title urls to canonical"
[lhc/web/wiklou.git] / includes / MediaWiki.php
index 1add24a..7d8232c 100644 (file)
@@ -313,8 +313,6 @@ class MediaWiki {
         * - Normalise empty title:
         *   /wiki/ -> /wiki/Main
         *   /w/index.php?title= -> /wiki/Main
-        * - Normalise non-standard title urls:
-        *   /w/index.php?title=Foo_Bar -> /wiki/Foo_Bar
         * - Don't redirect anything with query parameters other than 'title' or 'action=view'.
         *
         * @param Title $title
@@ -327,6 +325,8 @@ class MediaWiki {
 
                if ( $request->getVal( 'action', 'view' ) != 'view'
                        || $request->wasPosted()
+                       || ( $request->getVal( 'title' ) !== null
+                               && $title->getPrefixedDBkey() == $request->getVal( 'title' ) )
                        || count( $request->getValueNames( [ 'action', 'title' ] ) )
                        || !Hooks::run( 'TestCanonicalRedirect', [ $request, $title, $output ] )
                ) {
@@ -341,19 +341,7 @@ class MediaWiki {
                }
                // Redirect to canonical url, make it a 301 to allow caching
                $targetUrl = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
-
-               if ( $targetUrl != $request->getFullRequestURL() ) {
-                       $output->setCdnMaxage( 1200 );
-                       $output->redirect( $targetUrl, '301' );
-                       return true;
-               }
-
-               // If there is no title, or the title is in a non-standard encoding, we demand
-               // a redirect. If cgi somehow changed the 'title' query to be non-standard while
-               // the url is standard, the server is misconfigured.
-               if ( $request->getVal( 'title' ) === null
-                       || $title->getPrefixedDBkey() != $request->getVal( 'title' )
-               ) {
+               if ( $targetUrl == $request->getFullRequestURL() ) {
                        $message = "Redirect loop detected!\n\n" .
                                "This means the wiki got confused about what page was " .
                                "requested; this sometimes happens when moving a wiki " .
@@ -375,7 +363,9 @@ class MediaWiki {
                        }
                        throw new HttpError( 500, $message );
                }
-               return false;
+               $output->setSquidMaxage( 1200 );
+               $output->redirect( $targetUrl, '301' );
+               return true;
        }
 
        /**
@@ -554,9 +544,9 @@ class MediaWiki {
 
                $config = $context->getConfig();
 
-               $factory = wfGetLBFactory();
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                // Commit all changes
-               $factory->commitMasterChanges(
+               $lbFactory->commitMasterChanges(
                        __METHOD__,
                        // Abort if any transaction was too big
                        [ 'maxWriteDuration' => $config->get( 'MaxUserDBWriteDuration' ) ]
@@ -566,23 +556,23 @@ class MediaWiki {
                wfDebug( __METHOD__ . ': pre-send deferred updates completed' );
 
                // Record ChronologyProtector positions
-               $factory->shutdown();
+               $lbFactory->shutdown();
                wfDebug( __METHOD__ . ': all transactions committed' );
 
                // Set a cookie to tell all CDN edge nodes to "stick" the user to the DC that handles this
                // POST request (e.g. the "master" data center). Also have the user briefly bypass CDN so
                // ChronologyProtector works for cacheable URLs.
                $request = $context->getRequest();
-               if ( $request->wasPosted() && $factory->hasOrMadeRecentMasterChanges() ) {
+               if ( $request->wasPosted() && $lbFactory->hasOrMadeRecentMasterChanges() ) {
                        $expires = time() + $config->get( 'DataCenterUpdateStickTTL' );
                        $options = [ 'prefix' => '' ];
                        $request->response()->setCookie( 'UseDC', 'master', $expires, $options );
                        $request->response()->setCookie( 'UseCDNCache', 'false', $expires, $options );
                }
 
-               // Avoid letting a few seconds of slave lag cause a month of stale data. This logic is
+               // Avoid letting a few seconds of replica DB lag cause a month of stale data. This logic is
                // also intimately related to the value of $wgCdnReboundPurgeDelay.
-               if ( $factory->laggedSlaveUsed() ) {
+               if ( $lbFactory->laggedReplicaUsed() ) {
                        $maxAge = $config->get( 'CdnMaxageLagged' );
                        $context->getOutput()->lowerCdnMaxage( $maxAge );
                        $request->response()->header( "X-Database-Lagged: true" );
@@ -632,7 +622,7 @@ class MediaWiki {
                                fastcgi_finish_request();
                        } else {
                                // Either all DB and deferred updates should happen or none.
-                               // The later should not be cancelled due to client disconnect.
+                               // The latter should not be cancelled due to client disconnect.
                                ignore_user_abort( true );
                        }
 
@@ -763,9 +753,9 @@ class MediaWiki {
         * @param string $mode Use 'fast' to always skip job running
         */
        public function restInPeace( $mode = 'fast' ) {
-               $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                // Assure deferred updates are not in the main transaction
-               $factory->commitMasterChanges( __METHOD__ );
+               $lbFactory->commitMasterChanges( __METHOD__ );
 
                // Loosen DB query expectations since the HTTP client is unblocked
                $trxProfiler = Profiler::instance()->getTransactionProfiler();
@@ -791,8 +781,8 @@ class MediaWiki {
                wfLogProfilingData();
 
                // Commit and close up!
-               $factory->commitMasterChanges( __METHOD__ );
-               $factory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT );
+               $lbFactory->commitMasterChanges( __METHOD__ );
+               $lbFactory->shutdown( LBFactory::SHUTDOWN_NO_CHRONPROT );
 
                wfDebug( "Request ended normally\n" );
        }