r25522 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25521‎ | r25522 | r25523 >
Date:07:14, 5 September 2007
Author:david
Status:old
Tags:
Comment:
all fixed :)
Modified paths:
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtModel.php
@@ -465,6 +465,10 @@
466466 $this->changeComment = $line->thread_change_comment;
467467 $this->changeUser = $line->thread_change_user;
468468 $this->changeUserText = $line->thread_change_user_text;
 469+
 470+ }
 471+
 472+ function initWithReplies( $children ) {
469473
470474 $this->replies = $children;
471475
@@ -476,6 +480,8 @@
477481
478482 (we could do Revision::getPrevious() we just need to know whether or not
479483 there was a new revision saved at save time. make it run then make it right.)
 484+
 485+ TODO this is expensive and should be ripped out.
480486 */
481487 $rev = Revision::newFromTitle( $this->root()->getTitle() );
482488 $this->rootRevision = $rev->getId();
@@ -855,21 +861,46 @@
856862 SQL;
857863 $res = $dbr->query($sql);
858864
859 - $lines = array();
860865 $threads = array();
 866+ $top_level_threads = array();
861867
862868 while ( $line = $dbr->fetchObject($res) ) {
863 - $lines[] = $line;
 869+ $new_thread = new Thread($line, null);
 870+ $threads[] = $new_thread;
 871+ if( $line->is_root )
 872+ // thread is one of those that was directly queried for.
 873+ $top_level_threads[] = $new_thread;
 874+ if( strstr( $line->thread_path, '.' ) !== false ) {
 875+ // thread has a parent. extract second-to-last path element.
 876+ preg_match( '/([^.]+)\.[^.]+$/', $line->thread_path, $path_matches );
 877+ $parent_id = $path_matches[1];
 878+ if( !array_key_exists( $parent_id, self::$thread_children ) )
 879+ self::$thread_children[$parent_id] = array();
 880+ self::$thread_children[$parent_id][] = $new_thread;
 881+ }
864882 }
865883
866 - foreach( $lines as $key => $l ) {
867 - if( $l->is_root ) {
868 -// unset($lines[$key]);
869 - $threads[] = Threads::buildThread( $lines, $l );
 884+ foreach( $threads as $thread ) {
 885+ if( array_key_exists( $thread->id(), self::$thread_children ) ) {
 886+ $thread->initWithReplies( self::$thread_children[$thread->id()] );
 887+ } else {
 888+ $thread->initWithReplies( array() );
870889 }
871890 }
872 - return $threads;
 891+ return $top_level_threads;
873892 }
 893+
 894+ /*
 895+ private function splitIncrementFromSubject($subject_string) {
 896+ preg_match('/^(.*) \((\d+)\)$/', $subject_string, $matches);
 897+ if( count($matches) != 3 )
 898+ throw new MWException( __METHOD__ . ": thread subject has no increment: " . $subject_string );
 899+ else
 900+ return $matches;
 901+ }
 902+ */
 903+
 904+ static $thread_children = array();
874905
875906 private static function buildThread( $lines, $l ) {
876907 $children = array();

Status & tagging log