r22863 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22862‎ | r22863 | r22864 >
Date:08:29, 9 June 2007
Author:david
Status:old
Tags:
Comment:
Half an implementation of the 'older' and 'newer' links. Turns out you have to use the bignum arithmetic functions, because integers to represent dates are really, really big. Doh. It's scary that numbers in PHP are almost exactly like numbers in C.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -668,19 +668,19 @@
669669 $ignore_dates = ! $r->getVal('lqt_archive_filter_by_date', true);
670670 $s = $r->getVal('lqt_archive_start');
671671 if ($s && ctype_digit($s) && strlen($s) == 6 && !$ignore_dates) {
672 - $start = "{$s}00000000";
673 - $where[] = 'thread_touched >= ' . $start;
 672+ $this->start = "{$s}00000000";
 673+ $where[] = 'thread_touched >= ' . $this->start;
674674 }
675675 $e = $r->getVal('lqt_archive_end');
676676 if ($e && ctype_digit($e) && strlen($e) == 6 && !$ignore_dates) {
677 - $end = "{$e}31235959";
678 - $where[] = 'thread_touched <= ' . $end;
 677+ $this->end = "{$e}31235959";
 678+ $where[] = 'thread_touched <= ' . $this->end;
679679 }
680 - if ( isset($start) && isset($end) ) {
 680+ if ( isset($this->start) && isset($this->end) ) {
681681 $annotations[] = "from $start to $end";
682 - } else if (isset($start)) {
 682+ } else if (isset($this->start)) {
683683 $annotations[] = "after $start";
684 - } else if (isset($end)) {
 684+ } else if (isset($this->end)) {
685685 $annotations[] = "before $end";
686686 }
687687
@@ -714,6 +714,24 @@
715715 $result .= "</select>";
716716 return $result;
717717 }
 718+
 719+ /**
 720+ * Return a URL for the current page, including Title and query vars,
 721+ * with the given replacements made.
 722+ * @param $repls array( 'name'=>new_value, ... )
 723+ */
 724+ function queryReplace( $repls ) {
 725+ $vs = $this->request->getValues();
 726+ $rs = array();
 727+ foreach ($vs as $k => $v) {
 728+ if ( array_key_exists( $k, $repls ) ) {
 729+ $rs[$k] = $repls[$k];
 730+ } else {
 731+ $rs[$k] = $vs[$k];
 732+ }
 733+ }
 734+ return $this->title->getFullURL($this->queryStringFromArray($rs));
 735+ }
718736
719737 function showSearchForm() {
720738 $months = Thread::monthsWhereArticleHasThreads($this->article);
@@ -726,6 +744,25 @@
727745 $any_date_check = !$use_dates ? 'checked="1"' : '';
728746 $these_dates_check = $use_dates ? 'checked="1"' : '';
729747
 748+ // bcsub() and bcadd() do arithmetic on strings.
 749+ // wouldn't want to overflow any puny 32-bit machines with these
 750+ // giants numbers that reperesent dates.
 751+
 752+ if( isset($this->start, $this->end) ) {
 753+ var_dump($this->start, $this->end);
 754+ $delta = bcsub($this->end, $this->start);
 755+ $older_start = bcsub($this->start, $delta);
 756+ $newer_start = bcadd($this->start, $delta);
 757+ $older_end = bcsub($this->end, $delta);
 758+ $newer_end = bcadd($this->end, $delta);
 759+ }
 760+
 761+ var_dump($older_start, $older_end);
 762+
 763+ $older = $this->queryReplace(array('lqt_archive_filter_by_date'=>'1',
 764+ 'lqt_archive_start' => substr($older_start, 0, 6),
 765+ 'lqt_archive_end' => substr($older_end, 0, 6) ));
 766+
730767 $this->output->addHTML(<<<HTML
731768 <form id="lqt_archive_search_form" action="{$this->title->getLocalURL()}">
732769 <input type="hidden" name="lqt_show_archive" value="1">
@@ -742,6 +779,9 @@
743780 <label for="lqt_archive_end">End</label>
744781 {$this->monthSelect($months, 'lqt_archive_end')}
745782 <input type="submit">
 783+
 784+ <a href="$older">«older</a>
 785+ <a href="$newer">newer»</a>
746786 </form>
747787 HTML
748788 );

Status & tagging log