r22749 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22748‎ | r22749 | r22750 >
Date:09:22, 5 June 2007
Author:david
Status:old
Tags:
Comment:
Playing around with a different approach to selecting threads. Instead of having a bajillion factory methods builts into the Thread class, which properly shouldn't care about the peculiarities of when we want threads shown in the various states of archiving, give the queries names and let them be customized by subclasses or instantiators of the LqtView class. As yet have just inserted this mechanism in a couple places; still everything is rather broken, or rather, not yet fixed.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -58,6 +58,8 @@
5959 protected $user_colors;
6060 protected $user_color_index;
6161 const number_of_user_colors = 6;
 62+
 63+ protected $queries;
6264
6365 function __construct(&$output, &$article, &$title, &$user, &$request) {
6466 $this->article = $article;
@@ -67,7 +69,25 @@
6870 $this->request = $request;
6971 $this->user_colors = array();
7072 $this->user_color_index = 1;
 73+ $this->queries = $this->initializeQueries();
7174 }
 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+ }
7292
7393 static protected $occupied_titles = array();
7494
@@ -517,7 +537,8 @@
518538 $this->output->addHTML("<strong><a href=\"$url\">Start a Discussion</a></strong>");
519539 }
520540
521 - $threads = Thread::threadsOfArticleInLastNDays($this->article, 30);
 541+// $threads = Thread::threadsOfArticleInLastNDays($this->article, 30);
 542+ $threads = $this->queries->query('fresh');
522543 foreach($threads as $t) {
523544 $this->showThread($t);
524545 }
@@ -528,6 +549,16 @@
529550 return $wgLang->getMonthName( substr($yyyymm, 4, 2) ).' '.substr($yyyymm, 0, 4);
530551 }
531552
 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+
532563 function showArchiveWidget($month) {
533564 global $wgLang; // TODO global.
534565
@@ -540,15 +571,17 @@
541572 $options[$this->formattedMonth($m)] = $m;
542573 }
543574
 575+ $threads = $this->queries->query('recently-archived');
 576+ $threadlinks = $this->permalinksForThreads($threads);
 577+
544578 $this->openDiv('lqt_archive_widget');
545579 $this->output->addHTML(<<<HTML
546580 <div class="lqt_header_content">
547581 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
553586 <a href="#"><strong>Browse the Archive</strong></a>
554587 </div>
555588 <!--
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -320,7 +320,28 @@
321321 call_user_func($pop_callback);
322322 }
323323 }
 324+}
324325
 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+ }
325346 }
326347
327348 ?>

Status & tagging log