From 120cbf48644312a5745be4791d82a8ff11671615 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 18 Apr 2008 23:53:03 +0000 Subject: [PATCH] Revert r33565 pending some cleanup... A few notes: * This seems to drop the 'action=success' page in favor of dumping all the output directly on the POST response. That's probably necessary, but tends to cause annoyances with back/forward navigation (warnings about re-POSTing data etc) * The subpage checkbox is shown on the form based only on the target page's namespace. This means it'll show for the vast majority of, say, talk pages which don't have any subpages. To be consistent with the talk namespace, it should be kept hidden if there aren't any. * Subpages may exist for a talk namespace while not existing for the article namespace. When moving an article with its talk, and the talk has archive subpages, it would probably make sense to do the moves -- but no check will show here due to the check only on the article space. * There's a couple copy-pasted instances of $something ? ' checked="checked"' : '' ... since these are passed to a function looking for a boolean, they should just use the boolean $something. :) * I see some unnecessary uses of =& ... this is a PHP 4-ism and not needed here. * This query's kind of creepy: SELECT /* MovePageForm::doSubmit WikiSysop */ page_id,page_namespace,page_title FROM `page` WHERE 0 = 1 * Generally speaking, there may be a _lot_ of subpages. English Wikipedia Main_Page will net you 169 total including itself, talk, and all subpages. How safe is it to move potentially thousands in one request here? --- RELEASE-NOTES | 1 - includes/SpecialMovepage.php | 178 ++++++++++++------------------ languages/messages/MessagesEn.php | 6 +- maintenance/language/messages.inc | 6 +- 4 files changed, 73 insertions(+), 118 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index a98fd3c2c3..af5c2503e8 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -87,7 +87,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN text from Special:UserLogin title (new message 'nav-login-createaccount') * Say "log in / create account" if an anonymous user can create an account, otherwise just "log in", consistently across skins -* Users moving a page can now have all subpages automatically moved as well === Bug fixes in 1.13 === diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index becf7985aa..6c5232cec7 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -30,7 +30,9 @@ function wfSpecialMovepage( $par = null ) { $f = new MovePageForm( $par ); - if ( 'submit' == $action && $wgRequest->wasPosted() + if ( 'success' == $action ) { + $f->showSuccess(); + } else if ( 'submit' == $action && $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { $f->doSubmit(); } else { @@ -44,7 +46,7 @@ function wfSpecialMovepage( $par = null ) { */ class MovePageForm { var $oldTitle, $newTitle, $reason; # Text input - var $moveTalk, $deleteAndMove, $moveSubpages; + var $moveTalk, $deleteAndMove; private $watch = false; @@ -59,13 +61,12 @@ class MovePageForm { } else { $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true ); } - $this->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false ); $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' ); $this->watch = $wgRequest->getCheck( 'wpWatch' ); } function showForm( $err, $hookErr = '' ) { - global $wgOut, $wgUser, $wgNamespacesWithSubpages; + global $wgOut, $wgUser; $ot = Title::newFromURL( $this->oldTitle ); if( is_null( $ot ) ) { @@ -143,6 +144,8 @@ class MovePageForm { $wgOut->addHTML( $errMsg ); } + $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : ''; + $wgOut->addHTML( Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) . Xml::openElement( 'fieldset' ) . @@ -175,26 +178,12 @@ class MovePageForm { " ); - if( $considerTalk ) { + if ( $considerTalk ) { $wgOut->addHTML( " " . - Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', - 'wpMovetalk', $this->moveTalk ? ' checked="checked"' : ''). - " - " - ); - } - - if( isset( $wgNamespacesWithSubpages[$ot->getNamespace()] ) ) { - $wgOut->addHTML( " - - - " . - Xml::checkLabel( wfMsgHtml( 'move-subpages' ), - 'wpMovesubpages', 'wpMovesubpages', - $this->moveSubpages ? ' checked="checked"' : '' ) . + Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) . " " ); @@ -275,98 +264,26 @@ class MovePageForm { wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ; - $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) ); - - $oldUrl = $ot->getFullUrl( 'redirect=no' ); - $newUrl = $nt->getFullUrl(); - $oldText = $ot->getPrefixedText(); - $newText = $nt->getPrefixedText(); - $oldLink = "[$oldUrl $oldText]"; - $newLink = "[$newUrl $newText]"; - - $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText ); - - # 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 - # can't move any talk pages: cancel that. - if( $ot->isTalkPage() || $nt->isTalkPage() ) { - $this->moveTalk = false; - } - - # Next make a list of id's. This might be marginally less efficient - # than a more direct method, but this is not a highly performance-cri- - # tical code path and readable code is more important here. - # - # Note: this query works nicely on MySQL 5, but the optimizer in MySQL - # 4 might get confused. If so, consider rewriting as a UNION. - $dbr = wfGetDB( DB_SLAVE ); - if( $this->moveSubpages ) { - $conds = array( - 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' ) - .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() ) - ); - if( $this->moveTalk ) { - $conds['page_namespace'] = array( $ot->getNamespace(), - MWNamespace::getTalk($ot->getNamespace()) ); - } else { - $conds['page_namespace'] = $ot->getNamespace(); - } - } else { - if( $this->moveTalk ) { - $conds = array( - 'page_namespace' => MWNamespace::getTalk($ot->getNamespace()), - 'page_title' => $ot->getDBKey() - ); - } else { - $conds = '0 = 1'; - } - } - - $extrapages = $dbr->select( - 'page', - array( 'page_id', 'page_namespace', 'page_title' ), - $conds, - __METHOD__ - ); - - $extraOutput = ''; - $skin =& $wgUser->getSkin(); - foreach( $extrapages as $row ) { - if( $row->page_id == $ot->getArticleId() ) { - # Already did this one. - continue; - } - - $oldPage = Title::newFromRow( $row ); - $newPageName = preg_replace( - '#^'.preg_quote( $ot->getDBKey(), '#' ).'#', - $nt->getDBKey(), - $oldPage->getDBKey() - ); - # The following line is an atrocious hack. Kill it. - $newNs = $nt->getNamespace() + ($oldPage->getNamespace() & 1); - $newPage = Title::makeTitle( $newNs, $newPageName ); - - # This was copy-pasted from Renameuser, bleh. - if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) { - $link = $skin->makeKnownLinkObj( $newPage ); - $extraOutput .= '
  • ' . wfMsgHtml( 'movepage-page-exists', $link ) . '
  • '; - } else { - $success = $oldPage->moveTo( $newPage, true, $this->reason ); - if( $success === true ) { - $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' ); - $newLink = $skin->makeKnownLinkObj( $newPage ); - $extraOutput .= '
  • ' . wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink ) . '
  • '; + # Move the talk page if relevant, if it exists, and if we've been told to + $ott = $ot->getTalkPage(); + if( $ott->exists() ) { + if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) { + $ntt = $nt->getTalkPage(); + + # Attempt the move + $error = $ott->moveTo( $ntt, true, $this->reason ); + if ( $error === true ) { + $talkmoved = 1; + wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ); } else { - $oldLink = $skin->makeKnownLinkObj( $oldPage ); - $newLink = $skin->makeLinkObj( $newPage ); - $extraOutput .= '
  • ' . wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink ) . '
  • '; + $talkmoved = $error; } + } else { + # Stay silent on the subject of talk. + $talkmoved = ''; } - } - - if( $extraOutput !== '' ) { - $wgOut->addHTML( "" ); + } else { + $talkmoved = 'notalkpage'; } # Deal with watches @@ -377,6 +294,49 @@ class MovePageForm { $wgUser->removeWatch( $ot ); $wgUser->removeWatch( $nt ); } + + # Give back result to user. + $titleObj = SpecialPage::getTitleFor( 'Movepage' ); + $success = $titleObj->getFullURL( + 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) . + '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) . + '&talkmoved='.$talkmoved ); + + $wgOut->redirect( $success ); + } + + function showSuccess() { + global $wgOut, $wgRequest, $wgUser; + + $old = Title::newFromText( $wgRequest->getVal( 'oldtitle' ) ); + $new = Title::newFromText( $wgRequest->getVal( 'newtitle' ) ); + + if( is_null( $old ) || is_null( $new ) ) { + throw new ErrorPageError( 'badtitle', 'badtitletext' ); + } + + $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) ); + + $talkmoved = $wgRequest->getVal( 'talkmoved' ); + $oldUrl = $old->getFullUrl( 'redirect=no' ); + $newUrl = $new->getFullUrl(); + $oldText = $old->getPrefixedText(); + $newText = $new->getPrefixedText(); + $oldLink = "[$oldUrl $oldText]"; + $newLink = "[$newUrl $newText]"; + + $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText ); + + if ( $talkmoved == 1 ) { + $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' ); + } elseif( 'articleexists' == $talkmoved ) { + $s .= "\n\n" . wfMsgNoTrans( 'talkexists' ); + } else { + if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) { + $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) ); + } + } + $wgOut->addWikiText( $s ); } function showLogFragment( $title, &$out ) { diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 0de5d0fc3a..26559672b8 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2345,10 +2345,8 @@ Please choose another name.', Please merge them manually.'''", 'movedto' => 'moved to', 'movetalk' => 'Move associated talk page', -'move-subpages' => 'Move all subpages, if applicable', -'movepage-page-exists' => 'The page $1 already exists and cannot be automatically overwritten.', -'movepage-page-moved' => 'The page $1 has been moved to $2.', -'movepage-page-unmoved' => 'The page $1 could not be moved to $2.', +'talkpagemoved' => 'The corresponding talk page was also moved.', +'talkpagenotmoved' => 'The corresponding talk page was not moved.', '1movedto2' => '[[$1]] moved to [[$2]]', '1movedto2_redir' => '[[$1]] moved to [[$2]] over redirect', 'movelogpage' => 'Move log', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index cc5c2537d6..5f9c58a98a 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1581,10 +1581,8 @@ $wgMessageStructure = array( 'talkexists', 'movedto', 'movetalk', - 'move-subpages', - 'movepage-page-exists', - 'movepage-page-unmoved', - 'movepage-page-moved', + 'talkpagemoved', + 'talkpagenotmoved', '1movedto2', '1movedto2_redir', 'movelogpage', -- 2.20.1