Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -102,11 +102,14 @@ |
103 | 103 | #Undoing a specific edit overrides section editing; section-editing |
104 | 104 | # doesn't work with undoing. |
105 | 105 | $undorev = Revision::newFromId($undo); |
| 106 | + $oldrev = $undorev ? $undorev->getPrevious() : null; |
106 | 107 | |
107 | 108 | #Sanity check, make sure it's the right page. |
108 | 109 | # 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 | + |
111 | 114 | $undorev_text = $undorev->getText(); |
112 | 115 | $oldrev_text = $oldrev->getText(); |
113 | 116 | $currev_text = $text; |
— | — | @@ -118,17 +121,21 @@ |
119 | 122 | $text = $oldrev_text; |
120 | 123 | $result = true; |
121 | 124 | } |
| 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 | + } |
122 | 131 | |
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' ) ); |
133 | 140 | } |
134 | 141 | } |
135 | 142 | else if( $section != '' ) { |