From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- includes/filerepo/OldLocalFile.php | 100 ++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 7 deletions(-) (limited to 'includes/filerepo/OldLocalFile.php') diff --git a/includes/filerepo/OldLocalFile.php b/includes/filerepo/OldLocalFile.php index 9efe998f..bcb22c17 100644 --- a/includes/filerepo/OldLocalFile.php +++ b/includes/filerepo/OldLocalFile.php @@ -1,6 +1,6 @@ loadFromRow( $row, 'oi_' ); return $file; } - + + /** + * Create a OldLocalFile from a SHA-1 key + * Do not call this except from inside a repo class. + * + * @param $sha1 string base-36 SHA-1 + * @param $repo LocalRepo + * @param string|bool $timestamp MW_timestamp (optional) + * + * @return bool|OldLocalFile + */ static function newFromKey( $sha1, $repo, $timestamp = false ) { + $dbr = $repo->getSlaveDB(); + $conds = array( 'oi_sha1' => $sha1 ); - if( $timestamp ) { - $conds['oi_timestamp'] = $timestamp; + if ( $timestamp ) { + $conds['oi_timestamp'] = $dbr->timestamp( $timestamp ); } - $dbr = $repo->getSlaveDB(); + $row = $dbr->selectRow( 'oldimage', self::selectFields(), $conds, __METHOD__ ); - if( $row ) { + if ( $row ) { return self::newFromRow( $row, $repo ); } else { return false; @@ -205,4 +218,77 @@ class OldLocalFile extends LocalFile { $this->load(); return Revision::userCanBitfield( $this->deleted, $field ); } + + /** + * Upload a file directly into archive. Generally for Special:Import. + * + * @param $srcPath string File system path of the source file + * @param $archiveName string Full archive name of the file, in the form + * $timestamp!$filename, where $filename must match $this->getName() + * + * @return FileRepoStatus + */ + function uploadOld( $srcPath, $archiveName, $timestamp, $comment, $user, $flags = 0 ) { + $this->lock(); + + $dstRel = 'archive/' . $this->getHashPath() . $archiveName; + $status = $this->publishTo( $srcPath, $dstRel, + $flags & File::DELETE_SOURCE ? FileRepo::DELETE_SOURCE : 0 + ); + + if ( $status->isGood() ) { + if ( !$this->recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) ) { + $status->fatal( 'filenotfound', $srcPath ); + } + } + + $this->unlock(); + + return $status; + } + + /** + * Record a file upload in the oldimage table, without adding log entries. + * + * @param $srcPath string File system path to the source file + * @param $archiveName string The archive name of the file + * @param $comment string Upload comment + * @param $user User User who did this upload + * @return bool + */ + function recordOldUpload( $srcPath, $archiveName, $timestamp, $comment, $user ) { + $dbw = $this->repo->getMasterDB(); + $dbw->begin(); + + $dstPath = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel(); + $props = self::getPropsFromPath( $dstPath ); + if ( !$props['fileExists'] ) { + return false; + } + + $dbw->insert( 'oldimage', + array( + 'oi_name' => $this->getName(), + 'oi_archive_name' => $archiveName, + 'oi_size' => $props['size'], + 'oi_width' => intval( $props['width'] ), + 'oi_height' => intval( $props['height'] ), + 'oi_bits' => $props['bits'], + 'oi_timestamp' => $dbw->timestamp( $timestamp ), + 'oi_description' => $comment, + 'oi_user' => $user->getId(), + 'oi_user_text' => $user->getName(), + 'oi_metadata' => $props['metadata'], + 'oi_media_type' => $props['media_type'], + 'oi_major_mime' => $props['major_mime'], + 'oi_minor_mime' => $props['minor_mime'], + 'oi_sha1' => $props['sha1'], + ), __METHOD__ + ); + + $dbw->commit(); + + return true; + } + } -- cgit v1.2.3-54-g00ecf