* Let HTMLFileCache constructor take in a Title *or* a the prefixed dbkey itself.
authorAaron Schulz <aaron@users.mediawiki.org>
Wed, 2 Nov 2011 20:01:22 +0000 (20:01 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Wed, 2 Nov 2011 20:01:22 +0000 (20:01 +0000)
* 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.

includes/cache/HTMLFileCache.php
includes/db/DatabaseError.php

index c0c4a57..671b150 100644 (file)
@@ -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';
 
index acf97b9..d7bfe93 100644 (file)
@@ -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' );