Coding style
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
index 15e155b..3f0e6e1 100644 (file)
 <?php
 /**
+ * Implements Special:Movepage
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
- * Constructor
+ * A special page that allows users to change page titles
+ *
+ * @ingroup SpecialPage
  */
-function wfSpecialMovepage( $par = null ) {
-       global $wgUser, $wgOut, $wgRequest, $action;
+class MovePageForm extends UnlistedSpecialPage {
+       var $oldTitle, $newTitle; # Objects
+       var $reason; # Text input
+       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks
 
-       # Check for database lock
-       if ( wfReadOnly() ) {
-               $wgOut->readOnlyPage();
-               return;
+       private $watch = false;
+
+       public function __construct() {
+               parent::__construct( 'Movepage' );
        }
 
-       $target = isset( $par ) ? $par : $wgRequest->getVal( 'target' );
+       public function execute( $par ) {
+               global $wgUser, $wgOut, $wgRequest;
 
-       // Yes, the use of getVal() and getText() is wanted, see bug 20365
-       $oldTitleText = $wgRequest->getVal( 'wpOldTitle', $target );
-       $newTitleText = $wgRequest->getText( 'wpNewTitle' );
+               # Check for database lock
+               if ( wfReadOnly() ) {
+                       $wgOut->readOnlyPage();
+                       return;
+               }
 
-       $oldTitle = Title::newFromText( $oldTitleText );
-       $newTitle = Title::newFromText( $newTitleText );
+               $this->setHeaders();
+               $this->outputHeader();
 
-       if( is_null( $oldTitle ) ) {
-               $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
-               return;
-       }
-       if( !$oldTitle->exists() ) {
-               $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
-               return;
-       }
+               $target = !is_null( $par ) ? $par : $wgRequest->getVal( 'target' );
 
-       # Check rights
-       $permErrors = $oldTitle->getUserPermissionsErrors( 'move', $wgUser );
-       if( !empty( $permErrors ) ) {
-               $wgOut->showPermissionsErrorPage( $permErrors );
-               return;
-       }
+               // Yes, the use of getVal() and getText() is wanted, see bug 20365
+               $oldTitleText = $wgRequest->getVal( 'wpOldTitle', $target );
+               $newTitleText = $wgRequest->getText( 'wpNewTitle' );
 
-       $form = new MovePageForm( $oldTitle, $newTitle );
+               $this->oldTitle = Title::newFromText( $oldTitleText );
+               $this->newTitle = Title::newFromText( $newTitleText );
 
-       if ( 'submit' == $action && $wgRequest->wasPosted()
-               && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-               $form->doSubmit();
-       } else {
-               $form->showForm( '' );
-       }
-}
+               if( is_null( $this->oldTitle ) ) {
+                       $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
+                       return;
+               }
+               if( !$this->oldTitle->exists() ) {
+                       $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
+                       return;
+               }
 
-/**
- * HTML form for Special:Movepage
- * @ingroup SpecialPage
- */
-class MovePageForm {
-       var $oldTitle, $newTitle; # Objects
-       var $reason; # Text input
-       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks
+               # Check rights
+               $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $wgUser );
+               if( !empty( $permErrors ) ) {
+                       $wgOut->showPermissionsErrorPage( $permErrors );
+                       return;
+               }
 
-       private $watch = false;
+               $def = !$wgRequest->wasPosted();
 
-       function __construct( $oldTitle, $newTitle ) {
-               global $wgRequest, $wgUser;
-               $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
-               $this->oldTitle = $oldTitle;
-               $this->newTitle = $newTitle;
                $this->reason = $wgRequest->getText( 'wpReason' );
-               if ( $wgRequest->wasPosted() ) {
-                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', false );
-                       $this->fixRedirects = $wgRequest->getBool( 'wpFixRedirects', false );
-                       $this->leaveRedirect = $wgRequest->getBool( 'wpLeaveRedirect', false );
-               } else {
-                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
-                       $this->fixRedirects = $wgRequest->getBool( 'wpFixRedirects', true );
-                       $this->leaveRedirect = $wgRequest->getBool( 'wpLeaveRedirect', true );
-               }
+               $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', $def );
+               $this->fixRedirects = $wgRequest->getBool( 'wpFixRedirects', $def );
+               $this->leaveRedirect = $wgRequest->getBool( 'wpLeaveRedirect', $def );
                $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' ) && $wgUser->isLoggedIn();
+
+               if ( 'submit' == $wgRequest->getVal( 'action' ) && $wgRequest->wasPosted()
+                       && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
+                       $this->doSubmit();
+               } else {
+                       $this->showForm( '' );
+               }
        }
 
        /**
         * Show the form
-        * @param mixed $err Error message. May either be a string message name or 
+        *
+        * @param $err Mixed: error message. May either be a string message name or 
         *    array message name and parameters, like the second argument to 
         *    OutputPage::wrapWikiMsg(). 
         */
@@ -131,6 +142,9 @@ class MovePageForm {
                                </tr>";
                        $err = '';
                } else {
+                       if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
+                               $wgOut->wrapWikiMsg( "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>", 'moveuserpage-warning' );
+                       }
                        $wgOut->addWikiMsg( 'movepagetext' );
                        $movepagebtn = wfMsg( 'movepagebtn' );
                        $submitVar = 'wpMove';
@@ -161,7 +175,6 @@ class MovePageForm {
                        $wgOut->addWikiMsg( 'movepagetalktext' );
                }
 
-               $titleObj = SpecialPage::getTitleFor( 'Movepage' );
                $token = htmlspecialchars( $wgUser->editToken() );
 
                if ( !empty($err) ) {
@@ -171,7 +184,7 @@ class MovePageForm {
                                $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
                                $wgOut->addHTML( $errMsg );
                        } else {
-                               $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
+                               $wgOut->wrapWikiMsg( "<p><strong class=\"error\">\n$1\n</strong></p>", $err );
                        }
                }
 
@@ -192,7 +205,7 @@ class MovePageForm {
                }
 
                $wgOut->addHTML(
-                        Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
+                        Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
                         Xml::openElement( 'fieldset' ) .
                         Xml::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
                         Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
@@ -218,7 +231,8 @@ class MovePageForm {
                                        Xml::label( wfMsg( 'movereason' ), 'wpReason' ) .
                                "</td>
                                <td class='mw-input'>" .
-                                       Xml::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason ) ) .
+                                       Html::element( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2,
+                                       'maxlength' => 200 ), $this->reason ) .
                                "</td>
                        </tr>"
                );
@@ -273,7 +287,7 @@ class MovePageForm {
                                        # move and we aren't moving the talk page.
                                        $this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk),
                                        array( 'id' => 'wpMovesubpages' )
-                               ) . '&nbsp;' .
+                               ) . '&#160;' .
                                Xml::tags( 'label', array( 'for' => 'wpMovesubpages' ),
                                        wfMsgExt(
                                                ( $this->oldTitle->hasSubpages()
@@ -306,7 +320,7 @@ class MovePageForm {
                $wgOut->addHTML( "      
                                {$confirm}
                        <tr>
-                               <td>&nbsp;</td>
+                               <td>&#160;</td>
                                <td class='mw-submit'>" .
                                        Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
                                "</td>
@@ -324,7 +338,7 @@ class MovePageForm {
        }
 
        function doSubmit() {
-               global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
+               global $wgOut, $wgUser, $wgMaximumMovedPages, $wgLang;
                global $wgFixDoubleRedirects;
 
                if ( $wgUser->pingLimiter( 'move' ) ) {
@@ -342,7 +356,7 @@ class MovePageForm {
                        # Disallow deletions of big articles
                        $bigHistory = $article->isBigDeletion();
                        if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
-                               global $wgLang, $wgDeleteRevisionsLimit;
+                               global $wgDeleteRevisionsLimit;
                                $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
                                return;
                        }
@@ -481,7 +495,7 @@ class MovePageForm {
 
                        $newPageName = preg_replace(
                                '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
-                               str_replace( '\\', '\\\\', $nt->getDBkey() ), # bug 21234
+                               StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
                                $oldSubpage->getDBkey()
                        );
                        if( $oldSubpage->isTalkPage() ) {
@@ -543,6 +557,13 @@ class MovePageForm {
                        $wgUser->removeWatch( $ot );
                        $wgUser->removeWatch( $nt );
                }
+               
+               # Re-clear the file redirect cache, which may have been polluted by 
+               # parsing in messages above. See CR r56745.
+               # FIXME: needs a more robust solution inside FileRepo.
+               if( $ot->getNamespace() == NS_FILE ) {
+                       RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $ot );
+               }
        }
 
        function showLogFragment( $title, &$out ) {