(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.
This commit is contained in:
Alex Z 2009-10-24 04:36:11 +00:00
parent 630d97d41a
commit 216e60d01e
5 changed files with 44 additions and 4 deletions

View file

@ -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 ==

View file

@ -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"),

View file

@ -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'
);
}

View file

@ -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 {

View file

@ -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',