From: Aaron Schulz Date: Sun, 22 Feb 2009 18:26:27 +0000 (+0000) Subject: * Added titles to wfViewPrevNext() paging links X-Git-Tag: 1.31.0-rc.0~42721 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=f7ddb39d5095fe474ecd7cb331e10ca99f15675c;p=lhc%2Fweb%2Fwiklou.git * Added titles to wfViewPrevNext() paging links * Escape prevn/nextn messages. Other cleanup. * Added some comments --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index c9a7693b40..61c7657020 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -940,7 +940,8 @@ function wfBacktrace() { */ function wfShowingResults( $offset, $limit ) { global $wgLang; - return wfMsgExt( 'showingresults', array( 'parseinline' ), $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ) ); + return wfMsgExt( 'showingresults', array( 'parseinline' ), $wgLang->formatNum( $limit ), + $wgLang->formatNum( $offset+1 ) ); } /** @@ -948,18 +949,28 @@ function wfShowingResults( $offset, $limit ) { */ function wfShowingResultsNum( $offset, $limit, $num ) { global $wgLang; - return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) ); + return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ), + $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) ); } /** - * @todo document + * Generate (prev x| next x) (20|50|100...) type links for paging + * @param $offset string + * @param $limit int + * @param $link string + * @param $query string, optional URL query parameter string + * @param $atend bool, optional param for specified if this is the last page */ function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) { global $wgLang; $fmtLimit = $wgLang->formatNum( $limit ); - $prev = wfMsg( 'prevn', $fmtLimit ); - $next = wfMsg( 'nextn', $fmtLimit ); - + # Get prev/next link display text + $prev = wfMsgHtml( 'prevn', $fmtLimit ); + $next = wfMsgHtml( 'nextn', $fmtLimit ); + # Get prev/next link title text + $pTitle = wfMsgExt( 'prevn-title', array('parsemag','escape'), $fmtLimit ); + $nTitle = wfMsgExt( 'nextn-title', array('parsemag','escape'), $fmtLimit ); + # Fetch the title object if( is_object( $link ) ) { $title =& $link; } else { @@ -968,44 +979,58 @@ function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) { return false; } } - - if ( 0 != $offset ) { + # Make 'previous' link + if( 0 != $offset ) { $po = $offset - $limit; - if ( $po < 0 ) { $po = 0; } + $po = max($po,0); $q = "limit={$limit}&offset={$po}"; - if ( '' != $query ) { $q .= '&'.$query; } - $plink = '{$prev}"; - } else { $plink = $prev; } - + if( $query != '' ) { + $q .= '&'.$query; + } + $plink = '{$prev}"; + } else { + $plink = $prev; + } + # Make 'next' link $no = $offset + $limit; - $q = 'limit='.$limit.'&offset='.$no; - if ( '' != $query ) { $q .= '&'.$query; } - - if ( $atend ) { + $q = "limit={$limit}&offset={$no}"; + if( $query != '' ) { + $q .= '&'.$query; + } + if( $atend ) { $nlink = $next; } else { - $nlink = '{$next}"; - } - $nums = $wgLang->pipeList( array( wfNumLink( $offset, 20, $title, $query ), - wfNumLink( $offset, 50, $title, $query ), - wfNumLink( $offset, 100, $title, $query ), - wfNumLink( $offset, 250, $title, $query ), - wfNumLink( $offset, 500, $title, $query ) ) ); - + $nlink = '{$next}"; + } + # Make links to set number of items per page + $nums = $wgLang->pipeList( array( + wfNumLink( $offset, 20, $title, $query ), + wfNumLink( $offset, 50, $title, $query ), + wfNumLink( $offset, 100, $title, $query ), + wfNumLink( $offset, 250, $title, $query ), + wfNumLink( $offset, 500, $title, $query ) + ) ); return wfMsg( 'viewprevnext', $plink, $nlink, $nums ); } /** - * @todo document + * Generate links for (20|50|100...) items-per-page links + * @param $offset string + * @param $limit int + * @param $title Title + * @param $query string, optional URL query parameter string */ -function wfNumLink( $offset, $limit, &$title, $query = '' ) { +function wfNumLink( $offset, $limit, $title, $query = '' ) { global $wgLang; - if ( '' == $query ) { $q = ''; } - else { $q = $query.'&'; } - $q .= 'limit='.$limit.'&offset='.$offset; - + if( $query == '' ) { + $q = ''; + } else { + $q = $query.'&'; + } + $q .= "limit={$limit}&offset={$offset}"; $fmtLimit = $wgLang->formatNum( $limit ); - $s = '{$fmtLimit}"; + $lTitle = wfMsgExt('shown-title',array('parsemag','escape'),$limit); + $s = '{$fmtLimit}"; return $s; } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 6db4d1bd16..2295204771 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1457,6 +1457,9 @@ You can [[:\$1|create this page]].", 'notextmatches' => 'No page text matches', 'prevn' => 'previous $1', 'nextn' => 'next $1', +'prevn-title' => 'Previous $1 {{PLURAL:$1|result|results}}', +'nextn-title' => 'Next $1 {{PLURAL:$1|result|results}}', +'shown-title' => 'Show $1 {{PLURAL:$1|result|results}} per page', 'viewprevnext' => 'View ($1) ($2) ($3)', 'searchmenu-legend' => 'Search options', 'searchmenu-exists' => "'''There is a page named \"[[:\$1]]\" on this wiki'''",