r22925 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22924‎ | r22925 | r22926 >
Date:07:10, 12 June 2007
Author:david
Status:old
Tags:
Comment:
Much nicer if you do the arithmetic on indexes. Duh! This is still ridiculous, crappy, and toxic code.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/skins/common/lqt.js (modified) (history)
  • /branches/liquidthreads/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: branches/liquidthreads/skins/monobook/main.css
@@ -128,7 +128,14 @@
129129 display: inline;
130130 }
131131
 132+.lqt_search_annotations {
 133+ float: left;
 134+ text-align: right;
 135+ font-style: italic;
 136+}
 137+
132138 #lqt_archive_search_form {
 139+ clear:left;
133140 border: 1px solid #ddd;
134141 margin: 0.5em 0;
135142 background-color: #eee;
@@ -138,7 +145,9 @@
139146 #lqt_archive_search_form table {
140147 background-color: transparent;
141148 }
142 -
 149+.lqt_archive_listing {
 150+ clear: left;
 151+}
143152 .lqt_archive_listing td {
144153 padding-right: 2em;
145154 padding-bottom: 1em;
Index: branches/liquidthreads/skins/common/lqt.js
@@ -38,7 +38,7 @@
3939 // In order for this instance to recieve the events, we need to capture the
4040 // current value of 'this' with a closure, because this = the target object
4141 // in event handlers.
42 - me = this;
 42+ var me = this;
4343 lqt_add_event( this.startsel, 'change', function(e) { me.handle_start_changed(e) });
4444 lqt_add_event( this.endsel, 'change', function(e) { me.handle_end_changed(e) });
4545 }
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -670,26 +670,36 @@
671671 $r = $this->request;
672672
673673 /* START AND END DATES */
 674+ // $this->start and $this->end are clipped into the range of available
 675+ // months, for use in the actual query and the selects. $this->raw* are
 676+ // as actually provided, for use by the 'older' and 'newer' buttons.
674677 $ignore_dates = ! $r->getVal('lqt_archive_filter_by_date', true);
 678+ if ( !$ignore_dates ) {
 679+ $months = Thread::monthsWhereArticleHasThreads($this->article);
 680+ }
