From: Alex Z Date: Sat, 24 Oct 2009 04:36:11 +0000 (+0000) Subject: (bug 18019) Warn users when moving a file to a name in use on a shared repo. X-Git-Tag: 1.31.0-rc.0~39145 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=216e60d01e9d9f58b824b43525482a133696d806;p=lhc%2Fweb%2Fwiklou.git (bug 18019) Warn users when moving a file to a name in use on a shared repo. Allow only users with the 'reupload-shared' right to complete the move. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 605a8b8b83..e0c6e40570 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -591,6 +591,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 21006) maintenance/updateArticleCount.php now works again on PostgreSQL * (bug 19319) Add activeusers-intro message at top of SpecialActiveUsers page * (bug 21255) Fixed hostname construction for DNSBL checking +* (bug 18019) Users are now warned when moving a file to a name in use on a + shared repository and only users with the 'reupload-shared' permission can + complete the move. == API changes in 1.16 == diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 04c141ac45..79e7dcf36d 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -846,6 +846,8 @@ abstract class ApiBase { 'import-noarticle' => array('code' => 'badinterwiki', 'info' => 'Invalid interwiki title specified'), 'importbadinterwiki' => array('code' => 'badinterwiki', 'info' => 'Invalid interwiki title specified'), 'import-unknownerror' => array('code' => 'import-unknownerror', 'info' => "Unknown error on import: ``\$1''"), + 'cantoverwrite-sharedfile' => array('code' => 'cantoverwrite-sharedfile', 'info' => 'The target file exists on a shared repository and you do not have permission to override it'), + 'sharedfile-exists' => array('code' => 'fileexists-sharedrepo-perm', 'info' => 'The target file exists on a shared repository. Use the ignorewarnings parameter to override it.'), // ApiEditPage messages 'noimageredirect-anon' => array('code' => 'noimageredirect-anon', 'info' => "Anonymous users can't create image redirects"), diff --git a/includes/api/ApiMove.php b/includes/api/ApiMove.php index 975a8ba129..eaa2e1673d 100644 --- a/includes/api/ApiMove.php +++ b/includes/api/ApiMove.php @@ -71,7 +71,18 @@ class ApiMove extends ApiBase { if(!$toTitle) $this->dieUsageMsg(array('invalidtitle', $params['to'])); $toTalk = $toTitle->getTalkPage(); - + + if ( $toTitle->getNamespace() == NS_FILE + && !RepoGroup::singleton()->getLocalRepo()->findFile( $toTitle ) + && wfFindFile( $toTitle ) ) + { + if ( !$params['ignorewarnings'] && $wgUser->isAllowed( 'reupload-shared' ) ) { + $this->dieUsageMsg(array('sharedfile-exists')); + } elseif ( !$wgUser->isAllowed( 'reupload-shared' ) ) { + $this->dieUsageMsg(array('cantoverwrite-sharedfile')); + } + } + # Move the page $hookErr = null; $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']); @@ -171,7 +182,8 @@ class ApiMove extends ApiBase { 'movesubpages' => false, 'noredirect' => false, 'watch' => false, - 'unwatch' => false + 'unwatch' => false, + 'ignorewarnings' => false ); } @@ -186,7 +198,8 @@ class ApiMove extends ApiBase { 'movesubpages' => 'Move subpages, if applicable', 'noredirect' => 'Don\'t create a redirect', 'watch' => 'Add the page and the redirect to your watchlist', - 'unwatch' => 'Remove the page and the redirect from your watchlist' + 'unwatch' => 'Remove the page and the redirect from your watchlist', + 'ignorewarnings' => 'Ignore any warnings' ); } diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 391cfbb137..4dbadcfb8f 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -58,7 +58,7 @@ function wfSpecialMovepage( $par = null ) { class MovePageForm { var $oldTitle, $newTitle; # Objects var $reason; # Text input - var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect; # Checks + var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks private $watch = false; @@ -79,6 +79,7 @@ class MovePageForm { } $this->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false ); $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' ); + $this->moveOverShared = $wgRequest->getBool( 'wpMoveOverSharedFile', false ); $this->watch = $wgRequest->getCheck( 'wpWatch' ); } @@ -136,6 +137,12 @@ class MovePageForm { $confirm = false; } + if ( !empty($err) && $err[0] == 'file-exists-sharedrepo' && $wgUser->isAllowed( 'reupload-shared' ) ) { + $wgOut->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() ); + $submitVar = 'wpMoveOverSharedFile'; + $err = ''; + } + $oldTalk = $this->oldTitle->getTalkPage(); $considerTalk = ( !$this->oldTitle->isTalkPage() && $oldTalk->exists() ); @@ -351,6 +358,17 @@ class MovePageForm { return; } + # Show a warning if the target file exists on a shared repo + if ( $nt->getNamespace() == NS_FILE + && !( $this->moveOverShared && $wgUser->isAllowed( 'reupload-shared' ) ) + && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt ) + && wfFindFile( $nt ) ) + { + $this->showForm( array('file-exists-sharedrepo') ); + return; + + } + if ( $wgUser->isAllowed( 'suppressredirect' ) ) { $createRedirect = $this->leaveRedirect; } else { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index e03567e2a6..6e912f733b 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -3109,6 +3109,10 @@ cannot move a page over itself.', 'move-leave-redirect' => 'Leave a redirect behind', 'protectedpagemovewarning' => "'''Warning:''' This page has been locked so that only users with administrator privileges can move it.", 'semiprotectedpagemovewarning' => "'''Note:''' This page has been locked so that only registered users can move it.", +'move-over-sharedrepo' => '==File exists== +[[:$1]] exists on a shared repository. Moving a file to this title will override the shared file.', +'file-exists-sharedrepo' => 'The file name chosen is already in use on a shared repository. +Please choose another name.', # Export 'export' => 'Export pages',