* (bug 153) Adjust thumbnail size calculations to match consistently;
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
index 0134dc1..0bc51c8 100644 (file)
@@ -13,11 +13,11 @@ 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
-       if ( $wgUser->isAnon() or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
+       if ( !$wgUser->isAllowed( 'move' ) or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
                $wgOut->errorpage( "movenologin", "movenologintext" );
                return;
        }
@@ -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 );
@@ -62,41 +63,43 @@ class MovePageForm {
 
                $wgOut->setPagetitle( wfMsg( 'movepage' ) );
 
-               if ( $this->oldTitle == '' ) {
+               $ot = Title::newFromURL( $this->oldTitle );
+               if( is_null( $ot ) ) {
                        $wgOut->errorpage( 'notargettitle', 'notargettext' );
                        return;
                }
-
-               $ot = Title::newFromURL( $this->oldTitle );
                $oldTitle = $ot->getPrefixedText();
                
-               $encOldTitle = htmlspecialchars( $this->oldTitle );
+               $encOldTitle = htmlspecialchars( $oldTitle );
                if( $this->newTitle == '' ) {
                        # Show the current title as a default
                        # when the form is first opened.
-                       $encNewTitle = $oldTitle;
+                       $encNewTitle = $encOldTitle;
                } 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 );
 
                if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
                        $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
-                       $movepagebtn = wfMsg( 'delete_and_move' );
+                       $movepagebtn = wfMsgHtml( 'delete_and_move' );
                        $submitVar = 'wpDeleteAndMove';
                        $err = '';
                } else {
                        $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
-                       $movepagebtn = wfMsg( 'movepagebtn' );
+                       $movepagebtn = wfMsgHtml( 'movepagebtn' );
                        $submitVar = 'wpMove';
                }
 
@@ -104,10 +107,10 @@ class MovePageForm {
                        $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
                }
 
-               $movearticle = wfMsg( 'movearticle' );
-               $newtitle = wfMsg( 'newtitle' );
-               $movetalk = wfMsg( 'movetalk' );
-               $movereason = wfMsg( 'movereason' );
+               $movearticle = wfMsgHtml( 'movearticle' );
+               $newtitle = wfMsgHtml( 'newtitle' );
+               $movetalk = wfMsgHtml( 'movetalk' );
+               $movereason = wfMsgHtml( 'movereason' );
 
                $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
                $action = $titleObj->escapeLocalURL( 'action=submit' );
@@ -115,14 +118,10 @@ class MovePageForm {
 
                if ( $err != '' ) {
                        $wgOut->setSubtitle( wfMsg( 'formerror' ) );
-                       $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
+                       $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
                }
 
-               if ( $this->moveTalk ) {
-                       $moveTalkChecked = " checked='checked'";
-               } else {
-                       $moveTalkChecked = '';
-               }
+               $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
                
                $wgOut->addHTML( "
 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
@@ -132,16 +131,16 @@ class MovePageForm {
                        <td align='left'><strong>{$oldTitle}</strong></td>
                </tr>
                <tr>
-                       <td align='right'>{$newtitle}:</td>
+                       <td align='right'><label for='wpNewTitle'>{$newtitle}:</label></td>
                        <td align='left'>
-                               <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
+                               <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
                                <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
                        </td>
                </tr>
                <tr>
-                       <td align='right'>{$movereason}:</td>
-                       <td align='left'>
-                               <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
+                       <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>" );
 
@@ -149,9 +148,9 @@ class MovePageForm {
                        $wgOut->addHTML( "
                <tr>
                        <td align='right'>
-                               <input type='checkbox' name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
+                               <input type='checkbox' id=\"wpMovetalk\" name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
                        </td>
-                       <td>{$movetalk}</td>
+                       <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
                </tr>" );
                }
                $wgOut->addHTML( "
@@ -173,6 +172,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 );
@@ -196,43 +200,17 @@ class MovePageForm {
                        $this->showForm( $error );
                        return;
                }
-
-               # Update counters if the article got moved into or out of NS_MAIN namespace
-               $ons = $ot->getNamespace();
-               $nns = $nt->getNamespace();
-               
-               # moved out of article namespace?
-               if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
-                       $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
-               }
-               # moved into article namespace?
-               elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
-                       $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
-               } else {
-                       $u = false;
-               }
-               if ( $u !== false ) {
-                       # save it for later update
-                       array_push( $wgDeferredUpdateList, $u );
-                       unset($u);
-               }
                
                # Move talk page if
                # (1) the checkbox says to,
                # (2) the namespaces are not themselves talk namespaces, and of course
                # (3) it exists.
                if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
-                    ( ! Namespace::isTalk( $ons ) ) &&
-                    ( ! Namespace::isTalk( $nns ) ) ) {
+                    !$ot->isTalkPage() &&
+                    !$nt->isTalkPage() ) {
                        
-                       # get old talk page namespace
-                       $ons = Namespace::getTalk( $ons );
-                       # get new talk page namespace
-                       $nns = Namespace::getTalk( $nns );
-                       
-                       # make talk page title objects
-                       $ott = Title::makeTitle( $ons, $ot->getDBkey() );
-                       $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
+                       $ott = $ot->getTalkPage();
+                       $ntt = $nt->getTalkPage();
 
                        # Attempt the move
                        $error = $ott->moveTo( $ntt, true, $this->reason );
@@ -241,6 +219,9 @@ class MovePageForm {
                        } else {
                                $talkmoved = $error;
                        }
+               } else {
+                       # Stay silent on the subject of talk.
+                       $talkmoved = '';
                }
                
                # Give back result to user.
@@ -271,13 +252,13 @@ class MovePageForm {
                $wgRawHtml = $marchingantofdoom;
 
                if ( $talkmoved == 1 ) {
-                       $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
+                       $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
                } elseif( 'articleexists' == $talkmoved ) {
-                       $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
+                       $wgOut->addWikiText( wfMsg( 'talkexists' ) );
                } else {
                        $ot = Title::newFromURL( $oldtitle );
                        if ( ! $ot->isTalkPage() ) {
-                               $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );
+                               $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
                        }
                }
        }