Index: branches/liquidthreads/extensions/LqtExtension.php |
— | — | @@ -58,6 +58,8 @@ |
59 | 59 | protected $user_colors; |
60 | 60 | protected $user_color_index; |
61 | 61 | const number_of_user_colors = 6; |
| 62 | + |
| 63 | + protected $queries; |
62 | 64 | |
63 | 65 | function __construct(&$output, &$article, &$title, &$user, &$request) { |
64 | 66 | $this->article = $article; |
— | — | @@ -67,7 +69,25 @@ |
68 | 70 | $this->request = $request; |
69 | 71 | $this->user_colors = array(); |
70 | 72 | $this->user_color_index = 1; |
| 73 | + $this->queries = $this->initializeQueries(); |
71 | 74 | } |
| 75 | + |
| 76 | + function initializeQueries() { |
| 77 | + $g = new QueryGroup(); |
| 78 | + $startdate = Date::now()->nDaysAgo(14)->midnight(); |
| 79 | + $g->addQuery('fresh', |
| 80 | + array('thread_article' => $this->article->getID(), |
| 81 | + 'thread_subthread_of is null', |
| 82 | + 'thread_touched >= ' . $startdate->text() ), |
| 83 | + array('ORDER BY' => 'thread_touched DESC' )); |
| 84 | + $g->addQuery('recently-archived', |
| 85 | + array('thread_article' => $this->article->getID(), |
| 86 | + 'thread_subthread_of is null', |
| 87 | + 'thread_touched < ' . $startdate->text(), |
| 88 | + 'thread_touched >=' . $startdate->nDaysAgo(5)->text()), |
| 89 | + array('ORDER BY' => 'thread_touched DESC')); |
| 90 | + return $g; |
| 91 | + } |
72 | 92 | |
73 | 93 | static protected $occupied_titles = array(); |
74 | 94 | |
— | — | @@ -517,7 +537,8 @@ |
518 | 538 | $this->output->addHTML("<strong><a href=\"$url\">Start a Discussion</a></strong>"); |
519 | 539 | } |
520 | 540 | |
521 | | - $threads = Thread::threadsOfArticleInLastNDays($this->article, 30); |
| 541 | +// $threads = Thread::threadsOfArticleInLastNDays($this->article, 30); |
| 542 | + $threads = $this->queries->query('fresh'); |
522 | 543 | foreach($threads as $t) { |
523 | 544 | $this->showThread($t); |
524 | 545 | } |
— | — | @@ -528,6 +549,16 @@ |
529 | 550 | return $wgLang->getMonthName( substr($yyyymm, 4, 2) ).' '.substr($yyyymm, 0, 4); |
530 | 551 | } |
531 | 552 | |
| 553 | + function permalinksForThreads($ts, $query = '') { |
| 554 | + $ps = array(); |
| 555 | + foreach ($ts as $t) { |
| 556 | + $u = $this->permalinkUrl($t, $query); |
| 557 | + $l = $t->subjectWithoutIncrement(); |
| 558 | + $ps[] = "<a href=\"$u\">$l</a>"; |
| 559 | + } |
| 560 | + return $ps; |
| 561 | + } |
| 562 | + |
532 | 563 | function showArchiveWidget($month) { |
533 | 564 | global $wgLang; // TODO global. |
534 | 565 | |
— | — | @@ -540,15 +571,17 @@ |
541 | 572 | $options[$this->formattedMonth($m)] = $m; |
542 | 573 | } |
543 | 574 | |
| 575 | + $threads = $this->queries->query('recently-archived'); |
| 576 | + $threadlinks = $this->permalinksForThreads($threads); |
| 577 | + |
544 | 578 | $this->openDiv('lqt_archive_widget'); |
545 | 579 | $this->output->addHTML(<<<HTML |
546 | 580 | <div class="lqt_header_content"> |
547 | 581 | The following threads were archived recently: |
548 | | - <ul> |
549 | | - <li>Foo blah blah blah |
550 | | - <li>Quirks is a burps |
551 | | - <li>Lorem dipsum pompom tomtom. |
552 | | - </ul> |
| 582 | +HTML |
| 583 | +); |
| 584 | + $this->outputList('ul', '', '', $threadlinks); |
| 585 | + $this->output->addHTML(<<<HTML |
553 | 586 | <a href="#"><strong>Browse the Archive</strong></a> |
554 | 587 | </div> |
555 | 588 | <!-- |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -320,7 +320,28 @@ |
321 | 321 | call_user_func($pop_callback); |
322 | 322 | } |
323 | 323 | } |
| 324 | +} |
324 | 325 | |
| 326 | +class QueryGroup { |
| 327 | + protected $queries; |
| 328 | + |
| 329 | + function __construct() { |
| 330 | + $this->queries = array(); |
| 331 | + } |
| 332 | + |
| 333 | + function addQuery( $name, $where, $options = array() ) { |
| 334 | + $this->queries[$name] = array($where, $options); |
| 335 | + } |
| 336 | + |
| 337 | + function deleteQuery( $name ) { |
| 338 | + unset ($this->queries[$name]); |
| 339 | + } |
| 340 | + |
| 341 | + function query($name) { |
| 342 | + if ( !array_key_exists($name,$this->queries) ) return array(); |
| 343 | + list($where, $options) = $this->queries[$name]; |
| 344 | + return Thread::threadsWhere($where, $options); |
| 345 | + } |
325 | 346 | } |
326 | 347 | |
327 | 348 | ?> |