675681 $s = $r->getVal('lqt_archive_start');
676682 if ($s && ctype_digit($s) && strlen($s) == 6 && !$ignore_dates) {
677 - $this->start = new Date( "{$s}01000000" );
678 - $where[] = 'thread_touched >= ' . $this->start->text();
 683+ $this->selstart = new Date( "{$s}01000000" );
 684+ $this->starti = array_search($s, $months);
 685+ $where[] = 'thread_touched >= ' . $this->selstart->text();
679686 }
680687 $e = $r->getVal('lqt_archive_end');
681688 if ($e && ctype_digit($e) && strlen($e) == 6 && !$ignore_dates) {
682 - $end = new Date("{$e}01000000");
683 - $this->end = $end->nextMonth();
684 - $where[] = 'thread_touched < ' . $this->end->text();
 689+ $this->selend = new Date("{$e}01000000");
 690+ $this->endi = array_search($e, $months);
 691+ $where[] = 'thread_touched < ' . $this->selend->nextMonth()->text();
685692 }
686 - if ( isset($this->start) && isset($this->end) ) {
687 - $annotations[] = "from {$this->start->text()} to {$this->end->text()}";
688 - } else if (isset($this->start)) {
689 - $annotations[] = "after {$this->start->text()}";
690 - } else if (isset($this->end)) {
691 - $annotations[] = "before {$this->end->text()}";
 693+ if ( isset($this->selstart) && isset($this->selend) ) {
 694+
 695+ $this->datespan = $this->starti - $this->endi;
 696+
 697+ $annotations[] = "from {$this->selstart->text()} to {$this->selend->text()}";
 698+ } else if (isset($this->selstart)) {
 699+ $annotations[] = "after {$this->selstart->text()}";
 700+ } else if (isset($this->selend)) {
 701+ $annotations[] = "before {$this->selend->text()}";
692702 }
693 -
 703+
694704 $this->where = $where;
695705 $this->options = $options;
696706 $this->annotations = implode("<br>\n", $annotations);
@@ -706,6 +716,10 @@
707717
708718 function monthSelect($months, $name) {
709719 $selection = $this->request->getVal($name);
 720+
 721+ // Silently adjust to stay in range.
 722+ $selection = max( min( $selection, $months[0] ), $months[count($months)-1] );
 723+
710724 $options = array();
711725 foreach($months as $m) {
712726 $options[$this->formattedMonth($m)] = $m;
@@ -737,9 +751,15 @@
738752 return $this->title->getFullURL($this->queryStringFromArray($rs));
739753 }
740754
 755+ function clip( $vals, $min, $max ) {
 756+ $res = array();
 757+ foreach($vals as $val) $res[] = max( min( $val, $max ), $min );
 758+ return $res;
 759+ }
 760+
741761 function showSearchForm() {
742762 $months = Thread::monthsWhereArticleHasThreads($this->article);
743 -
 763+
744764 $use_dates = $this->request->getVal('lqt_archive_filter_by_date', null);
745765 if ( $use_dates === null ) {
746766 $use_dates = $this->request->getBool('lqt_archive_start', false) ||
@@ -748,27 +768,31 @@
749769 $any_date_check = !$use_dates ? 'checked="1"' : '';
750770 $these_dates_check = $use_dates ? 'checked="1"' : '';
751771
752 - if( isset($this->start, $this->end) ) {
753 - $older_end = $this->start->lastMonth();
754 - $older_start = $older_end->moved( $this->start->delta( $this->end ) )->nextMonth();
 772+ if( isset($this->datespan) ) {
 773+ $oatte = $this->starti + 1;
 774+ $oatts = $this->starti + 1 + $this->datespan;
755775
756 - $newer_start = $this->end;
757 - $newer_end = $newer_start->moved( $this->end->delta( $this->start ) )->lastMonth();
 776+ $natts = $this->endi - 1;
 777+ $natte = $this->endi - 1 - $this->datespan;
758778
 779+ list($oe, $os, $ns, $ne) =
 780+ $this->clip( array($oatte, $oatts, $natts, $natte),
 781+ 0, count($months)-1 );
 782+
759783 $older = '<a href="' . $this->queryReplace(array(
760784 'lqt_archive_filter_by_date'=>'1',
761 - 'lqt_archive_start' => substr($older_start->text(), 0, 6),
762 - 'lqt_archive_end' => substr($older_end->text(), 0, 6) ))
 785+ 'lqt_archive_start' => $months[$os],
 786+ 'lqt_archive_end' => $months[$oe]))
763787 . '">«older</a>';
764788 $newer = '<a href="' . $this->queryReplace(array(
765789 'lqt_archive_filter_by_date'=>'1',
766 - 'lqt_archive_start' => substr($newer_start->text(), 0, 6),
767 - 'lqt_archive_end' => substr($newer_end->text(), 0, 6) ))
 790+ 'lqt_archive_start' => $months[$ns],
 791+ 'lqt_archive_end' => $months[$ne]))
768792 . '">newer»</a>';
769793 }
770794 else {
771 - $older = '<span class="lqt_disabled_link">«older</span>';
772 - $newer = '<span class="lqt_disabled_link">newer»</span>';
 795+ $older = '<span class="lqt_disabled_link" title="This link is disabled because you are viewing threads from all dates.">«older</span>';
 796+ $newer = '<span class="lqt_disabled_link" title="This link is disabled because you are viewing threads from all dates.">newer»</span>';
773797 }
774798
775799 $this->output->addHTML(<<<HTML
@@ -805,8 +829,9 @@
806830 $this->addJSandCSS();
807831
808832 $this->showSearchForm();
809 - $this->output->addHTML("<p>" . $this->annotations . ".</p>");
 833+
810834 $this->output->addHTML(<<<HTML
 835+<p class="lqt_search_annotations">{$this->annotations}</p>
811836 <table class="lqt_archive_listing">
812837 <col class="lqt_titles" />
813838 <col class="lqt_summaries" />

Status & tagging log