r57730 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57729‎ | r57730 | r57731 >
Date:22:23, 14 October 2009
Author:dale
Status:reverted (Comments)
Tags:
Comment:
* added db commit logic to the watch request in api queries
Modified paths:
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -1,18 +1,18 @@
22 <?php
33 /**
4 - * @file
 4+ * @file
55 * @ingroup upload
6 - *
 6+ *
77 * UploadBase and subclasses are the backend of MediaWiki's file uploads.
88 * The frontends are formed by ApiUpload and SpecialUpload.
9 - *
 9+ *
1010 * See also includes/docs/upload.txt
11 - *
 11+ *
1212 * @author Brion Vibber
1313 * @author Bryan Tong Minh
1414 * @author Michael Dale
1515 */
16 -
 16+
1717 abstract class UploadBase {
1818 protected $mTempPath;
1919 protected $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType;
@@ -117,7 +117,7 @@
118118 $this->mFileSize = $fileSize;
119119 $this->mRemoveTempFile = $removeTempFile;
120120 }
121 -
 121+
122122 /**
123123 * Initialize from a WebRequest. Override this in a subclass.
124124 */
@@ -222,7 +222,7 @@
223223
224224 #check mime type, if desired
225225 global $wgVerifyMimeType;
226 - if ( $wgVerifyMimeType ) {
 226+ if ( $wgVerifyMimeType ) {
227227 global $wgMimeTypeBlacklist;
228228 if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) )
229229 return array( 'filetype-badmime', $mime );
@@ -263,7 +263,7 @@
264264
265265 /**
266266 * Check whether the user can edit, upload and create the image.
267 - *
 267+ *
268268 * @param User $user the user to verify the permissions against
269269 * @return mixed An array as returned by getUserPermissionsErrors or true
270270 * in case the user has proper permissions.
@@ -289,7 +289,7 @@
290290
291291 /**
292292 * Check for non fatal problems with the file
293 - *
 293+ *
294294 * @return array Array of warnings
295295 */
296296 public function checkWarnings() {
@@ -349,9 +349,9 @@
350350 }
351351
352352 /**
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
354354 * if necessary and runs the UploadComplete hook.
355 - *
 355+ *
356356 * @return mixed Status indicating the whether the upload succeeded.
357357 */
358358 public function performUpload( $comment, $pageText, $watch, $user ) {
@@ -359,8 +359,13 @@
360360 $status = $this->getLocalFile()->upload( $this->mTempPath, $comment, $pageText,
361361 File::DELETE_SOURCE, $this->mFileProps, false, $user );
362362
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+ }
365370
366371 if( $status->isGood() )
367372 wfRunHooks( 'UploadComplete', array( &$this ) );
@@ -371,7 +376,7 @@
372377 /**
373378 * Returns the title of the file to be uploaded. Sets mTitleError in case
374379 * the name was illegal.
375 - *
 380+ *
376381 * @return Title The title of the file or null in case the name was illegal
377382 */
378383 public function getTitle() {
@@ -440,7 +445,7 @@
441446 }
442447
443448 /**
444 - * Return the local file and initializes if necessary.
 449+ * Return the local file and initializes if necessary.
445450 */
446451 public function getLocalFile() {
447452 if( is_null( $this->mLocalFile ) ) {
@@ -468,9 +473,9 @@
469474 return $status;
470475 }
471476
472 - /**
 477+ /**
473478 * Append a file to a stashed file.
474 - *
 479+ *
475480 * @param string $srcPath Path to file to append from
476481 * @param string $toAppendPath Path to file to append to
477482 * @return Status Status
@@ -503,7 +508,7 @@
504509 'mFileSize' => $this->mFileSize,
505510 'mFileProps' => $this->mFileProps,
506511 'version' => self::SESSION_VERSION,
507 - );
 512+ );
508513 return $key;
509514 }
510515
@@ -826,7 +831,7 @@
827832 }
828833 }
829834
830 -
 835+
831836 if ( $mappedCode === AV_SCAN_FAILED ) {
832837 # scan failed (code was mapped to false by $exitCodeMap)
833838 wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" );
@@ -908,9 +913,9 @@
909914 return true;
910915 }
911916
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+ */
915920 $file = wfFindFile( $this->getTitle() );
916921 if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) )
917922 return 'fileexists-shared-forbidden';
@@ -940,13 +945,13 @@
941946
942947 /**
943948 * Helper function that does various existence checks for a file.
944 - * The following checks are performed:
 949+ * The following checks are performed:
945950 * - The file exists
946951 * - Article with the same name as the file exists
947952 * - File exists with normalized extension
948953 * - 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
951956 * @return mixed False if the file does not exists, else an array
952957 */
953958 public static function getExistsWarning( $file ) {
@@ -955,10 +960,10 @@
956961
957962 if( $file->getTitle()->getArticleID() )
958963 return array( 'warning' => 'page-exists', 'file' => $file );
959 -
 964+
960965 if ( $file->wasDeleted() && !$file->exists() )
961 - return array( 'warning' => 'was-deleted', 'file' => $file );
962 -
 966+ return array( 'warning' => 'was-deleted', 'file' => $file );
 967+
963968 if( strpos( $file->getName(), '.' ) == false ) {
964969 $partname = $file->getName();
965970 $extension = '';
@@ -992,15 +997,15 @@
993998 // File does not exist, but we just don't like the name
994999 return array( 'warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb );
9951000 }
996 -
9971001
 1002+
9981003 foreach( self::getFilenamePrefixBlacklist() as $prefix ) {
9991004 if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix )
10001005 return array( 'warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix );
10011006 }
1002 -
10031007
10041008
 1009+
10051010 return false;
10061011 }
10071012

Comments

#Comment by Mdale (talk | contribs)   22:24, 14 October 2009

opps forgot to mention the bug this was addressing: bug 21142

#Comment by Bryan (talk | contribs)   22:59, 5 December 2009

Shouldn't the LBFactory or whatever class is responsible for that automatically commit at shutdown?

#Comment by Tim Starling (talk | contribs)   05:38, 15 December 2009

Yes, since r34951 a commit is done automatically. The problem may have been a rollback due to an abnormal termination, say via dieUsage() or by throwing an exception. This needs to be clarified, since other queries may also be affected.

Note that this revision was reverted in the JS2 demerge.

Status & tagging log