Merge "Move list generation out of TablePager::getLimitSelect()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 26 Apr 2013 15:20:47 +0000 (15:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 26 Apr 2013 15:20:47 +0000 (15:20 +0000)
1  2 
includes/Pager.php

diff --combined includes/Pager.php
@@@ -155,13 -155,13 +155,13 @@@ abstract class IndexPager extends Conte
                $index = $this->getIndexField(); // column to sort on
                $extraSort = $this->getExtraSortFields(); // extra columns to sort on for query planning
                $order = $this->mRequest->getVal( 'order' );
 -              if( is_array( $index ) && isset( $index[$order] ) ) {
 +              if ( is_array( $index ) && isset( $index[$order] ) ) {
                        $this->mOrderType = $order;
                        $this->mIndexField = $index[$order];
                        $this->mExtraSortFields = isset( $extraSort[$order] )
                                ? (array)$extraSort[$order]
                                : array();
 -              } elseif( is_array( $index ) ) {
 +              } elseif ( is_array( $index ) ) {
                        # First element is the default
                        reset( $index );
                        list( $this->mOrderType, $this->mIndexField ) = each( $index );
                        $this->mExtraSortFields = (array)$extraSort;
                }
  
 -              if( !isset( $this->mDefaultDirection ) ) {
 +              if ( !isset( $this->mDefaultDirection ) ) {
                        $dir = $this->getDefaultDirections();
                        $this->mDefaultDirection = is_array( $dir )
                                ? $dir[$this->mOrderType]
                }
  
                $attrs = array();
 -              if( in_array( $type, array( 'first', 'prev', 'next', 'last' ) ) ) {
 +              if ( in_array( $type, array( 'first', 'prev', 'next', 'last' ) ) ) {
                        # HTML5 rel attributes
                        $attrs['rel'] = $type;
                }
  
 -              if( $type ) {
 +              if ( $type ) {
                        $attrs['class'] = "mw-{$type}link";
                }
  
         *
         * @return Array
         */
 -      protected function getExtraSortFields() { return array(); }
 +      protected function getExtraSortFields() {
 +              return array();
 +      }
  
        /**
         * Return the default sorting direction: false for ascending, true for
         *
         * @return Boolean
         */
 -      protected function getDefaultDirections() { return false; }
 +      protected function getDefaultDirections() {
 +              return false;
 +      }
  }
  
  /**
@@@ -730,7 -726,7 +730,7 @@@ abstract class AlphabeticPager extends 
                        return '';
                }
  
 -              if( isset( $this->mNavigationBar ) ) {
 +              if ( isset( $this->mNavigationBar ) ) {
                        return $this->mNavigationBar;
                }
  
                        $this->msg( 'viewprevnext' )->rawParams( $pagingLinks['prev'],
                                $pagingLinks['next'], $limits )->escaped();
  
 -              if( !is_array( $this->getIndexField() ) ) {
 +              if ( !is_array( $this->getIndexField() ) ) {
                        # Early return to avoid undue nesting
                        return $this->mNavigationBar;
                }
                $extra = '';
                $first = true;
                $msgs = $this->getOrderTypeMessages();
 -              foreach( array_keys( $msgs ) as $order ) {
 -                      if( $first ) {
 +              foreach ( array_keys( $msgs ) as $order ) {
 +                      if ( $first ) {
                                $first = false;
                        } else {
                                $extra .= $this->msg( 'pipe-separator' )->escaped();
                        }
  
 -                      if( $order == $this->mOrderType ) {
 +                      if ( $order == $this->mOrderType ) {
                                $extra .= $this->msg( $msgs[$order] )->escaped();
                        } else {
                                $extra .= $this->makeLink(
                        }
                }
  
 -              if( $extra !== '' ) {
 +              if ( $extra !== '' ) {
                        $extra = ' ' . $this->msg( 'parentheses' )->rawParams( $extra )->escaped();
                        $this->mNavigationBar .= $extra;
                }
@@@ -861,7 -857,7 +861,7 @@@ abstract class ReverseChronologicalPage
                        // If no year given, assume the current one
                        $year = gmdate( 'Y' );
                        // If this month hasn't happened yet this year, go back to last year's month
 -                      if( $this->mMonth > gmdate( 'n' ) ) {
 +                      if ( $this->mMonth > gmdate( 'n' ) ) {
                                $year--;
                        }
                }
@@@ -908,9 -904,7 +908,9 @@@ abstract class TablePager extends Index
                }
  
                $this->mSort = $this->getRequest()->getText( 'sort' );
 -              if ( !array_key_exists( $this->mSort, $this->getFieldNames() ) ) {
 +              if ( !array_key_exists( $this->mSort, $this->getFieldNames() )
 +                      || !$this->isFieldSortable( $this->mSort )
 +              ) {
                        $this->mSort = $this->getDefaultSort();
                }
                if ( $this->getRequest()->getBool( 'asc' ) ) {
                        'next' => 'arrow_disabled_right_25.png',
                        'last' => 'arrow_disabled_last_25.png',
                );
 -              if( $this->getLanguage()->isRTL() ) {
 +              if ( $this->getLanguage()->isRTL() ) {
                        $keys = array_keys( $labels );
                        $images = array_combine( $keys, array_reverse( $images ) );
                        $disabledImages = array_combine( $keys, array_reverse( $disabledImages ) );
         * @return String: HTML fragment
         */
        public function getLimitSelect() {
+               $select = new XmlSelect( 'limit', false, $this->mLimit );
+               $select->addOptions( $this->getLimitSelectList() );
+               return $select->getHTML();
+       }
+       /**
+        * Get a list of items to show in a "<select>" element of limits.
+        * This can be passed directly to XmlSelect::addOptions().
+        *
+        * @since 1.22
+        * @return array
+        */
+       public function getLimitSelectList() {
                # Add the current limit from the query string
                # to avoid that the limit is lost after clicking Go next time
                if ( !in_array( $this->mLimit, $this->mLimitsShown ) ) {
                        $this->mLimitsShown[] = $this->mLimit;
                        sort( $this->mLimitsShown );
                }
-               $s = Html::openElement( 'select', array( 'name' => 'limit' ) ) . "\n";
+               $ret = array();
                foreach ( $this->mLimitsShown as $key => $value ) {
                        # The pair is either $index => $limit, in which case the $value
                        # will be numeric, or $limit => $text, in which case the $value
                        # will be a string.
 -                      if( is_int( $value ) ) {
 +                      if ( is_int( $value ) ) {
                                $limit = $value;
                                $text = $this->getLanguage()->formatNum( $limit );
                        } else {
                                $limit = $key;
                                $text = $value;
                        }
-                       $s .= Xml::option( $text, $limit, $limit == $this->mLimit ) . "\n";
+                       $ret[$text] = $limit;
                }
-               $s .= Html::closeElement( 'select' );
-               return $s;
+               return $ret;
        }
  
        /**