uploads overwriting existing files; default is the old behavior (allowed).
* (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 ===
$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;
$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
$fname
);
}
+
+ /**
+ * Returns true if the image does not come from the shared
+ * image repository.
+ *
+ * @return bool
+ */
+ function isLocal() {
+ return !$this->fromSharedDirectory;
+ }
} //class
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>' );
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;
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;
+ }
}
?>
'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