From df4fc4f8d62273630ebf8f3c6a40fc10f18071d1 Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Wed, 29 Jun 2005 03:54:11 +0000 Subject: [PATCH] ask the database for the low and high ts instead of trying to fudge it --- includes/PageHistory.php | 41 +++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 3329684313..06ee5fca8c 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -99,7 +99,7 @@ class PageHistory { if (($gowhere = $wgRequest->getText("go")) !== NULL) { switch ($gowhere) { case "first": - if (($lastid = $this->getLastOffset($id, $limit)) === NULL) + if (($lastid = $this->getLastOffsetForPaging($id, $limit)) === NULL) break; $gourl = $wgTitle->getLocalURL("action=history&limit={$limit}&offset={$lastid}"); break; @@ -338,11 +338,27 @@ class PageHistory { } } - function getLastOffset($id, $step = 50) { + function getFirstOffset($id) { + $db =& wfGetDB(DB_SLAVE); + $sql = "SELECT MAX(rev_timestamp) AS lowest FROM revision WHERE rev_page = $id"; + $res = $db->query($sql, "getFirstOffset"); + $obj = $db->fetchObject($res); + return $obj->lowest; + } + + function getLastOffset($id) { + $db =& wfGetDB(DB_SLAVE); + $sql = "SELECT MIN(rev_timestamp) AS lowest FROM revision WHERE rev_page = $id"; + $res = $db->query($sql, "getLastOffset"); + $obj = $db->fetchObject($res); + return $obj->lowest; + } + + function getLastOffsetForPaging($id, $step = 50) { $db =& wfGetDB(DB_SLAVE); $sql = "SELECT rev_timestamp FROM revision WHERE rev_page = $id " . "ORDER BY rev_timestamp ASC LIMIT $step"; - $res = $db->query($sql, "getLastOffset"); + $res = $db->query($sql, "getLastOffsetForPaging"); $n = $db->numRows($res); if ($n == 0) @@ -433,14 +449,11 @@ wfdebug("limits=$limits offset=$offsets got=".count($result)."\n"); function makeNavbar($revisions, $offset, $limit, $direction) { global $wgTitle, $wgLang; - /* - * lowts is the timestamp of the first revision on this page. - * hights is the timestamp of the last revision. - */ - $atend = !(count($revisions) > $limit); -wfDebug("offset=$offset limit=$limit dir=$direction count=".count($revisions)."\n"); $revisions = array_slice($revisions, 0, $limit); + $abslowts = $this->getLastOffset($this->mTitle->getArticleID()); + $abshights = $this->getFirstOffset($this->mTitle->getArticleID()); + /* * When we're displaying previous revisions, we need to reverse * the array, because it's queried in reverse order. @@ -448,6 +461,11 @@ wfDebug("offset=$offset limit=$limit dir=$direction count=".count($revisions)."\ if ($direction == DIR_PREV) $revisions = array_reverse($revisions); + /* + * lowts is the timestamp of the first revision on this page. + * hights is the timestamp of the last revision. + */ + $lowts = $hights = 0; if (count($revisions)) { @@ -468,13 +486,14 @@ wfDebug("offset=$offset limit=$limit dir=$direction count=".count($revisions)."\ $urls[] = "escapeLocalURL( "action=history&offset={$offset}&limit={$num}")."\">".$wgLang->formatNum($num).""; } +wfDebug("lowts=$lowts abslowts=$abslowts\n"); $bits = implode($urls, ' | '); - if (($direction == DIR_NEXT && $offset) || ($direction == DIR_PREV && !$atend)) { + if ($lowts < $abslowts) { $prevtext = "".wfMsg("prevn", $limit).""; $lasttext = "$lasttext"; } else $prevtext = wfMsg("prevn", $limit); - if (!$atend || $direction == DIR_PREV) { + if ($hights < $abshights) { $nexttext = "".wfMsg("nextn", $limit).""; $firsttext = "$firsttext"; } else $nexttext = wfMsg("nextn", $limit); -- 2.20.1