r25302 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25301‎ | r25302 | r25303 >
Date:07:02, 30 August 2007
Author:david
Status:old
Tags:
Comment:
History... works? Can it be? Factored display of old revisions into a new subclass of ThreadPermalinkView instead of being embedded into the base view. Moved constructor-type code into a constructer to make ThreadPermalinkView easier to subclass.
Modified paths:
  • /branches/liquidthreads/extensions/LqtBaseView.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtPages.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtPages.php
@@ -386,31 +386,14 @@
387387 }
388388 }
389389
390 - function showHistoryInfo() {
391 - global $wgLang; // TODO global.
392 - $this->openDiv('lqt_history_info');
393 - $this->output->addHTML('Revision as of ' . $wgLang->timeanddate($this->thread->timestamp()) . '.<br>' );
394 - if( $this->thread->changeType() == Threads::CHANGE_NEW_THREAD ) {
395 - $this->output->addHTML('This is the thread\'s initial revision.');
396 - }
397 - else if( $this->thread->changeType() == Threads::CHANGE_REPLY_CREATED ) {
398 - $this->output->addHTML('The highlighted comment was created in this revision.');
399 - } else if( $this->thread->changeType() == Threads::CHANGE_EDITED_ROOT ) {
400 - $diff_url = $this->permalinkUrlWithDiff($this->thread);
401 - $this->output->addHTML('The highlighted comment was edited in this revision. ');
402 - $this->output->addHTML( "[<a href=\"$diff_url\">show diffs</a>]" );
403 - }
404 - $this->closeDiv();
405 - }
406 -
407390 function noSuchRevision() {
408391 $this->output->addHTML("There is no such revision of this thread.");
409392 }
410 -
411 - function show() {
412 - global $wgHooks;
413 - $wgHooks['SkinTemplateTabs'][] = array($this, 'customizeTabs');
 393+
 394+ function __construct(&$output, &$article, &$title, &$user, &$request) {
414395
 396+ parent::__construct($output, $article, $title, $user, $request);
 397+
415398 $t = Threads::withRoot( $this->article );
416399 $r = $this->request->getVal('lqt_oldid', null); if( $r ) {
417400 $t = $t->atRevision($r);
@@ -422,32 +405,34 @@
423406 // TODO this is a holdover from the special page; not sure what's correct here.
424407 // we now have a real true $this->article that makes some sense.
425408 // but we still want to know about $t->article.
426 - $this->article = $t->article(); # for creating reply threads.
 409+// $this->article = $t->article(); # for creating reply threads.
427410
 411+ }
 412+
 413+ function show() {
 414+ global $wgHooks;
 415+ $wgHooks['SkinTemplateTabs'][] = array($this, 'customizeTabs');
 416+
428417 // Make a link back to the talk page, including the correct archive month.
429418 // TODO this is obsolete.
430 - if (Date::now()->nDaysAgo(30)->midnight()->isBefore( new Date($t->timestamp()) ))
 419+ if (Date::now()->nDaysAgo(30)->midnight()->isBefore( new Date($this->thread->timestamp()) ))
431420 $query = '';
432421 else
433 - $query = 'lqt_archive_month=' . substr($t->timestamp(),0,6);
 422+ $query = 'lqt_archive_month=' . substr($this->thread->timestamp(),0,6);
434423
435 - $talkpage = $t->article()->getTitle()->getTalkpage();
 424+ $talkpage = $this->thread->article()->getTitle()->getTalkpage();
436425 $talkpage_link = $this->user->getSkin()->makeKnownLinkObj($talkpage, '', $query);
437426
438 - if ( $t->hasSuperthread() ) {
439 - $this->output->setSubtitle( "a fragment of <a href=\"{$this->permalinkUrl($t->topmostThread())}\">a discussion</a> from " . $talkpage_link );
 427+ if ( $this->thread->hasSuperthread() ) {
 428+ $this->output->setSubtitle( "a fragment of <a href=\"{$this->permalinkUrl($this->thread->topmostThread())}\">a discussion</a> from " . $talkpage_link );
440429 } else {
441430 $this->output->setSubtitle( "from " . $talkpage_link );
442431 }
443432
444433 if( $this->methodApplies('summarize') )
445 - $this->showSummarizeForm($t);
 434+ $this->showSummarizeForm($this->thread);
446435
447 - if($t->isHistorical()) {
448 - $this->showHistoryInfo();
449 - }
450 -
451 - $this->showThread($t);
 436+ $this->showThread($this->thread);
452437 }
453438 }
454439
@@ -555,7 +540,7 @@
556541 }
557542 }
558543
559 -class ThreadHistoryView extends ThreadPermalinkView {
 544+class ThreadHistoryListingView extends ThreadPermalinkView {
560545
561546 private function rowForThread($t) {
562547 global $wgLang, $wgOut; // TODO global.
@@ -596,26 +581,65 @@
597582 function show() {
598583 global $wgHooks;
599584 $wgHooks['SkinTemplateTabs'][] = array($this, 'customizeTabs');
600 -
 585+
 586+/* var_dump($this->article);
601587 $t = Threads::withRoot( $this->article );
602588 $this->thread = $t;
603 -
 589+*/
604590 // TODO this is a holdover from the special page; not sure what's correct here.
605591 // we now have a real true $this->article that makes some sense.
606592 // but we still want to know about $t->article.
607 - $this->article = $t->article(); # for creating reply threads.
 593+// $this->article = $t->article(); # for creating reply threads.
608594
609595 $this->output->setSubtitle("Viewing a history listing.");
610596
611 - $this->showThreadHeading($t);
612 - $this->showHistoryListing($t);
 597+ $this->showThreadHeading($this->thread);
 598+ $this->showHistoryListing($this->thread);
613599
614 - $this->showThread($t);
 600+ $this->showThread($this->thread);
615601 }
616602 }
617603
 604+class ThreadHistoricalRevisionView extends ThreadPermalinkView {
 605+
 606+ /* TOOD: customize tabs so that History is highlighted. */
618607
 608+ function threadDivClass($thread) {
 609+ // efVarDump($this->output, $thread->changeObject()->id());
 610+ $is_changed_thread = $thread->changeObject() &&
 611+ $thread->changeObject()->id() == $thread->id();
619612
 613+ if ( $is_changed_thread )
 614+ return 'lqt_thread lqt_thread_changed_by_history';
 615+ else
 616+ return 'lqt_thread';
 617+ }
 618+
 619+
 620+ function showHistoryInfo() {
 621+ global $wgLang; // TODO global.
 622+ $this->openDiv('lqt_history_info');
 623+ $this->output->addHTML('Revision as of ' . $wgLang->timeanddate($this->thread->timestamp()) . '.<br>' );
 624+ if( $this->thread->changeType() == Threads::CHANGE_NEW_THREAD ) {
 625+ $this->output->addHTML('This is the thread\'s initial revision.');
 626+ }
 627+ else if( $this->thread->changeType() == Threads::CHANGE_REPLY_CREATED ) {
 628+ $this->output->addHTML('The highlighted comment was created in this revision.');
 629+ } else if( $this->thread->changeType() == Threads::CHANGE_EDITED_ROOT ) {
 630+ $diff_url = $this->permalinkUrlWithDiff($this->thread);
 631+ $this->output->addHTML('The highlighted comment was edited in this revision. ');
 632+ $this->output->addHTML( "[<a href=\"$diff_url\">show diffs</a>]" );
 633+ }
 634+ $this->closeDiv();
 635+ }
 636+
 637+ function show() {
 638+ $this->showHistoryInfo();
 639+ parent::show();
 640+ }
 641+}
 642+
 643+
620644 /* We have to do this goofy wgExtensionFunctions run-around because
621645 the files required by SpecialPage aren't required_onced() yet by
622646 the time this file is. Don't ask me why. */
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -292,8 +292,16 @@
293293 }
294294
295295 private static function setChangeOnDescendents($thread, $change_type, $change_object) {
 296+ // TODO this is ludicrously inefficient.
296297 $thread->setChangeType($change_type);
297298 $thread->setChangeObject($change_object);
 299+ $dbr =& wfGetDB( DB_MASTER );
 300+ $res = $dbr->update( 'thread',
 301+ /* SET */ array('thread_revision' => $thread->revisionNumber,
 302+ 'thread_change_type'=>$thread->changeType,
 303+ 'thread_change_object'=>$thread->changeObject),
 304+ /* WHERE */ array( 'thread_id' => $thread->id ),
 305+ __METHOD__);
298306 foreach($thread->replies() as $r)
299307 self::setChangeOnDescendents($r, $change_type, $change_object);
300308 return $thread;
@@ -310,7 +318,7 @@
311319 HistoricalThread::create( $this->double, $change_type, $change_object );
312320
313321 $this->bumpRevisionsOnAncestors($change_type, $change_object);
314 - // self::setChangeOnDescendents($this->topmostThread(), $change_type, $change_object);
 322+ self::setChangeOnDescendents($this->topmostThread(), $change_type, $change_object);
315323
316324 /* SCHEMA changes must be reflected here. */
317325
@@ -461,6 +469,18 @@
462470
463471 $this->double = clone $this;
464472 }
 473+
 474+ function __clone() {
 475+ // Cloning does not normally create a new array (but the clone keyword doesn't
 476+ // work on arrays -- go figure).
 477+
 478+ // Update: this doesn't work for some reason, but why do we update the replies array
 479+ // in the first place after creating a new reply?
 480+ $new_array = array();
 481+ foreach( $this->replies as $r )
 482+ $new_array[] = $r;
 483+ $this->replies = $new_array;
 484+ }
465485
466486 /*
467487 More evidence that the way I'm doing history is totally screwed.
@@ -468,7 +488,9 @@
469489 is make sure the latest info gets into any historicalthreads we commit.
470490 */
471491 function addReply($thread) {
472 - $this->replies[] = $thread;
 492+ // TODO: question for myself to ponder: We don't want the latest info in the
 493+ // historical thread, duh. Why were we doing this?
 494+// $this->replies[] = $thread;
473495 }
474496 function removeReplyWithId($id) {
475497 $target = null;
Index: branches/liquidthreads/extensions/LqtBaseView.php
@@ -30,7 +30,8 @@
3131 'TalkpageArchiveView' => 'TalkpageArchiveView',
3232 'TalkpageHeaderView' => 'TalkpageHeaderView',
3333 'TalkpageView' => 'TalkpageView',
34 - 'ThreadHistoryView' => 'ThreadHistoryView',
 34+ 'ThreadHistoryListingView' => 'ThreadHistoryListingView',
 35+ 'ThreadHistoricalRevisionView' => 'ThreadHistoricalRevisionView',
3536 'ThreadPermalinkView' => 'ThreadPermalinkView'
3637 );
3738
@@ -66,7 +67,9 @@
6768 /* breaking the lqt_method paradigm to make the history tab work.
6869 (just changing the href doesn't make the highlighting correct.) */
6970 if( $request->getVal('action') == 'history' ) {
70 - $viewname = self::$views['ThreadHistoryView'];
 71+ $viewname = self::$views['ThreadHistoryListingView'];
 72+ } else if ( $request->getVal('lqt_oldid', null) !== null ) {
 73+ $viewname = self::$views['ThreadHistoricalRevisionView'];
7174 } else {
7275 $viewname = self::$views['ThreadPermalinkView'];
7376 }
@@ -547,21 +550,16 @@
548551 $html . wfCloseElement("h{$this->headerLevel}") );
549552 }
550553 }
 554+
 555+ function threadDivClass( $thread ) {
 556+ return 'lqt_thread';
 557+ }
