diff options
Diffstat (limited to 'includes/filerepo')
-rw-r--r-- | includes/filerepo/ArchivedFile.php | 12 | ||||
-rw-r--r-- | includes/filerepo/File.php | 28 | ||||
-rw-r--r-- | includes/filerepo/FileRepo.php | 80 | ||||
-rw-r--r-- | includes/filerepo/ForeignAPIFile.php | 26 | ||||
-rw-r--r-- | includes/filerepo/ForeignAPIRepo.php | 13 | ||||
-rw-r--r-- | includes/filerepo/ForeignDBFile.php | 2 | ||||
-rw-r--r-- | includes/filerepo/LocalFile.php | 4 | ||||
-rw-r--r-- | includes/filerepo/LocalRepo.php | 51 |
8 files changed, 131 insertions, 85 deletions
diff --git a/includes/filerepo/ArchivedFile.php b/includes/filerepo/ArchivedFile.php index 3919cfbc..68c93b8f 100644 --- a/includes/filerepo/ArchivedFile.php +++ b/includes/filerepo/ArchivedFile.php @@ -74,14 +74,16 @@ class ArchivedFile } $conds = array(); - if ($this->id>0) + if( $this->id > 0 ) $conds['fa_id'] = $this->id; - if ($this->key) - $conds['fa_storage_key'] = $this->key; - if ($this->title) + if( $this->key ) { + $conds['fa_storage_group'] = $this->group; + $conds['fa_storage_key'] = $this->key; + } + if( $this->title ) $conds['fa_name'] = $this->title->getDBkey(); - if (!count($conds)) + if( !count($conds)) throw new MWException( "No specific information for retrieving archived file" ); if( !$this->title || $this->title->getNamespace() == NS_FILE ) { diff --git a/includes/filerepo/File.php b/includes/filerepo/File.php index 4f0990af..523a1c09 100644 --- a/includes/filerepo/File.php +++ b/includes/filerepo/File.php @@ -586,7 +586,7 @@ abstract class File { } while (false); wfProfileOut( __METHOD__ ); - return $thumb; + return is_object( $thumb ) ? $thumb : false; } /** @@ -865,22 +865,23 @@ abstract class File { * * @deprecated Use HTMLCacheUpdate, this function uses too much memory */ - function getLinksTo( $options = '' ) { + function getLinksTo( $options = array() ) { wfProfileIn( __METHOD__ ); // Note: use local DB not repo DB, we want to know local links - if ( $options ) { + if ( count( $options ) > 0 ) { $db = wfGetDB( DB_MASTER ); } else { $db = wfGetDB( DB_SLAVE ); } $linkCache = LinkCache::singleton(); - list( $page, $imagelinks ) = $db->tableNamesN( 'page', 'imagelinks' ); $encName = $db->addQuotes( $this->getName() ); - $sql = "SELECT page_namespace,page_title,page_id,page_len,page_is_redirect, - FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options"; - $res = $db->query( $sql, __METHOD__ ); + $res = $db->select( array( 'page', 'imagelinks'), + array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ), + array( 'page_id' => 'il_from', 'il_to' => $encName ), + __METHOD__, + $options ); $retVal = array(); if ( $db->numRows( $res ) ) { @@ -950,7 +951,7 @@ abstract class File { */ function wasDeleted() { $title = $this->getTitle(); - return $title && $title->isDeleted() > 0; + return $title && $title->isDeletedQuick(); } /** @@ -1068,15 +1069,16 @@ abstract class File { * Get the HTML text of the description page, if available */ function getDescriptionText() { - global $wgMemc; + global $wgMemc, $wgContLang; if ( !$this->repo->fetchDescription ) { return false; } - $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName() ); + $renderUrl = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() ); if ( $renderUrl ) { if ( $this->repo->descriptionCacheExpiry > 0 ) { wfDebug("Attempting to get the description from cache..."); - $key = wfMemcKey( 'RemoteFileDescription', 'url', md5($renderUrl) ); + $key = wfMemcKey( 'RemoteFileDescription', 'url', $wgContLang->getCode(), + $this->getName() ); $obj = $wgMemc->get($key); if ($obj) { wfDebug("success!\n"); @@ -1086,7 +1088,9 @@ abstract class File { } wfDebug( "Fetching shared description from $renderUrl\n" ); $res = Http::get( $renderUrl ); - if ( $res && $this->repo->descriptionCacheExpiry > 0 ) $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry ); + if ( $res && $this->repo->descriptionCacheExpiry > 0 ) { + $wgMemc->set( $key, $res, $this->repo->descriptionCacheExpiry ); + } return $res; } else { return false; diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 5beac732..face1614 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -294,16 +294,22 @@ abstract class FileRepo { * MediaWiki this means action=render. This should only be called by the * repository's file class, since it may return invalid results. User code * should use File::getDescriptionText(). + * @param string $name Name of image to fetch + * @param string $lang Language to fetch it in, if any. */ - function getDescriptionRenderUrl( $name ) { + function getDescriptionRenderUrl( $name, $lang = null ) { + $query = 'action=render'; + if ( !is_null( $lang ) ) { + $query .= '&uselang=' . $lang; + } if ( isset( $this->scriptDirUrl ) ) { return $this->scriptDirUrl . '/index.php?title=' . wfUrlencode( 'Image:' . $name ) . - '&action=render'; + "&$query"; } else { $descUrl = $this->getDescriptionUrl( $name ); if ( $descUrl ) { - return wfAppendQuery( $descUrl, 'action=render' ); + return wfAppendQuery( $descUrl, $query ); } else { return false; } @@ -512,24 +518,84 @@ abstract class FileRepo { /** * Checks if there is a redirect named as $title - * STUB * * @param Title $title Title of image */ function checkRedirect( $title ) { - return false; + global $wgMemc; + + if( is_string( $title ) ) { + $title = Title::newFromTitle( $title ); + } + if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) { + $title = Title::makeTitle( NS_FILE, $title->getText() ); + } + + $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); + $cachedValue = $wgMemc->get( $memcKey ); + if( $cachedValue ) { + return Title::newFromDbKey( $cachedValue ); + } elseif( $cachedValue == ' ' ) { # FIXME: ugly hack, but BagOStuff caching seems to be weird and return false if !cachedValue, not only if it doesn't exist + return false; + } + + $id = $this->getArticleID( $title ); + if( !$id ) { + $wgMemc->set( $memcKey, " ", 9000 ); + return false; + } + $dbr = $this->getSlaveDB(); + $row = $dbr->selectRow( + 'redirect', + array( 'rd_title', 'rd_namespace' ), + array( 'rd_from' => $id ), + __METHOD__ + ); + + if( $row ) $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title ); + $wgMemc->set( $memcKey, ($row ? $targetTitle->getPrefixedDBkey() : " "), 9000 ); + if( !$row ) { + return false; + } + return $targetTitle; } /** * Invalidates image redirect cache related to that image - * STUB * * @param Title $title Title of image - */ + */ function invalidateImageRedirect( $title ) { + global $wgMemc; + $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); + $wgMemc->delete( $memcKey ); } function findBySha1( $hash ) { return array(); } + + /** + * Get the human-readable name of the repo. + * @return string + */ + public function getDisplayName() { + // We don't name our own repo, return nothing + if ( $this->name == 'local' ) { + return null; + } + $repoName = wfMsg( 'shared-repo-name-' . $this->name ); + if ( !wfEmptyMsg( 'shared-repo-name-' . $this->name, $repoName ) ) { + return $repoName; + } + return wfMsg( 'shared-repo' ); + } + + function getSlaveDB() { + return wfGetDB( DB_SLAVE ); + } + + function getMasterDB() { + return wfGetDB( DB_MASTER ); + } } diff --git a/includes/filerepo/ForeignAPIFile.php b/includes/filerepo/ForeignAPIFile.php index d9fb85d0..03498fb1 100644 --- a/includes/filerepo/ForeignAPIFile.php +++ b/includes/filerepo/ForeignAPIFile.php @@ -59,7 +59,21 @@ class ForeignAPIFile extends File { } public function getMetadata() { - return serialize( (array)@$this->mInfo['metadata'] ); + if ( isset( $this->mInfo['metadata'] ) ) { + return serialize( self::parseMetadata( $this->mInfo['metadata'] ) ); + } + return null; + } + + public static function parseMetadata( $metadata ) { + if( !is_array( $metadata ) ) { + return $metadata; + } + $ret = array(); + foreach( $metadata as $meta ) { + $ret[ $meta['name'] ] = self::parseMetadata( $meta['value'] ); + } + return $ret; } public function getSize() { @@ -87,11 +101,11 @@ class ForeignAPIFile extends File { } function getMimeType() { - if( empty( $info['mime'] ) ) { + if( !isset( $this->mInfo['mime'] ) ) { $magic = MimeMagic::singleton(); - $info['mime'] = $magic->guessTypesForExtension( $this->getExtension() ); + $this->mInfo['mime'] = $magic->guessTypesForExtension( $this->getExtension() ); } - return $info['mime']; + return $this->mInfo['mime']; } /// @fixme May guess wrong on file types that can be eg audio or video @@ -146,8 +160,8 @@ class ForeignAPIFile extends File { } function purgeDescriptionPage() { - global $wgMemc; - $url = $this->repo->getDescriptionRenderUrl( $this->getName() ); + global $wgMemc, $wgContLang; + $url = $this->repo->getDescriptionRenderUrl( $this->getName(), $wgContLang->getCode() ); $key = wfMemcKey( 'RemoteFileDescription', 'url', md5($url) ); $wgMemc->delete( $key ); } diff --git a/includes/filerepo/ForeignAPIRepo.php b/includes/filerepo/ForeignAPIRepo.php index 6fc9c465..e63e4a6b 100644 --- a/includes/filerepo/ForeignAPIRepo.php +++ b/includes/filerepo/ForeignAPIRepo.php @@ -30,6 +30,17 @@ class ForeignAPIRepo extends FileRepo { $this->scriptDirUrl = dirname( $this->mApiBase ); } } + + /** + * Per docs in FileRepo, this needs to return false if we don't support versioned + * files. Well, we don't. + */ + function newFile( $title, $time = false ) { + if ( $time ) { + return false; + } + return parent::newFile( $title, $time ); + } /** * No-ops @@ -109,7 +120,7 @@ class ForeignAPIRepo extends FileRepo { $ret = array(); if ( isset( $results['query']['allimages'] ) ) { foreach ( $results['query']['allimages'] as $img ) { - $ret[] = new ForeignAPIFile( Title::makeTitle( NS_IMAGE, $img['name'] ), $this, $img ); + $ret[] = new ForeignAPIFile( Title::makeTitle( NS_FILE, $img['name'] ), $this, $img ); } } return $ret; diff --git a/includes/filerepo/ForeignDBFile.php b/includes/filerepo/ForeignDBFile.php index 5fb432c8..8fe6f921 100644 --- a/includes/filerepo/ForeignDBFile.php +++ b/includes/filerepo/ForeignDBFile.php @@ -20,7 +20,7 @@ class ForeignDBFile extends LocalFile { } function getCacheKey() { - if ( $this->repo->hasSharedCache ) { + if ( $this->repo->hasSharedCache() ) { $hashedName = md5($this->name); return wfForeignMemcKey( $this->repo->dbName, $this->repo->tablePrefix, 'file', $hashedName ); diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 6fd6de72..b997d75f 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -1760,12 +1760,12 @@ class LocalFileMoveBatch { $oldName = $row->oi_archive_name; $bits = explode( '!', $oldName, 2 ); if( count( $bits ) != 2 ) { - wfDebug( 'Invalid old file name: ' . $oldName ); + wfDebug( "Invalid old file name: $oldName \n" ); continue; } list( $timestamp, $filename ) = $bits; if( $this->oldName != $filename ) { - wfDebug( 'Invalid old file name:' . $oldName ); + wfDebug( "Invalid old file name: $oldName \n" ); continue; } $this->oldCount++; diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 5eb1a11c..1ec1b9a6 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -10,14 +10,6 @@ class LocalRepo extends FSRepo { var $fileFromRowFactory = array( 'LocalFile', 'newFromRow' ); var $oldFileFromRowFactory = array( 'OldLocalFile', 'newFromRow' ); - function getSlaveDB() { - return wfGetDB( DB_SLAVE ); - } - - function getMasterDB() { - return wfGetDB( DB_MASTER ); - } - function getMemcKey( $key ) { return wfWikiID( $this->getSlaveDB() ) . ":{$key}"; } @@ -101,50 +93,7 @@ class LocalRepo extends FSRepo { return $id; } - function checkRedirect( $title ) { - global $wgMemc; - - if( is_string( $title ) ) { - $title = Title::newFromTitle( $title ); - } - if( $title instanceof Title && $title->getNamespace() == NS_MEDIA ) { - $title = Title::makeTitle( NS_FILE, $title->getText() ); - } - - $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); - $cachedValue = $wgMemc->get( $memcKey ); - if( $cachedValue ) { - return Title::newFromDbKey( $cachedValue ); - } elseif( $cachedValue == ' ' ) { # FIXME: ugly hack, but BagOStuff caching seems to be weird and return false if !cachedValue, not only if it doesn't exist - return false; - } - $id = $this->getArticleID( $title ); - if( !$id ) { - $wgMemc->set( $memcKey, " ", 9000 ); - return false; - } - $dbr = $this->getSlaveDB(); - $row = $dbr->selectRow( - 'redirect', - array( 'rd_title', 'rd_namespace' ), - array( 'rd_from' => $id ), - __METHOD__ - ); - - if( $row ) $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title ); - $wgMemc->set( $memcKey, ($row ? $targetTitle->getPrefixedDBkey() : " "), 9000 ); - if( !$row ) { - return false; - } - return $targetTitle; - } - - function invalidateImageRedirect( $title ) { - global $wgMemc; - $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); - $wgMemc->delete( $memcKey ); - } function findBySha1( $hash ) { $dbr = $this->getSlaveDB(); |