Move list generation out of TablePager::getLimitSelect()
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Thu, 18 Apr 2013 12:59:04 +0000 (14:59 +0200)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Thu, 18 Apr 2013 12:59:04 +0000 (14:59 +0200)
Added TablePager::getLimitSelectList() to get the list of values to
show for the drop-down so that it can be used to generate a custom
<select> or to be used on a form generated with HTMLForm.

Also changed HTML generation to use XmlSelect class.

Change-Id: I13ac9f17c95445b04f3cf6feec6ae36f0b9cb03d

includes/Pager.php

index 56b5d48..1219552 100644 (file)
@@ -1156,13 +1156,26 @@ abstract class TablePager extends IndexPager {
         * @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
@@ -1174,10 +1187,9 @@ abstract class TablePager extends IndexPager {
                                $limit = $key;
                                $text = $value;
                        }
-                       $s .= Xml::option( $text, $limit, $limit == $this->mLimit ) . "\n";
+                       $ret[$text] = $limit;
                }
-               $s .= Html::closeElement( 'select' );
-               return $s;
+               return $ret;
        }
 
        /**