X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialMovepage.php;h=fb66e311467a99db6d237bbdaf8bc3722e445ff4;hb=0ea2bcdbeaa453f00324c14f90b71f545e1d706c;hp=08c39d9b8e6e950b3a3dd9f284ab42d7d227f511;hpb=8f8bdca420e69925375edb1777cfca28a9d8b16c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SpecialMovepage.php b/includes/SpecialMovepage.php index 08c39d9b8e..fb66e31146 100644 --- a/includes/SpecialMovepage.php +++ b/includes/SpecialMovepage.php @@ -13,11 +13,11 @@ require_once( "LinksUpdate.php" ); /** * Constructor */ -function wfSpecialMovepage() { +function wfSpecialMovepage( $par = null ) { global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove; # check rights. We don't want newbies to move pages to prevents possible attack - if ( 0 == $wgUser->getID() or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) { + if ( $wgUser->isAnon() or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) { $wgOut->errorpage( "movenologin", "movenologintext" ); return; } @@ -27,11 +27,16 @@ function wfSpecialMovepage() { return; } - $f = new MovePageForm(); + $f = new MovePageForm( $par ); - if ( 'success' == $action ) { $f->showSuccess(); } - else if ( 'submit' == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); } - else { $f->showForm( '' ); } + if ( 'success' == $action ) { + $f->showSuccess(); + } else if ( 'submit' == $action && $wgRequest->wasPosted() + && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) { + $f->doSubmit(); + } else { + $f->showForm( '' ); + } } /** @@ -40,12 +45,17 @@ function wfSpecialMovepage() { * @subpackage SpecialPage */ class MovePageForm { - var $oldTitle, $newTitle; # Text input + var $oldTitle, $newTitle, $reason; # Text input + var $moveTalk, $deleteAndMove; - function MovePageForm() { + 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' ); } function showForm( $err ) { @@ -53,60 +63,92 @@ class MovePageForm { $wgOut->setPagetitle( wfMsg( 'movepage' ) ); - if ( $this->oldTitle == '' ) { + $ot = Title::newFromURL( $this->oldTitle ); + if( is_null( $ot ) ) { $wgOut->errorpage( 'notargettitle', 'notargettext' ); return; } - - $ot = Title::newFromURL( $this->oldTitle ); - $ott = $ot->getPrefixedText(); + $oldTitle = $ot->getPrefixedText(); - $encOldTitle = htmlspecialchars( $this->oldTitle ); + $encOldTitle = htmlspecialchars( $oldTitle ); if( $this->newTitle == '' ) { # Show the current title as a default # when the form is first opened. - $encNewTitle = $ott; + $encNewTitle = $encOldTitle; } else { + 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 ); } + $encReason = htmlspecialchars( $this->reason ); - $wgOut->addWikiText( wfMsg( 'movepagetext' ) ); - if ( ! Namespace::isTalk( $ot->getNamespace() ) ) { + if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) { + $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) ); + $movepagebtn = wfMsgHtml( 'delete_and_move' ); + $submitVar = 'wpDeleteAndMove'; + $err = ''; + } else { + $wgOut->addWikiText( wfMsg( 'movepagetext' ) ); + $movepagebtn = wfMsgHtml( 'movepagebtn' ); + $submitVar = 'wpMove'; + } + + if ( !$ot->isTalkPage() ) { $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) ); } - $ma = wfMsg( 'movearticle' ); - $newt = wfMsg( 'newtitle' ); - $mpb = wfMsg( 'movepagebtn' ); - $movetalk = wfMsg( 'movetalk' ); + $movearticle = wfMsgHtml( 'movearticle' ); + $newtitle = wfMsgHtml( 'newtitle' ); + $movetalk = wfMsgHtml( 'movetalk' ); + $movereason = wfMsgHtml( 'movereason' ); $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' ); $action = $titleObj->escapeLocalURL( 'action=submit' ); + $token = htmlspecialchars( $wgUser->editToken() ); if ( $err != '' ) { $wgOut->setSubtitle( wfMsg( 'formerror' ) ); - $wgOut->addHTML( '

'.$err."

\n" ); + $wgOut->addWikiText( '

' . wfMsg($err) . "

\n" ); } + + $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : ''; + $wgOut->addHTML( "
- - + + - + + + + + " ); - if ( ! Namespace::isTalk( $ot->getNamespace() ) ) { + if ( ! $ot->isTalkPage() ) { $wgOut->addHTML( " " ); @@ -115,10 +157,11 @@ class MovePageForm {
{$ma}:{$ott}{$movearticle}:{$oldTitle}
{$newt}:{$newtitle}:
{$movereason}: + +
- + {$movetalk}
  - +
+
\n" ); } @@ -129,43 +172,34 @@ class MovePageForm { global $wgUseSquid, $wgRequest; $fname = "MovePageForm::doSubmit"; + if ( $wgUser->pingLimiter( 'move' ) ) { + $wgOut->rateLimited(); + return; + } + # Variables beginning with 'o' for old article 'n' for new article - # Attempt to move the article $ot = Title::newFromText( $this->oldTitle ); $nt = Title::newFromText( $this->newTitle ); + # Delete to make way if requested + if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) { + $article = new Article( $nt ); + // This may output an error message and exit + $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) ); + } + # don't allow moving to pages with # in if ( !$nt || $nt->getFragment() != '' ) { - $this->showForm( wfMsg( "badtitletext" ) ); + $this->showForm( 'badtitletext' ); return; } - $error = $ot->moveTo( $nt ); + $error = $ot->moveTo( $nt, true, $this->reason ); if ( $error !== true ) { - $this->showForm( wfMsg( $error ) ); + $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, @@ -185,12 +219,15 @@ class MovePageForm { $ntt = Title::makeTitle( $nns, $nt->getDBkey() ); # Attempt the move - $error = $ott->moveTo( $ntt ); + $error = $ott->moveTo( $ntt, true, $this->reason ); if ( $error === true ) { $talkmoved = 1; } else { $talkmoved = $error; } + } else { + # Stay silent on the subject of talk. + $talkmoved = ''; } # Give back result to user. @@ -204,7 +241,7 @@ class MovePageForm { } function showSuccess() { - global $wgOut, $wgUser, $wgRequest, $wgRawHtml; + global $wgOut, $wgRequest, $wgRawHtml; $wgOut->setPagetitle( wfMsg( 'movepage' ) ); $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) ); @@ -221,13 +258,13 @@ class MovePageForm { $wgRawHtml = $marchingantofdoom; if ( $talkmoved == 1 ) { - $wgOut->addHTML( "\n

" . wfMsg( 'talkpagemoved' ) . "

\n" ); + $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) ); } elseif( 'articleexists' == $talkmoved ) { - $wgOut->addHTML( "\n

" . wfMsg( 'talkexists' ) . "

\n" ); + $wgOut->addWikiText( wfMsg( 'talkexists' ) ); } else { $ot = Title::newFromURL( $oldtitle ); - if ( ! Namespace::isTalk( $ot->getNamespace() ) ) { - $wgOut->addHTML( "\n

" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "

\n" ); + if ( ! $ot->isTalkPage() ) { + $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) ); } } }