Index: trunk/phase3/includes/SpecialUpload.php |
— | — | @@ -1285,7 +1285,7 @@ |
1286 | 1286 | if( $img->exists() ) { |
1287 | 1287 | global $wgUser, $wgOut; |
1288 | 1288 | if( $img->isLocal() ) { |
1289 | | - if( !$wgUser->isAllowed( 'reupload' ) ) { |
| 1289 | + if( !$this->userCanReUpload( $wgUser, $img->name ) ) { |
1290 | 1290 | $error = 'fileexists-forbidden'; |
1291 | 1291 | } |
1292 | 1292 | } else { |
— | — | @@ -1304,6 +1304,31 @@ |
1305 | 1305 | // Rockin', go ahead and upload |
1306 | 1306 | return true; |
1307 | 1307 | } |
| 1308 | + |
| 1309 | + /** |
| 1310 | + * Check if a user is the last uploader |
| 1311 | + * |
| 1312 | + * @param User $user |
| 1313 | + * @param string $img, image name |
| 1314 | + * @return bool |
| 1315 | + * @access private |
| 1316 | + */ |
| 1317 | + function userCanReUpload( $user, $img ) { |
| 1318 | + if( $user->isAllowed('reupload' ) ) |
| 1319 | + return true; // non-conditional |
| 1320 | + if( !$user->isAllowed('reupload-own') ) |
| 1321 | + return false; |
| 1322 | + |
| 1323 | + $dbr = wfGetDB( DB_SLAVE ); |
| 1324 | + $row = $dbr->selectRow( |
| 1325 | + /* FROM */ 'image', |
| 1326 | + /* SELECT */ 'img_user', |
| 1327 | + /* WHERE */ array( 'img_name' => $img ) |
| 1328 | + ); |
| 1329 | + if ( !$row ) |
| 1330 | + return false; |
1308 | 1331 | |
| 1332 | + return $user->getID() == $row->img_user; |
| 1333 | + } |
1309 | 1334 | } |
1310 | 1335 | ?> |