r1532 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r1531‎ | r1532 | r1533 >
Date:05:13, 8 August 2003
Author:vibber
Status:old
Tags:
Comment:
Use default time cutoff only for users with over 250 items watched; add explicit 'all' option as well
Modified paths:
  • /trunk/phase3/includes/SpecialWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialWatchlist.php
@@ -11,25 +11,8 @@
1212 $wgOut->setPagetitle( wfMsg( "watchlist" ) );
1313 $sub = str_replace( "$1", $wgUser->getName(), wfMsg( "watchlistsub" ) );
1414 $wgOut->setSubtitle( $sub );
15 - $wgOut->setRobotpolicy( "index,follow" );
 15+ $wgOut->setRobotpolicy( "noindex,nofollow" );
1616
17 - if ( ! isset( $days ) ) {
18 - /*
19 - $days = $wgUser->getOption( "rcdays" );
20 - if ( ! $days ) { $days = 3; }
21 - */
22 - $days = (1.0 / 24.0); # 1 hour...
23 - }
24 - $days = floatval($days);
25 -
26 - if ( $days <= 0 ) {
27 - $docutoff = '';
28 - } else {
29 - $docutoff = "cur_timestamp > '" .
30 - ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
31 - . "' AND";
32 - }
33 -
3417 $uid = $wgUser->getID();
3518 if( $uid == 0 ) {
3619 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
@@ -67,13 +50,33 @@
6851 $wgOut->addHTML( wfMsg( "nowatchlist" ) );
6952 return;
7053 }
 54+
 55+ if ( ! isset( $days ) ) {
 56+ $big = 250;
 57+ if($nitems > $big) {
 58+ # Set default cutoff shorter
 59+ $days = (1.0 / 24.0); # 1 hour...
 60+ } else {
 61+ $days = 0; # no time cutoff for shortlisters
 62+ }
 63+ } else {
 64+ $days = floatval($days);
 65+ }
7166
72 - $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
73 - $res = wfQuery( $sql );
74 - $s = wfFetchObject( $res );
75 - $npages = $s->n;
76 -
77 -
 67+ if ( $days <= 0 ) {
 68+ $docutoff = '';
 69+ $cutoff = false;
 70+ $npages = wfMsg( "all" );
 71+ } else {
 72+ $docutoff = "AND cur_timestamp > '" .
 73+ ( $cutoff = wfUnix2Timestamp( time() - intval( $days * 86400 ) ) )
 74+ . "'";
 75+ $sql = "SELECT COUNT(*) AS n FROM cur WHERE cur_timestamp>'$cutoff'";
 76+ $res = wfQuery( $sql );
 77+ $s = wfFetchObject( $res );
 78+ $npages = $s->n;
 79+ }
 80+
7881 if(isset($_REQUEST['magic'])) {
7982 $wgOut->addHTML( wfMsg( "watchlistcontains", $nitems ) .
8083 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
@@ -105,10 +108,10 @@
106109 # down its entirety and then sort the results.
107110
108111 # If it's relatively long, it may be worth our while to zip
109 - # through the time-sorted page list checking for
 112+ # through the time-sorted page list checking for watched items.
110113
111114 # Up estimate of watched items by 15% to compensate for talk pages...
112 - if( ( $nitems*1.15 > $npages ) ) {
 115+ if( $cutoff && ( $nitems*1.15 > $npages ) ) {
113116 $x = "cur_timestamp";
114117 $y = wfMsg( "watchmethod-recent" );
115118 $z = "wl_namespace=cur_namespace&65534";
@@ -129,7 +132,7 @@
130133 WHERE wl_user=$uid
131134 AND $z
132135 AND wl_title=cur_title
133 - AND cur_timestamp>'$cutoff'
 136+ $docutoff
134137 ORDER BY cur_timestamp DESC";
135138
136139
@@ -137,8 +140,10 @@
138141
139142 if($days >= 1)
140143 $note = wfMsg( "rcnote", $limit, $days );
 144+ elseif($days > 0)
 145+ $note = wfMsg( "wlnote", $limit, round($days*24) );
141146 else
142 - $note = wfMsg( "wlnote", $limit, round($days*24) );
 147+ $note = "";
143148 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
144149 $note = wlCutoffLinks( $days, $limit );
145150 $wgOut->addHTML( "{$note}\n" );
@@ -186,7 +191,7 @@
187192 $sk = $wgUser->getSkin();
188193 $s = $sk->makeKnownLink(
189194 $wgLang->specialPage( $page ),
190 - $d, "days=$d" );
 195+ ($d ? $d : wfMsg( "all" ) ), "days=$d" );
191196 return $s;
192197 }
193198
@@ -206,7 +211,8 @@
207212 return
208213 "Show last " .
209214 implode(" | ", $hours) . " hours " .
210 - implode(" | ", $days) . " days";
 215+ implode(" | ", $days) . " days " .
 216+ wlDaysLink( 0, $page );
211217 # $note = wfMsg( "rclinks", $cl, $dl, $mlink );
212218 }
213219

Status & tagging log