From 209ed51d275be5cc7d97f1e60f7aff2735a03845 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 11 Dec 2006 19:29:41 +0000 Subject: [PATCH] Implements bug #4673 : Special:Allpages should display "previous" link Notes: added a 'prevpage' message, you might want to review database queries --- RELEASE-NOTES | 2 +- includes/SpecialAllpages.php | 56 +++++++++++++++++++++++++++---- languages/messages/MessagesEn.php | 1 + 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 8a03d01de2..a8de8927b9 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -268,7 +268,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN Duplicated code merged into wfResetOutputBuffers() and wfClearOutputBuffers() * Special:AllPages : 'next page' link now point to the first title of the next chunk instead of pointing to the last title of current chunk. - +* (bug 4673) Special:AllPages : add a 'previous' link (new message 'prevpage') == Languages updated == diff --git a/includes/SpecialAllpages.php b/includes/SpecialAllpages.php index 51ef5c9742..c68026af57 100644 --- a/includes/SpecialAllpages.php +++ b/includes/SpecialAllpages.php @@ -231,8 +231,6 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) { ) ); - ### FIXME: side link to previous - $n = 0; $out = ''; @@ -263,15 +261,52 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) { if ( $including ) { $out2 = ''; } else { + + # Get the last title from previous chunk + $res_prev = $dbr->select( + 'page', + 'page_title', + array( 'page_namespace' => $namespace, 'page_title < '.$dbr->addQuotes($from) ), + $fname, + array( 'ORDER BY' => 'page_title DESC', 'LIMIT' => $this->maxPerPage, 'OFFSET' => ($this->maxPerPage - 1 ) ) + ); + + # Get first title of previous complete chunk + if( $dbr->numrows( $res_prev ) >= $this->maxPerPage ) { + $pt = $dbr->fetchObject( $res_prev ); + $prevTitle = Title::makeTitle( $namespace, $pt->page_title ); + } else { + # The previous chunk is not complete, need to link to the very first title + # available in the database + $reallyFirstPage_title = $dbr->selectField( 'page', 'page_title', array( 'page_namespace' => $namespace ), $fname, array( 'LIMIT' => 1) ); + + # Show the previous link if it s not the current requested chunk + if( $from != $reallyFirstPage_title ) { + $prevTitle = Title::makeTitle( $namespace, $reallyFirstPage_title ); + } else { + $prevTitle = null; + } + } + $nsForm = $this->namespaceForm ( $namespace, $from ); $out2 = '
'; $out2 .= '
' . $nsForm; $out2 .= '' . $sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ), wfMsgHtml ( 'allpages' ) ); - if ( isset($dbr) && $dbr && ($n == $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) { - $t = Title::MakeTitle( $s->page_namespace, $s->page_title ); - $self = SpecialPage::getTitleFor( 'Allpages' ); + + $self = SpecialPage::getTitleFor( 'Allpages' ); + + # Do we put a previous link ? + if( isset( $prevTitle ) && $pt = $prevTitle->getText() ) { + $q = 'from=' . $prevTitle->getPartialUrl() . ( $namespace ? '&namespace=' . $namespace : '' ); + $prevLink = $sk->makeKnownLinkObj( $self, wfMsgHTML( 'prevpage', $pt ), $q ); + $out2 .= ' | ' . $prevLink; + } + + if( $n == $this->maxPerPage && $s = $dbr->fetchObject($res) ) { + # $s is the first link of the next chunk + $t = Title::MakeTitle($namespace, $s->page_title); $q = 'from=' . $t->getPartialUrl() . ( $namespace ? '&namespace=' . $namespace : '' ); $nextLink = $sk->makeKnownLinkObj( $self, wfMsgHtml( 'nextpage', $t->getText() ), $q ); $out2 .= ' | ' . $nextLink; @@ -280,8 +315,15 @@ function showChunk( $namespace = NS_MAIN, $from, $including = false ) { } $wgOut->addHtml( $out2 . $out ); - if( isset( $nextLink ) ) - $wgOut->addHtml( '

' . $nextLink . '

' ); + if( isset($prevLink) or isset($nextLink) ) { + $wgOut->addHtml( '

' ); + if( isset( $prevLink ) ) + $wgOut->addHTML( $prevLink . ' | '); + if( isset( $nextLink ) ) + $wgOut->addHTML( $nextLink ); + $wgOut->addHTML( '

' ); + + } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index d799fd06af..eac35cd45a 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1525,6 +1525,7 @@ You can narrow down the view by selecting a log type, the user name, or the affe # Special:Allpages 'nextpage' => 'Next page ($1)', +'prevpage' => 'Previous page ($1)', 'allpagesfrom' => 'Display pages starting at:', 'allarticles' => 'All articles', 'allinnamespace' => 'All pages ($1 namespace)', -- 2.20.1