r101667 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101666‎ | r101667 | r101668 >
Date:20:01, 2 November 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/includes/cache/HTMLFileCache.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseError.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseError.php
@@ -220,16 +220,23 @@
221221 * @return string
222222 */
223223 private function fileCachedPage() {
224 - global $wgTitle, $wgOut;
 224+ global $wgTitle, $wgOut, $wgRequest;
225225
226226 if ( $wgOut->isDisabled() ) {
227227 return; // Done already?
228228 }
229229
230 - if ( $wgTitle ) {
231 - $t =& $wgTitle;
 230+ if ( $wgTitle ) { // use $wgTitle if we managed to set it
 231+ $t = $wgTitle->getPrefixedDBkey();
232232 } else {
233 - $t = Title::newFromText( $this->msg( 'mainpage', 'Main Page' ) );
 233+ # Fallback to the raw title URL param. We can't use the Title
 234+ # class is it may hit the interwiki table and give a DB error.
 235+ # We may get a cache miss due to not sanitizing the title though.
 236+ $t = str_replace( ' ', '_', $wgRequest->getVal( 'title' ) );
 237+ if ( $t == '' ) { // fallback to main page
 238+ $t = Title::newFromText(
 239+ $this->msg( 'mainpage', 'Main Page' ) )->getPrefixedDBkey();
 240+ }
234241 }
235242
236243 $cache = HTMLFileCache::newFromTitle( $t, 'view' );
Index: trunk/phase3/includes/cache/HTMLFileCache.php
@@ -7,18 +7,20 @@
88 class HTMLFileCache extends FileCacheBase {
99 /**
1010 * Construct an ObjectFileCache from a Title and an action
11 - * @param $title Title
 11+ * @param $title Title|string Title object or prefixed DB key string
1212 * @param $action string
1313 * @return HTMLFileCache
1414 */
15 - public static function newFromTitle( Title $title, $action ) {
 15+ public static function newFromTitle( $title, $action ) {
1616 $cache = new self();
1717
1818 $allowedTypes = self::cacheablePageActions();
1919 if ( !in_array( $action, $allowedTypes ) ) {
2020 throw new MWException( "Invalid filecache type given." );
2121 }
22 - $cache->mKey = $title->getPrefixedDBkey();
 22+ $cache->mKey = ( $title instanceof Title )
 23+ ? $title->getPrefixedDBkey()
 24+ : (string)$title;
2325 $cache->mType = (string)$action;
2426 $cache->mExt = 'html';
2527

Comments

#Comment by MaxSem (talk | contribs)   07:33, 23 December 2011

Why not Title::newMainPage?

#Comment by Aaron Schulz (talk | contribs)   07:54, 23 December 2011

This is how the old code was. It was (and is) trying to avoid a DB hit getting the message, which would often just create another exception when we were trying to handle a DBError to begin with.

Status & tagging log