From: Aaron Schulz Date: Wed, 2 Nov 2011 20:01:22 +0000 (+0000) Subject: * Let HTMLFileCache constructor take in a Title *or* a the prefixed dbkey itself. X-Git-Tag: 1.31.0-rc.0~26753 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=5214c4f07397c891564eb85ea3e8396e0fe127a0;p=lhc%2Fweb%2Fwiklou.git * Let HTMLFileCache constructor take in a Title *or* a the prefixed dbkey itself. * Tweaked filecache fallback in fileCachedPage() to try the raw title param. If the DB is down, we can get most views of titles with colons in them to work this way. Previously, it could fail on an interwiki lookup. --- diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php index c0c4a577f8..671b15002a 100644 --- a/includes/cache/HTMLFileCache.php +++ b/includes/cache/HTMLFileCache.php @@ -7,18 +7,20 @@ class HTMLFileCache extends FileCacheBase { /** * Construct an ObjectFileCache from a Title and an action - * @param $title Title + * @param $title Title|string Title object or prefixed DB key string * @param $action string * @return HTMLFileCache */ - public static function newFromTitle( Title $title, $action ) { + public static function newFromTitle( $title, $action ) { $cache = new self(); $allowedTypes = self::cacheablePageActions(); if ( !in_array( $action, $allowedTypes ) ) { throw new MWException( "Invalid filecache type given." ); } - $cache->mKey = $title->getPrefixedDBkey(); + $cache->mKey = ( $title instanceof Title ) + ? $title->getPrefixedDBkey() + : (string)$title; $cache->mType = (string)$action; $cache->mExt = 'html'; diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index acf97b98f0..d7bfe93312 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -220,16 +220,23 @@ EOT; * @return string */ private function fileCachedPage() { - global $wgTitle, $wgOut; + global $wgTitle, $wgOut, $wgRequest; if ( $wgOut->isDisabled() ) { return; // Done already? } - if ( $wgTitle ) { - $t =& $wgTitle; + if ( $wgTitle ) { // use $wgTitle if we managed to set it + $t = $wgTitle->getPrefixedDBkey(); } else { - $t = Title::newFromText( $this->msg( 'mainpage', 'Main Page' ) ); + # Fallback to the raw title URL param. We can't use the Title + # class is it may hit the interwiki table and give a DB error. + # We may get a cache miss due to not sanitizing the title though. + $t = str_replace( ' ', '_', $wgRequest->getVal( 'title' ) ); + if ( $t == '' ) { // fallback to main page + $t = Title::newFromText( + $this->msg( 'mainpage', 'Main Page' ) )->getPrefixedDBkey(); + } } $cache = HTMLFileCache::newFromTitle( $t, 'view' );