From a1ae55577c3aed9e683a2304f5b014462c018abf Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Wed, 29 Jun 2005 00:23:42 +0000 Subject: [PATCH] * (bug 2595) Show "Earlier" and "Latest" links on history go to the first/last page in the article history pager. --- RELEASE-NOTES | 2 ++ includes/PageHistory.php | 41 ++++++++++++++++++++++++++++++++++++++-- languages/Language.php | 2 ++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 0e07b1a310..4375dbec2c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -411,6 +411,8 @@ Various bugfixes, small features, and a few experimental things: * (bug 2583) Add --missinig option on rebuildImages.php to add db entries for uploaded files that don't have them * (bug 2572) Fix edit conflict handling +* (bug 2595) Show "Earlier" and "Latest" links on history go to the first/last + page in the article history pager. === Caveats === diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 830d14f399..798ab3c5db 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -37,7 +37,7 @@ class PageHistory { $fname = 'PageHistory::history'; wfProfileIn( $fname ); - $wgOut->setPageTitle( $this->mTitle->getPRefixedText() ); + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); $wgOut->setSubtitle( wfMsg( 'revhistory' ) ); $wgOut->setArticleFlag( false ); $wgOut->setArticleRelated( true ); @@ -55,6 +55,30 @@ class PageHistory { $offset = $wgRequest->getText('offset'); if (!isset($offset) || !preg_match("/^[0-9]+$/", $offset)) $offset = 0; + if (($gowhere = $wgRequest->getText("go")) !== NULL) { + switch ($gowhere) { + case "first": + if (($lastid = $this->getLastOffset($id, $limit)) === NULL) + break; + $gourl = $wgTitle->getLocalURL("action=history&limit={$limit}&offset={$lastid}"); + break; + default: + $gourl = NULL; + } + + if (!is_null($gourl)) { + $wgOut->redirect($gourl); + return; + } + } + + $firsturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}&go=first"); + $lasturl = $wgTitle->escapeLocalURL("action=history&limit={$limit}"); + $firsttext = wfMsg("histfirst"); + $lasttext = wfMsg("histlast"); + + $firstlast = "($firsttext | $lasttext)"; + /* Check one extra row to see whether we need to show 'next' and diff links */ $limitplus = $limit + 1; @@ -127,7 +151,7 @@ class PageHistory { "action=history&offset={$offset}&limit={$num}")."\">".$wgLang->formatNum($num).""; } $bits = implode($urls, ' | '); - $numbar = wfMsg("viewprevnext", + $numbar = "$firstlast " . wfMsg("viewprevnext", "".wfMsg("prevn", $limit)."", "".wfMsg("nextn", $limit)."", $bits); @@ -321,6 +345,19 @@ class PageHistory { } } + function getLastOffset($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"); + $n = $db->numRows($res); + + if ($n == 0) + return NULL; + + while ($n--) + $obj = $db->fetchObject($res); + return $obj->rev_timestamp; + } } ?> diff --git a/languages/Language.php b/languages/Language.php index 27d33446f8..045f26f867 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -774,6 +774,8 @@ Legend: (cur) = difference with current version, (last) = difference with preceding version, M = minor edit.', 'history_copyright' => '-', 'deletedrev' => '[deleted]', +'histfirst' => 'Earliest', +'histlast' => 'Latest', # Diffs # -- 2.20.1