summaryrefslogtreecommitdiff
path: root/includes/filerepo/OldLocalFile.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
committerPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
commitca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch)
treeec04cc15b867bc21eedca904cea9af0254531a11 /includes/filerepo/OldLocalFile.php
parenta22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff)
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing
Diffstat (limited to 'includes/filerepo/OldLocalFile.php')
-rw-r--r--includes/filerepo/OldLocalFile.php100
1 files changed, 93 insertions, 7 deletions
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 @@
<?php
/**
- * Old file in the in the oldimage table
+ * Old file in the oldimage table
*
* @file
* @ingroup FileRepo
@@ -19,8 +19,9 @@ class OldLocalFile extends LocalFile {
static function newFromTitle( $title, $repo, $time = null ) {
# The null default value is only here to avoid an E_STRICT
- if( $time === null )
+ if ( $time === null ) {
throw new MWException( __METHOD__.' got null for $time parameter' );
+ }
return new self( $title, $repo, $time, null );
}
@@ -34,15 +35,27 @@ class OldLocalFile extends LocalFile {
$file->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;
+ }
+
}