(bug 20052) Watch checkbox on Special:Movepage is checked by default when the old...
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
index 955dd54..f583d1a 100644 (file)
@@ -56,7 +56,7 @@ function wfSpecialMovepage( $par = null ) {
 class MovePageForm {
        var $oldTitle, $newTitle; # Objects
        var $reason; # Text input
-       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects; # Checks
+       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect; # Checks
 
        private $watch = false;
 
@@ -69,21 +69,29 @@ class MovePageForm {
                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->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false );
                $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
                $this->watch = $wgRequest->getCheck( 'wpWatch' );
        }
 
+       /**
+        * Show the form
+        * @param mixed $err Error message. May either be a string message name or 
+        *    array message name and parameters, like the second argument to 
+        *    OutputPage::wrapWikiMsg(). 
+        */
        function showForm( $err ) {
-               global $wgOut, $wgUser;
+               global $wgOut, $wgUser, $wgFixDoubleRedirects;
 
                $skin = $wgUser->getSkin();
 
-               $oldTitleLink = $skin->makeLinkObj( $this->oldTitle );
+               $oldTitleLink = $skin->link( $this->oldTitle );
 
                $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle->getPrefixedText() ) );
                $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
@@ -95,21 +103,17 @@ class MovePageForm {
                        # when the form is first opened.
                        $newTitle = $this->oldTitle;
                }
-               // WTF is this doing, passing title *object* to newFromUrl()??
-               /*else {
+               else {
                        if( empty($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 = $this->oldTitle->isValidMoveOperation( $nt );
-                                       if( is_string( $newerr ) ) {
-                                               $err = $newerr;
-                                       }
+                               # 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 = $this->oldTitle->isValidMoveOperation( $newTitle );
+                               if( $newerr ) {
+                                       $err = $newerr[0];
                                }
                        }
-               }*/
+               }
 
                if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
                        $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
@@ -134,12 +138,16 @@ class MovePageForm {
                $considerTalk = ( !$this->oldTitle->isTalkPage() && $oldTalk->exists() );
 
                $dbr = wfGetDB( DB_SLAVE );
-               $hasRedirects = $dbr->selectField( 'redirect', '1', 
-                       array( 
-                               'rd_namespace' => $this->oldTitle->getNamespace(),
-                               'rd_title' => $this->oldTitle->getDBkey(),
-                       ) , __METHOD__ );
-               
+               if ( $wgFixDoubleRedirects ) {
+                       $hasRedirects = $dbr->selectField( 'redirect', '1', 
+                               array( 
+                                       'rd_namespace' => $this->oldTitle->getNamespace(),
+                                       'rd_title' => $this->oldTitle->getDBkey(),
+                               ) , __METHOD__ );
+               } else {
+                       $hasRedirects = false;
+               }
+
                if ( $considerTalk ) {
                        $wgOut->addWikiMsg( 'movepagetalktext' );
                }
@@ -158,6 +166,22 @@ class MovePageForm {
                        }
                }
 
+               if ( $this->oldTitle->isProtected( 'move' ) ) {
+                       # Is the title semi-protected?
+                       if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
+                               $noticeMsg = 'semiprotectedpagemovewarning';
+                               $classes[] = 'mw-textarea-sprotected';
+                       } else {
+                               # Then it must be protected based on static groups (regular)
+                               $noticeMsg = 'protectedpagemovewarning';
+                               $classes[] = 'mw-textarea-protected';
+                       }
+                       $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
+                       $wgOut->addWikiMsg( $noticeMsg );
+                       LogEventsList::showLogExtract( $wgOut, 'protect', $this->oldTitle->getPrefixedText(), '', 1 );
+                       $wgOut->addHTML( "</div>\n" );
+               }
+
                $wgOut->addHTML(
                         Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
                         Xml::openElement( 'fieldset' ) .
@@ -201,6 +225,18 @@ class MovePageForm {
                        );
                }
 
