r49655 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49654‎ | r49655 | r49656 >
Date:03:06, 20 April 2009
Author:tstarling
Status:ok
Tags:
Comment:
Move checkRedirect() from FileRepo to LocalRepo, leaving only a stub behind. It's inappropriate for FileRepo to be accessing the database or memcached, this is exclusively a job for a subclass. Avoids error "Call to undefined method <class>::getArticleID()" whenever anyone uses a repo which is not derived from LocalRepo, such as FSRepo or ForeignAPIRepo.
Modified paths:
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalRepo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -518,47 +518,14 @@
519519 function cleanupDeletedBatch( $storageKeys ) {}
520520
521521 /**
522 - * Checks if there is a redirect named as $title
 522+ * Checks if there is a redirect named as $title. If there is, return the
 523+ * title object. If not, return false.
 524+ * STUB
523525 *
524526 * @param Title $title Title of image
525527 */
526528 function checkRedirect( $title ) {
527 - global $wgMemc;
528 -
529 - if( is_string( $title ) ) {
530 - $title = Title::newFromTitle( $title );
531 - }
532 - if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) {
533 - $title = Title::makeTitle( NS_FILE, $title->getText() );
534 - }
535 -
536 - $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
537 - $cachedValue = $wgMemc->get( $memcKey );
538 - if( $cachedValue ) {
539 - return Title::newFromDbKey( $cachedValue );
540 - } elseif( $cachedValue == ' ' ) { # FIXME: ugly hack, but BagOStuff caching seems to be weird and return false if !cachedValue, not only if it doesn't exist
541 - return false;
542 - }
543 -
544 - $id = $this->getArticleID( $title );
545 - if( !$id ) {
546 - $wgMemc->set( $memcKey, " ", 9000 );
547 - return false;
548 - }
549 - $dbr = $this->getSlaveDB();
550 - $row = $dbr->selectRow(
551 - 'redirect',
552 - array( 'rd_title', 'rd_namespace' ),
553 - array( 'rd_from' => $id ),
554 - __METHOD__
555 - );
556 -
557 - if( $row ) $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title );
558 - $wgMemc->set( $memcKey, ($row ? $targetTitle->getPrefixedDBkey() : " "), 9000 );
559 - if( !$row ) {
560 - return false;
561 - }
562 - return $targetTitle;
 529+ return false;
563530 }
564531
565532 /**
Index: trunk/phase3/includes/filerepo/LocalRepo.php
@@ -67,7 +67,52 @@
6868 }
6969 return $status;
7070 }
 71+
 72+ /**
 73+ * Checks if there is a redirect named as $title
 74+ *
 75+ * @param Title $title Title of image
 76+ */
 77+ function checkRedirect( $title ) {
 78+ global $wgMemc;
7179
 80+ if( is_string( $title ) ) {
 81+ $title = Title::newFromTitle( $title );
 82+ }
 83+ if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) {
 84+ $title = Title::makeTitle( NS_FILE, $title->getText() );
 85+ }
 86+
 87+ $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
 88+ $cachedValue = $wgMemc->get( $memcKey );
 89+ if( $cachedValue ) {
 90+ return Title::newFromDbKey( $cachedValue );
 91+ } elseif( $cachedValue == ' ' ) { # FIXME: ugly hack, but BagOStuff caching seems to be weird and return false if !cachedValue, not only if it doesn't exist
 92+ return false;
 93+ }
 94+
 95+ $id = $this->getArticleID( $title );
 96+ if( !$id ) {
 97+ $wgMemc->set( $memcKey, " ", 9000 );
 98+ return false;
 99+ }
 100+ $dbr = $this->getSlaveDB();
 101+ $row = $dbr->selectRow(
 102+ 'redirect',
 103+ array( 'rd_title', 'rd_namespace' ),
 104+ array( 'rd_from' => $id ),
 105+ __METHOD__
 106+ );
 107+
 108+ if( $row ) $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title );
 109+ $wgMemc->set( $memcKey, ($row ? $targetTitle->getPrefixedDBkey() : " "), 9000 );
 110+ if( !$row ) {
 111+ return false;
 112+ }
 113+ return $targetTitle;
 114+ }
 115+
 116+
72117 /**
73118 * Function link Title::getArticleID().
74119 * We can't say Title object, what database it should use, so we duplicate that function here.

Follow-up revisions

RevisionCommit summaryAuthorDate
r52009Backport r49655, fatal errors for some users...simetrical22:48, 16 June 2009
r82424Followup r49655...reedy23:42, 18 February 2011

Status & tagging log