r22554 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22553‎ | r22554 | r22555 >
Date:07:43, 30 May 2007
Author:david
Status:old
Tags:
Comment:
Thread touching now is reasonable, although this is not the final word on when a thread is touched. Implemented monthly archive viewing, and started work on the UI, which doesn't really work yet but exists.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: branches/liquidthreads/skins/monobook/main.css
@@ -33,6 +33,17 @@
3434 margin-bottom: .1em;
3535 }*/
3636
 37+.lqt_archive_widget {
 38+ /* floats to the right of the main h1 page title. */
 39+ float:right;
 40+ position:relative;
 41+ top:-3.2em;
 42+}
 43+
 44+h1.firstHeading {
 45+ padding-right: 4.5em;
 46+}
 47+
3748 #lqt_archive_hide_show {
3849 display: block;
3950 }
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -185,6 +185,8 @@
186186 if ( $e->didSave && $subject != '' ) {
187187 $thread->setSubject( Sanitizer::stripAllTags($subject) );
188188 }
 189+
 190+ if ($e->didSave) $thread->touch(); // TODO reduntent if above $thread->setX called.
189191 }
190192
191193 function scratchTitle() {
@@ -245,6 +247,11 @@
246248 $this->output->addWikitext( $sig, false );
247249 $this->output->addHTML( wfCloseElement( 'li' ) );
248250
 251+ $this->output->addHTML( wfOpenElement( 'li' ) );
 252+ $d = new Date($thread->touched());
 253+ $this->output->addHTML( $d->lastMonth()->text() );
 254+ $this->output->addHTML( wfCloseElement( 'li' ) );
 255+
249256 $commands = array( 'Edit' => $this->lqtTalkpageUrl( $this->title, 'lqt_edit_post', $thread ),
250257 'Reply' => $this->lqtTalkpageUrl( $this->title, 'lqt_reply_to', $thread ),
251258 'Permalink' => $this->permalinkUrl( $thread ) );
@@ -338,23 +345,57 @@
339346 logged-in users, don't really fit the metaphor. What to do, what to do?
340347 */
341348 }
342 - function show() {
343 - global $wgHooks;
344 - $wgHooks['SkinTemplateTabs'][] = array($this, 'customizeTabs');
345 -
346 - $this->output->setPageTitle( "Talk:" . $this->title->getText() );
347 -
 349+
 350+ function showArchive($month) {
 351+ $threads = Thread::threadsOfArticleInMonth( $this->article, $month );
 352+ foreach($threads as $t) {
 353+ $this->showThread($t);
 354+ }
 355+ }
 356+
 357+ function showLatest() {
348358 if( $this->request->getBool('lqt_new_thread_form') ) {
349359 $this->showNewThreadForm();
350360 } else {
351361 $url = $this->lqtTalkpageUrl( $this->title, 'lqt_new_thread_form' );
352362 $this->output->addHTML("<strong><a href=\"$url\">Start a Discussion</a></strong>");
353363 }
354 - $threads = Thread::latestNThreadsOfArticle($this->article, 10);
 364+
 365+ $threads = Thread::latestNThreadsOfArticle($this->article, 10);
355366 foreach($threads as $t) {
356367 $this->showThread($t);
357368 }
358369 }
 370+
 371+ function showArchiveWidget($month) {
 372+ global $wgLang; // TODO global.
 373+
 374+ $options = Thread::monthsWhereArticleHasThreads($this->article);
 375+ array_unshift($options, 'Last 30 days' ); # prepend.
 376+
 377+ $this->openDiv('lqt_archive_widget');
 378+ $this->output->addHTML('<form><select>');
 379+ foreach( $options as $o ) {
 380+ $this->output->addHTML("<option>$o");
 381+ }
 382+ $this->output->addHTML('</select></form>');
 383+ $this->closeDiv();
 384+ }
 385+
 386+ function show() {
 387+ global $wgHooks;
 388+ $wgHooks['SkinTemplateTabs'][] = array($this, 'customizeTabs');
 389+
 390+ $this->output->setPageTitle( "Talk:" . $this->title->getText() );
 391+
 392+ $month = $this->request->getVal('lqt_archive_month');
 393+ $this->showArchiveWidget($month);
 394+ if ( $month ) {
 395+ $this->showArchive($month);
 396+ } else {
 397+ $this->showLatest();
 398+ }
 399+ }
359400 }
360401
361402 class ThreadPermalinkView extends LqtView {
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -2,6 +2,41 @@
33
44 require_once('Article.php');
55
 6+// TODO if we're gonna have a Date class we should really do it.
 7+class Date {
 8+ public $year, $month, $day, $hour, $minute, $second;
 9+
 10+ // ex. "20070530033751"
 11+ function __construct( $text ) {
 12+ if ( !strlen( $text ) == 14 || !ctype_digit($text) ) {
 13+ $this->isValid = false;
 14+ return null;
 15+ }
 16+ $this->year = intval( substr( $text, 0, 4 ) );
 17+ $this->month = intval( substr( $text, 4, 2 ) );
 18+ $this->day = intval( substr( $text, 6, 2 ) );
 19+ $this->hour = intval( substr( $text, 8, 2 ) );
 20+ $this->minute = intval( substr( $text, 10, 2 ) );
 21+ $this->second = intval( substr( $text, 12, 2 ) );
 22+ }
 23+ function lastMonth() {
 24+ $d = clone $this;
 25+ $d->month -= 1;
 26+ return $d;
 27+ }
 28+/* function monthString() {
 29+ return sprintf( '%04d%02d', $this->year, $this->month );
 30+ }*/
 31+ static function monthString($text) {
 32+ return substr($text, 0, 6);
 33+ }
 34+ static function beginningOfMonth($yyyymm) { return $yyyymm . '00000000'; }
 35+ static function endOfMonth($yyyymm) { return $yyyymm . '31235959'; }
 36+ function text() {
 37+ return sprintf( '%04d%02d%02d%02d%02d%02d', $this->year, $this->month, $this->day,
 38+ $this->hour, $this->minute, $this->second );
 39+ }
 40+}
641
742 class Post extends Article {
843 /**
@@ -25,8 +60,6 @@
2661
2762 }
2863
29 -// TODO when exactly do we update thraed_touched?
30 -
3164 class Thread {
3265
3366 /* ID references to other objects that are loaded on demand: */
@@ -108,6 +141,17 @@
109142 array('ORDER BY' => 'thread_touched') );
110143 }
111144
 145+ function touch() {
 146+ $this->updateRecord(); // TODO side-effect, ugly, etc.
 147+ if ( $this->superthread() ) {
 148+ $this->superthread()->touch();
 149+ }
 150+ }
 151+
 152+ function touched() {
 153+ return $this->touched;
 154+ }
 155+