551558
552559 function showThread( $thread ) {
553560 global $wgLang; # TODO global.
554561
555 - efVarDump($this->output, $thread->changeObject()->id());
556 - $is_changed_thread = $thread->isHistorical() && $thread->changeObject()->id() == $thread->id();
557 -
558562 $this->showThreadHeading( $thread );
559563
560 -
561 -
562 -/* efVarDump($this->output, $thread->isHistorical());
563 - efVarDump($this->output, $thread->id());
564 - efVarDump($this->output, $thread->changeObject()->id());
565 -*/
566564 $this->output->addHTML( "<a name=\"lqt_thread_{$thread->id()}\" ></a>" );
567565
568566 if ($thread->type() == Threads::TYPE_MOVED) {
@@ -597,13 +595,9 @@
598596 && !$thread->summary() && !$thread->hasSuperthread() && !$thread->isHistorical() ) {
599597 $this->output->addHTML("<p class=\"lqt_summary_notice\">If this discussion seems to be concluded, you are encouraged to <a href=\"{$this->permalinkUrl($thread, 'summarize')}\">write a summary</a>. There have been no changes here for at least $this->archive_start_days days.</p>");
600598 }
 599+
 600+ $this->openDiv($this->threadDivClass($thread), "lqt_thread_id_{$thread->id()}");
601601
602 - if( $is_changed_thread ) {
603 - $this->openDiv('lqt_thread lqt_thread_changed_by_history', "lqt_thread_id_{$thread->id()}");
604 - } else {
605 - $this->openDiv('lqt_thread', "lqt_thread_id_{$thread->id()}");
606 - }
607 -
608602 $this->showRootPost( $thread );
609603 $this->indent();
610604 foreach( $thread->subthreads() as $st ) {

Status & tagging log