r59455 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59454‎ | r59455 | r59456 >
Date:15:41, 26 November 2009
Author:werdna
Status:deferred
Tags:
Comment:
Handle revisions with data corruption from 65536-byte limit of BLOB fields gracefully
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/ThreadHistoryPager.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/ThreadRevision.php (modified) (history)
  • /trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/i18n/Lqt.i18n.php
@@ -55,6 +55,7 @@
5656 'lqt_hist_tooltip_older_disabled' => 'This link is disabled because you are on the last page.',
5757 'lqt_hist_split' => 'Reply split to a new thread',
5858 'lqt_hist_edited_subject' => 'Changed subject from "$2" to "$3"',
 59+ 'lqt_hist_edited_subject_corrupt' => 'Changed subject',
5960 'lqt_hist_merged_from' => '[[$1|Reply]] moved to another thread',
6061 'lqt_hist_merged_to' => '[[$1|Reply]] moved from another thread',
6162 'lqt_hist_split_from' => 'Split to a new thread',
@@ -280,6 +281,9 @@
281282
282283 'lqt-edit-bump' => 'Bump this thread',
283284 'lqt-edit-bump-tooltip' => 'Move this thread to the top of its discussion page',
 285+
 286+ 'lqt-historicalrevision-error' => 'The revision you have selected is corrupt, '.
 287+ ' and cannot be viewed.',
284288 );
285289
286290 /** Message documentation (Message documentation)
Index: trunk/extensions/LiquidThreads/classes/ThreadRevision.php
@@ -25,10 +25,14 @@
2626 $dbr = wfGetDB( DB_SLAVE );
2727 $row = $dbr->selectRow( 'thread_history', '*', array( 'th_id' => $id ), __METHOD__ );
2828
 29+ if (!$row) return null;
 30+
2931 return self::loadFromRow( $row );
3032 }
3133
3234 static function loadFromRow( $row ) {
 35+ if (!$row) return null;
 36+
3337 $rev = new ThreadRevision;
3438
3539 foreach ( self::$load as $col => $field ) {
@@ -133,13 +137,16 @@
134138 }
135139
136140 function getChangeObject() {
137 - if ( !$this->mChangeObject && $this->mChangeObjectId ) {
 141+ if ( is_null($this->mChangeObject) && $this->mChangeObjectId ) {
138142 $threadObj = $this->getThreadObj();
139 - $objectId = $this->mChangeObjectId;
140 - $this->mChangeObject = $threadObj->replyWithId( $objectId );
141143
 144+ if ( $threadObj instanceof Thread ) {
 145+ $objectId = $this->mChangeObjectId;
 146+ $this->mChangeObject = $threadObj->replyWithId( $objectId );
 147+ }
 148+
142149 if ( !$this->mChangeObject ) {
143 - $this->mChangeObject = Threads::withId( $objectId );
 150+ $this->mChangeObject = false;
144151 }
145152 }
146153
@@ -155,16 +162,16 @@
156163 }
157164
158165 function getThreadObj() {
159 - if ( !$this->mThreadObj && $this->mObjSer ) {
 166+ if ( is_null($this->mThreadObj) && !is_null($this->mObjSer) ) {
160167 $this->mThreadObj = unserialize( $this->mObjSer );
161 - } elseif ( !$this->mThreadObj ) {
 168+ } elseif ( is_null($this->mThreadObj) && is_null($this->mObjSer) ) {
 169+ var_dump($this);
162170 throw new MWException( "Missing mObjSer" );
163171 }
164172
165173 if ( !($this->mThreadObj instanceof Thread) ) {
166 - throw new MWException( "Expected mThreadObj for rev ".$this->getId().
167 - "to be a Thread, but it is actually a ".
168 - gettype($this->mThreadObj) );
 174+ $this->mThreadObj = false;
 175+ return false;
169176 }
170177
171178 $this->mThreadObj->threadRevision = $this;
Index: trunk/extensions/LiquidThreads/classes/ThreadHistoryPager.php
@@ -102,25 +102,35 @@
103103
104104 $args = array();
105105 $revision = ThreadRevision::loadFromRow( $this->mCurrentRow );
 106+ $changeObject = $revision->getChangeObject();
106107
107 - if ( $revision->getChangeObject()->title() ) {
108 - $args[] = $revision->getChangeObject()->title()->getPrefixedText();
 108+ if ( $revision && $revision->prev() ) {
 109+ $lastChangeObject = $revision->prev()->getChangeObject();
 110+ }
 111+
 112+ if ( $changeObject && $changeObject->title() ) {
 113+ $args[] = $changeObject->title()->getPrefixedText();
109114 } else {
110115 $args[] = '';
111116 }
112117
 118+ $msg = self::$change_names[$type];
 119+
113120 switch( $type ) {
114121 case Threads::CHANGE_EDITED_SUBJECT:
115 - $args[] = $revision->prev()->getChangeObject()->subject();
116 - $args[] = $revision->getChangeObject()->subject();
 122+ if ($changeObject && $lastChangeObject) {
 123+ $args[] = $lastChangeObject->subject();
 124+ $args[] = $changeObject->subject();
 125+ } else {
 126+ $msg = wfMsg( 'lqt_hist_edited_subject_corrupt', 'parseinline' );
 127+ }
117128 break;
118129 case Threads::CHANGE_EDITED_ROOT:
119130 case Threads::CHANGE_ROOT_BLANKED:
120 - $post = $revision->getChangeObject();
121131 $view = $this->view;
122132
123 - if ( $post->title() ) {
124 - $diffLink = $view->diffPermalinkURL( $post, $revision );
 133+ if ( $changeObject && $changeObject->title() ) {
 134+ $diffLink = $view->diffPermalinkURL( $changeObject, $revision );
125135 $args[] = $diffLink;
126136 } else {
127137 $args[] = '';
@@ -128,7 +138,7 @@
129139 break;
130140 }
131141
132 - $content = wfMsgReplaceArgs( self::$change_names[$type], $args );
 142+ $content = wfMsgReplaceArgs( $msg, $args );
133143 return $wgOut->parseInline( $content );
134144 }
135145
Index: trunk/extensions/LiquidThreads/pages/ThreadHistoricalRevisionView.php
@@ -112,12 +112,15 @@
113113
114114 $this->thread = $this->mDisplayRevision->getThreadObj();
115115
116 - $this->showHistoryInfo();
117 -
118 - if ( !$this->thread ) {
 116+ if (!$this->mDisplayRevision) {
119117 $this->showMissingThreadPage();
120118 return false;
 119+ } elseif ( !$this->thread ) {
 120+ $this->output->addWikiMsg( 'lqt-historicalrevision-error' );
 121+ return false;
121122 }
 123+
 124+ $this->showHistoryInfo();
122125
123126 self::addJSandCSS();
124127 $this->output->setSubtitle( $this->getSubtitle() );

Status & tagging log