Clarification for $wgRestrictionLevels
[lhc/web/wiklou.git] / includes / Pager.php
index e882a36..a475dc1 100644 (file)
@@ -2,6 +2,7 @@
 
 /**
  * Basic pager interface.
+ * @addtogroup Pager
  */
 interface Pager {
        function getNavigationBar();
@@ -46,6 +47,8 @@ interface Pager {
  *  please see the examples in PageHistory.php and SpecialIpblocklist.php. You just need 
  *  to override formatRow(), getQueryInfo() and getIndexField(). Don't forget to call the 
  *  parent constructor if you override it.
+ *
+ * @addtogroup Pager
  */
 abstract class IndexPager implements Pager {
        public $mRequest;
@@ -69,17 +72,18 @@ abstract class IndexPager implements Pager {
        public $mResult;
 
        function __construct() {
-               global $wgRequest;
+               global $wgRequest, $wgUser;
                $this->mRequest = $wgRequest;
-
+               
                # NB: the offset is quoted, not validated. It is treated as an arbitrary string
                # to support the widest variety of index types. Be careful outputting it into 
                # HTML!
                $this->mOffset = $this->mRequest->getText( 'offset' );
-               $this->mLimit = $this->mRequest->getInt( 'limit', $this->mDefaultLimit );
-               if ( $this->mLimit <= 0 ) {
-                       $this->mLimit = $this->mDefaultLimit;
-               }
+               
+               # Use consistent behavior for the limit options
+               $this->mDefaultLimit = intval( $wgUser->getOption( 'rclimit' ) );
+               list( $this->mLimit, /* $offset */ ) = $this->mRequest->getLimitOffset();
+               
                $this->mIsBackwards = ( $this->mRequest->getVal( 'dir' ) == 'prev' );
                $this->mIndexField = $this->getIndexField();
                $this->mDb = wfGetDB( DB_SLAVE );
@@ -323,7 +327,7 @@ abstract class IndexPager implements Pager {
                        $next = array( 'offset' => $this->mLastShown, 'limit' => $urlLimit );
                        $last = array( 'dir' => 'prev', 'limit' => $urlLimit );
                }
-               return compact( 'prev', 'next', 'first', 'last' );
+               return array( 'prev' => $prev, 'next' => $next, 'first' => $first, 'last' => $last );
        }
 
        /**
@@ -358,6 +362,7 @@ abstract class IndexPager implements Pager {
                        $links[] = $this->makeLink( $wgLang->formatNum( $limit ),
                                array( 'offset' => $offset, 'limit' => $limit ) );
                }
+               return $links;
        }
 
        /**
@@ -385,8 +390,45 @@ abstract class IndexPager implements Pager {
        abstract function getIndexField();
 }
 
+
+/**
+ * IndexPager with an alphabetic list and a formatted navigation bar
+ * @addtogroup Pager
+ */
+abstract class AlphabeticPager extends IndexPager {
+       public $mDefaultDirection = false;
+       
+       function __construct() {
+               parent::__construct();
+       }
+       
+       /** 
+        * Shamelessly stolen bits from ReverseChronologicalPager, d
+        * didn't want to do class magic as may be still revamped 
+        */
+       function getNavigationBar() {
+               global $wgLang;
+               
+               $linkTexts = array(
+                       'prev' => wfMsgHtml( "prevn", $this->mLimit ),
+                       'next' => wfMsgHtml( 'nextn', $this->mLimit ),
+                       'first' => wfMsgHtml('page_first'), /* Introduced the message */
+                       'last' => wfMsgHtml( 'page_last' )  /* Introduced the message */
+               );
+               
+               $pagingLinks = $this->getPagingLinks( $linkTexts );
+               $limitLinks = $this->getLimitLinks();
+               $limits = implode( ' | ', $limitLinks );
+               
+               $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
+               return $this->mNavigationBar;
+               
+       }
+}
+
 /**
  * IndexPager with a formatted navigation bar
+ * @addtogroup Pager
  */
 abstract class ReverseChronologicalPager extends IndexPager {
        public $mDefaultDirection = true;
@@ -412,13 +454,15 @@ abstract class ReverseChronologicalPager extends IndexPager {
                $limitLinks = $this->getLimitLinks();
                $limits = implode( ' | ', $limitLinks );
                
-               $this->mNavigationBar = "($latestText | $earliestText) " . wfMsgHtml("viewprevnext", $prevText, $nextText, $limits);
+               $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " . 
+                       wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
                return $this->mNavigationBar;
        }
 }
 
 /**
  * Table-based display with a user-selectable sort order
+ * @addtogroup Pager
  */
 abstract class TablePager extends IndexPager {
        var $mSort;
@@ -441,8 +485,13 @@ abstract class TablePager extends IndexPager {
 
        function getStartBody() {
                global $wgStylePath;
-               $s = "<table border='1' class=\"TablePager\"><thead><tr>\n";
+               $tableClass = htmlspecialchars( $this->getTableClass() );
+               $sortClass = htmlspecialchars( $this->getSortHeaderClass() );
+               
+               $s = "<table border='1' class=\"$tableClass\"><thead><tr>\n";
                $fields = $this->getFieldNames();
+
+               # Make table header
                foreach ( $fields as $field => $name ) {
                        if ( strval( $name ) == '' ) {
                                $s .= "<th>&nbsp;</th>\n";
@@ -468,7 +517,7 @@ abstract class TablePager extends IndexPager {
                                        $link = $this->makeLink( 
                                                "<img width=\"12\" height=\"12\" alt=\"$alt\" src=\"$image\" />" .
                                                htmlspecialchars( $name ), $query );
-                                       $s .= "<th class=\"TablePager_sort\">$link</th>\n";
+                                       $s .= "<th class=\"$sortClass\">$link</th>\n";
                                } else {
                                        $s .= '<th>' . $this->makeLink( htmlspecialchars( $name ), $query ) . "</th>\n";
                                }
@@ -481,7 +530,7 @@ abstract class TablePager extends IndexPager {
        }
 
        function getEndBody() {
-               return '</tbody></table>';
+               return "</tbody></table>\n";
        }
 
        function getEmptyBody() {
@@ -500,7 +549,8 @@ abstract class TablePager extends IndexPager {
                        if ( $formatted == '' ) {
                                $formatted = '&nbsp;';
                        }
-                       $s .= "<td>$formatted</td>\n";
+                       $class = 'TablePager_col_' . htmlspecialchars( $field );
+                       $s .= "<td class=\"$class\">$formatted</td>\n";
                }
                $s .= "</tr>\n";
                return $s;
@@ -510,31 +560,43 @@ abstract class TablePager extends IndexPager {
                return $this->mSort;
        }
 
+       function getTableClass() {
+               return 'TablePager';
+       }
+
+       function getNavClass() {
+               return 'TablePager_nav';
+       }
+
+       function getSortHeaderClass() {
+               return 'TablePager_sort';
+       }
+
        /**
         * A navigation bar with images
         */
        function getNavigationBar() {
-               global $wgStylePath;
+               global $wgStylePath, $wgContLang;
                $path = "$wgStylePath/common/images";
-               $labels = array( 
+               $labels = array(
                        'first' => 'table_pager_first',
                        'prev' => 'table_pager_prev',
                        'next' => 'table_pager_next',
                        'last' => 'table_pager_last',
                );
                $images = array(
-                       'first' => 'arrow_first_25.png',
-                       'prev' =>  'arrow_left_25.png',
-                       'next' =>  'arrow_right_25.png',
-                       'last' =>  'arrow_last_25.png',
+                       'first' => $wgContLang->isRTL() ? 'arrow_last_25.png' : 'arrow_first_25.png',
+                       'prev' =>  $wgContLang->isRTL() ? 'arrow_right_25.png' : 'arrow_left_25.png',
+                       'next' =>  $wgContLang->isRTL() ? 'arrow_left_25.png' : 'arrow_right_25.png',
+                       'last' =>  $wgContLang->isRTL() ? 'arrow_first_25.png' : 'arrow_last_25.png',
                );
                $disabledImages = array(
-                       'first' => 'arrow_disabled_first_25.png',
-                       'prev' =>  'arrow_disabled_left_25.png',
-                       'next' =>  'arrow_disabled_right_25.png',
-                       'last' =>  'arrow_disabled_last_25.png',
+                       'first' => $wgContLang->isRTL() ? 'arrow_disabled_last_25.png' : 'arrow_disabled_first_25.png',
+                       'prev' =>  $wgContLang->isRTL() ? 'arrow_disabled_right_25.png' : 'arrow_disabled_left_25.png',
+                       'next' =>  $wgContLang->isRTL() ? 'arrow_disabled_left_25.png' : 'arrow_disabled_right_25.png',
+                       'last' =>  $wgContLang->isRTL() ? 'arrow_disabled_first_25.png' : 'arrow_disabled_last_25.png',
                );
-                       
+
                $linkTexts = array();
                $disabledTexts = array();
                foreach ( $labels as $type => $label ) {
@@ -544,12 +606,13 @@ abstract class TablePager extends IndexPager {
                }
                $links = $this->getPagingLinks( $linkTexts, $disabledTexts );
 
-               $s = '<table class="TablePager_nav" align="center" cellpadding="3"><tr>';
+               $navClass = htmlspecialchars( $this->getNavClass() );
+               $s = "<table class=\"$navClass\" align=\"center\" cellpadding=\"3\"><tr>\n";
                $cellAttrs = 'valign="top" align="center" width="' . 100 / count( $links ) . '%"';
                foreach ( $labels as $type => $label ) {
                        $s .= "<td $cellAttrs>{$links[$type]}</td>\n";
                }
-               $s .= '</tr></table>';
+               $s .= "</tr></table>\n";
                return $s;
        }