Merge "Move LoadMonitor to Rdbms namespace"
[lhc/web/wiklou.git] / includes / filerepo / file / LocalFile.php
index d3a14fa..8c088b9 100644 (file)
@@ -174,7 +174,7 @@ class LocalFile extends File {
         * @return bool|LocalFile
         */
        static function newFromKey( $sha1, $repo, $timestamp = false ) {
-               $dbr = $repo->getSlaveDB();
+               $dbr = $repo->getReplicaDB();
 
                $conds = [ 'img_sha1' => $sha1 ];
                if ( $timestamp ) {
@@ -240,6 +240,15 @@ class LocalFile extends File {
                return $this->repo->getSharedCacheKey( 'file', sha1( $this->getName() ) );
        }
 
+       /**
+        * @param WANObjectCache $cache
+        * @return string[]
+        * @since 1.28
+        */
+       public function getMutableCacheKeys( WANObjectCache $cache ) {
+               return [ $this->getCacheKey() ];
+       }
+
        /**
         * Try to load file metadata from memcached, falling back to the database
         */
@@ -259,7 +268,7 @@ class LocalFile extends File {
                        $key,
                        $cache::TTL_WEEK,
                        function ( $oldValue, &$ttl, array &$setOpts ) use ( $cache ) {
-                               $setOpts += Database::getCacheSetOptions( $this->repo->getSlaveDB() );
+                               $setOpts += Database::getCacheSetOptions( $this->repo->getReplicaDB() );
 
                                $this->loadFromDB( self::READ_NORMAL );
 
@@ -390,7 +399,7 @@ class LocalFile extends File {
 
                $dbr = ( $flags & self::READ_LATEST )
                        ? $this->repo->getMasterDB()
-                       : $this->repo->getSlaveDB();
+                       : $this->repo->getReplicaDB();
 
                $row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ),
                        [ 'img_name' => $this->getName() ], $fname );
@@ -412,7 +421,7 @@ class LocalFile extends File {
                # Unconditionally set loaded=true, we don't want the accessors constantly rechecking
                $this->extraDataLoaded = true;
 
-               $fieldMap = $this->loadFieldsWithTimestamp( $this->repo->getSlaveDB(), $fname );
+               $fieldMap = $this->loadFieldsWithTimestamp( $this->repo->getReplicaDB(), $fname );
                if ( !$fieldMap ) {
                        $fieldMap = $this->loadFieldsWithTimestamp( $this->repo->getMasterDB(), $fname );
                }
@@ -490,7 +499,7 @@ class LocalFile extends File {
 
                $decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] );
 
-               $decoded['metadata'] = $this->repo->getSlaveDB()->decodeBlob( $decoded['metadata'] );
+               $decoded['metadata'] = $this->repo->getReplicaDB()->decodeBlob( $decoded['metadata'] );
 
                if ( empty( $decoded['major_mime'] ) ) {
                        $decoded['mime'] = 'unknown/unknown';
@@ -1037,7 +1046,7 @@ class LocalFile extends File {
         * @return OldLocalFile[]
         */
        function getHistory( $limit = null, $start = null, $end = null, $inc = true ) {
-               $dbr = $this->repo->getSlaveDB();
+               $dbr = $this->repo->getReplicaDB();
                $tables = [ 'oldimage' ];
                $fields = OldLocalFile::selectFields();
                $conds = $opts = $join_conds = [];
@@ -1061,7 +1070,9 @@ class LocalFile extends File {
                $opts['ORDER BY'] = "oi_timestamp $order";
                $opts['USE INDEX'] = [ 'oldimage' => 'oi_name_timestamp' ];
 
-               Hooks::run( 'LocalFile::getHistory', [ &$this, &$tables, &$fields,
+               // Avoid PHP 7.1 warning from passing $this by reference
+               $localFile = $this;
+               Hooks::run( 'LocalFile::getHistory', [ &$localFile, &$tables, &$fields,
                        &$conds, &$opts, &$join_conds ] );
 
                $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $opts, $join_conds );
@@ -1091,7 +1102,7 @@ class LocalFile extends File {
                # Polymorphic function name to distinguish foreign and local fetches
                $fname = get_class( $this ) . '::' . __FUNCTION__;
 
-               $dbr = $this->repo->getSlaveDB();
+               $dbr = $this->repo->getReplicaDB();
 
                if ( $this->historyLine == 0 ) { // called for the first time, return line from cur
                        $this->historyRes = $dbr->select( 'image',
@@ -1572,7 +1583,7 @@ class LocalFile extends File {
 
        /**
         * Move or copy a file to its public location. If a file exists at the
-        * destination, move it to an archive. Returns a FileRepoStatus object with
+        * destination, move it to an archive. Returns a Status object with
         * the archive name in the "value" member on success.
         *
         * The archive name should be passed through to recordUpload for database
@@ -1590,7 +1601,7 @@ class LocalFile extends File {
        }
 
        /**
-        * Move or copy a file to a specified location. Returns a FileRepoStatus
+        * Move or copy a file to a specified location. Returns a Status
         * object with the archive name in the "value" member on success.
         *
         * The archive name should be passed through to recordUpload for database
@@ -1917,7 +1928,7 @@ class LocalFile extends File {
                                'page_namespace' => $this->title->getNamespace(),
                                'page_title' => $this->title->getDBkey()
                        ];
-                       $touched = $this->repo->getSlaveDB()->selectField( 'page', 'page_touched', $cond, __METHOD__ );
+                       $touched = $this->repo->getReplicaDB()->selectField( 'page', 'page_touched', $cond, __METHOD__ );
                        $this->descriptionTouched = $touched ? wfTimestamp( TS_MW, $touched ) : false;
                }
 
@@ -2086,7 +2097,7 @@ class LocalFileDeleteBatch {
        /** @var bool Whether to suppress all suppressable fields when deleting */
        private $suppress;
 
-       /** @var FileRepoStatus */
+       /** @var Status */
        private $status;
 
        /** @var User */
@@ -2993,7 +3004,7 @@ class LocalFileMoveBatch {
        }
 
        /**
-        * Verify the database updates and return a new FileRepoStatus indicating how
+        * Verify the database updates and return a new Status indicating how
         * many rows would be updated.
         *
         * @return Status
@@ -3036,7 +3047,7 @@ class LocalFileMoveBatch {
        }
 
        /**
-        * Do the database updates and return a new FileRepoStatus indicating how
+        * Do the database updates and return a new Status indicating how
         * many rows where updated.
         */
        protected function doDBUpdates() {