From: Brion Vibber Date: Mon, 5 Mar 2007 20:58:17 +0000 (+0000) Subject: Fix PHP fatal error when doing 'undo' on a revision which exists but has no predecessors. X-Git-Tag: 1.31.0-rc.0~53902 X-Git-Url: http://git.cyclocoop.org/%22.%24redirect_annul.%22?a=commitdiff_plain;h=27d0fcc43f28b25b9096846a702a6756d6cbb028;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/includes/EditPage.php b/includes/EditPage.php index f10d1ea037..1c16dc2b5e 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -102,11 +102,14 @@ class EditPage { #Undoing a specific edit overrides section editing; section-editing # doesn't work with undoing. $undorev = Revision::newFromId($undo); + $oldrev = $undorev ? $undorev->getPrevious() : null; #Sanity check, make sure it's the right page. # Otherwise, $text will be left as-is. - if (!is_null($undorev) && $undorev->getPage() == $this->mArticle->getID()) { - $oldrev = $undorev->getPrevious(); + if( !is_null($undorev) + && !is_null( $oldrev ) + && $undorev->getPage() == $this->mArticle->getID() ) { + $undorev_text = $undorev->getText(); $oldrev_text = $oldrev->getText(); $currev_text = $text; @@ -118,17 +121,21 @@ class EditPage { $text = $oldrev_text; $result = true; } + } else { + // Failed basic sanity checks. + // Older revisions may have been removed since the link + // was created, or we may simply have got bogus input. + $result = false; + } - 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() ); - $this->formtype = 'diff'; - } else { - # Warn the user that something went wrong - $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) ); - } - + 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() ); + $this->formtype = 'diff'; + } else { + # Warn the user that something went wrong + $this->editFormPageTop .= $wgOut->parse( wfMsgNoTrans( 'undo-failure' ) ); } } else if( $section != '' ) {