From f7e9b3556a3839bb5d693415c1f167757e7ef5db Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 6 May 2007 20:51:06 +0000 Subject: [PATCH] *Let users with 'reupload-own' upload over image where they are the last uploader, right is not assigned by default (bug 5057) --- includes/SpecialUpload.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index e07c414c67..af7597f645 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -1285,7 +1285,7 @@ class UploadForm { 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 @@ class UploadForm { // 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; + } } ?> -- 2.20.1