X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilerepo%2FLocalRepo.php;h=965f677c7353b4f488827e57484e790d67313ca8;hb=075b90235e86de663c000db2c90253509bb97375;hp=5121c4dd45b8aea2de2599aacc9bf31875e463ca;hpb=073a675adfc984835fd0cab406b9ca9f5d45355c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 5121c4dd45..965f677c73 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -29,12 +29,12 @@ * @ingroup FileRepo */ class LocalRepo extends FileRepo { - var $fileFactory = array( 'LocalFile' , 'newFromTitle' ); - var $fileFactoryKey = array( 'LocalFile' , 'newFromKey' ); - var $fileFromRowFactory = array( 'LocalFile' , 'newFromRow' ); - var $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' ); - var $oldFileFactoryKey = array( 'OldLocalFile', 'newFromKey' ); - var $oldFileFromRowFactory = array( 'OldLocalFile', 'newFromRow' ); + protected $fileFactory = array( 'LocalFile', 'newFromTitle' ); + protected $fileFactoryKey = array( 'LocalFile', 'newFromKey' ); + protected $fileFromRowFactory = array( 'LocalFile', 'newFromRow' ); + protected $oldFileFromRowFactory = array( 'OldLocalFile', 'newFromRow' ); + protected $oldFileFactory = array( 'OldLocalFile', 'newFromTitle' ); + protected $oldFileFactoryKey = array( 'OldLocalFile', 'newFromKey' ); /** * @throws MWException @@ -47,7 +47,7 @@ class LocalRepo extends FileRepo { } elseif ( isset( $row->oi_name ) ) { return call_user_func( $this->oldFileFromRowFactory, $row, $this ); } else { - throw new MWException( __METHOD__.': invalid row' ); + throw new MWException( __METHOD__ . ': invalid row' ); } } @@ -97,20 +97,22 @@ class LocalRepo extends FileRepo { } $dbw->commit( __METHOD__ ); } + return $status; } /** * Check if a deleted (filearchive) file has this sha1 key * - * @param $key String File storage key (base-36 sha1 key with file extension) - * @param $lock String|null Use "lock" to lock the row via FOR UPDATE + * @param string $key File storage key (base-36 sha1 key with file extension) + * @param string|null $lock Use "lock" to lock the row via FOR UPDATE * @return bool File with this key is in use */ protected function deletedFileHasKey( $key, $lock = null ) { $options = ( $lock === 'lock' ) ? array( 'FOR UPDATE' ) : array(); $dbw = $this->getMasterDB(); + return (bool)$dbw->selectField( 'filearchive', '1', array( 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ), __METHOD__, $options @@ -120,8 +122,8 @@ class LocalRepo extends FileRepo { /** * Check if a hidden (revision delete) file has this sha1 key * - * @param $key String File storage key (base-36 sha1 key with file extension) - * @param $lock String|null Use "lock" to lock the row via FOR UPDATE + * @param string $key File storage key (base-36 sha1 key with file extension) + * @param string|null $lock Use "lock" to lock the row via FOR UPDATE * @return bool File with this key is in use */ protected function hiddenFileHasKey( $key, $lock = null ) { @@ -131,6 +133,7 @@ class LocalRepo extends FileRepo { $ext = File::normalizeExtension( substr( $key, strcspn( $key, '.' ) + 1 ) ); $dbw = $this->getMasterDB(); + return (bool)$dbw->selectField( 'oldimage', '1', array( 'oi_sha1' => $sha1, 'oi_archive_name ' . $dbw->buildLike( $dbw->anyString(), ".$ext" ), @@ -171,13 +174,14 @@ class LocalRepo extends FileRepo { if ( $cachedValue === ' ' || $cachedValue === '' ) { // Does not exist return false; - } elseif ( strval( $cachedValue ) !== '' ) { + } elseif ( strval( $cachedValue ) !== '' && $cachedValue !== ' PURGED' ) { return Title::newFromText( $cachedValue, NS_FILE ); } // else $cachedValue is false or null: cache miss $id = $this->getArticleID( $title ); - if( !$id ) { - $wgMemc->set( $memcKey, " ", $expiry ); + if ( !$id ) { + $wgMemc->add( $memcKey, " ", $expiry ); + return false; } $dbr = $this->getSlaveDB(); @@ -188,12 +192,14 @@ class LocalRepo extends FileRepo { __METHOD__ ); - if( $row && $row->rd_namespace == NS_FILE ) { + if ( $row && $row->rd_namespace == NS_FILE ) { $targetTitle = Title::makeTitle( $row->rd_namespace, $row->rd_title ); - $wgMemc->set( $memcKey, $targetTitle->getDBkey(), $expiry ); + $wgMemc->add( $memcKey, $targetTitle->getDBkey(), $expiry ); + return $targetTitle; } else { - $wgMemc->set( $memcKey, '', $expiry ); + $wgMemc->add( $memcKey, '', $expiry ); + return false; } } @@ -206,7 +212,7 @@ class LocalRepo extends FileRepo { * @return bool|int|mixed */ protected function getArticleID( $title ) { - if( !$title instanceof Title ) { + if ( !$title instanceof Title ) { return 0; } $dbr = $this->getSlaveDB(); @@ -219,6 +225,7 @@ class LocalRepo extends FileRepo { ), __METHOD__ //Function name ); + return $id; } @@ -226,7 +233,7 @@ class LocalRepo extends FileRepo { * Get an array or iterator of file objects for files that have a given * SHA-1 content hash. * - * @param $hash String a sha1 hash to look for + * @param string $hash a sha1 hash to look for * @return Array */ function findBySha1( $hash ) { @@ -254,11 +261,11 @@ class LocalRepo extends FileRepo { * * Overrides generic implementation in FileRepo for performance reason * - * @param $hashes array An array of hashes + * @param array $hashes An array of hashes * @return array An Array of arrays or iterators of file objects and the hash as key */ function findBySha1s( array $hashes ) { - if( !count( $hashes ) ) { + if ( !count( $hashes ) ) { return array(); //empty parameter } @@ -281,17 +288,17 @@ class LocalRepo extends FileRepo { return $result; } - /** - * Return an array of files where the name starts with $prefix. - * - * @param string $prefix The prefix to search for - * @param int $limit The maximum amount of files to return - * @return array - */ + /** + * Return an array of files where the name starts with $prefix. + * + * @param string $prefix The prefix to search for + * @param int $limit The maximum amount of files to return + * @return array + */ public function findFilesByPrefix( $prefix, $limit ) { $selectOptions = array( 'ORDER BY' => 'img_name', 'LIMIT' => intval( $limit ) ); - // Query database + // Query database $dbr = $this->getSlaveDB(); $res = $dbr->select( 'image', @@ -299,14 +306,15 @@ class LocalRepo extends FileRepo { 'img_name ' . $dbr->buildLike( $prefix, $dbr->anyString() ), __METHOD__, $selectOptions - ); + ); // Build file objects $files = array(); foreach ( $res as $row ) { $files[] = $this->newFileFromRow( $row ); } - return $files; + + return $files; } /** @@ -334,6 +342,7 @@ class LocalRepo extends FileRepo { */ function getSharedCacheKey( /*...*/ ) { $args = func_get_args(); + return call_user_func_array( 'wfMemcKey', $args ); } @@ -347,7 +356,11 @@ class LocalRepo extends FileRepo { global $wgMemc; $memcKey = $this->getSharedCacheKey( 'image_redirect', md5( $title->getDBkey() ) ); if ( $memcKey ) { - $wgMemc->delete( $memcKey ); + // Set a temporary value for the cache key, to ensure + // that this value stays purged long enough so that + // it isn't refreshed with a stale value due to a + // lagged slave. + $wgMemc->set( $memcKey, ' PURGED', 12 ); } } }