X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialMovepage.php;h=dbed975ad1caee596b67473aa989480ac97fb1f6;hb=90c703d61c485c633b214f78f48102c2848b82d8;hp=596b62b2d09a51ab51f61a46f8e7c74515428e28;hpb=4a099928f73222b2c92c6bc66384649f3022def1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 596b62b2d0..dbed975ad1 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -1,93 +1,104 @@ readOnlyPage(); - return; + public function __construct() { + parent::__construct( 'Movepage' ); } - $target = isset( $par ) ? $par : $wgRequest->getVal( 'target' ); + public function execute( $par ) { + global $wgUser, $wgOut, $wgRequest; - // Yes, the use of getVal() and getText() is wanted, see bug 20365 - $oldTitleText = $wgRequest->getVal( 'wpOldTitle', $target ); - $newTitleText = $wgRequest->getText( 'wpNewTitle' ); + # Check for database lock + if ( wfReadOnly() ) { + $wgOut->readOnlyPage(); + return; + } - $oldTitle = Title::newFromText( $oldTitleText ); - $newTitle = Title::newFromText( $newTitleText ); + $this->setHeaders(); + $this->outputHeader(); - if( is_null( $oldTitle ) ) { - $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); - return; - } - if( !$oldTitle->exists() ) { - $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' ); - return; - } + $target = !is_null( $par ) ? $par : $wgRequest->getVal( 'target' ); - # Check rights - $permErrors = $oldTitle->getUserPermissionsErrors( 'move', $wgUser ); - if( !empty( $permErrors ) ) { - $wgOut->showPermissionsErrorPage( $permErrors ); - return; - } + // Yes, the use of getVal() and getText() is wanted, see bug 20365 + $oldTitleText = $wgRequest->getVal( 'wpOldTitle', $target ); + $newTitleText = $wgRequest->getText( 'wpNewTitle' ); - $form = new MovePageForm( $oldTitle, $newTitle ); + $this->oldTitle = Title::newFromText( $oldTitleText ); + $this->newTitle = Title::newFromText( $newTitleText ); - if ( 'submit' == $action && $wgRequest->wasPosted() - && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { - $form->doSubmit(); - } else { - $form->showForm( '' ); - } -} + if( is_null( $this->oldTitle ) ) { + $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); + return; + } + if( !$this->oldTitle->exists() ) { + $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' ); + return; + } -/** - * HTML form for Special:Movepage - * @ingroup SpecialPage - */ -class MovePageForm { - var $oldTitle, $newTitle; # Objects - var $reason; # Text input - var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks + # Check rights + $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $wgUser ); + if( !empty( $permErrors ) ) { + $wgOut->showPermissionsErrorPage( $permErrors ); + return; + } - private $watch = false; + $def = !$wgRequest->wasPosted(); - function __construct( $oldTitle, $newTitle ) { - global $wgRequest; - $target = isset($par) ? $par : $wgRequest->getVal( 'target' ); - $this->oldTitle = $oldTitle; - $this->newTitle = $newTitle; $this->reason = $wgRequest->getText( 'wpReason' ); - 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->moveTalk = $wgRequest->getBool( 'wpMovetalk', $def ); + $this->fixRedirects = $wgRequest->getBool( 'wpFixRedirects', $def ); + $this->leaveRedirect = $wgRequest->getBool( 'wpLeaveRedirect', $def ); $this->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false ); $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' ); $this->moveOverShared = $wgRequest->getBool( 'wpMoveOverSharedFile', false ); $this->watch = $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn(); + + if ( 'submit' == $wgRequest->getVal( 'action' ) && $wgRequest->wasPosted() + && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { + $this->doSubmit(); + } else { + $this->showForm( '' ); + } } /** * 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(). + * + * @param $err Mixed: 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, $wgContLang, $wgFixDoubleRedirects; @@ -97,7 +108,7 @@ class MovePageForm { $oldTitleLink = $skin->link( $this->oldTitle ); $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle->getPrefixedText() ) ); - $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) ); + $skin->setRelevantTitle( $this->oldTitle ); $newTitle = $this->newTitle; @@ -131,7 +142,11 @@ class MovePageForm { "; $err = ''; } else { - $wgOut->addWikiMsg( 'movepagetext' ); + if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) { + $wgOut->wrapWikiMsg( "
\n$1\n
", 'moveuserpage-warning' ); + } + $wgOut->addWikiMsg( $wgFixDoubleRedirects ? 'movepagetext' : + 'movepagetext-noredirectfixer' ); $movepagebtn = wfMsg( 'movepagebtn' ); $submitVar = 'wpMove'; $confirm = false; @@ -142,14 +157,14 @@ class MovePageForm { $submitVar = 'wpMoveOverSharedFile'; $err = ''; } - + $oldTalk = $this->oldTitle->getTalkPage(); $considerTalk = ( !$this->oldTitle->isTalkPage() && $oldTalk->exists() ); $dbr = wfGetDB( DB_SLAVE ); if ( $wgFixDoubleRedirects ) { - $hasRedirects = $dbr->selectField( 'redirect', '1', - array( + $hasRedirects = $dbr->selectField( 'redirect', '1', + array( 'rd_namespace' => $this->oldTitle->getNamespace(), 'rd_title' => $this->oldTitle->getDBkey(), ) , __METHOD__ ); @@ -161,7 +176,6 @@ class MovePageForm { $wgOut->addWikiMsg( 'movepagetalktext' ); } - $titleObj = SpecialPage::getTitleFor( 'Movepage' ); $token = htmlspecialchars( $wgUser->editToken() ); if ( !empty($err) ) { @@ -171,7 +185,7 @@ class MovePageForm { $errMsg = "

$hookErr

\n"; $wgOut->addHTML( $errMsg ); } else { - $wgOut->wrapWikiMsg( '

$1

', $err ); + $wgOut->wrapWikiMsg( "

\n$1\n

", $err ); } } @@ -192,7 +206,7 @@ class MovePageForm { } $wgOut->addHTML( - Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) . + 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' ) ) . @@ -210,7 +224,7 @@ class MovePageForm { " " . Xml::input( 'wpNewTitle', 40, $wgContLang->recodeForEdit( $newTitle->getPrefixedText() ), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) . - Xml::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) . + Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) . " @@ -218,7 +232,8 @@ class MovePageForm { Xml::label( wfMsg( 'movereason' ), 'wpReason' ) . " " . - 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 ) . " " ); @@ -239,7 +254,7 @@ class MovePageForm { " . - Xml::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect', + Xml::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect', 'wpLeaveRedirect', $this->leaveRedirect ) . " " @@ -251,7 +266,7 @@ class MovePageForm { " . - Xml::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects', + Xml::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects', 'wpFixRedirects', $this->fixRedirects ) . " " @@ -273,7 +288,7 @@ class MovePageForm { # 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() @@ -290,7 +305,7 @@ class MovePageForm { ); } - $watchChecked = $wgUser->isLoggedIn() && ($this->watch || $wgUser->getBoolOption( 'watchmoves' ) + $watchChecked = $wgUser->isLoggedIn() && ($this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $this->oldTitle->userIsWatching()); # Don't allow watching if user is not logged in if( $wgUser->isLoggedIn() ) { @@ -303,16 +318,16 @@ class MovePageForm { "); } - $wgOut->addHTML( " + $wgOut->addHTML( " {$confirm} -   +   " . Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) . " " . Xml::closeElement( 'table' ) . - Xml::hidden( 'wpEditToken', $token ) . + Html::hidden( 'wpEditToken', $token ) . Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ) . "\n" @@ -324,7 +339,7 @@ class MovePageForm { } function doSubmit() { - global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang; + global $wgOut, $wgUser, $wgMaximumMovedPages, $wgLang; global $wgFixDoubleRedirects; if ( $wgUser->pingLimiter( 'move' ) ) { @@ -342,7 +357,7 @@ class MovePageForm { # Disallow deletions of big articles $bigHistory = $article->isBigDeletion(); if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) { - global $wgLang, $wgDeleteRevisionsLimit; + global $wgDeleteRevisionsLimit; $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) ); return; } @@ -364,16 +379,16 @@ class MovePageForm { } # Show a warning if the target file exists on a shared repo - if ( $nt->getNamespace() == NS_FILE + if ( $nt->getNamespace() == NS_FILE && !( $this->moveOverShared && $wgUser->isAllowed( 'reupload-shared' ) ) - && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt ) + && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt ) && wfFindFile( $nt ) ) { $this->showForm( array('file-exists-sharedrepo') ); return; - + } - + if ( $wgUser->isAllowed( 'suppressredirect' ) ) { $createRedirect = $this->leaveRedirect; } else { @@ -429,7 +444,7 @@ 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 && ( @@ -481,7 +496,7 @@ class MovePageForm { $newPageName = preg_replace( '#^'.preg_quote( $ot->getDBkey(), '#' ).'#', - str_replace( '\\', '\\\\', $nt->getDBkey() ), # bug 21234 + StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234 $oldSubpage->getDBkey() ); if( $oldSubpage->isTalkPage() ) { @@ -543,10 +558,17 @@ class MovePageForm { $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() ); }