Tweak timestamp handling to allow no lower limit
[lhc/web/wiklou.git] / includes / filerepo / LocalFile.php
index 63ce035..2072ebd 100644 (file)
@@ -68,7 +68,7 @@ class LocalFile extends File
         * Do not call this except from inside a repo class.
         */
        static function newFromRow( $row, $repo ) {
-               $title = Title::makeTitle( NS_IMAGE, $row->img_name );
+               $title = Title::makeTitle( NS_FILE, $row->img_name );
                $file = new self( $title, $repo );
                $file->loadFromRow( $row );
                return $file;
@@ -635,7 +635,8 @@ class LocalFile extends File
                        $conds[] = "oi_timestamp <= " . $dbr->addQuotes( $dbr->timestamp( $start ) );
                }
                if( $end !== null ) {
-                       $conds[] = "oi_timestamp >= " . $dbr->addQuotes( $dbr->timestamp( $end ) );
+                       $endTS = $end ? $dbr->timestamp( $end ) : "";
+                       $conds[] = "oi_timestamp >= " . $dbr->addQuotes( $endTS );
                }
                if( $limit ) {
                        $opts['LIMIT'] = $limit;
@@ -779,6 +780,7 @@ class LocalFile extends File
                }
 
                $dbw = $this->repo->getMasterDB();
+               $dbw->begin();
 
                if ( !$props ) {
                        $props = $this->repo->getFileProps( $this->getVirtualUrl() );
@@ -895,7 +897,7 @@ class LocalFile extends File
                        $nullRevision = Revision::newNullRevision( $dbw, $descTitle->getArticleId(), $log->getRcComment(), false );
                        $nullRevision->insertOn( $dbw );
                        
-                       wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest) );
+                       wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $user) );
                        $article->updateRevisionOn( $dbw, $nullRevision );
 
                        # Invalidate the cache for the description page
@@ -1137,7 +1139,7 @@ class LocalFile extends File
                // Initialise now if necessary
                if ( $this->sha1 == '' && $this->fileExists ) {
                        $this->sha1 = File::sha1Base36( $this->getPath() );
-                       if ( strval( $this->sha1 ) != '' ) {
+                       if ( !wfReadOnly() && strval( $this->sha1 ) != '' ) {
                                $dbw = $this->repo->getMasterDB();
                                $dbw->update( 'image',
                                        array( 'img_sha1' => $this->sha1 ),
@@ -1364,7 +1366,7 @@ class LocalFileDeleteBatch {
                        $dbw->delete( 'oldimage',
                                array(
                                        'oi_name' => $this->file->getName(),
-                                       'oi_archive_name IN (' . $dbw->makeList( array_keys( $oldRels ) ) . ')'
+                                       'oi_archive_name' => array_keys( $oldRels )
                                ), __METHOD__ );
                }
                if ( $deleteCurrent ) {
@@ -1518,7 +1520,8 @@ class LocalFileRestoreBatch {
                $result = $dbw->select( 'filearchive', '*',
                        $conditions,
                        __METHOD__,
-                       array( 'ORDER BY' => 'fa_timestamp DESC' ) );
+                       array( 'ORDER BY' => 'fa_timestamp DESC' )
+               );
 
                $idsPresent = array();
                $storeBatch = array();
@@ -1563,15 +1566,11 @@ class LocalFileRestoreBatch {
                                        'minor_mime' => $row->fa_minor_mime,
                                        'major_mime' => $row->fa_major_mime,
                                        'media_type' => $row->fa_media_type,
-                                       'metadata' => $row->fa_metadata );
+                                       'metadata'   => $row->fa_metadata
+                               );
                        }
 
                        if ( $first && !$exists ) {
-                               // The live (current) version cannot be hidden!
-                               if( !$this->unsuppress && $row->fa_deleted ) {
-                                       $this->file->unlock();
-                                       return $status;
-                               }
                                // This revision will be published as the new current version
                                $destRel = $this->file->getRel();
                                $insertCurrent = array(
@@ -1588,7 +1587,13 @@ class LocalFileRestoreBatch {
                                        'img_user'        => $row->fa_user,
                                        'img_user_text'   => $row->fa_user_text,
                                        'img_timestamp'   => $row->fa_timestamp,
-                                       'img_sha1'        => $sha1);
+                                       'img_sha1'        => $sha1
+                               );
+                               // The live (current) version cannot be hidden!
+                               if( !$this->unsuppress && $row->fa_deleted ) {
+                                       $storeBatch[] = array( $deletedUrl, 'public', $destRel );
+                                       $this->cleanupBatch[] = $row->fa_storage_key;
+                               }
                        } else {
                                $archiveName = $row->fa_archive_name;
                                if( $archiveName == '' ) {
@@ -1715,7 +1720,7 @@ class LocalFileMoveBatch {
                $this->file = $file;
                $this->target = $target;
                $this->oldHash = $this->file->repo->getHashPath( $this->file->getName() );
-               $this->newHash = $this->file->repo->getHashPath( $this->target->getDbKey() );
+               $this->newHash = $this->file->repo->getHashPath( $this->target->getDBKey() );
                $this->oldName = $this->file->getName();
                $this->newName = $this->file->repo->getNameFromTitle( $this->target );
                $this->oldRel = $this->oldHash . $this->oldName;
@@ -1761,7 +1766,7 @@ class LocalFileMoveBatch {
                                continue;
                        }
                        $this->olds[] = array(
-                               "{$archiveBase}/{$this->oldHash}{$oldname}",
+                               "{$archiveBase}/{$this->oldHash}{$oldName}",
                                "{$archiveBase}/{$this->newHash}{$timestamp}!{$this->newName}"
                        );
                }