r20317 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20316‎ | r20317 | r20318 >
Date:23:03, 10 March 2007
Author:aaron
Status:old
Tags:
Comment:
* Enable multi-edit undo (bug 8133)
Modified paths:
  • /trunk/phase3/includes/DifferenceEngine.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -73,7 +73,8 @@
7474 # Get variables from query string :P
7575 $section = $wgRequest->getVal( 'section' );
7676 $preload = $wgRequest->getVal( 'preload' );
77 - $undo = $wgRequest->getVal( 'undo' );
 77+ $undoafter = $wgRequest->getVal( 'undoafter' );
 78+ $undoto = $wgRequest->getVal( 'undoto' );
7879
7980 wfProfileIn( __METHOD__ );
8081
@@ -98,24 +99,21 @@
99100
100101 $text = $this->mArticle->getContent();
101102
102 - if ( $undo > 0 ) {
 103+ if ( $undoafter > 0 && $undoto > $undoafter ) {
103104 #Undoing a specific edit overrides section editing; section-editing
104105 # doesn't work with undoing.
105 - $undorev = Revision::newFromId($undo);
106 - $oldrev = $undorev ? $undorev->getPrevious() : null;
 106+ $undorev = Revision::newFromId($undoto);
 107+ $oldrev = Revision::newFromId($undoafter);
107108
108109 #Sanity check, make sure it's the right page.
109110 # Otherwise, $text will be left as-is.
110 - if( !is_null($undorev)
111 - && !is_null( $oldrev )
112 - && $undorev->getPage() == $this->mArticle->getID() ) {
113 -
 111+ if ( !is_null($undorev) && !is_null($oldrev) && $undorev->getPage()==$oldrev->getPage() && $undorev->getPage()==$this->mArticle->getID() ) {
114112 $undorev_text = $undorev->getText();
115 - $oldrev_text = $oldrev->getText();
116 - $currev_text = $text;
 113+ $oldrev_text = $oldrev->getText();
 114+ $currev_text = $text;
117115
118116 #No use doing a merge if it's just a straight revert.
119 - if ($currev_text != $undorev_text) {
 117+ if ( $currev_text != $undorev_text ) {
120118 $result = wfMerge($undorev_text, $oldrev_text, $currev_text, $text);
121119 } else {
122120 $text = $oldrev_text;
@@ -131,21 +129,24 @@
132130 if( $result ) {
133131 # Inform the user of our success and set an automatic edit summary
134132 $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
135 - $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
 133+ $firstrev = $oldrev->getNext();
 134+ # If we just undid one rev, use an autosummary
 135+ if ( $firstrev->mId == $undoto ) {
 136+ $this->summary = wfMsgForContent('undo-summary', $undoto, $undorev->getUserText());
 137+ }
136138 $this->formtype = 'diff';
137139 } else {
138140 # Warn the user that something went wrong
139141 $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
140142 }
 143+ } else if( $section != '' ) {
 144+ if( $section == 'new' ) {
 145+ $text = $this->getPreloadedText( $preload );
 146+ } else {
 147+ $text = $wgParser->getSection( $text, $section );
141148 }
142 - else if( $section != '' ) {
143 - if( $section == 'new' ) {
144 - $text = $this->getPreloadedText( $preload );
145 - } else {
146 - $text = $wgParser->getSection( $text, $section );
147 - }
148 - }
149149 }
 150+ }
150151
151152 wfProfileOut( __METHOD__ );
152153 return $text;
Index: trunk/phase3/includes/DifferenceEngine.php
@@ -546,21 +546,17 @@
547547 $newLink = $this->mNewPage->escapeLocalUrl();
548548 $this->mPagetitle = htmlspecialchars( wfMsg( 'currentrev' ) );
549549 $newEdit = $this->mNewPage->escapeLocalUrl( 'action=edit' );
550 - $newUndo = $this->mNewPage->escapeLocalUrl( 'action=edit&undo=' . $this->mNewid );
551550
552551 $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a> ($timestamp)"
553 - . " (<a href='$newEdit'>" . htmlspecialchars( wfMsg( 'editold' ) ) . "</a>)"
554 - . " (<a href='$newUndo'>" . htmlspecialchars( wfMsg( 'editundo' ) ) . "</a>)";
 552+ . " (<a href='$newEdit'>" . htmlspecialchars( wfMsg( 'editold' ) ) . "</a>)";
555553
556554 } else {
557555 $newLink = $this->mNewPage->escapeLocalUrl( 'oldid=' . $this->mNewid );
558556 $newEdit = $this->mNewPage->escapeLocalUrl( 'action=edit&oldid=' . $this->mNewid );
559 - $newUndo = $this->mNewPage->escapeLocalUrl( 'action=edit&undo=' . $this->mNewid );
560557 $this->mPagetitle = htmlspecialchars( wfMsg( 'revisionasof', $timestamp ) );
561558
562559 $this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>"
563 - . " (<a href='$newEdit'>" . htmlspecialchars( wfMsg( 'editold' ) ) . "</a>)"
564 - . " (<a href='$newUndo'>" . htmlspecialchars( wfMsg( 'editundo' ) ) . "</a>)";
 560+ . " (<a href='$newEdit'>" . htmlspecialchars( wfMsg( 'editold' ) ) . "</a>)";
565561 }
566562
567563 // Load the old revision object
@@ -591,6 +587,9 @@
592588 $oldEdit = $this->mOldPage->escapeLocalUrl( 'action=edit&oldid=' . $this->mOldid );
593589 $this->mOldtitle = "<a href='$oldLink'>" . htmlspecialchars( wfMsg( 'revisionasof', $t ) )
594590 . "</a> (<a href='$oldEdit'>" . htmlspecialchars( wfMsg( 'editold' ) ) . "</a>)";
 591+ //now that we considered old rev, we can make undo link (bug 8133, multi-edit undo)
 592+ $newUndo = $this->mNewPage->escapeLocalUrl( 'action=edit&undoafter=' . $this->mOldid . '&undoto=' . $this->mNewid);
 593+ $this->mNewtitle .= " (<a href='$newUndo'>" . htmlspecialchars( wfMsg( 'editundo' ) ) . "</a>)";
595594 }
596595
597596 return true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r20755Revert r20317 for the moment; incompatible changes to URL parameters for undobrion21:30, 27 March 2007
r20785*Re-add r20317 with support for older URL param, rename "undoto" to just "undo"aaron19:41, 28 March 2007