r20154 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20153‎ | r20154 | r20155 >
Date:20:58, 5 March 2007
Author:brion
Status:old
Tags:
Comment:
Fix PHP fatal error when doing 'undo' on a revision which exists but has no predecessors.
Failure of sanity checks for undo now shows warning instead of silent ignore.
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -102,11 +102,14 @@
103103 #Undoing a specific edit overrides section editing; section-editing
104104 # doesn't work with undoing.
105105 $undorev = Revision::newFromId($undo);
 106+ $oldrev = $undorev ? $undorev->getPrevious() : null;
106107
107108 #Sanity check, make sure it's the right page.
108109 # Otherwise, $text will be left as-is.
109 - if (!is_null($undorev) && $undorev->getPage() == $this->mArticle->getID()) {
110 - $oldrev = $undorev->getPrevious();
 110+ if( !is_null($undorev)
 111+ && !is_null( $oldrev )
 112+ && $undorev->getPage() == $this->mArticle->getID() ) {
 113+
111114 $undorev_text = $undorev->getText();
112115 $oldrev_text = $oldrev->getText();
113116 $currev_text = $text;
@@ -118,17 +121,21 @@
119122 $text = $oldrev_text;
120123 $result = true;
121124 }
 125+ } else {
 126+ // Failed basic sanity checks.
 127+ // Older revisions may have been removed since the link
 128+ // was created, or we may simply have got bogus input.
 129+ $result = false;
 130+ }
122131
123 - if( $result ) {
124 - # Inform the user of our success and set an automatic edit summary
125 - $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
126 - $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
127 - $this->formtype = 'diff';
128 - } else {
129 - # Warn the user that something went wrong
130 - $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
131 - }
132 -
 132+ if( $result ) {
 133+ # Inform the user of our success and set an automatic edit summary
 134+ $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-success' ) );
 135+ $this->summary = wfMsgForContent( 'undo-summary', $undo, $undorev->getUserText() );
 136+ $this->formtype = 'diff';
 137+ } else {
 138+ # Warn the user that something went wrong
 139+ $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) );
133140 }
134141 }
135142 else if( $section != '' ) {