+               if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
+                       $wgOut->addHTML( "
+                               <tr>
+                                       <td></td>
+                                       <td class='mw-input' >" .
+                                               Xml::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect', 
+                                                       'wpLeaveRedirect', $this->leaveRedirect ) .
+                                       "</td>
+                               </tr>"
+                       );
+               }
+
                if ( $hasRedirects ) {
                        $wgOut->addHTML( "
                                <tr>
@@ -214,15 +250,22 @@ class MovePageForm {
                }
 
                if( ($this->oldTitle->hasSubpages() || $this->oldTitle->getTalkPage()->hasSubpages())
-               && $this->oldTitle->userCan( 'move-subpages' ) ) {
+                       && $this->oldTitle->userCan( 'move-subpages' ) )
+               {
+                       global $wgMaximumMovedPages, $wgLang;
+
                        $wgOut->addHTML( "
                                <tr>
                                        <td></td>
                                        <td class=\"mw-input\">" .
-                               Xml::checkLabel( wfMsg(
-                                               $this->oldTitle->hasSubpages()
-                                               ? 'move-subpages'
-                                               : 'move-talk-subpages'
+                               Xml::checkLabel( wfMsgExt(
+                                               ( $this->oldTitle->hasSubpages()
+                                                       ? 'move-subpages'
+                                                       : 'move-talk-subpages' ),
+                                               array( 'parsemag' ),
+                                               $wgLang->formatNum( $wgMaximumMovedPages ),
+                                               # $2 to allow use of PLURAL in message.
+                                               $wgMaximumMovedPages
                                        ),
                                        'wpMovesubpages', 'wpMovesubpages',
                                        # Don't check the box if we only have talk subpages to
@@ -234,8 +277,11 @@ class MovePageForm {
                        );
                }
 
+               # Check the watch checkbox in case the watch parameter was given in the 
+               # request, the preferences say so, or either the old or new title is 
+               # being watched.
                $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) 
-                       || $this->oldTitle->userIsWatching();
+                       || $this->oldTitle->userIsWatching() || $this->newTitle->userIsWatching();
                $wgOut->addHTML( "
                        <tr>
                                <td></td>
@@ -258,11 +304,13 @@ class MovePageForm {
                );
 
                $this->showLogFragment( $this->oldTitle, $wgOut );
+               $this->showSubpages( $this->oldTitle, $wgOut );
 
        }
 
        function doSubmit() {
                global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
+               global $wgFixDoubleRedirects;
 
                if ( $wgUser->pingLimiter( 'move' ) ) {
                        $wgOut->rateLimited();
@@ -284,6 +332,12 @@ class MovePageForm {
                                return;
                        }
 
+                       // Delete an associated image if there is
+                       $file = wfLocalFile( $nt );
+                       if( $file->exists() ) {
+                               $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
+                       }
+
                        // This may output an error message and exit
                        $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
                }
@@ -294,13 +348,20 @@ class MovePageForm {
                        return;
                }
 
-               $error = $ot->moveTo( $nt, true, $this->reason );
+               if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
+                       $createRedirect = $this->leaveRedirect;
+               } else {
+                       $createRedirect = true;
+               }
+
+               $error = $ot->moveTo( $nt, true, $this->reason, $createRedirect );
                if ( $error !== true ) {
-                       call_user_func_array( array($this, 'showForm'), $error );
+                       # FIXME: show all the errors in a list, not just the first one
+                       $this->showForm( reset( $error ) );
                        return;
                }
 
-               if ( $this->fixRedirects ) {
+               if ( $wgFixDoubleRedirects && $this->fixRedirects ) {
                        DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
                }
 
@@ -315,7 +376,9 @@ class MovePageForm {
                $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
                $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
 
+               $msgName = $createRedirect ? 'movepage-moved-redirect' : 'movepage-moved-noredirect';
                $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
+               $wgOut->addWikiMsg( $msgName );
 
                # Now we move extra pages we've been asked to move: subpages and talk
                # pages.  First, if the old page or the new page is a talk page, we
@@ -339,6 +402,8 @@ class MovePageForm {
                # would mean that you couldn't move them back in one operation, which
                # is bad.  FIXME: A specific error message should be given in this
                # case.
+               
+               // FIXME: Use Title::moveSubpages() here
                $dbr = wfGetDB( DB_MASTER );
                if( $this->moveSubpages && (
                        MWNamespace::hasSubpages( $nt->getNamespace() ) || (
@@ -360,7 +425,7 @@ class MovePageForm {
                } elseif( $this->moveTalk ) {
                        $conds = array(
                                'page_namespace' => $ot->getTalkPage()->getNamespace(),
-                               'page_title' => $ot->getDBKey()
+                               'page_title' => $ot->getDBkey()
                        );
                } else {
                        # Skip the query
@@ -388,9 +453,9 @@ class MovePageForm {
                        }
 
                        $newPageName = preg_replace(
-                               '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
-                               $nt->getDBKey(),
-                               $oldSubpage->getDBKey()
+                               '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
+                               $nt->getDBkey(),
+                               $oldSubpage->getDBkey()
                        );
                        if( $oldSubpage->isTalkPage() ) {
                                $newNs = $nt->getTalkPage()->getNamespace();
@@ -401,7 +466,7 @@ class MovePageForm {
                        # be longer than 255 characters.
                        $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
                        if( !$newSubpage ) {
-                               $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
+                               $oldLink = $skin->linkKnown( $oldSubpage );
                                $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
                                        htmlspecialchars(Title::makeName( $newNs, $newPageName )));
                                continue;
@@ -409,20 +474,25 @@ class MovePageForm {
 
                        # This was copy-pasted from Renameuser, bleh.
                        if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
-                               $link = $skin->makeKnownLinkObj( $newSubpage );
+                               $link = $skin->linkKnown( $newSubpage );
                                $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
                        } else {
-                               $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason );
+                               $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
                                if( $success === true ) {
                                        if ( $this->fixRedirects ) {
                                                DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
                                        }
-                                       $oldLink = $skin->makeKnownLinkObj( $oldSubpage, '', 'redirect=no' );
-                                       $newLink = $skin->makeKnownLinkObj( $newSubpage );
+                                       $oldLink = $skin->linkKnown(
+                                               $oldSubpage,
+                                               null,
+                                               array(),
+                                               array( 'redirect' => 'no' )
+                                       );
+                                       $newLink = $skin->linkKnown( $newSubpage );
                                        $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
                                } else {
-                                       $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
-                                       $newLink = $skin->makeLinkObj( $newSubpage );
+                                       $oldLink = $skin->linkKnown( $oldSubpage );
+                                       $newLink = $skin->link( $newSubpage );
                                        $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
                                }
                        }
@@ -453,4 +523,32 @@ class MovePageForm {
                LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() );
        }
 
+       function showSubpages( $title, $out ) {
+               global $wgUser, $wgLang;
+
+               if( !MWNamespace::hasSubpages( $title->getNamespace() ) )
+                       return;
+
+               $subpages = $title->getSubpages();
+               $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
+
+               $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
+
+               # No subpages.
+               if ( $count == 0 ) {
+                       $out->addWikiMsg( 'movenosubpage' );
+                       return;
+               }
+
+               $out->addWikiMsg( 'movesubpagetext', $wgLang->formatNum( $count ) );
+               $skin = $wgUser->getSkin();
+               $out->addHTML( "<ul>\n" );
+
+               foreach( $subpages as $subpage ) {
+                       $link = $skin->link( $subpage );
+                       $out->addHTML( "<li>$link</li>\n" );
+               }
+               $out->addHTML( "</ul>\n" );
+       }
 }
+