<?php
/**
*
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
*/
-/**
- *
- */
-require_once( "LinksUpdate.php" );
-
/**
* Constructor
*/
-function wfSpecialMovepage() {
- global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
+function wfSpecialMovepage( $par = null ) {
+ global $wgUser, $wgOut, $wgRequest, $action;
- # check rights. We don't want newbies to move pages to prevents possible attack
- if ( $wgUser->isAnon() or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
- $wgOut->errorpage( "movenologin", "movenologintext" );
+ # Check rights
+ if ( !$wgUser->isAllowed( 'move' ) ) {
+ $wgOut->showPermissionsErrorPage( array( $wgUser->isAnon() ? 'movenologintext' : 'movenotallowed' ) );
return;
}
- # We don't move protected pages
+
+ # Don't allow blocked users to move pages
+ if ( $wgUser->isBlocked() ) {
+ $wgOut->blockedPage();
+ return;
+ }
+
+ # Check for database lock
if ( wfReadOnly() ) {
$wgOut->readOnlyPage();
return;
}
- $f = new MovePageForm();
+ $f = new MovePageForm( $par );
if ( 'success' == $action ) {
$f->showSuccess();
}
/**
- *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * HTML form for Special:Movepage
+ * @addtogroup SpecialPage
*/
class MovePageForm {
var $oldTitle, $newTitle, $reason; # Text input
var $moveTalk, $deleteAndMove;
-
- function MovePageForm() {
+
+ private $watch = false;
+
+ function MovePageForm( $par ) {
global $wgRequest;
- $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
+ $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
+ $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
$this->newTitle = $wgRequest->getText( 'wpNewTitle' );
$this->reason = $wgRequest->getText( 'wpReason' );
- $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
- $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' );
+ if ( $wgRequest->wasPosted() ) {
+ $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', false );
+ } else {
+ $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
+ }
+ $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
+ $this->watch = $wgRequest->getCheck( 'wpWatch' );
}
-
- function showForm( $err ) {
- global $wgOut, $wgUser, $wgLang;
- $wgOut->setPagetitle( wfMsg( 'movepage' ) );
+ function showForm( $err, $hookErr = '' ) {
+ global $wgOut, $wgUser;
- if ( $this->oldTitle == '' ) {
- $wgOut->errorpage( 'notargettitle', 'notargettext' );
+ $ot = Title::newFromURL( $this->oldTitle );
+ if( is_null( $ot ) ) {
+ $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
return;
}
- $ot = Title::newFromURL( $this->oldTitle );
+ $sk = $wgUser->getSkin();
+
+ $oldTitleLink = $sk->makeLinkObj( $ot );
$oldTitle = $ot->getPrefixedText();
-
- $encOldTitle = htmlspecialchars( $this->oldTitle );
+
+ $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
+ $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
+
if( $this->newTitle == '' ) {
# Show the current title as a default
# when the form is first opened.
- $encNewTitle = $oldTitle;
+ $newTitle = $oldTitle;
} else {
- $nt = Title::newFromURL( $this->newTitle );
- if ( $nt ) {
- // Check if it's valid
- if ( !$nt->isValidMoveTarget( $ot ) ) {
- $err = 'articleexists';
+ if( $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 = $ot->isValidMoveOperation( $nt );
+ if( is_string( $newerr ) ) {
+ $err = $newerr;
+ }
}
- $encNewTitle = htmlspecialchars( $this->newTitle );
- } else {
- $encNewTitle = $oldTitle;
}
+ $newTitle = $this->newTitle;
}
- $encReason = htmlspecialchars( $this->reason );
if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
- $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
+ $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
$movepagebtn = wfMsg( 'delete_and_move' );
$submitVar = 'wpDeleteAndMove';
+ $confirm = "
+ <tr>
+ <td></td>
+ <td class='mw-input'>" .
+ Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
+ "</td>
+ </tr>";
$err = '';
} else {
- $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
+ $wgOut->addWikiMsg( 'movepagetext' );
$movepagebtn = wfMsg( 'movepagebtn' );
$submitVar = 'wpMove';
+ $confirm = false;
}
- if ( !$ot->isTalkPage() ) {
- $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
- }
+ $oldTalk = $ot->getTalkPage();
+ $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
- $movearticle = wfMsg( 'movearticle' );
- $newtitle = wfMsg( 'newtitle' );
- $movetalk = wfMsg( 'movetalk' );
- $movereason = wfMsg( 'movereason' );
+ if ( $considerTalk ) {
+ $wgOut->addWikiMsg( 'movepagetalktext' );
+ }
- $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
- $action = $titleObj->escapeLocalURL( 'action=submit' );
+ $titleObj = SpecialPage::getTitleFor( 'Movepage' );
$token = htmlspecialchars( $wgUser->editToken() );
if ( $err != '' ) {
$wgOut->setSubtitle( wfMsg( 'formerror' ) );
- $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
+ $errMsg = "";
+ if( $err == 'hookaborted' ) {
+ $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
+ } else if (is_array($err)) {
+ $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
+ } else {
+ $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
+ }
+ $wgOut->addHTML( $errMsg );
}
- if ( $this->moveTalk ) {
- $moveTalkChecked = " checked='checked'";
- } else {
- $moveTalkChecked = '';
- }
-
- $wgOut->addHTML( "
-<form id=\"movepage\" method=\"post\" action=\"{$action}\">
- <table border='0'>
- <tr>
- <td align='right'>{$movearticle}:</td>
- <td align='left'><strong>{$oldTitle}</strong></td>
- </tr>
- <tr>
- <td align='right'>{$newtitle}:</td>
- <td align='left'>
- <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
- <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
- </td>
- </tr>
- <tr>
- <td align='right'>{$movereason}:</td>
- <td align='left'>
- <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
- </td>
- </tr>" );
-
- if ( ! $ot->isTalkPage() ) {
+ $wgOut->addHTML(
+ Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->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' ) ) .
+ "<tr>
+ <td class='mw-label'>" .
+ wfMsgHtml( 'movearticle' ) .
+ "</td>
+ <td class='mw-input'>
+ <strong>{$oldTitleLink}</strong>
+ </td>
+ </tr>
+ <tr>
+ <td class='mw-label'>" .
+ Xml::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
+ "</td>
+ <td class='mw-input'>" .
+ Xml::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
+ Xml::hidden( 'wpOldTitle', $oldTitle ) .
+ "</td>
+ </tr>
+ <tr>
+ <td class='mw-label'>" .
+ 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 ) ) .
+ "</td>
+ </tr>"
+ );
+
+ if ( $considerTalk ) {
$wgOut->addHTML( "
- <tr>
- <td align='right'>
- <input type='checkbox' name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
- </td>
- <td>{$movetalk}</td>
- </tr>" );
+ <tr>
+ <td></td>
+ <td class='mw-input'>" .
+ Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk ) .
+ "</td>
+ </tr>"
+ );
}
+
+ $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
$wgOut->addHTML( "
- <tr>
- <td> </td>
- <td align='left'>
- <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
- </td>
- </tr>
- </table>
- <input type='hidden' name='wpEditToken' value=\"{$token}\" />
-</form>\n" );
+ <tr>
+ <td></td>
+ <td class='mw-input'>" .
+ Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
+ "</td>
+ </tr>
+ {$confirm}
+ <tr>
+ <td> </td>
+ <td class='mw-submit'>" .
+ Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
+ "</td>
+ </tr>" .
+ Xml::closeElement( 'table' ) .
+ Xml::hidden( 'wpEditToken', $token ) .
+ Xml::closeElement( 'fieldset' ) .
+ Xml::closeElement( 'form' ) .
+ "\n"
+ );
+
+ $this->showLogFragment( $ot, $wgOut );
}
function doSubmit() {
- global $wgOut, $wgUser, $wgLang;
- global $wgDeferredUpdateList, $wgMessageCache;
- global $wgUseSquid, $wgRequest;
- $fname = "MovePageForm::doSubmit";
-
+ global $wgOut, $wgUser, $wgRequest;
+
+ if ( $wgUser->pingLimiter( 'move' ) ) {
+ $wgOut->rateLimited();
+ return;
+ }
+
# Variables beginning with 'o' for old article 'n' for new article
$ot = Title::newFromText( $this->oldTitle );
# Delete to make way if requested
if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
$article = new Article( $nt );
+
+ # Disallow deletions of big articles
+ $bigHistory = $article->isBigDeletion();
+ if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
+ global $wgLang, $wgDeleteRevisionsLimit;
+ $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
+ return;
+ }
+
// This may output an error message and exit
$article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
}
return;
}
+ $hookErr = null;
+ if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
+ $this->showForm( 'hookaborted', $hookErr );
+ return;
+ }
+
$error = $ot->moveTo( $nt, true, $this->reason );
if ( $error !== true ) {
$this->showForm( $error );
return;
}
- # Update counters if the article got moved into or out of NS_MAIN namespace
- $ons = $ot->getNamespace();
- $nns = $nt->getNamespace();
-
- # moved out of article namespace?
- if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
- $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
- }
- # moved into article namespace?
- elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
- $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
- } else {
- $u = false;
- }
- if ( $u !== false ) {
- # save it for later update
- array_push( $wgDeferredUpdateList, $u );
- unset($u);
- }
-
- # Move talk page if
- # (1) the checkbox says to,
- # (2) the namespaces are not themselves talk namespaces, and of course
- # (3) it exists.
- if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
- ( ! Namespace::isTalk( $ons ) ) &&
- ( ! Namespace::isTalk( $nns ) ) ) {
-
- # get old talk page namespace
- $ons = Namespace::getTalk( $ons );
- # get new talk page namespace
- $nns = Namespace::getTalk( $nns );
-
- # make talk page title objects
- $ott = Title::makeTitle( $ons, $ot->getDBkey() );
- $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
-
- # Attempt the move
- $error = $ott->moveTo( $ntt, true, $this->reason );
- if ( $error === true ) {
- $talkmoved = 1;
+ wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
+
+ # 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 {
+ $talkmoved = $error;
+ }
} else {
- $talkmoved = $error;
+ # Stay silent on the subject of talk.
+ $talkmoved = '';
}
+ } else {
+ $talkmoved = 'notalkpage';
+ }
+
+ # Deal with watches
+ if( $this->watch ) {
+ $wgUser->addWatch( $ot );
+ $wgUser->addWatch( $nt );
+ } else {
+ $wgUser->removeWatch( $ot );
+ $wgUser->removeWatch( $nt );
}
-
+
# Give back result to user.
- $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
- $success = $titleObj->getFullURL(
+ $titleObj = SpecialPage::getTitleFor( 'Movepage' );
+ $success = $titleObj->getFullURL(
'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
'&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
'&talkmoved='.$talkmoved );
}
function showSuccess() {
- global $wgOut, $wgRequest, $wgRawHtml;
-
- $wgOut->setPagetitle( wfMsg( 'movepage' ) );
- $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
- $oldtitle = $wgRequest->getVal('oldtitle');
- $newtitle = $wgRequest->getVal('newtitle');
- $talkmoved = $wgRequest->getVal('talkmoved');
-
- $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
-
- # Temporarily disable raw html wikitext option out of XSS paranoia
- $marchingantofdoom = $wgRawHtml;
- $wgRawHtml = false;
- $wgOut->addWikiText( $text );
- $wgRawHtml = $marchingantofdoom;
+ 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 = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
+ $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
+
+ $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
if ( $talkmoved == 1 ) {
- $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
+ $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
} elseif( 'articleexists' == $talkmoved ) {
- $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
+ $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
} else {
- $ot = Title::newFromURL( $oldtitle );
- if ( ! $ot->isTalkPage() ) {
- $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );
+ if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
+ $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
}
}
+ $wgOut->addWikiText( $s );
}
+
+ function showLogFragment( $title, &$out ) {
+ $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) );
+ LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() );
+ }
+
}
-?>