r10906 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10905‎ | r10906 | r10907 >
Date:06:16, 5 September 2005
Author:vibber
Status:old
Tags:
Comment:
* Add 'reupload' and 'reupload-shared' permission keys to restrict new
uploads overwriting existing files; default is the old behavior (allowed).
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/SpecialUpload.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ImagePage.php
@@ -286,9 +286,11 @@
287287 return;
288288
289289 $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>' );
293295 $wgOut->addHTML( $sk->makeKnownLinkObj( $this->mTitle,
294296 wfMsg( 'edit-externally' ), "action=edit&externaledit=true&mode=file" ) );
295297 $wgOut->addWikiText( '<div>' . wfMsg('edit-externally-help') . '</div>' );
Index: trunk/phase3/includes/SpecialUpload.php
@@ -201,6 +201,14 @@
202202 if( !$nt->userCanEdit() ) {
203203 return $this->uploadError( wfMsgWikiHtml( 'protectedpage' ) );
204204 }
 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+ }
205213
206214 /* Don't allow users to override the blacklist (check file extension) */
207215 global $wgStrictFileExtensions;
@@ -949,6 +957,45 @@
950958 unlink( $this->mUploadTempName );
951959 }
952960 }
 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+ }
9531000
9541001 }
9551002 ?>
Index: trunk/phase3/includes/Image.php
@@ -1484,6 +1484,16 @@
14851485 $fname
14861486 );
14871487 }
 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+ }
14881498
14891499 } //class
14901500
Index: trunk/phase3/includes/DefaultSettings.php
@@ -710,6 +710,8 @@
711711 $wgGroupPermissions['user' ]['read'] = true;
712712 $wgGroupPermissions['user' ]['edit'] = true;
713713 $wgGroupPermissions['user' ]['upload'] = true;
 714+$wgGroupPermissions['user' ]['reupload'] = true;
 715+$wgGroupPermissions['user' ]['reupload-shared'] = true;
714716
715717 $wgGroupPermissions['bot' ]['bot'] = true;
716718
@@ -724,6 +726,8 @@
725727 $wgGroupPermissions['sysop']['protect'] = true;
726728 $wgGroupPermissions['sysop']['rollback'] = true;
727729 $wgGroupPermissions['sysop']['upload'] = true;
 730+$wgGroupPermissions['sysop']['reupload'] = true;
 731+$wgGroupPermissions['sysop']['reupload-shared'] = true;
728732
729733 $wgGroupPermissions['bureaucrat']['userrights'] = true;
730734 // Used by the Special:Renameuser extension
Index: trunk/phase3/RELEASE-NOTES
@@ -82,6 +82,8 @@
8383 * (bug 3306) Document $wgLocalTZoffset
8484 * (bug 3304) Language file for Croatian (LanguageHr.php)
8585 * (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).
8688
8789
8890 === Caveats ===
Index: trunk/phase3/languages/Language.php
@@ -1017,6 +1017,8 @@
10181018 'largefileserver' => 'This file is bigger than the server is configured to allow.',
10191019 '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.',
10201020 '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]]',
10211023 'successfulupload' => 'Successful upload',
10221024 'fileuploaded' => "File $1 uploaded successfully.
10231025 Please follow this link: $2 to the description page and fill

Status & tagging log