X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialMovepage.php;h=3f0e6e10e00d62a419dac2ea1df3aa42ee1941ea;hb=144c825809748330e6a51eb862beed7ef61b0219;hp=70b15948f14efd300f59a4af2351e18c02765efe;hpb=a0b5676996e84f2916d32ba684fecf4f024a4899;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index 70b15948f1..3f0e6e10e0 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -1,93 +1,107 @@ readOnlyPage(); - return; + private $watch = false; + + public function __construct() { + parent::__construct( 'Movepage' ); } - $target = isset( $par ) ? $par : $wgRequest->getVal( 'target' ); - $oldTitleText = $wgRequest->getText( 'wpOldTitle', $target ); - $newTitleText = $wgRequest->getText( 'wpNewTitle' ); + public function execute( $par ) { + global $wgUser, $wgOut, $wgRequest; - $oldTitle = Title::newFromText( $oldTitleText ); - $newTitle = Title::newFromText( $newTitleText ); + # Check for database lock + if ( wfReadOnly() ) { + $wgOut->readOnlyPage(); + return; + } - if( is_null( $oldTitle ) ) { - $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); - return; - } - if( !$oldTitle->exists() ) { - $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' ); - return; - } + $this->setHeaders(); + $this->outputHeader(); - # Check rights - $permErrors = $oldTitle->getUserPermissionsErrors( 'move', $wgUser ); - if( !empty( $permErrors ) ) { - $wgOut->showPermissionsErrorPage( $permErrors ); - return; - } + $target = !is_null( $par ) ? $par : $wgRequest->getVal( 'target' ); - $form = new MovePageForm( $oldTitle, $newTitle ); + // Yes, the use of getVal() and getText() is wanted, see bug 20365 + $oldTitleText = $wgRequest->getVal( 'wpOldTitle', $target ); + $newTitleText = $wgRequest->getText( 'wpNewTitle' ); - if ( 'submit' == $action && $wgRequest->wasPosted() - && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { - $form->doSubmit(); - } else { - $form->showForm( '' ); - } -} + $this->oldTitle = Title::newFromText( $oldTitleText ); + $this->newTitle = Title::newFromText( $newTitleText ); -/** - * HTML form for Special:Movepage - * @ingroup SpecialPage - */ -class MovePageForm { - var $oldTitle, $newTitle; # Objects - var $reason; # Text input - var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect; # Checks + if( is_null( $this->oldTitle ) ) { + $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); + return; + } + if( !$this->oldTitle->exists() ) { + $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' ); + return; + } - private $watch = false; + # Check rights + $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $wgUser ); + if( !empty( $permErrors ) ) { + $wgOut->showPermissionsErrorPage( $permErrors ); + return; + } + + $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->watch = $wgRequest->getCheck( 'wpWatch' ); + $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 + * + * @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, $wgFixDoubleRedirects; + global $wgOut, $wgUser, $wgContLang, $wgFixDoubleRedirects; $skin = $wgUser->getSkin(); @@ -128,12 +142,21 @@ class MovePageForm { "; $err = ''; } else { + if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) { + $wgOut->wrapWikiMsg( "
\n$1\n
", 'moveuserpage-warning' ); + } $wgOut->addWikiMsg( 'movepagetext' ); $movepagebtn = wfMsg( 'movepagebtn' ); $submitVar = 'wpMove'; $confirm = false; } + if ( !empty($err) && $err[0] == 'file-exists-sharedrepo' && $wgUser->isAllowed( 'reupload-shared' ) ) { + $wgOut->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() ); + $submitVar = 'wpMoveOverSharedFile'; + $err = ''; + } + $oldTalk = $this->oldTitle->getTalkPage(); $considerTalk = ( !$this->oldTitle->isTalkPage() && $oldTalk->exists() ); @@ -152,7 +175,6 @@ class MovePageForm { $wgOut->addWikiMsg( 'movepagetalktext' ); } - $titleObj = SpecialPage::getTitleFor( 'Movepage' ); $token = htmlspecialchars( $wgUser->editToken() ); if ( !empty($err) ) { @@ -162,7 +184,7 @@ class MovePageForm { $errMsg = "

$hookErr

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

$1

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

\n$1\n

", $err ); } } @@ -178,12 +200,12 @@ class MovePageForm { } $wgOut->addHTML( "
\n" ); $wgOut->addWikiMsg( $noticeMsg ); - LogEventsList::showLogExtract( $wgOut, 'protect', $this->oldTitle->getPrefixedText(), '', 1 ); + LogEventsList::showLogExtract( $wgOut, 'protect', $this->oldTitle->getPrefixedText(), '', array( 'lim' => 1 ) ); $wgOut->addHTML( "
\n" ); } $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' ) ) . @@ -200,7 +222,7 @@ class MovePageForm { Xml::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) . " " . - Xml::input( 'wpNewTitle', 40, $newTitle->getPrefixedText(), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) . + Xml::input( 'wpNewTitle', 40, $wgContLang->recodeForEdit( $newTitle->getPrefixedText() ), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) . Xml::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) . " @@ -209,7 +231,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 ) . " " ); @@ -258,37 +281,46 @@ class MovePageForm { " . - Xml::checkLabel( wfMsgExt( + 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( 'parsemag' ), + array( 'parseinline' ), $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 - # move and we aren't moving the talk page. - $this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk) + ) ) . " " ); } - $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) - || $this->oldTitle->userIsWatching(); - $wgOut->addHTML( " + $watchChecked = $wgUser->isLoggedIn() && ($this->watch || $wgUser->getBoolOption( 'watchmoves' ) + || $this->oldTitle->userIsWatching()); + # Don't allow watching if user is not logged in + if( $wgUser->isLoggedIn() ) { + $wgOut->addHTML( " " . Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) . " - + "); + } + + $wgOut->addHTML( " {$confirm} -   +   " . Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) . " @@ -306,7 +338,7 @@ class MovePageForm { } function doSubmit() { - global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang; + global $wgOut, $wgUser, $wgMaximumMovedPages, $wgLang; global $wgFixDoubleRedirects; if ( $wgUser->pingLimiter( 'move' ) ) { @@ -324,7 +356,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; } @@ -345,12 +377,24 @@ class MovePageForm { return; } + # Show a warning if the target file exists on a shared repo + if ( $nt->getNamespace() == NS_FILE + && !( $this->moveOverShared && $wgUser->isAllowed( 'reupload-shared' ) ) + && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt ) + && wfFindFile( $nt ) ) + { + $this->showForm( array('file-exists-sharedrepo') ); + return; + + } + if ( $wgUser->isAllowed( 'suppressredirect' ) ) { $createRedirect = $this->leaveRedirect; } else { $createRedirect = true; } + # Do the actual move. $error = $ot->moveTo( $nt, true, $this->reason, $createRedirect ); if ( $error !== true ) { # FIXME: show all the errors in a list, not just the first one @@ -409,7 +453,7 @@ class MovePageForm { ) ) ) { $conds = array( - 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' ) + 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() ) .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() ) ); $conds['page_namespace'] = array(); @@ -444,14 +488,14 @@ class MovePageForm { $skin = $wgUser->getSkin(); $count = 1; foreach( $extraPages as $oldSubpage ) { - if( $oldSubpage->getArticleId() == $ot->getArticleId() ) { + if( $ot->equals( $oldSubpage ) ) { # Already did this one. continue; } $newPageName = preg_replace( '#^'.preg_quote( $ot->getDBkey(), '#' ).'#', - $nt->getDBkey(), + StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234 $oldSubpage->getDBkey() ); if( $oldSubpage->isTalkPage() ) { @@ -487,6 +531,11 @@ class MovePageForm { ); $newLink = $skin->linkKnown( $newSubpage ); $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink ); + ++$count; + if( $count >= $wgMaximumMovedPages ) { + $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) ); + break; + } } else { $oldLink = $skin->linkKnown( $oldSubpage ); $newLink = $skin->link( $newSubpage ); @@ -494,11 +543,6 @@ class MovePageForm { } } - ++$count; - if( $count >= $wgMaximumMovedPages ) { - $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) ); - break; - } } if( $extraOutput !== array() ) { @@ -506,17 +550,24 @@ class MovePageForm { } # Deal with watches (we don't watch subpages) - if( $this->watch ) { + if( $this->watch && $wgUser->isLoggedIn() ) { $wgUser->addWatch( $ot ); $wgUser->addWatch( $nt ); } else { $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() ); }