* Added titles to wfViewPrevNext() paging links
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 22 Feb 2009 18:26:27 +0000 (18:26 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 22 Feb 2009 18:26:27 +0000 (18:26 +0000)
* Escape prevn/nextn messages. Other cleanup.
* Added some comments

includes/GlobalFunctions.php
languages/messages/MessagesEn.php

index c9a7693..61c7657 100644 (file)
@@ -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 = '<a href="' . $title->escapeLocalUrl( $q ) . "\" class=\"mw-prevlink\">{$prev}</a>";
-       } else { $plink = $prev; }
-
+               if( $query != '' ) {
+                       $q .= '&'.$query;
+               }
+               $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>";
+       } 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 = '<a href="' . $title->escapeLocalUrl( $q ) . "\" class=\"mw-nextlink\">{$next}</a>";
-       }
-       $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 = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>";
+       }
+       # 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 = '<a href="' . $title->escapeLocalUrl( $q ) . "\" class=\"mw-numlink\">{$fmtLimit}</a>";
+       $lTitle = wfMsgExt('shown-title',array('parsemag','escape'),$limit);
+       $s = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$lTitle}\" class=\"mw-numlink\">{$fmtLimit}</a>";
        return $s;
 }
 
index 6db4d1b..2295204 100644 (file)
@@ -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'''",