If 'tables' is a string that starts with a space, treat it as user-enforced FROM...
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
index f8f0c6c..6a3e03e 100644 (file)
 <?php
-include_once( "LinksUpdate.php" );
-
-function wfSpecialMovepage()
-{
-       global $wgUser, $wgOut;
+/**
+ *
+ * @addtogroup SpecialPage
+ */
+
+/**
+ * Constructor
+ */
+function wfSpecialMovepage( $par = null ) {
+       global $wgUser, $wgOut, $wgRequest, $action;
+
+       # Check rights
+       if ( !$wgUser->isAllowed( 'move' ) ) {
+               $wgOut->showErrorPage( 'movenologin', 'movenologintext' );
+               return;
+       }
 
-       if ( 0 == $wgUser->getID() or $wgUser->isBlocked() ) {
-               $wgOut->errorpage( "movenologin", "movenologintext" );
+       # Don't allow blocked users to move pages
+       if ( $wgUser->isBlocked() ) {
+               $wgOut->blockedPage();
                return;
        }
+
+       # Check for database lock
        if ( wfReadOnly() ) {
                $wgOut->readOnlyPage();
                return;
        }
-       $fields = array( "wpNewTitle", "wpOldTitle" );
-       wfCleanFormFields( $fields );
 
-       $f = new MovePageForm();
+       $f = new MovePageForm( $par );
 
-       if ( "success" == $_REQUEST['action'] ) { $f->showSuccess(); }
-       else if ( "submit" == $_REQUEST['action'] ) { $f->doSubmit(); }
-       else { $f->showForm( "" ); }
+       if ( 'success' == $action ) {
+               $f->showSuccess();
+       } else if ( 'submit' == $action && $wgRequest->wasPosted()
+               && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+               $f->doSubmit();
+       } else {
+               $f->showForm( '' );
+       }
 }
 
+/**
+ *
+ * @addtogroup SpecialPage
+ */
 class MovePageForm {
-
-       var $ot, $nt;           # Old, new Title objects
-       var $ons, $nns;         # Namespaces
-       var $odt, $ndt;         # Pagenames (dbkey form)
-       var $oft, $nft;         # Full page titles (DBkey form)
-       var $ofx, $nfx;         # Full page titles (Text form)
-       var $oldid, $newid;     # "cur_id" field (yes, both from "cur")
-       var $talkmoved = 0;
+       var $oldTitle, $newTitle, $reason; # Text input
+       var $moveTalk, $deleteAndMove;
        
-       function showForm( $err )
-       {
-               global $wgOut, $wgUser, $wgLang;
-
-               $wgOut->setPagetitle( wfMsg( "movepage" ) );
-
-               if ( ! $_REQUEST['wpOldTitle'] ) {
-                       if ( "" == $_REQUEST['target'] ) {
-                               $wgOut->errorpage( "notargettitle", "notargettext" );
-                               return;
-                       }
-                       $oldTitle = htmlspecialchars( $_REQUEST['target'] );
+       private $watch = false;
+
+       function MovePageForm( $par ) {
+               global $wgRequest;
+               $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
+               $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
+               $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
+               $this->reason = $wgRequest->getText( 'wpReason' );
+               if ( $wgRequest->wasPosted() ) {
+                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', false );
                } else {
-                       $oldTitle = htmlspecialchars( $_REQUEST['wpOldTitle'] );
-               }
-               
-               $encOldTitle = htmlspecialchars( $oldTitle );
-               $encNewTitle = htmlspecialchars( $_REQUEST['wpNewTitle'] );
-               $ot = Title::newFromURL( $oldTitle );
-               $ott = $ot->getPrefixedText();
-
-               $wgOut->addWikiText( wfMsg( "movepagetext" ) );
-               if ( ! Namespace::isTalk( $ot->getNamespace() ) )
-                       $wgOut->addWikiText( "\n\n" . wfMsg( "movepagetalktext" ) );
-
-               $ma = wfMsg( "movearticle" );
-               $newt = wfMsg( "newtitle" );
-               $mpb = wfMsg( "movepagebtn" );
-               $movetalk = wfMsg( "movetalk" );
-
-               $titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" );
-               $action = $titleObj->escapeLocalURL( "action=submit" );
-
-               if ( "" != $err ) {
-                       $wgOut->setSubtitle( wfMsg( "formerror" ) );
-                       $wgOut->addHTML( "<p><font color='red' size='+1'>{$err}</font>\n" );
+                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
                }
-               $wgOut->addHTML( "<p>
-<form id=\"movepage\" method=\"post\" action=\"{$action}\">
-<table border=0><tr>
-<td align=right>{$ma}:</td>
-<td align=left><strong>{$ott}</strong></td>
-</tr><tr>
-<td align=right>{$newt}:</td>
-<td align=left>
-<input type=text size=40 name=\"wpNewTitle\" value=\"{$encNewTitle}\">
-<input type=hidden name=\"wpOldTitle\" value=\"{$encOldTitle}\">
-</td>
-</tr>" );
-
-               if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
-                       $wgOut->addHTML(
-"<tr>
-<td align=right>
-<input type=checkbox name=\"wpMovetalk\" checked value=\"1\">
-</td><td>{$movetalk}</td>
-</tr>" );
-               }
-               $wgOut->addHTML(
-"<tr>
-<td>&nbsp;</td><td align=left>
-<input type=submit name=\"wpMove\" value=\"{$mpb}\">
-</td></tr></table>
-</form>\n" );
-
+               $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
+               $this->watch = $wgRequest->getCheck( 'wpWatch' );
        }
 
-       function doSubmit()
-       {
-               global $wgOut, $wgUser, $wgLang;
-               global $wgDeferredUpdateList, $wgMessageCache;
-               global  $wgUseSquid, $wgInternalServer;
-               $fname = "MovePageForm::doSubmit";
-
-               $this->ot = Title::newFromText( $_REQUEST['wpOldTitle'] );
-               $this->nt = Title::newFromText( $_REQUEST['wpNewTitle'] );
-               if( !$this->ot or !$this->nt ) {
-                       $this->showForm( wfMsg( "badtitletext" ) );
-                       return;
-               }
-               $this->ons = $this->ot->getNamespace();
-               $this->nns = $this->nt->getNamespace();
-               $this->odt = wfStrencode( $this->ot->getDBkey() );
-               $this->ndt = wfStrencode( $this->nt->getDBkey() );
-               $this->oft = wfStrencode( $this->ot->getPrefixedDBkey() );
-               $this->nft = wfStrencode( $this->nt->getPrefixedDBkey() );
-               $this->ofx = $this->ot->getPrefixedText();
-               $this->nfx = $this->nt->getPrefixedText();
-
-               $this->oldid = $this->ot->getArticleID();
-               $this->newid = $this->nt->getArticleID();
-
-               if ( strlen( trim( $this->ndt ) ) < 1 ) {
-                       $this->showForm( wfMsg( "articleexists" ) );
-                       return;
-               }
-               if ( ( ! Namespace::isMovable( $this->ons ) ) ||
-                        ( "" == $this->odt ) ||
-                        ( "" != $this->ot->getInterwiki() ) ||
-                        ( !$this->ot->userCanEdit() ) ||
-                        ( !$this->oldid ) ||
-                    ( ! Namespace::isMovable( $nns ) ) ||
-                        ( "" == $this->ndt ) ||
-                        ( "" != $this->nt->getInterwiki() ) ||
-                        ( !$this->nt->userCanEdit() ) || 
-                        ( $this->ons == NS_MEDIAWIKI && $wgMessageCache->isCacheable( $this->odt ) ) ) {
-                       $this->showForm( wfMsg( "badarticleerror" ) );
-                       return;
-               }
-               # The move is allowed only if (1) the target doesn't exist, or
-               # (2) the target is a redirect to the source, and has no history
-               # (so we can undo bad moves right after they're done).
-
-               if ( 0 != $this->newid ) { # Target exists; check for validity
-                       if ( ! $this->isValidTarget() ) {
-                               $this->showForm( wfMsg( "articleexists" ) );
-                               return;
-                       }
-                       $this->moveOverExistingRedirect();
-               } else { # Target didn't exist, do normal move.
-                       $this->moveToNewTitle();
-               }
+       function showForm( $err ) {
+               global $wgOut, $wgUser;
 
-               $this->updateWatchlists();
+               $wgOut->setPagetitle( wfMsg( 'movepage' ) );
 
-               $u = new SearchUpdate( $this->oldid, $this->nt->getPrefixedDBkey() );
-               $u->doUpdate();
-               $u = new SearchUpdate( $this->newid, $this->ot->getPrefixedDBkey(), "" );
-               $u->doUpdate();
-               
-               # Squid purging
-               if ( $wgUseSquid ) {
-                       /* this needs to be done after LinksUpdate */
-                       $urlArr = Array(                                
-                               # purge new title
-                               $wgInternalServer.$this->nt->getLocalURL(),
-                               # purge old title
-                               $wgInternalServer.$this->ot->getLocalURL(),
-                       );                      
-                       wfPurgeSquidServers($urlArr);   
-                       # purge pages linking to new title
-                       $u = new SquidUpdate($this->nt);
-                       array_push( $wgDeferredUpdateList, $u );
-                       # purge pages linking to old title
-                       $u = new SquidUpdate($this->ot);
-                       array_push( $wgDeferredUpdateList, $u );
-                       
-                       
+               $ot = Title::newFromURL( $this->oldTitle );
+               if( is_null( $ot ) ) {
+                       $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
+                       return;
                }
+               $oldTitle = $ot->getPrefixedText();
 
-               # Move talk page if (1) the checkbox says to, (2) the source
-               # and target namespaces are identical, (3) the namespaces are not
-               # themselves talk namespaces, and of course (4) it exists.
-
-               if ( ( 1 == $_REQUEST['wpMovetalk'] ) &&
-                        ( ! Namespace::isTalk( $this->ons ) ) &&
-                        ( $this->ons == $this->nns ) ) {
-                       
-                       $this->ons = $this->nns = Namespace::getTalk( $this->ons );
-                       $this->ot = Title::makeTitle( $this->ons, $this->ot->getDBkey() );
-                       $this->nt = Title::makeTitle( $this->nns, $this->nt->getDBkey() );
-
-                       # odt, ndt, ofx, nfx remain the same
-
-                       $this->oft = wfStrencode( $this->ot->getPrefixedDBkey() );
-                       $this->nft = wfStrencode( $this->nt->getPrefixedDBkey() );
-
-                       $this->oldid = $this->ot->getArticleID();
-                       $this->newid = $this->nt->getArticleID();
-
-                       if ( 0 != $this->oldid ) {
-                               if ( 0 != $this->newid ) {
-                                       if ( $this->isValidTarget() ) {
-                                               $this->moveOverExistingRedirect();
-                                               $this->talkmoved = 1;
-                                       } else {
-                                               $this->talkmoved = 'invalid';
+               $encOldTitle = htmlspecialchars( $oldTitle );
+               if( $this->newTitle == '' ) {
+                       # Show the current title as a default
+                       # when the form is first opened.
+                       $encNewTitle = $encOldTitle;
+               } else {
+                       if( $err == '' ) {
+                               $nt = Title::newFromURL( $this->newTitle );
+                               if( $nt ) {
+                                       # If a title was supplied, probably from the move log revert
+                                       # link, check for validity. We can then show some diagnostic
+                                       # information and save a click.
+                                       $newerr = $ot->isValidMoveOperation( $nt );
+                                       if( is_string( $newerr ) ) {
+                                               $err = $newerr;
                                        }
-                               } else {
-                                       $this->moveToNewTitle();
-                                       $this->talkmoved = 1;
-                               }
-                               $u = new SearchUpdate( $this->oldid, $this->nt->getPrefixedDBkey() );
-                               $u->doUpdate();
-                               $u = new SearchUpdate( $this->newid, $this->ot->getPrefixedDBkey(), "" );
-                               $u->doUpdate();
-                               
-                               # Squid purging
-                               if ( $wgUseSquid ) {
-                                       /* this needs to be done after LinksUpdate */
-                                       $urlArr = Array(                                
-                                               # purge new title
-                                               $nt->getInternalURL(),
-                                               # purge old title
-                                               $ot->getInternalURL(),
-                                       );                      
-                                       wfPurgeSquidServers($urlArr);   
-                                       # purge pages linking to new title
-                                       $u = new SquidUpdate($this->nt);
-                                       array_push( $wgDeferredUpdateList, $u );
-                                       # purge pages linking to old title
-                                       $u = new SquidUpdate($this->ot);
-                                       array_push( $wgDeferredUpdateList, $u );
-
-
                                }
                        }
+                       $encNewTitle = htmlspecialchars( $this->newTitle );
+               }
+               $encReason = htmlspecialchars( $this->reason );
+
+               if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
+                       $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
+                       $movepagebtn = wfMsgHtml( 'delete_and_move' );
+                       $confirmText = wfMsgHtml( 'delete_and_move_confirm' );
+                       $submitVar = 'wpDeleteAndMove';
+                       $confirm = "
+                               <tr>
+                                       <td align='right'>
+                                               <input type='checkbox' name='wpConfirm' id='wpConfirm' value=\"true\" />
+                                       </td>
+                                       <td align='left'><label for='wpConfirm'>{$confirmText}</label></td>
+                               </tr>";
+                       $err = '';
+               } else {
+                       $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
+                       $movepagebtn = wfMsgHtml( 'movepagebtn' );
+                       $submitVar = 'wpMove';
+                       $confirm = false;
                }
-               $titleObj = Title::makeTitle( NS_SPECIAL, "Movepage" );
-               $success = $titleObj->getFullURL( 
-                 "action=success&oldtitle=" . wfUrlencode( $this->ofx ) .
-                 "&newtitle=" . wfUrlencode( $this->nfx ) .
-                 "&talkmoved={$this->talkmoved}" );
-
-               $wgOut->redirect( $success );
-       }
-
-       function showSuccess()
-       {
-               global $wgOut, $wgUser;
 
-               $wgOut->setPagetitle( wfMsg( "movepage" ) );
-               $wgOut->setSubtitle( wfMsg( "pagemovedsub" ) );
-       
-               $text = wfMsg( "pagemovedtext", $_REQUEST['oldtitle'], $_REQUEST['newtitle'] );
-               $wgOut->addWikiText( $text );
+               $oldTalk = $ot->getTalkPage();
+               $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
 
-               if ( 1 == $_REQUEST['talkmoved'] ) {
-                       $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagemoved" ) );
-               } elseif( 'invalid' == $_REQUEST['talkmoved'] ) {
-                       $wgOut->addHTML( "\n<p><strong>" . wfMsg( "talkexists" ) . "</strong>" );
-               } else {
-                       $ot = Title::newFromURL( $_REQUEST['oldtitle'] );
-                       if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
-                               $wgOut->addHTML( "\n<p>" . wfMsg( "talkpagenotmoved" ) );
-                       }
+               if ( $considerTalk ) {
+                       $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
                }
-       }
 
-       # Is the the existing target title valid?
+               $movearticle = wfMsgHtml( 'movearticle' );
+               $newtitle = wfMsgHtml( 'newtitle' );
+               $movetalk = wfMsgHtml( 'movetalk' );
+               $movereason = wfMsgHtml( 'movereason' );
 
-       function isValidTarget()
-       {
-               $fname = "MovePageForm::isValidTarget";
+               $titleObj = SpecialPage::getTitleFor( 'Movepage' );
+               $action = $titleObj->escapeLocalURL( 'action=submit' );
+               $token = htmlspecialchars( $wgUser->editToken() );
 
-               $sql = "SELECT cur_is_redirect,cur_text FROM cur " .
-                 "WHERE cur_id={$this->newid}";
-               $res = wfQuery( $sql, DB_READ, $fname );
-               $obj = wfFetchObject( $res );
+               if ( $err != '' ) {
+                       $wgOut->setSubtitle( wfMsg( 'formerror' ) );
+                       $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
+               }
 
-               if ( 0 == $obj->cur_is_redirect ) { return false; }
+               $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
 
-               if ( preg_match( "/\\[\\[\\s*([^\\]]*)]]/", $obj->cur_text, $m ) ) {
-                       $rt = Title::newFromText( $m[1] );
-                       if ( 0 != strcmp( wfStrencode( $rt->getPrefixedDBkey() ),
-                         $this->oft ) ) {
-                               return false;
-                       }
+               $wgOut->addHTML( "
+<form id=\"movepage\" method=\"post\" action=\"{$action}\">
+       <table border='0'>
+               <tr>
+                       <td align='right'>{$movearticle}:</td>
+                       <td align='left'><strong>{$oldTitle}</strong></td>
+               </tr>
+               <tr>
+                       <td align='right'><label for='wpNewTitle'>{$newtitle}:</label></td>
+                       <td align='left'>
+                               <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
+                               <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
+                       </td>
+               </tr>
+               <tr>
+                       <td align='right' valign='top'><br /><label for='wpReason'>{$movereason}:</label></td>
+                       <td align='left' valign='top'><br />
+                               <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
+                       </td>
+               </tr>" );
+
+               if ( $considerTalk ) {
+                       $wgOut->addHTML( "
+               <tr>
+                       <td align='right'>
+                               <input type='checkbox' id=\"wpMovetalk\" name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
+                       </td>
+                       <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
+               </tr>" );
                }
-               $sql = "SELECT old_id FROM old WHERE old_namespace={$this->nns} " .
-                 "AND old_title='{$this->ndt}'";
-               $res = wfQuery( $sql, DB_READ, $fname );
-               if ( 0 != wfNumRows( $res ) ) { return false; }
+               
+               $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
+               $watch  = '<tr>';
+               $watch .= '<td align="right">' . Xml::check( 'wpWatch', $watchChecked, array( 'id' => 'watch' ) ) . '</td>';
+               $watch .= '<td>' . Xml::label( wfMsg( 'move-watch' ), 'watch' ) . '</td>';
+               $watch .= '</tr>';
+               $wgOut->addHtml( $watch );
+               
+               $wgOut->addHTML( "
+               {$confirm}
+               <tr>
+                       <td>&nbsp;</td>
+                       <td align='left'>
+                               <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
+                       </td>
+               </tr>
+       </table>
+       <input type='hidden' name='wpEditToken' value=\"{$token}\" />
+</form>\n" );
+
+       $this->showLogFragment( $ot, $wgOut );
 
-               return true;
        }
 
-       # Move page to title which is presently a redirect to the source
-       # page.  Handling link tables here is tricky.
-
-       function moveOverExistingRedirect()
-       {
-               global $wgUser, $wgLinkCache;
-               $fname = "MovePageForm::moveOverExistingRedirect";
-               $mt = wfMsg( "movedto" );
-
-               # Change the name of the target page:
-        $now = wfTimestampNow();
-        $won = wfInvertTimestamp( $now );
-               $sql = "UPDATE cur SET cur_touched='{$now}'," .
-                 "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
-                 "WHERE cur_id={$this->oldid}";
-               wfQuery( $sql, DB_WRITE, $fname );
-               $wgLinkCache->clearLink( $this->nft );
-
-               # Repurpose the old redirect. We don't save it to history since
-               # by definition if we've got here it's rather uninteresting.
-               $sql = "UPDATE cur SET cur_touched='{$now}',cur_timestamp='{$now}',inverse_timestamp='${won}'," .
-                 "cur_namespace={$this->ons},cur_title='{$this->odt}'," .
-                 "cur_text='#REDIRECT [[{$this->nft}]]\n',cur_comment='" .
-                 "{$mt} \\\"{$this->nft}\\\"',cur_user='" .  $wgUser->getID() .
-                 "',cur_minor_edit=0,cur_counter=0,cur_restrictions=''," .
-                 "cur_user_text='" . wfStrencode( $wgUser->getName() ) . "'," .
-                 "cur_is_redirect=1,cur_is_new=0 WHERE cur_id={$this->newid}";
-               wfQuery( $sql, DB_WRITE, $fname );
-               $wgLinkCache->clearLink( $this->oft );
-
-               # Fix the redundant names for the past revisions of the target page.
-               # The redirect should have no old revisions.
-               $sql = "UPDATE old SET " .
-                 "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
-                 "old_namespace={$this->ons} AND old_title='{$this->odt}'";
-               wfQuery( $sql, DB_WRITE, $fname );
-               
-               RecentChange::notifyMove( $now, $this->ot, $this->nt, $wgUser, $mt );
+       function doSubmit() {
+               global $wgOut, $wgUser, $wgRequest;
 
-               # The only link from here should be the old redirect
+               if ( $wgUser->pingLimiter( 'move' ) ) {
+                       $wgOut->rateLimited();
+                       return;
+               }
 
-               $sql = "DELETE FROM links WHERE l_from='{$this->nft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
+               # Variables beginning with 'o' for old article 'n' for new article
 
-               $sql = "UPDATE links SET l_from='{$this->nft}' WHERE l_from='{$this->oft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
+               $ot = Title::newFromText( $this->oldTitle );
+               $nt = Title::newFromText( $this->newTitle );
 
-               # Swap links.  Using MAXINT as a temp; if there's ever an article
-               # with id 4294967295, this will fail, but I think that's pretty safe
+               # 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' ) );
+               }
 
-               $sql = "UPDATE links SET l_to=4294967295 WHERE l_to={$this->oldid}";
-               wfQuery( $sql, DB_WRITE, $fname );
+               # don't allow moving to pages with # in
+               if ( !$nt || $nt->getFragment() != '' ) {
+                       $this->showForm( 'badtitletext' );
+                       return;
+               }
 
-               $sql = "UPDATE links SET l_to={$this->oldid} WHERE l_to={$this->newid}";
-               wfQuery( $sql, DB_WRITE, $fname );
+               $error = $ot->moveTo( $nt, true, $this->reason );
+               if ( $error !== true ) {
+                       $this->showForm( $error );
+                       return;
+               }
 
-               $sql = "UPDATE links SET l_to={$this->newid} WHERE l_to=4294967295";
-               wfQuery( $sql, DB_WRITE, $fname );
+               wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
 
-               # Note: the insert below must be after the updates above!
+               # Move the talk page if relevant, if it exists, and if we've been told to
+               $ott = $ot->getTalkPage();
+               if( $ott->exists() ) {
+                       if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
+                               $ntt = $nt->getTalkPage();
+       
+                               # Attempt the move
+                               $error = $ott->moveTo( $ntt, true, $this->reason );
+                               if ( $error === true ) {
+                                       $talkmoved = 1;
+                                       wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) )       ;
+                               } else {
+                                       $talkmoved = $error;
+                               }
+                       } else {
+                               # Stay silent on the subject of talk.
+                               $talkmoved = '';
+                       }
+               } else {
+                       $talkmoved = 'notalkpage';
+               }
+               
+               # Deal with watches
+               if( $this->watch ) {
+                       $wgUser->addWatch( $ot );
+                       $wgUser->addWatch( $nt );
+               } else {
+                       $wgUser->removeWatch( $ot );
+                       $wgUser->removeWatch( $nt );
+               }
 
-               $sql = "INSERT INTO links (l_from,l_to) VALUES ('{$this->oft}',{$this->oldid})";
-               wfQuery( $sql, DB_WRITE, $fname );
+               # Give back result to user.
+               $titleObj = SpecialPage::getTitleFor( 'Movepage' );
+               $success = $titleObj->getFullURL(
+                 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
+                 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
+                 '&talkmoved='.$talkmoved );
 
-               $sql = "UPDATE imagelinks SET il_from='{$this->nft}' WHERE il_from='{$this->oft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
+               $wgOut->redirect( $success );
        }
 
-       # Move page to non-existing title.
-
-       function moveToNewTitle()
-       {
-               global $wgUser, $wgLinkCache;
-               $fname = "MovePageForm::moveToNewTitle";
-               $mt = wfMsg( "movedto" );
-
-               $now = wfTimestampNow();
-               $won = wfInvertTimestamp( $now );
-               $sql = "UPDATE cur SET cur_touched='{$now}'," .
-                 "cur_namespace={$this->nns},cur_title='{$this->ndt}' " .
-                 "WHERE cur_id={$this->oldid}";
-               wfQuery( $sql, DB_WRITE, $fname );
-               $wgLinkCache->clearLink( $this->nft );
-
-               $comment = "{$mt} \"{$this->nft}\"";
-               $encComment = wfStrencode( $comment );
-               $common = "{$this->ons},'{$this->odt}'," .
-                 "'$encComment','" .$wgUser->getID() . "','" . 
-                 wfStrencode( $wgUser->getName() ) ."','{$now}'";
-               $sql = "INSERT INTO cur (cur_namespace,cur_title," .
-                 "cur_comment,cur_user,cur_user_text,cur_timestamp,inverse_timestamp," .
-                 "cur_touched,cur_text,cur_is_redirect,cur_is_new) " .
-                 "VALUES ({$common},'{$won}','{$now}','#REDIRECT [[{$this->nft}]]\n',1,1)";
-               wfQuery( $sql, DB_WRITE, $fname );
-               $this->newid = wfInsertId();
-               $wgLinkCache->clearLink( $this->oft );
-
-               $sql = "UPDATE old SET " .
-                 "old_namespace={$this->nns},old_title='{$this->ndt}' WHERE " .
-                 "old_namespace={$this->ons} AND old_title='{$this->odt}'";
-               wfQuery( $sql, DB_WRITE, $fname );
-
-               RecentChange::notifyMove( $now, $this->ot, $this->nt, $wgUser, $comment );
-               Article::onArticleCreate( $this->nt );
-
-               $sql = "UPDATE links SET l_from='{$this->nft}' WHERE l_from='{$this->oft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
-
-               $sql = "UPDATE links SET l_to={$this->newid} WHERE l_to={$this->oldid}";
-               wfQuery( $sql, DB_WRITE, $fname );
-
-               $sql = "INSERT INTO links (l_from,l_to) VALUES ('{$this->oft}',{$this->oldid})";
-               wfQuery( $sql, DB_WRITE, $fname );
-
-               # Non-existent target may have had broken links to it; these must
-               # now be removed and made into good links.
-               $update = new LinksUpdate( $this->oldid, $this->nft );
-               $update->fixBrokenLinks();
-
-               $sql = "UPDATE imagelinks SET il_from='{$this->nft}' WHERE il_from='{$this->oft}'";
-               wfQuery( $sql, DB_WRITE, $fname );
-       }
+       function showSuccess() {
+               global $wgOut, $wgRequest, $wgRawHtml;
+               
+               $wgOut->setPagetitle( wfMsg( 'movepage' ) );
+               $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
 
-       function updateWatchlists()
-       {
-               $oldnamespace = $this->ons & ~1;
-               $newnamespace = $this->nns & ~1;
-               $oldtitle = $this->odt;
-               $newtitle = $this->ndt;
+               $oldText = wfEscapeWikiText( $wgRequest->getVal('oldtitle') );
+               $newText = wfEscapeWikiText( $wgRequest->getVal('newtitle') );
+               $talkmoved = $wgRequest->getVal('talkmoved');
 
-               if( $oldnamespace == $newnamespace and $oldtitle == $newtitle )
-                       return;
+               $text = wfMsg( 'pagemovedtext', $oldText, $newText );
+               
+               $allowHTML = $wgRawHtml;
+               $wgRawHtml = false;
+               $wgOut->addWikiText( $text );
+               $wgRawHtml = $allowHTML;
 
-               WatchedItem::duplicateEntries( $this->ot, $this->nt );
+               if ( $talkmoved == 1 ) {
+                       $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
+               } elseif( 'articleexists' == $talkmoved ) {
+                       $wgOut->addWikiText( wfMsg( 'talkexists' ) );
+               } else {
+                       $oldTitle = Title::newFromText( $oldText );
+                       if ( isset( $oldTitle ) && !$oldTitle->isTalkPage() && $talkmoved != 'notalkpage' ) {
+                               $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
+                       }
+               }
        }
-
+       
+       function showLogFragment( $title, &$out ) {
+               $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'move' ) ) );
+               $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
+               $viewer = new LogViewer( new LogReader( $request ) );
+               $viewer->showList( $out );
+       }
+       
 }
 ?>