* Simple rate limiter for edits and page moves; set $wgRateLimits
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
index 9f33992..39e5fac 100644 (file)
@@ -13,7 +13,7 @@ require_once( "LinksUpdate.php" );
 /**
  * Constructor
  */
-function wfSpecialMovepage() {
+function wfSpecialMovepage( $par = null ) {
        global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
 
        # check rights. We don't want newbies to move pages to prevents possible attack
@@ -27,7 +27,7 @@ function wfSpecialMovepage() {
                return;
        }
 
-       $f = new MovePageForm();
+       $f = new MovePageForm( $par );
 
        if ( 'success' == $action ) {
                $f->showSuccess();
@@ -48,9 +48,10 @@ class MovePageForm {
        var $oldTitle, $newTitle, $reason; # Text input
        var $moveTalk, $deleteAndMove;
                
-       function MovePageForm() {
+       function MovePageForm( $par ) {
                global $wgRequest;
-               $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
+               $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
+               $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
                $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
                $this->reason = $wgRequest->getText( 'wpReason' );
                $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
@@ -76,16 +77,19 @@ class MovePageForm {
                        # when the form is first opened.
                        $encNewTitle = $oldTitle;
                } else {
-                       $nt = Title::newFromURL( $this->newTitle );
-                       if ( $nt ) {
-                               // Check if it's valid
-                               if ( !$nt->isValidMoveTarget( $ot ) ) {
-                                       $err = 'articleexists';
+                       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;
+                                       }
                                }
-                               $encNewTitle = htmlspecialchars( $this->newTitle );
-                       } else {
-                               $encNewTitle = $oldTitle;
                        }
+                       $encNewTitle = htmlspecialchars( $this->newTitle );
                }
                $encReason = htmlspecialchars( $this->reason );
 
@@ -137,7 +141,7 @@ class MovePageForm {
                <tr>
                        <td align='right'>{$movereason}:</td>
                        <td align='left'>
-                               <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
+                               <input type='text' size='40' name=\"wpReason\" value=\"{$encReason}\" />
                        </td>
                </tr>" );
 
@@ -169,6 +173,11 @@ class MovePageForm {
                global  $wgUseSquid, $wgRequest;
                $fname = "MovePageForm::doSubmit";
                
+               if ( $wgUser->pingLimiter( 'move' ) ) {
+                       $wgOut->rateLimited();
+                       return;
+               }
+               
                # Variables beginning with 'o' for old article 'n' for new article
 
                $ot = Title::newFromText( $this->oldTitle );
@@ -237,6 +246,9 @@ class MovePageForm {
                        } else {
                                $talkmoved = $error;
                        }
+               } else {
+                       # Stay silent on the subject of talk.
+                       $talkmoved = '';
                }
                
                # Give back result to user.