Index: trunk/phase3/includes/upload/UploadBase.php |
— | — | @@ -1,18 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * @file |
| 4 | + * @file |
5 | 5 | * @ingroup upload |
6 | | - * |
| 6 | + * |
7 | 7 | * UploadBase and subclasses are the backend of MediaWiki's file uploads. |
8 | 8 | * The frontends are formed by ApiUpload and SpecialUpload. |
9 | | - * |
| 9 | + * |
10 | 10 | * See also includes/docs/upload.txt |
11 | | - * |
| 11 | + * |
12 | 12 | * @author Brion Vibber |
13 | 13 | * @author Bryan Tong Minh |
14 | 14 | * @author Michael Dale |
15 | 15 | */ |
16 | | - |
| 16 | + |
17 | 17 | abstract class UploadBase { |
18 | 18 | protected $mTempPath; |
19 | 19 | protected $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType; |
— | — | @@ -117,7 +117,7 @@ |
118 | 118 | $this->mFileSize = $fileSize; |
119 | 119 | $this->mRemoveTempFile = $removeTempFile; |
120 | 120 | } |
121 | | - |
| 121 | + |
122 | 122 | /** |
123 | 123 | * Initialize from a WebRequest. Override this in a subclass. |
124 | 124 | */ |
— | — | @@ -222,7 +222,7 @@ |
223 | 223 | |
224 | 224 | #check mime type, if desired |
225 | 225 | global $wgVerifyMimeType; |
226 | | - if ( $wgVerifyMimeType ) { |
| 226 | + if ( $wgVerifyMimeType ) { |
227 | 227 | global $wgMimeTypeBlacklist; |
228 | 228 | if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) |
229 | 229 | return array( 'filetype-badmime', $mime ); |
— | — | @@ -263,7 +263,7 @@ |
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Check whether the user can edit, upload and create the image. |
267 | | - * |
| 267 | + * |
268 | 268 | * @param User $user the user to verify the permissions against |
269 | 269 | * @return mixed An array as returned by getUserPermissionsErrors or true |
270 | 270 | * in case the user has proper permissions. |
— | — | @@ -289,7 +289,7 @@ |
290 | 290 | |
291 | 291 | /** |
292 | 292 | * Check for non fatal problems with the file |
293 | | - * |
| 293 | + * |
294 | 294 | * @return array Array of warnings |
295 | 295 | */ |
296 | 296 | public function checkWarnings() { |
— | — | @@ -349,9 +349,9 @@ |
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
353 | | - * Really perform the upload. Stores the file in the local repo, watches |
| 353 | + * Really perform the upload. Stores the file in the local repo, watches |
354 | 354 | * if necessary and runs the UploadComplete hook. |
355 | | - * |
| 355 | + * |
356 | 356 | * @return mixed Status indicating the whether the upload succeeded. |
357 | 357 | */ |
358 | 358 | public function performUpload( $comment, $pageText, $watch, $user ) { |
— | — | @@ -359,8 +359,13 @@ |
360 | 360 | $status = $this->getLocalFile()->upload( $this->mTempPath, $comment, $pageText, |
361 | 361 | File::DELETE_SOURCE, $this->mFileProps, false, $user ); |
362 | 362 | |
363 | | - if( $status->isGood() && $watch ) |
364 | | - $user->addWatch( $this->getLocalFile()->getTitle() ); |
| 363 | + if( $status->isGood() && $watch ){ |
| 364 | + //make sure the watch commit happens inline |
| 365 | + $dbw = wfGetDB(DB_MASTER); |
| 366 | + $dbw->begin(); |
| 367 | + $user->addWatch( $this->getLocalFile()->getTitle() ); |
| 368 | + $dbw->commit(); |
| 369 | + } |
365 | 370 | |
366 | 371 | if( $status->isGood() ) |
367 | 372 | wfRunHooks( 'UploadComplete', array( &$this ) ); |
— | — | @@ -371,7 +376,7 @@ |
372 | 377 | /** |
373 | 378 | * Returns the title of the file to be uploaded. Sets mTitleError in case |
374 | 379 | * the name was illegal. |
375 | | - * |
| 380 | + * |
376 | 381 | * @return Title The title of the file or null in case the name was illegal |
377 | 382 | */ |
378 | 383 | public function getTitle() { |
— | — | @@ -440,7 +445,7 @@ |
441 | 446 | } |
442 | 447 | |
443 | 448 | /** |
444 | | - * Return the local file and initializes if necessary. |
| 449 | + * Return the local file and initializes if necessary. |
445 | 450 | */ |
446 | 451 | public function getLocalFile() { |
447 | 452 | if( is_null( $this->mLocalFile ) ) { |
— | — | @@ -468,9 +473,9 @@ |
469 | 474 | return $status; |
470 | 475 | } |
471 | 476 | |
472 | | - /** |
| 477 | + /** |
473 | 478 | * Append a file to a stashed file. |
474 | | - * |
| 479 | + * |
475 | 480 | * @param string $srcPath Path to file to append from |
476 | 481 | * @param string $toAppendPath Path to file to append to |
477 | 482 | * @return Status Status |
— | — | @@ -503,7 +508,7 @@ |
504 | 509 | 'mFileSize' => $this->mFileSize, |
505 | 510 | 'mFileProps' => $this->mFileProps, |
506 | 511 | 'version' => self::SESSION_VERSION, |
507 | | - ); |
| 512 | + ); |
508 | 513 | return $key; |
509 | 514 | } |
510 | 515 | |
— | — | @@ -826,7 +831,7 @@ |
827 | 832 | } |
828 | 833 | } |
829 | 834 | |
830 | | - |
| 835 | + |
831 | 836 | if ( $mappedCode === AV_SCAN_FAILED ) { |
832 | 837 | # scan failed (code was mapped to false by $exitCodeMap) |
833 | 838 | wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" ); |
— | — | @@ -908,9 +913,9 @@ |
909 | 914 | return true; |
910 | 915 | } |
911 | 916 | |
912 | | - /* Check shared conflicts: if the local file does not exist, but |
913 | | - * wfFindFile finds a file, it exists in a shared repository. |
914 | | - */ |
| 917 | + /* Check shared conflicts: if the local file does not exist, but |
| 918 | + * wfFindFile finds a file, it exists in a shared repository. |
| 919 | + */ |
915 | 920 | $file = wfFindFile( $this->getTitle() ); |
916 | 921 | if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) ) |
917 | 922 | return 'fileexists-shared-forbidden'; |
— | — | @@ -940,13 +945,13 @@ |
941 | 946 | |
942 | 947 | /** |
943 | 948 | * Helper function that does various existence checks for a file. |
944 | | - * The following checks are performed: |
| 949 | + * The following checks are performed: |
945 | 950 | * - The file exists |
946 | 951 | * - Article with the same name as the file exists |
947 | 952 | * - File exists with normalized extension |
948 | 953 | * - The file looks like a thumbnail and the original exists |
949 | | - * |
950 | | - * @param File $file The file to check |
| 954 | + * |
| 955 | + * @param File $file The file to check |
951 | 956 | * @return mixed False if the file does not exists, else an array |
952 | 957 | */ |
953 | 958 | public static function getExistsWarning( $file ) { |
— | — | @@ -955,10 +960,10 @@ |
956 | 961 | |
957 | 962 | if( $file->getTitle()->getArticleID() ) |
958 | 963 | return array( 'warning' => 'page-exists', 'file' => $file ); |
959 | | - |
| 964 | + |
960 | 965 | if ( $file->wasDeleted() && !$file->exists() ) |
961 | | - return array( 'warning' => 'was-deleted', 'file' => $file ); |
962 | | - |
| 966 | + return array( 'warning' => 'was-deleted', 'file' => $file ); |
| 967 | + |
963 | 968 | if( strpos( $file->getName(), '.' ) == false ) { |
964 | 969 | $partname = $file->getName(); |
965 | 970 | $extension = ''; |
— | — | @@ -992,15 +997,15 @@ |
993 | 998 | // File does not exist, but we just don't like the name |
994 | 999 | return array( 'warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb ); |
995 | 1000 | } |
996 | | - |
997 | 1001 | |
| 1002 | + |
998 | 1003 | foreach( self::getFilenamePrefixBlacklist() as $prefix ) { |
999 | 1004 | if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) |
1000 | 1005 | return array( 'warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix ); |
1001 | 1006 | } |
1002 | | - |
1003 | 1007 | |
1004 | 1008 | |
| 1009 | + |
1005 | 1010 | return false; |
1006 | 1011 | } |
1007 | 1012 | |