112156 protected function updateRecord() {
113157 $dbr =& wfGetDB( DB_MASTER );
114158 $res = $dbr->update( 'lqt_thread',
@@ -116,7 +160,7 @@
117161 'thread_subthread_of' => $this->superthreadId,
118162 'thread_summary_page' => $this->summaryId,
119163 'thread_subject' => $this->subject,
120 - 'thread_touched' => $this->touched ),
 164+ 'thread_touched' => wfTimestampNow() ),
121165 /* WHERE */ array( 'thread_id' => $this->id, ),
122166 __METHOD__);
123167 }
@@ -149,6 +193,17 @@
150194 return Thread::newFromId( $dbr->insertId() );
151195 }
152196
 197+ /** List of months in which there are >0 threads, suitable for threadsOfArticleInMonth. */
 198+ static function monthsWhereArticleHasThreads( $article ) {
 199+ $threads = Thread::allThreadsOfArticle( $article );
 200+ $months = array();
 201+ foreach( $threads as $t ) {
 202+ $m = substr( $t->touched(), 0, 6 );
 203+ if (!in_array( $m, $months )) $months[] = $m;
 204+ }
 205+ return $months;
 206+ }
 207+
153208 static function latestNThreadsOfArticle( $article, $n ) {
154209 return Thread::threadsWhere( array('thread_article' => $article->getID(),
155210 'thread_subthread_of is null'),
@@ -159,16 +214,31 @@
160215 static function allThreadsOfArticle( $article ) {
161216 return Thread::threadsWhere( array('thread_article' => $article->getID(),
162217 'thread_subthread_of is null'),
163 - array('ORDER BY' => 'thread_touched DESC') );
 218+ array('ORDER BY' => 'thread_touched DESC') );
164219 }
165220
166 - static function threadsOfPost( $post ) {
 221+ static function threadsOfArticleInMonth( $article, $yyyymm ) {
 222+ return Thread::threadsWhere( array('thread_article' => $article->getID(),
 223+ 'thread_subthread_of is null',
 224+ 'thread_touched >= "'.Date::beginningOfMonth($yyyymm).'"',
 225+ 'thread_touched <= "'.Date::endOfMonth($yyyymm).'"'),
 226+ array('ORDER BY' => 'thread_touched DESC') );
 227+ }
 228+
 229+ /*
 230+ static function threadsOfArticleInLastNDays( $article, $n ) {
 231+ return Thread::threadsWhere( array('thread_article' => $article->getID(),
 232+ 'thread_subthread_of is null',
 233+ 'thread_touched > ' . 'foo' ),
 234+ array('ORDER BY' => 'thread_touched DESC' );
 235+ }*/
 236+
 237+ static function threadsWhoseRootPostIs( $post ) {
167238 return Thread::threadsWhere( array('thread_root_post' => $post->getID()) );
168239 }
169240
170241 static function threadsWhere( $where_clause, $options = array() ) {
171242 $dbr =& wfGetDB( DB_SLAVE );
172 -
173243 $res = $dbr->select( array('lqt_thread'),
174244 array('*'),
175245 $where_clause,