r58150 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58149‎ | r58150 | r58151 >
Date:17:38, 26 October 2009
Author:werdna
Status:resolved (Comments)
Tags:
Comment:
LiquidThreads bug fixes.
* Make Thread constructor private, route calls to new Thread via a new static function, newFromRow(), which makes each thread object a singleton.
* Fixes issue where reply count was not being properly updated.
* Fixes issue where replies to replies were not being properly loaded in the API action=render, causing posted responses to not appear when re-loaded.
Modified paths:
  • /trunk/extensions/LiquidThreads/api/ApiFeedLQTThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/api/ApiQueryLQTThreads.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Hooks.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/Hooks.php
@@ -206,7 +206,7 @@
207207 Threads::TYPE_DELETED => 'deleted' );
208208 // Is it a thread
209209 if ( !empty($row->thread_id) ) {
210 - $thread = new Thread( $row );
 210+ $thread = Thread::newFromRow( $row );
211211 $threadInfo = "\n";
212212 $attribs = array();
213213 $attribs['ThreadSubject'] = $thread->subject();
Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -396,8 +396,18 @@
397397 function decrementReplyCount( $val = 1 ) {
398398 $this->incrementReplyCount( - $val );
399399 }
 400+
 401+ static function newFromRow( $row ) {
 402+ $id = $row->thread_id;
 403+
 404+ if ( isset( Threads::$cache_by_id[$id] ) ) {
 405+ return Threads::$cache_by_id[$id];
 406+ }
 407+
 408+ return new Thread( $row );
 409+ }
400410
401 - function __construct( $line, $unused = null ) {
 411+ protected function __construct( $line, $unused = null ) {
402412 /* SCHEMA changes must be reflected here. */
403413
404414 if ( is_null( $line ) ) { // For Thread::create().
@@ -550,7 +560,7 @@
551561 // user talk pages to a link batch, cache the relevant user id/name pair, and
552562 // populate the reply cache.
553563 foreach ( $all_thread_rows as $row ) {
554 - $thread = new Thread( $row, null );
 564+ $thread = Thread::newFromRow( $row, null );
555565
556566 if ( isset( $articlesById[$thread->rootId] ) )
557567 $thread->root = $articlesById[$thread->rootId];
Index: trunk/extensions/LiquidThreads/api/ApiFeedLQTThreads.php
@@ -75,7 +75,7 @@
7676
7777 private function createFeedItem( $row ) {
7878 global $wgOut;
79 - $thread = new Thread( $row );
 79+ $thread = Thread::newFromRow( $row );
8080 $linker = new Linker;
8181
8282 $titleStr = $thread->subject();
Index: trunk/extensions/LiquidThreads/api/ApiQueryLQTThreads.php
@@ -83,13 +83,18 @@
8484 'thread_article_title', 'thread_summary_page', 'thread_ancestor',
8585 'thread_parent', 'thread_modified', 'thread_created', 'thread_type',
8686 'thread_editedness', 'thread_subject', 'thread_author_id',
87 - 'thread_author_name'
 87+ 'thread_author_name',
8888 );
8989
9090 $this->addFields( $allFields );
9191 }
9292
9393 $res = $this->select( __METHOD__ );
 94+
 95+ if ( $params['render'] ) {
 96+ $threads = Threads::loadFromResult( $res, $this->getDB() );
 97+ }
 98+
9499 $count = 0;
95100 foreach ( $res as $row )
96101 {
@@ -130,7 +135,7 @@
131136 $wgOut->clearHTML();
132137
133138 // Setup
134 - $thread = new Thread( $row );
 139+ $thread = Thread::newFromRow( $row );
135140 $article = $thread->root();
136141 $title = $article->getTitle();
137142 $view = new LqtView( $wgOut, $article, $title, $wgUser, $wgRequest );

Follow-up revisions

RevisionCommit summaryAuthorDate
r80503Fix FIXME on r58150werdna18:14, 18 January 2011

Comments

#Comment by Reedy (talk | contribs)   19:41, 25 July 2010

Marking as fixme..

+ if ( $params['render'] ) { + $threads = Threads::loadFromResult( $res, $this->getDB() ); + }

but then you never use $threads

#Comment by 😂 (talk | contribs)   20:33, 30 January 2011

Fixing awful unclosed tags

#Comment by Krinkle (talk | contribs)   20:34, 30 January 2011

Ooeoeoeo. Unsanatized/Tidyfied content. Nice!

Status & tagging log