*/
class MovePageForm {
var $oldTitle, $newTitle, $reason; # Text input
- var $moveTalk;
+ var $moveTalk, $deleteAndMove;
function MovePageForm() {
global $wgRequest;
$this->newTitle = $wgRequest->getText( 'wpNewTitle' );
$this->reason = $wgRequest->getText( 'wpReason' );
$this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
+ $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' );
}
function showForm( $err ) {
# when the form is first opened.
$encNewTitle = $oldTitle;
} else {
- $encNewTitle = htmlspecialchars( $this->newTitle );
+ $nt = Title::newFromURL( $this->newTitle );
+ if ( $nt ) {
+ // Check if it's valid
+ if ( !$nt->isValidMoveTarget( $ot ) ) {
+ $err = 'articleexists';
+ }
+ $encNewTitle = htmlspecialchars( $this->newTitle );
+ } else {
+ $encNewTitle = $oldTitle;
+ }
}
$encReason = htmlspecialchars( $this->reason );
- $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
+ if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
+ $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
+ $movepagebtn = wfMsg( 'delete_and_move' );
+ $submitVar = 'wpDeleteAndMove';
+ $err = '';
+ } else {
+ $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
+ $movepagebtn = wfMsg( 'movepagebtn' );
+ $submitVar = 'wpMove';
+ }
+
if ( !$ot->isTalkPage() ) {
$wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
}
$movearticle = wfMsg( 'movearticle' );
$newtitle = wfMsg( 'newtitle' );
- $movepagebtn = wfMsg( 'movepagebtn' );
$movetalk = wfMsg( 'movetalk' );
$movereason = wfMsg( 'movereason' );
if ( $err != '' ) {
$wgOut->setSubtitle( wfMsg( 'formerror' ) );
- $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
+ $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
}
if ( $this->moveTalk ) {
<tr>
<td> </td>
<td align='left'>
- <input type='submit' name=\"wpMove\" value=\"{$movepagebtn}\" />
+ <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
</td>
</tr>
</table>
# Variables beginning with 'o' for old article 'n' for new article
- # Attempt to move the article
$ot = Title::newFromText( $this->oldTitle );
$nt = Title::newFromText( $this->newTitle );
+ # Delete to make way if requested
+ if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
+ $article = new Article( $nt );
+ // This may output an error message and exit
+ $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
+ }
+
# don't allow moving to pages with # in
if ( !$nt || $nt->getFragment() != '' ) {
- $this->showForm( wfMsg( "badtitletext" ) );
+ $this->showForm( 'badtitletext' );
return;
}
$error = $ot->moveTo( $nt, true, $this->reason );
if ( $error !== true ) {
- $this->showForm( wfMsg( $error ) );
+ $this->showForm( $error );
return;
}