Index: branches/liquidthreads/maintenance/lqt.sql |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | CREATE TABLE /*$wgDBprefix*/thread ( |
3 | 3 | thread_id int(8) unsigned NOT NULL auto_increment, |
4 | | - thread_root int(8) unsigned NOT NULL, |
| 4 | + thread_root int(8) unsigned UNIQUE NOT NULL, |
5 | 5 | thread_article int(8) unsigned NOT NULL, |
6 | 6 | thread_path text NOT NULL, |
7 | 7 | thread_summary_page int(8) unsigned NULL, |
Index: branches/liquidthreads/extensions/LqtExtension.php |
— | — | @@ -836,10 +836,7 @@ |
837 | 837 | } |
838 | 838 | |
839 | 839 | function show() { |
840 | | - $ts = Threads::withRoot( $this->article ); |
841 | | - if( count($ts) == 0 ) {echo "no such thread"; die();} |
842 | | - if ( count($ts) >1 ) {die();} // TODO handle this screwy situation. |
843 | | - $t = $ts[0]; |
| 840 | + $t = Threads::withRoot( $this->article ); |
844 | 841 | |
845 | 842 | // TODO this is a holdover from the special page; not sure what's correct here. |
846 | 843 | // we now have a real true $this->article that makes some sense. |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -136,13 +136,12 @@ |
137 | 137 | } |
138 | 138 | |
139 | 139 | function superthread() { |
140 | | - var_dump("warning superthread unimplemented"); return; |
141 | | - // TODO we have to find threads that may not be looked up yet |
142 | | - // and look them up if needed. |
143 | | - if( false === strpos($this->path,'.') ) { |
| 140 | + if( !$this->hasSuperthread() ) { |
144 | 141 | return null; |
145 | 142 | } else { |
146 | | - return array_slice( $this->path, strpos($this->path, '.') ); |
| 143 | + preg_match("/(\d+)\.\d+$/", $this->path, $matches); |
| 144 | + $superthread_id = $matches[1]; |
| 145 | + return Threads::withId( $superthread_id ); |
147 | 146 | } |
148 | 147 | } |
149 | 148 | |
— | — | @@ -152,8 +151,13 @@ |
153 | 152 | } |
154 | 153 | |
155 | 154 | function topmostThread() { |
156 | | - if ( !$this->superthread() ) return $this; |
157 | | - else return $this->superthread()->topmostThread(); |
| 155 | + if( !$this->hasSuperthread() ) { |
| 156 | + return $this; |
| 157 | + } else { |
| 158 | + preg_match("/^(\d+)\..*/", $this->path, $matches); |
| 159 | + $superthread_id = $matches[1]; |
| 160 | + return Threads::withId( $superthread_id ); |
| 161 | + } |
158 | 162 | } |
159 | 163 | |
160 | 164 | function setArticle($a) { |
— | — | @@ -199,7 +203,7 @@ |
200 | 204 | } |
201 | 205 | |
202 | 206 | function hasDistinctSubject() { |
203 | | - if( $this->superthread() ) { |
| 207 | + if( $this->hasSuperthread() ) { |
204 | 208 | return $this->superthread()->subjectWithoutIncrement() |
205 | 209 | != $this->subjectWithoutIncrement(); |
206 | 210 | } else { |
— | — | @@ -250,6 +254,8 @@ |
251 | 255 | |
252 | 256 | /** Module of factory methods. */ |
253 | 257 | class Threads { |
| 258 | + |
| 259 | + static $loadedLiveThreads = array(); |
254 | 260 | |
255 | 261 | static function where( $where, $options = array(), $extra_tables = array() ) { |
256 | 262 | $dbr =& wfGetDB( DB_SLAVE ); |
— | — | @@ -289,7 +295,6 @@ |
290 | 296 | $threads[] = Threads::buildLiveThread( &$lines, $l ); |
291 | 297 | } |
292 | 298 | } |
293 | | - |
294 | 299 | return $threads; |
295 | 300 | } |
296 | 301 | |
— | — | @@ -303,31 +308,41 @@ |
304 | 309 | $children[] = Threads::buildLiveThread( &$lines, $m ); |
305 | 310 | } |
306 | 311 | } |
307 | | - return new LiveThread($l, $children); |
| 312 | + $t = new LiveThread($l, $children); |
| 313 | + Threads::$loadedLiveThreads[$l->thread_id] = $t; |
| 314 | + return $t; |
308 | 315 | } |
309 | 316 | |
| 317 | + private static function databaseError( $msg ) { |
| 318 | + // TODO tie into MW's error reporting facilities. |
| 319 | + echo("Corrupt liquidthreads database: $msg"); |
| 320 | + die(); |
| 321 | + } |
| 322 | + |
310 | 323 | static function withRoot( $post ) { |
311 | | - return Threads::where( array('thread.thread_root' => $post->getID()) ); |
| 324 | + $ts = Threads::where( array('thread.thread_root' => $post->getID()) ); |
| 325 | + if( count($ts) == 0 ) { return null; } |
| 326 | + if ( count($ts) >1 ) { |
| 327 | + Threads::databaseError("More than one thread with thread_root = {$post->getID()}."); |
| 328 | + } |
| 329 | + return $ts[0]; |
312 | 330 | } |
313 | 331 | |
314 | | -} |
315 | | -/* |
316 | | -function lqtCheapTest() { |
317 | | - $threads = Threads::threadsWhere( "thread.thread_id = 1", "order by thread_timestamp" ); |
318 | | - function cheapShowThread($t) { |
319 | | - global $wgOut; |
320 | | - $wgOut->addHTML($t->id()); |
321 | | - $wgOut->addHTML('<dl><dd>'); |
322 | | - foreach( $t->replies as $r ) { |
323 | | - cheapShowThread($r); |
| 332 | + static function withId( $id ) { |
| 333 | + if( array_key_exists( $id, Threads::$loadedLiveThreads ) ) { |
| 334 | + return Threads::$loadedLiveThreads[ $id ]; |
324 | 335 | } |
325 | | - $wgOut->addHTML('</dd></dl>'); |
| 336 | + |
| 337 | + $ts = Threads::where( array('thread.thread_id' => $id ) ); |
| 338 | + if( count($ts) == 0 ) { return null; } |
| 339 | + if ( count($ts) >1 ) { |
| 340 | + Threads::databaseError("More than one thread with thread_id = {$id}."); |
| 341 | + } |
| 342 | + return $ts[0]; |
326 | 343 | } |
327 | | - foreach( $threads as $t ) { |
328 | | - cheapShowThread($t); |
329 | | - } |
| 344 | + |
330 | 345 | } |
331 | | -*/ |
| 346 | + |
332 | 347 | class QueryGroup { |
333 | 348 | protected $queries; |
334 | 349 | |