r58473 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58472‎ | r58473 | r58474 >
Date:13:49, 3 November 2009
Author:werdna
Status:deferred
Tags:
Comment:
Fix bug 21319. Checking for replies on a thread that had not yet been saved resulted in loading all top-level threads as replies. Added checks when retrieving replies to prevent this kind of error in the future, and a short-circuit in replies() to prevent it.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -851,8 +851,27 @@
852852 $this->decrementReplyCount( 1 + $threadObj->replyCount() );
853853 }
854854
 855+ function checkReplies( $replies ) {
 856+ foreach( $replies as $reply ) {
 857+ if ( ! $reply->hasSuperthread() ) {
 858+ throw new MWException( "Post ".$this->id().
 859+ " has contaminated reply ".$reply->id()."\n" );
 860+ }
 861+
 862+ if ( $reply->superthread()->id() != $this->id() ) {
 863+ throw new MWException( "Post ". $this->id() .
 864+ " has contaminated reply ".$reply->id()."\n" );
 865+ }
 866+ }
 867+ }
 868+
855869 function replies() {
 870+ if ( !$this->id() ) {
 871+ return array();
 872+ }
 873+
856874 if ( !is_null( $this->replies ) ) {
 875+ $this->checkReplies( $this->replies );
857876 return $this->replies;
858877 }
859878
@@ -879,6 +898,8 @@
880899
881900 $this->replies = Thread::bulkLoad( $rows );
882901
 902+ $this->checkReplies( $this->replies );
 903+
883904 return $this->replies;
884905 }
885906
@@ -1172,11 +1193,11 @@
11731194 //
11741195 // // Insert a revision into the database.
11751196 // $rev = ThreadRevision::create( $historical_thread,
1176 -// $historical_thread->changeType(),
1177 -// $historical_thread->changeObject(),
1178 -// $historical_thread->changeComment(),
1179 -// $historical_thread->changeUser(),
1180 -// $historical_thread->modified() );
 1197+// $historical_thread->changeType(),
 1198+// $historical_thread->changeObject(),
 1199+// $historical_thread->changeComment(),
 1200+// $historical_thread->changeUser(),
 1201+// $historical_thread->modified() );
11811202 // }
11821203 }
11831204

Status & tagging log