X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FMediaWiki.php;h=eaa1c99539d72e249c590077be03f4d1f0bf4f89;hb=84851a43f3ea8ea146c4d82c55fd01b9fa302347;hp=2aa4b80c66cd6e97adf22108f97d8e44f53ec3db;hpb=355f271d2454a19e0e56c34de48e381a99fdcd80;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php index 2aa4b80c66..eaa1c99539 100644 --- a/includes/MediaWiki.php +++ b/includes/MediaWiki.php @@ -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; } /** @@ -528,6 +518,25 @@ class MediaWiki { $e->report(); // display the GUI error } } catch ( Exception $e ) { + $context = $this->context; + $action = $context->getRequest()->getVal( 'action', 'view' ); + if ( + $e instanceof DBConnectionError && + $context->hasTitle() && + $context->getTitle()->canExist() && + in_array( $action, [ 'view', 'history' ], true ) && + HTMLFileCache::useFileCache( $this->context, HTMLFileCache::MODE_OUTAGE ) + ) { + // Try to use any (even stale) file during outages... + $cache = new HTMLFileCache( $context->getTitle(), 'view' ); + if ( $cache->isCached() ) { + $cache->loadFromFileCache( $context, HTMLFileCache::MODE_OUTAGE ); + print MWExceptionRenderer::getHTML( $e ); + exit; + } + + } + MWExceptionHandler::handleException( $e ); } @@ -657,14 +666,14 @@ class MediaWiki { /** * @param string $url * @param IContextSource $context - * @return string|bool Either "local" or "remote" if in the farm, false otherwise + * @return string Either "local", "remote" if in the farm, "external" otherwise */ - private function getUrlDomainDistance( $url, IContextSource $context ) { + private static function getUrlDomainDistance( $url, IContextSource $context ) { static $relevantKeys = [ 'host' => true, 'port' => true ]; $infoCandidate = wfParseUrl( $url ); if ( $infoCandidate === false ) { - return false; + return 'external'; } $infoCandidate = array_intersect_key( $infoCandidate, $relevantKeys ); @@ -686,7 +695,7 @@ class MediaWiki { } } - return false; + return 'external'; } /** @@ -819,24 +828,22 @@ class MediaWiki { } } - if ( $this->config->get( 'UseFileCache' ) && $title->getNamespace() >= 0 ) { - if ( HTMLFileCache::useFileCache( $this->context ) ) { - // Try low-level file cache hit - $cache = new HTMLFileCache( $title, $action ); - if ( $cache->isCacheGood( /* Assume up to date */ ) ) { - // Check incoming headers to see if client has this cached - $timestamp = $cache->cacheTimestamp(); - if ( !$output->checkLastModified( $timestamp ) ) { - $cache->loadFromFileCache( $this->context ); - } - // Do any stats increment/watchlist stuff - // Assume we're viewing the latest revision (this should always be the case with file cache) - $this->context->getWikiPage()->doViewUpdates( $this->context->getUser() ); - // Tell OutputPage that output is taken care of - $output->disable(); - - return; + if ( $title->canExist() && HTMLFileCache::useFileCache( $this->context ) ) { + // Try low-level file cache hit + $cache = new HTMLFileCache( $title, $action ); + if ( $cache->isCacheGood( /* Assume up to date */ ) ) { + // Check incoming headers to see if client has this cached + $timestamp = $cache->cacheTimestamp(); + if ( !$output->checkLastModified( $timestamp ) ) { + $cache->loadFromFileCache( $this->context ); } + // Do any stats increment/watchlist stuff, assuming user is viewing the + // latest revision (which should always be the case for file cache) + $this->context->getWikiPage()->doViewUpdates( $this->context->getUser() ); + // Tell OutputPage that output is taken care of + $output->disable(); + + return; } } @@ -882,6 +889,7 @@ class MediaWiki { // Do any deferred jobs DeferredUpdates::doUpdates( 'enqueue' ); + DeferredUpdates::setImmediateMode( true ); // Make sure any lazy jobs are pushed JobQueueGroup::pushLazyJobs();