r21943 - Code Review

From MediaWiki.org

Jump to: navigation, search
Repository:MediaWiki
Revision:r21942 | r21943 (on ViewVC) | r21944 >
Date:20:51, 6 May 2007
Author:aaron
Status:new
Tags:
Comment:*Let users with 'reupload-own' upload over image where they are the last uploader, right is not assigned by default (bug 5057)
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/SpecialUpload.php
===================================================================
--- trunk/phase3/includes/SpecialUpload.php	(revision 21942)
+++ trunk/phase3/includes/SpecialUpload.php	(revision 21943)
@@ -1285,7 +1285,7 @@
 		if( $img->exists() ) {
 			global $wgUser, $wgOut;
 			if( $img->isLocal() ) {
-				if( !$wgUser->isAllowed( 'reupload' ) ) {
+				if( !$this->userCanReUpload( $wgUser, $img->name ) ) {
 					$error = 'fileexists-forbidden';
 				}
 			} else {
@@ -1304,6 +1304,31 @@
 		// Rockin', go ahead and upload
 		return true;
 	}
+	
+	 /**
+	 * Check if a user is the last uploader
+	 *
+	 * @param User $user
+	 * @param string $img, image name
+	 * @return bool
+	 * @access private
+	 */
+	function userCanReUpload( $user, $img ) {
+		if( $user->isAllowed('reupload' ) )
+			return true; // non-conditional
+		if( !$user->isAllowed('reupload-own') )
+			return false;
+		
+		$dbr = wfGetDB( DB_SLAVE );
+		$row = $dbr->selectRow(
+		/* FROM */ 'image',
+		/* SELECT */ 'img_user',
+		/* WHERE */ array( 'img_name' => $img )
+		);
+		if ( !$row )
+			return false;
 
+		return $user->getID() == $row->img_user;
+	}
 }
 ?>
Views
Toolbox