Index: trunk/phase3/includes/ImagePage.php |
— | — | @@ -286,9 +286,11 @@ |
287 | 287 | return; |
288 | 288 | |
289 | 289 | $sk = $wgUser->getSkin(); |
290 | | - $wgOut->addHTML( '<br /><ul><li>' ); |
291 | | - $wgOut->addWikiText( '<div>'. wfMsg( 'uploadnewversion', $this->getUploadUrl() ) .'</div>' ); |
292 | | - $wgOut->addHTML( '</li><li>' ); |
| 290 | + $wgOut->addHTML( '<br /><ul>' ); |
| 291 | + if( $wgUser->isAllowed( 'reupload' ) ) { |
| 292 | + $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" ); |
| 293 | + } |
| 294 | + $wgOut->addHTML( '<li>' ); |
293 | 295 | $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle, |
294 | 296 | wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) ); |
295 | 297 | $wgOut->addWikiText( '<div>' . wfMsg('edit-externally-help') . '</div>' ); |
Index: trunk/phase3/includes/SpecialUpload.php |
— | — | @@ -201,6 +201,14 @@ |
202 | 202 | if( !$nt->userCanEdit() ) { |
203 | 203 | return $this->uploadError( wfMsgWikiHtml( 'protectedpage' ) ); |
204 | 204 | } |
| 205 | + |
| 206 | + /** |
| 207 | + * In some cases we may forbid overwriting of existing files. |
| 208 | + */ |
| 209 | + $overwrite = $this->checkOverwrite( $this->mUploadSaveName ); |
| 210 | + if( WikiError::isError( $overwrite ) ) { |
| 211 | + return $this->uploadError( $overwrite->toString() ); |
| 212 | + } |
205 | 213 | |
206 | 214 | /* Don't allow users to override the blacklist (check file extension) */ |
207 | 215 | global $wgStrictFileExtensions; |
— | — | @@ -949,6 +957,45 @@ |
950 | 958 | unlink( $this->mUploadTempName ); |
951 | 959 | } |
952 | 960 | } |
| 961 | + |
| 962 | + /** |
| 963 | + * Check if there's an overwrite conflict and, if so, if restrictions |
| 964 | + * forbid this user from performing the upload. |
| 965 | + * |
| 966 | + * @return mixed true on success, WikiError on failure |
| 967 | + * @access private |
| 968 | + */ |
| 969 | + function checkOverwrite( $name ) { |
| 970 | + $img = Image::newFromName( $name ); |
| 971 | + if( is_null( $img ) ) { |
| 972 | + // Uh... this shouldn't happen ;) |
| 973 | + // But if it does, fall through to previous behavior |
| 974 | + return false; |
| 975 | + } |
| 976 | + |
| 977 | + $error = ''; |
| 978 | + if( $img->exists() ) { |
| 979 | + global $wgUser, $wgOut; |
| 980 | + if( $img->isLocal() ) { |
| 981 | + if( !$wgUser->isAllowed( 'reupload' ) ) { |
| 982 | + $error = 'fileexists-forbidden'; |
| 983 | + } |
| 984 | + } else { |
| 985 | + if( !$wgUser->isAllowed( 'reupload' ) || |
| 986 | + !$wgUser->isAllowed( 'reupload-shared' ) ) { |
| 987 | + $error = "fileexists-shared-forbidden"; |
| 988 | + } |
| 989 | + } |
| 990 | + } |
| 991 | + |
| 992 | + if( $error ) { |
| 993 | + $errorText = wfMsg( $error, wfEscapeWikiText( $img->getName() ) ); |
| 994 | + return new WikiError( $wgOut->parse( $errorText ) ); |
| 995 | + } |
| 996 | + |
| 997 | + // Rockin', go ahead and upload |
| 998 | + return true; |
| 999 | + } |
953 | 1000 | |
954 | 1001 | } |
955 | 1002 | ?> |
Index: trunk/phase3/includes/Image.php |
— | — | @@ -1484,6 +1484,16 @@ |
1485 | 1485 | $fname |
1486 | 1486 | ); |
1487 | 1487 | } |
| 1488 | + |
| 1489 | + /** |
| 1490 | + * Returns true if the image does not come from the shared |
| 1491 | + * image repository. |
| 1492 | + * |
| 1493 | + * @return bool |
| 1494 | + */ |
| 1495 | + function isLocal() { |
| 1496 | + return !$this->fromSharedDirectory; |
| 1497 | + } |
1488 | 1498 | |
1489 | 1499 | } //class |
1490 | 1500 | |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -710,6 +710,8 @@ |
711 | 711 | $wgGroupPermissions['user' ]['read'] = true; |
712 | 712 | $wgGroupPermissions['user' ]['edit'] = true; |
713 | 713 | $wgGroupPermissions['user' ]['upload'] = true; |
| 714 | +$wgGroupPermissions['user' ]['reupload'] = true; |
| 715 | +$wgGroupPermissions['user' ]['reupload-shared'] = true; |
714 | 716 | |
715 | 717 | $wgGroupPermissions['bot' ]['bot'] = true; |
716 | 718 | |
— | — | @@ -724,6 +726,8 @@ |
725 | 727 | $wgGroupPermissions['sysop']['protect'] = true; |
726 | 728 | $wgGroupPermissions['sysop']['rollback'] = true; |
727 | 729 | $wgGroupPermissions['sysop']['upload'] = true; |
| 730 | +$wgGroupPermissions['sysop']['reupload'] = true; |
| 731 | +$wgGroupPermissions['sysop']['reupload-shared'] = true; |
728 | 732 | |
729 | 733 | $wgGroupPermissions['bureaucrat']['userrights'] = true; |
730 | 734 | // Used by the Special:Renameuser extension |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -82,6 +82,8 @@ |
83 | 83 | * (bug 3306) Document $wgLocalTZoffset |
84 | 84 | * (bug 3304) Language file for Croatian (LanguageHr.php) |
85 | 85 | * (bug 2143) Update Vietnamese interface |
| 86 | +* Add 'reupload' and 'reupload-shared' permission keys to restrict new uploads |
| 87 | + overwriting existing files; default is the old behavior (allowed). |
86 | 88 | |
87 | 89 | |
88 | 90 | === Caveats === |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -1017,6 +1017,8 @@ |
1018 | 1018 | 'largefileserver' => 'This file is bigger than the server is configured to allow.', |
1019 | 1019 | 'emptyfile' => 'The file you uploaded seems to be empty. This might be due to a typo in the file name. Please check whether you really want to upload this file.', |
1020 | 1020 | 'fileexists' => 'A file with this name exists already, please check $1 if you are not sure if you want to change it.', |
| 1021 | +'fileexists-forbidden' => 'A file with this name exists already; please go back and upload this file under a new name. [[Image:$1|thumb|center|$1]]', |
| 1022 | +'fileexists-shared-forbidden' => 'A file with this name exists already in the shared file repository; lease go back and upload this file under a new name. [[Image:$1|thumb|center|$1]]', |
1021 | 1023 | 'successfulupload' => 'Successful upload', |
1022 | 1024 | 'fileuploaded' => "File $1 uploaded successfully. |
1023 | 1025 | Please follow this link: $2 to the description page and fill |