From: Aaron Schulz Date: Sat, 10 Mar 2007 23:03:24 +0000 (+0000) Subject: * Enable multi-edit undo (bug 8133) X-Git-Tag: 1.31.0-rc.0~53813 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=f35f38276b25f5bab8dcad1c435a16f86d677209;p=lhc%2Fweb%2Fwiklou.git * Enable multi-edit undo (bug 8133) --- diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index e6218b6d9c..884e82a6e0 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -546,21 +546,17 @@ CONTROL; $newLink = $this->mNewPage->escapeLocalUrl(); $this->mPagetitle = htmlspecialchars( wfMsg( 'currentrev' ) ); $newEdit = $this->mNewPage->escapeLocalUrl( 'action=edit' ); - $newUndo = $this->mNewPage->escapeLocalUrl( 'action=edit&undo=' . $this->mNewid ); $this->mNewtitle = "{$this->mPagetitle} ($timestamp)" - . " (" . htmlspecialchars( wfMsg( 'editold' ) ) . ")" - . " (" . htmlspecialchars( wfMsg( 'editundo' ) ) . ")"; + . " (" . htmlspecialchars( wfMsg( 'editold' ) ) . ")"; } else { $newLink = $this->mNewPage->escapeLocalUrl( 'oldid=' . $this->mNewid ); $newEdit = $this->mNewPage->escapeLocalUrl( 'action=edit&oldid=' . $this->mNewid ); - $newUndo = $this->mNewPage->escapeLocalUrl( 'action=edit&undo=' . $this->mNewid ); $this->mPagetitle = htmlspecialchars( wfMsg( 'revisionasof', $timestamp ) ); $this->mNewtitle = "{$this->mPagetitle}" - . " (" . htmlspecialchars( wfMsg( 'editold' ) ) . ")" - . " (" . htmlspecialchars( wfMsg( 'editundo' ) ) . ")"; + . " (" . htmlspecialchars( wfMsg( 'editold' ) ) . ")"; } // Load the old revision object @@ -591,6 +587,9 @@ CONTROL; $oldEdit = $this->mOldPage->escapeLocalUrl( 'action=edit&oldid=' . $this->mOldid ); $this->mOldtitle = "" . htmlspecialchars( wfMsg( 'revisionasof', $t ) ) . " (" . htmlspecialchars( wfMsg( 'editold' ) ) . ")"; + //now that we considered old rev, we can make undo link (bug 8133, multi-edit undo) + $newUndo = $this->mNewPage->escapeLocalUrl( 'action=edit&undoafter=' . $this->mOldid . '&undoto=' . $this->mNewid); + $this->mNewtitle .= " (" . htmlspecialchars( wfMsg( 'editundo' ) ) . ")"; } return true; diff --git a/includes/EditPage.php b/includes/EditPage.php index 1c16dc2b5e..0b9a476b00 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -73,7 +73,8 @@ class EditPage { # Get variables from query string :P $section = $wgRequest->getVal( 'section' ); $preload = $wgRequest->getVal( 'preload' ); - $undo = $wgRequest->getVal( 'undo' ); + $undoafter = $wgRequest->getVal( 'undoafter' ); + $undoto = $wgRequest->getVal( 'undoto' ); wfProfileIn( __METHOD__ ); @@ -98,24 +99,21 @@ class EditPage { $text = $this->mArticle->getContent(); - if ( $undo > 0 ) { + if ( $undoafter > 0 && $undoto > $undoafter ) { #Undoing a specific edit overrides section editing; section-editing # doesn't work with undoing. - $undorev = Revision::newFromId($undo); - $oldrev = $undorev ? $undorev->getPrevious() : null; + $undorev = Revision::newFromId($undoto); + $oldrev = Revision::newFromId($undoafter); #Sanity check, make sure it's the right page. # Otherwise, $text will be left as-is. - if( !is_null($undorev) - && !is_null( $oldrev ) - && $undorev->getPage() == $this->mArticle->getID() ) { - + if ( !is_null($undorev) && !is_null($oldrev) && $undorev->getPage()==$oldrev->getPage() && $undorev->getPage()==$this->mArticle->getID() ) { $undorev_text = $undorev->getText(); - $oldrev_text = $oldrev->getText(); - $currev_text = $text; + $oldrev_text = $oldrev->getText(); + $currev_text = $text; #No use doing a merge if it's just a straight revert. - if ($currev_text != $undorev_text) { + if ( $currev_text != $undorev_text ) { $result = wfMerge($undorev_text, $oldrev_text, $currev_text, $text); } else { $text = $oldrev_text; @@ -131,21 +129,24 @@ class EditPage { if( $result ) { # Inform the user of our success and set an automatic edit summary $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) ); - $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() ); + $firstrev = $oldrev->getNext(); + # If we just undid one rev, use an autosummary + if ( $firstrev->mId == $undoto ) { + $this->summary = wfMsgForContent('undo-summary', $undoto, $undorev->getUserText()); + } $this->formtype = 'diff'; } else { # Warn the user that something went wrong $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) ); } - } - else if( $section != '' ) { - if( $section == 'new' ) { - $text = $this->getPreloadedText( $preload ); - } else { - $text = $wgParser->getSection( $text, $section ); - } + } else if( $section != '' ) { + if( $section == 'new' ) { + $text = $this->getPreloadedText( $preload ); + } else { + $text = $wgParser->getSection( $text, $section ); } } + } wfProfileOut( __METHOD__ ); return $text;