checkReadOnly();
$this->setHeaders();
$this->outputHeader();
$request = $this->getRequest();
$target = !is_null( $par ) ? $par : $request->getVal( 'target' );
// Yes, the use of getVal() and getText() is wanted, see bug 20365
$oldTitleText = $request->getVal( 'wpOldTitle', $target );
$newTitleText = $request->getText( 'wpNewTitle' );
$this->oldTitle = Title::newFromText( $oldTitleText );
$this->newTitle = Title::newFromText( $newTitleText );
if( is_null( $this->oldTitle ) ) {
throw new ErrorPageError( 'notargettitle', 'notargettext' );
}
if( !$this->oldTitle->exists() ) {
throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
}
$user = $this->getUser();
# Check rights
$permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
if ( count( $permErrors ) ) {
// Auto-block user's IP if the account was "hard" blocked
$user->spreadAnyEditBlock();
throw new PermissionsError( 'move', $permErrors );
}
$def = !$request->wasPosted();
$this->reason = $request->getText( 'wpReason' );
$this->moveTalk = $request->getBool( 'wpMovetalk', $def );
$this->fixRedirects = $request->getBool( 'wpFixRedirects', $def );
$this->leaveRedirect = $request->getBool( 'wpLeaveRedirect', $def );
$this->moveSubpages = $request->getBool( 'wpMovesubpages', false );
$this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' ) && $request->getBool( 'wpConfirm' );
$this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile', false );
$this->watch = $request->getCheck( 'wpWatch' ) && $user->isLoggedIn();
if ( 'submit' == $request->getVal( 'action' ) && $request->wasPosted()
&& $user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
$this->doSubmit();
} else {
$this->showForm( array() );
}
}
/**
* Show the form
*
* @param $err Array: error messages. Each item is an error message.
* It may either be a string message name or array message name and
* parameters, like the second argument to OutputPage::wrapWikiMsg().
*/
function showForm( $err ) {
global $wgContLang, $wgFixDoubleRedirects, $wgMaximumMovedPages;
$this->getSkin()->setRelevantTitle( $this->oldTitle );
$oldTitleLink = Linker::link( $this->oldTitle );
$out = $this->getOutput();
$out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
$out->addModules( 'mediawiki.special.movePage' );
$newTitle = $this->newTitle;
if( !$newTitle ) {
# Show the current title as a default
# when the form is first opened.
$newTitle = $this->oldTitle;
} elseif ( !count( $err ) ) {
# 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( is_array( $newerr ) ) {
$err = $newerr;
}
}
$user = $this->getUser();
if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
&& $newTitle->quickUserCan( 'delete', $user )
) {
$out->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
$movepagebtn = wfMsg( 'delete_and_move' );
$submitVar = 'wpDeleteAndMove';
$confirm = "
|
" .
Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
" |
";
$err = array();
} else {
if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
$out->wrapWikiMsg( "\n$1\n
", 'moveuserpage-warning' );
}
$out->addWikiMsg( $wgFixDoubleRedirects ? 'movepagetext' :
'movepagetext-noredirectfixer' );
$movepagebtn = wfMsg( 'movepagebtn' );
$submitVar = 'wpMove';
$confirm = false;
}
if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
&& $user->isAllowed( 'reupload-shared' )
) {
$out->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
$submitVar = 'wpMoveOverSharedFile';
$err = array();
}
$oldTalk = $this->oldTitle->getTalkPage();
$oldTitleSubpages = $this->oldTitle->hasSubpages();
$oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
$canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
!count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
# We also want to be able to move assoc. subpage talk-pages even if base page
# has no associated talk page, so || with $oldTitleTalkSubpages.
$considerTalk = !$this->oldTitle->isTalkPage() &&
( $oldTalk->exists()
|| ( $oldTitleTalkSubpages && $canMoveSubpage ) );
$dbr = wfGetDB( DB_SLAVE );
if ( $wgFixDoubleRedirects ) {
$hasRedirects = $dbr->selectField( 'redirect', '1',
array(
'rd_namespace' => $this->oldTitle->getNamespace(),
'rd_title' => $this->oldTitle->getDBkey(),
) , __METHOD__ );
} else {
$hasRedirects = false;
}
if ( $considerTalk ) {
$out->addWikiMsg( 'movepagetalktext' );
}
if ( count( $err ) ) {
$out->addHTML( "\n" );
$action_desc = $this->msg( 'action-move' )->plain();
$out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
if ( count( $err ) ) {
$errMsg = $err[0];
$errMsgName = array_shift( $errMsg );
if ( $errMsgName == 'hookaborted' ) {
$out->addHTML( "
{$errMsg[0]}
\n" );
} else {
$out->addWikiMsgArray( $errMsg, $errMsgName );
}
} else {
$errStr = array();
foreach( $err as $errMsg ) {
if( $errMsg[0] == 'hookaborted' ) {
$errStr[] = $errMsg[1];
} else {
$errMsgName = array_shift( $errMsg );
$errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
}
}
$out->addHTML( '
- ' . implode( "
\n- ", $errStr ) . "
\n" );
}
$out->addHTML( "
\n" );
}
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';
}
$out->addHTML( "\n" );
$out->addWikiMsg( $noticeMsg );
LogEventsList::showLogExtract( $out, 'protect', $this->oldTitle, '', array( 'lim' => 1 ) );
$out->addHTML( "
\n" );
}
$out->addHTML(
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' ) ) .
"
" .
wfMsgHtml( 'movearticle' ) .
" |
{$oldTitleLink}
|
" .
Xml::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
" |
" .
Xml::input( 'wpNewTitle', 60, $wgContLang->recodeForEdit( $newTitle->getPrefixedText() ), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
" |
" .
Xml::label( wfMsg( 'movereason' ), 'wpReason' ) .
" |
" .
Html::element( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2,
'maxlength' => 200 ), $this->reason ) . // maxlength byte limit is enforce in mediawiki.special.movePage.js
" |
"
);
if( $considerTalk ) {
$out->addHTML( "
|
" .
Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk ) .
" |
"
);
}
if ( $user->isAllowed( 'suppressredirect' ) ) {
$out->addHTML( "
|
" .
Xml::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
'wpLeaveRedirect', $this->leaveRedirect ) .
" |
"
);
}
if ( $hasRedirects ) {
$out->addHTML( "
|
" .
Xml::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
'wpFixRedirects', $this->fixRedirects ) .
" |
"
);
}
if( $canMoveSubpage ) {
$out->addHTML( "
|
" .
Xml::check(
'wpMovesubpages',
# Don't check the box if we only have talk subpages to
# move and we aren't moving the talk page.
$this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk),
array( 'id' => 'wpMovesubpages' )
) . ' ' .
Xml::tags( 'label', array( 'for' => 'wpMovesubpages' ),
wfMsgExt(
( $this->oldTitle->hasSubpages()
? 'move-subpages'
: 'move-talk-subpages' ),
array( 'parseinline' ),
$this->getLanguage()->formatNum( $wgMaximumMovedPages ),
# $2 to allow use of PLURAL in message.
$wgMaximumMovedPages
)
) .
" |
"
);
}
$watchChecked = $user->isLoggedIn() && ($this->watch || $user->getBoolOption( 'watchmoves' )
|| $this->oldTitle->userIsWatching());
# Don't allow watching if user is not logged in
if( $user->isLoggedIn() ) {
$out->addHTML( "
|
" .
Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
" |
");
}
$out->addHTML( "
{$confirm}
|
" .
Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
" |
" .
Xml::closeElement( 'table' ) .
Html::hidden( 'wpEditToken', $user->getEditToken() ) .
Xml::closeElement( 'fieldset' ) .
Xml::closeElement( 'form' ) .
"\n"
);
$this->showLogFragment( $this->oldTitle );
$this->showSubpages( $this->oldTitle );
}
function doSubmit() {
global $wgMaximumMovedPages, $wgFixDoubleRedirects, $wgDeleteRevisionsLimit;
$user = $this->getUser();
if ( $user->pingLimiter( 'move' ) ) {
throw new ThrottledError;
}
$ot = $this->oldTitle;
$nt = $this->newTitle;
# don't allow moving to pages with # in
if ( !$nt || $nt->getFragment() != '' ) {
$this->showForm( array( array( 'badtitletext' ) ) );
return;
}
# Show a warning if the target file exists on a shared repo
if ( $nt->getNamespace() == NS_FILE
&& !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
&& !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
&& wfFindFile( $nt ) )
{
$this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
return;
}
# Delete to make way if requested
if ( $this->deleteAndMove ) {
$permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
if ( count( $permErrors ) ) {
# Only show the first error
$this->showForm( $permErrors );
return;
}
$reason = wfMessage( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
// Delete an associated image if there is
if ( $nt->getNamespace() == NS_FILE ) {
$file = wfLocalFile( $nt );
if ( $file->exists() ) {
$file->delete( $reason, false );
}
}
$error = ''; // passed by ref
$page = WikiPage::factory( $nt );
if ( !$page->doDeleteArticle( $reason, false, 0, true, $error, $user ) ) {
$this->showForm( array( array( 'cannotdelete', wfEscapeWikiText( $nt->getPrefixedText() ) ) ) );
return;
}
}
if ( $user->isAllowed( 'suppressredirect' ) ) {
$createRedirect = $this->leaveRedirect;
} else {
$createRedirect = true;
}
# Do the actual move.
$error = $ot->moveTo( $nt, true, $this->reason, $createRedirect );
if ( $error !== true ) {
$this->showForm( $error );
return;
}
if ( $wgFixDoubleRedirects && $this->fixRedirects ) {
DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
}
wfRunHooks( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
$out = $this->getOutput();
$out->setPagetitle( wfMsg( 'pagemovedsub' ) );
$oldLink = Linker::link(
$ot,
null,
array(),
array( 'redirect' => 'no' )
);
$newLink = Linker::linkKnown( $nt );
$oldText = $ot->getPrefixedText();
$newText = $nt->getPrefixedText();
$msgName = $createRedirect ? 'movepage-moved-redirect' : 'movepage-moved-noredirect';
$out->addHTML( wfMessage( 'movepage-moved' )->rawParams( $oldLink, $newLink, $oldText, $newText )->parseAsBlock() );
$out->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
# can't move any talk pages: cancel that.
if( $ot->isTalkPage() || $nt->isTalkPage() ) {
$this->moveTalk = false;
}
if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
$this->moveSubpages = 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.
#
# If the target namespace doesn't allow subpages, moving with subpages
# would mean that you couldn't move them back in one operation, which
# is bad.
# @todo FIXME: A specific error message should be given in this case.
// @todo FIXME: Use Title::moveSubpages() here
$dbr = wfGetDB( DB_MASTER );
if( $this->moveSubpages && (
MWNamespace::hasSubpages( $nt->getNamespace() ) || (
$this->moveTalk &&
MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
)
) ) {
$conds = array(
'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
.' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
);
$conds['page_namespace'] = array();
if( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
$conds['page_namespace'] []= $ot->getNamespace();
}
if( $this->moveTalk && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
$conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
}
} elseif( $this->moveTalk ) {
$conds = array(
'page_namespace' => $ot->getTalkPage()->getNamespace(),
'page_title' => $ot->getDBkey()
);
} else {
# Skip the query
$conds = null;
}
$extraPages = array();
if( !is_null( $conds ) ) {
$extraPages = TitleArray::newFromResult(
$dbr->select( 'page',
array( 'page_id', 'page_namespace', 'page_title' ),
$conds,
__METHOD__
)
);
}
$extraOutput = array();
$count = 1;
foreach( $extraPages as $oldSubpage ) {
if( $ot->equals( $oldSubpage ) ) {
# Already did this one.
continue;
}
$newPageName = preg_replace(
'#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
$oldSubpage->getDBkey()
);
if( $oldSubpage->isTalkPage() ) {
$newNs = $nt->getTalkPage()->getNamespace();
} else {
$newNs = $nt->getSubjectPage()->getNamespace();
}
# Bug 14385: we need makeTitleSafe because the new page names may
# be longer than 255 characters.
$newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
if( !$newSubpage ) {
$oldLink = Linker::linkKnown( $oldSubpage );
$extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
htmlspecialchars(Title::makeName( $newNs, $newPageName )));
continue;
}
# This was copy-pasted from Renameuser, bleh.
if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
$link = Linker::linkKnown( $newSubpage );
$extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
} else {
$success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
if( $success === true ) {
if ( $this->fixRedirects ) {
DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
}
$oldLink = Linker::link(
$oldSubpage,
null,
array(),
array( 'redirect' => 'no' )
);
$newLink = Linker::linkKnown( $newSubpage );
$extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
++$count;
if( $count >= $wgMaximumMovedPages ) {
$extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $wgMaximumMovedPages ) );
break;
}
} else {
$oldLink = Linker::linkKnown( $oldSubpage );
$newLink = Linker::link( $newSubpage );
$extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
}
}
}
if( $extraOutput !== array() ) {
$out->addHTML( "\n- " . implode( "
\n- ", $extraOutput ) . "
\n
" );
}
# Deal with watches (we don't watch subpages)
if( $this->watch && $user->isLoggedIn() ) {
$user->addWatch( $ot );
$user->addWatch( $nt );
} else {
$user->removeWatch( $ot );
$user->removeWatch( $nt );
}
# Re-clear the file redirect cache, which may have been polluted by
# parsing in messages above. See CR r56745.
# @todo FIXME: Needs a more robust solution inside FileRepo.
if( $ot->getNamespace() == NS_FILE ) {
RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $ot );
}
}
function showLogFragment( $title ) {
$out = $this->getOutput();
$out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'move' ) ) );
LogEventsList::showLogExtract( $out, 'move', $title );
}
function showSubpages( $title ) {
if( !MWNamespace::hasSubpages( $title->getNamespace() ) )
return;
$subpages = $title->getSubpages();
$count = $subpages instanceof TitleArray ? $subpages->count() : 0;
$out = $this->getOutput();
$out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
# No subpages.
if ( $count == 0 ) {
$out->addWikiMsg( 'movenosubpage' );
return;
}
$out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
$out->addHTML( "\n" );
foreach( $subpages as $subpage ) {
$link = Linker::link( $subpage );
$out->addHTML( "- $link
\n" );
}
$out->addHTML( "
\n" );
}
}