* Add 'reupload' and 'reupload-shared' permission keys to restrict new
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 5 Sep 2005 06:16:48 +0000 (06:16 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 5 Sep 2005 06:16:48 +0000 (06:16 +0000)
uploads overwriting existing files; default is the old behavior (allowed).

RELEASE-NOTES
includes/DefaultSettings.php
includes/Image.php
includes/ImagePage.php
includes/SpecialUpload.php
languages/Language.php

index c583565..4944172 100644 (file)
@@ -82,6 +82,8 @@ fully support the editing toolbar, but was found to be too confusing.
 * (bug 3306) Document $wgLocalTZoffset
 * (bug 3304) Language file for Croatian (LanguageHr.php)
 * (bug 2143) Update Vietnamese interface
+* Add 'reupload' and 'reupload-shared' permission keys to restrict new uploads
+  overwriting existing files; default is the old behavior (allowed).
 
 
 === Caveats ===
index 273146a..0fbc7ee 100644 (file)
@@ -710,6 +710,8 @@ $wgGroupPermissions['user' ]['move']            = true;
 $wgGroupPermissions['user' ]['read']            = true;
 $wgGroupPermissions['user' ]['edit']            = true;
 $wgGroupPermissions['user' ]['upload']          = true;
+$wgGroupPermissions['user' ]['reupload']        = true;
+$wgGroupPermissions['user' ]['reupload-shared'] = true;
 
 $wgGroupPermissions['bot'  ]['bot']             = true;
 
@@ -724,6 +726,8 @@ $wgGroupPermissions['sysop']['patrol']          = true;
 $wgGroupPermissions['sysop']['protect']         = true;
 $wgGroupPermissions['sysop']['rollback']        = true;
 $wgGroupPermissions['sysop']['upload']          = true;
+$wgGroupPermissions['sysop']['reupload']        = true;
+$wgGroupPermissions['sysop']['reupload-shared'] = true;
 
 $wgGroupPermissions['bureaucrat']['userrights'] = true;
 // Used by the Special:Renameuser extension
index 8076a71..674ce74 100644 (file)
@@ -1484,6 +1484,16 @@ class Image
                        $fname
                );
        }
+       
+       /**
+        * Returns true if the image does not come from the shared
+        * image repository.
+        *
+        * @return bool
+        */
+       function isLocal() {
+               return !$this->fromSharedDirectory;
+       }
 
 } //class
 
index 4c6cf28..33c3c9c 100644 (file)
@@ -286,9 +286,11 @@ END
                        return;
 
                $sk = $wgUser->getSkin();
-               $wgOut->addHTML( '<br /><ul><li>' );
-               $wgOut->addWikiText( '<div>'. wfMsg( 'uploadnewversion', $this->getUploadUrl() ) .'</div>' );
-               $wgOut->addHTML( '</li><li>' );
+               $wgOut->addHTML( '<br /><ul>' );
+               if( $wgUser->isAllowed( 'reupload' ) ) {        
+                       $wgOut->addWikiText( "<li>\n<div>". wfMsg( 'uploadnewversion', $this->getUploadUrl() ) ."</div>\n</li>\n" );
+               }
+               $wgOut->addHTML( '<li>' );
                $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
                        wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
                $wgOut->addWikiText( '<div>' .  wfMsg('edit-externally-help') . '</div>' );
index 951b23b..185700f 100644 (file)
@@ -201,6 +201,14 @@ class UploadForm {
                if( !$nt->userCanEdit() ) {
                        return $this->uploadError( wfMsgWikiHtml( 'protectedpage' ) );
                }
+               
+               /**
+                * In some cases we may forbid overwriting of existing files.
+                */
+               $overwrite = $this->checkOverwrite( $this->mUploadSaveName );
+               if( WikiError::isError( $overwrite ) ) {
+                       return $this->uploadError( $overwrite->toString() );
+               }
 
                /* Don't allow users to override the blacklist (check file extension) */
                global $wgStrictFileExtensions;
@@ -949,6 +957,45 @@ class UploadForm {
                        unlink( $this->mUploadTempName );
                }
        }
+       
+       /**
+        * Check if there's an overwrite conflict and, if so, if restrictions
+        * forbid this user from performing the upload.
+        *
+        * @return mixed true on success, WikiError on failure
+        * @access private
+        */
+       function checkOverwrite( $name ) {
+               $img = Image::newFromName( $name );
+               if( is_null( $img ) ) {
+                       // Uh... this shouldn't happen ;)
+                       // But if it does, fall through to previous behavior
+                       return false;
+               }
+               
+               $error = '';
+               if( $img->exists() ) {
+                       global $wgUser, $wgOut;
+                       if( $img->isLocal() ) {
+                               if( !$wgUser->isAllowed( 'reupload' ) ) {
+                                       $error = 'fileexists-forbidden';
+                               }
+                       } else {
+                               if( !$wgUser->isAllowed( 'reupload' ) ||
+                                   !$wgUser->isAllowed( 'reupload-shared' ) ) {
+                                       $error = "fileexists-shared-forbidden";
+                               }
+                       }
+               }
+               
+               if( $error ) {
+                       $errorText = wfMsg( $error, wfEscapeWikiText( $img->getName() ) );
+                       return new WikiError( $wgOut->parse( $errorText ) );
+               }
+               
+               // Rockin', go ahead and upload
+               return true;
+       }
 
 }
 ?>
index 9ac4113..f8b1970 100644 (file)
@@ -1017,6 +1017,8 @@ To include the image in a page, use a link in the form
 'largefileserver' => 'This file is bigger than the server is configured to allow.',
 '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.',
 'fileexists'           => 'A file with this name exists already, please check $1 if you are not sure if you want to change it.',
+'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]]',
+'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]]',
 'successfulupload' => 'Successful upload',
 'fileuploaded' => "File $1 uploaded successfully.
 Please follow this link: $2 to the description page and fill