Index: trunk/phase3/includes/filerepo/OldLocalFile.php |
— | — | @@ -212,4 +212,71 @@ |
213 | 213 | $this->load(); |
214 | 214 | return Revision::userCanBitfield( $this->deleted, $field ); |
215 | 215 | } |
| 216 | + |
| 217 | + /** |
| 218 | + * Upload a file directly into archive. Generally for Special:Import. |
| 219 | + * |
| 220 | + * @param $srcPath string File system path of the source file |
| 221 | + * @param $archiveName string Full archive name of the file, in the form |
| 222 | + * $timestamp!$filename, where $filename must match $this->getName() |
| 223 | + */ |
| 224 | + function uploadOld( $srcPath, $archiveName, $comment, $user ) { |
| 225 | + $this->lock(); |
| 226 | + $status = $this->publish( $srcPath, $flags, $archiveName ); |
| 227 | + |
| 228 | + if ( $status->isGood() ) { |
| 229 | + if ( !$this->recordOldUpload( $srcPath, $archiveName, $comment, $user ) ) { |
| 230 | + $status->fatal( 'filenotfound', $srcPath ); |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + $this->unlock(); |
| 235 | + |
| 236 | + return $status; |
| 237 | + } |
| 238 | + |
| 239 | + /** |
| 240 | + * Record a file upload in the oldimage table, without adding log entries. |
| 241 | + * |
| 242 | + * @param $srcPath string File system path to the source file |
| 243 | + * @param $archiveName string The archive name of the file |
| 244 | + * @param $comment string Upload comment |
| 245 | + * @param $user User User who did this upload |
| 246 | + * @return bool |
| 247 | + */ |
| 248 | + function recordOldUpload( $srcPath, $archiveName, $comment, $user ) { |
| 249 | + $dbw = $this->repo->getMasterDB(); |
| 250 | + $dbw->begin(); |
| 251 | + |
| 252 | + $dstPath = $this->repo->getZonePath( 'public' ) . '/' . $this->getRel(); |
| 253 | + $props = self::getPropsFromPath( $dstPath ); |
| 254 | + if ( !$props['fileExists'] ) { |
| 255 | + return false; |
| 256 | + } |
| 257 | + |
| 258 | + $dbw->insert( 'oldimage', |
| 259 | + array( |
| 260 | + 'oi_name' => $this->getName(), |
| 261 | + 'oi_archive_name' => $archiveName, |
| 262 | + 'oi_size' => $props['size'], |
| 263 | + 'oi_width' => intval( $props['width'] ), |
| 264 | + 'oi_height' => intval( $props['height'] ), |
| 265 | + 'oi_bits' => $props['bits'], |
| 266 | + 'oi_timestamp' => $props['timestamp'], |
| 267 | + 'oi_description' => $comment, |
| 268 | + 'oi_user' => $user->getId(), |
| 269 | + 'oi_user_text' => $user->getName(), |
| 270 | + 'oi_metadata' => $props['metadata'], |
| 271 | + 'oi_media_type' => $props['media_type'], |
| 272 | + 'oi_major_mime' => $props['major_mime'], |
| 273 | + 'oi_minor_mime' => $props['minor_mime'], |
| 274 | + 'oi_sha1' => $props['sha1'], |
| 275 | + ), __METHOD__ |
| 276 | + ); |
| 277 | + |
| 278 | + $dbw->commit(); |
| 279 | + |
| 280 | + return true; |
| 281 | + } |
| 282 | + |
216 | 283 | } |
Index: trunk/phase3/includes/filerepo/LocalFile.php |
— | — | @@ -1045,16 +1045,22 @@ |
1046 | 1046 | * |
1047 | 1047 | * @param $srcPath String: local filesystem path to the source image |
1048 | 1048 | * @param $flags Integer: a bitwise combination of: |
1049 | | - * File::DELETE_SOURCE Delete the source file, i.e. move |
1050 | | - * rather than copy |
| 1049 | + * File::DELETE_SOURCE Delete the source file, i.e. move rather than copy |
| 1050 | + * @param $dstArchiveName string File name if the file is to be published |
| 1051 | + * into the archive |
1051 | 1052 | * @return FileRepoStatus object. On success, the value member contains the |
1052 | 1053 | * archive name, or an empty string if it was a new file. |
1053 | 1054 | */ |
1054 | | - function publish( $srcPath, $flags = 0 ) { |
| 1055 | + function publish( $srcPath, $flags = 0, $dstArchiveName = null ) { |
1055 | 1056 | $this->lock(); |
1056 | 1057 | |
1057 | | - $dstRel = $this->getRel(); |
1058 | | - $archiveName = gmdate( 'YmdHis' ) . '!' . $this->getName(); |
| 1058 | + if ( $dstArchiveName ) { |
| 1059 | + $dstRel = 'archive/' . $this->getHashPath() . $dstArchiveName; |
| 1060 | + } else { |
| 1061 | + $dstRel = $this->getRel(); |
| 1062 | + } |
| 1063 | + |
| 1064 | + $archiveName = wfTimestamp( TS_MW ) . '!'. $this->getName(); |
1059 | 1065 | $archiveRel = 'archive/' . $this->getHashPath() . $archiveName; |
1060 | 1066 | $flags = $flags & File::DELETE_SOURCE ? LocalRepo::DELETE_SOURCE : 0; |
1061 | 1067 | $status = $this->repo->publish( $srcPath, $dstRel, $archiveRel, $flags ); |