Bug 23699: Add trailing \n at the end of <div>s in wrapWikiMsg()
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
index 68ba065..9b480bb 100644 (file)
@@ -58,12 +58,12 @@ function wfSpecialMovepage( $par = null ) {
 class MovePageForm {
        var $oldTitle, $newTitle; # Objects
        var $reason; # Text input
-       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect; # Checks
+       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks
 
        private $watch = false;
 
        function __construct( $oldTitle, $newTitle ) {
-               global $wgRequest;
+               global $wgRequest, $wgUser;
                $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
                $this->oldTitle = $oldTitle;
                $this->newTitle = $newTitle;
@@ -79,7 +79,8 @@ class MovePageForm {
                }
                $this->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false );
                $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
-               $this->watch = $wgRequest->getCheck( 'wpWatch' );
+               $this->moveOverShared = $wgRequest->getBool( 'wpMoveOverSharedFile', false );
+               $this->watch = $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn();
        }
 
        /**
@@ -130,12 +131,21 @@ 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';
                        $confirm = false;
                }
 
+               if ( !empty($err) && $err[0] == 'file-exists-sharedrepo' && $wgUser->isAllowed( 'reupload-shared' ) ) {
+                       $wgOut->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
+                       $submitVar = 'wpMoveOverSharedFile';
+                       $err = '';
+               }
+               
                $oldTalk = $this->oldTitle->getTalkPage();
                $considerTalk = ( !$this->oldTitle->isTalkPage() && $oldTalk->exists() );
 
@@ -164,7 +174,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 );
                        }
                }
 
@@ -180,7 +190,7 @@ class MovePageForm {
                        }
                        $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
                        $wgOut->addWikiMsg( $noticeMsg );
-                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->oldTitle->getPrefixedText(), '', 1 );
+                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->oldTitle->getPrefixedText(), '', array( 'lim' => 1 ) );
                        $wgOut->addHTML( "</div>\n" );
                }
 
@@ -211,7 +221,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>"
                );
@@ -283,15 +294,20 @@ class MovePageForm {
                        );
                }
 
-               $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) 
-                       || $this->oldTitle->userIsWatching();
-               $wgOut->addHTML( "
+               $watchChecked = $wgUser->isLoggedIn() && ($this->watch || $wgUser->getBoolOption( 'watchmoves' ) 
+                       || $this->oldTitle->userIsWatching());
+               # Don't allow watching if user is not logged in
+               if( $wgUser->isLoggedIn() ) {
+                       $wgOut->addHTML( "
                        <tr>
                                <td></td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
                                "</td>
-                       </tr>
+                       </tr>");
+               }
+
+               $wgOut->addHTML( "      
                                {$confirm}
                        <tr>
                                <td>&nbsp;</td>
@@ -351,15 +367,24 @@ class MovePageForm {
                        return;
                }
 
+               # Show a warning if the target file exists on a shared repo
+               if ( $nt->getNamespace() == NS_FILE 
+                       && !( $this->moveOverShared && $wgUser->isAllowed( 'reupload-shared' ) )
+                       && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt ) 
+                       && wfFindFile( $nt ) )
+               {
+                       $this->showForm( array('file-exists-sharedrepo') );
+                       return;
+                       
+               }
+               
                if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
                        $createRedirect = $this->leaveRedirect;
                } else {
                        $createRedirect = true;
                }
 
-               # Do the actual move.  First remember the old ID for later reference,
-               # so that we don't get the ID of the redirect.
-               $oldId = $ot->getArticleId();
+               # Do the actual move.
                $error = $ot->moveTo( $nt, true, $this->reason, $createRedirect );
                if ( $error !== true ) {
                        # FIXME: show all the errors in a list, not just the first one
@@ -418,7 +443,7 @@ class MovePageForm {
                        )
                ) ) {
                        $conds = array(
-                               'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
+                               'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
                                        .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
                        );
                        $conds['page_namespace'] = array();
@@ -453,14 +478,14 @@ class MovePageForm {
                $skin = $wgUser->getSkin();
                $count = 1;
                foreach( $extraPages as $oldSubpage ) {
-                       if( $oldSubpage->getArticleId() == $oldId ) {
+                       if( $ot->equals( $oldSubpage ) ) {
                                # Already did this one.
                                continue;
                        }
 
                        $newPageName = preg_replace(
                                '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
-                               $nt->getDBkey(),
+                               StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
                                $oldSubpage->getDBkey()
                        );
                        if( $oldSubpage->isTalkPage() ) {
@@ -515,17 +540,24 @@ class MovePageForm {
                }
 
                # Deal with watches (we don't watch subpages)
-               if( $this->watch ) {
+               if( $this->watch && $wgUser->isLoggedIn() ) {
                        $wgUser->addWatch( $ot );
                        $wgUser->addWatch( $nt );
                } else {
                        $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 ) {
-               $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) );
+               $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'move' ) ) );
                LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() );
        }