Fixed spacing in files direct in includes folder
[lhc/web/wiklou.git] / includes / Pager.php
index 29ff894..d70734c 100644 (file)
@@ -155,13 +155,13 @@ abstract class IndexPager extends ContextSource implements Pager {
                $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 );
@@ -175,7 +175,7 @@ abstract class IndexPager extends ContextSource implements Pager {
                        $this->mExtraSortFields = (array)$extraSort;
                }
 
-               if( !isset( $this->mDefaultDirection ) ) {
+               if ( !isset( $this->mDefaultDirection ) ) {
                        $dir = $this->getDefaultDirections();
                        $this->mDefaultDirection = is_array( $dir )
                                ? $dir[$this->mOrderType]
@@ -432,7 +432,7 @@ abstract class IndexPager extends ContextSource implements Pager {
         * Make a self-link
         *
         * @param string $text text displayed on the link
-        * @param array $query associative array of paramter to be in the query string
+        * @param array $query associative array of parameter to be in the query string
         * @param string $type value of the "rel" attribute
         *
         * @return String: HTML fragment
@@ -443,12 +443,12 @@ abstract class IndexPager extends ContextSource implements Pager {
                }
 
                $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";
                }
 
@@ -685,11 +685,13 @@ abstract class IndexPager extends ContextSource implements Pager {
         *
         * @return Array
         */
-       protected function getExtraSortFields() { return array(); }
+       protected function getExtraSortFields() {
+               return array();
+       }
 
        /**
-        * Return the default sorting direction: false for ascending, true for de-
-        * scending.  You can also have an associative array of ordertype => dir,
+        * Return the default sorting direction: false for ascending, true for
+        * descending.  You can also have an associative array of ordertype => dir,
         * if multiple order types are supported.  In this case getIndexField()
         * must return an array, and the keys of that must exactly match the keys
         * of this.
@@ -706,7 +708,9 @@ abstract class IndexPager extends ContextSource implements Pager {
         *
         * @return Boolean
         */
-       protected function getDefaultDirections() { return false; }
+       protected function getDefaultDirections() {
+               return false;
+       }
 }
 
 /**
@@ -726,7 +730,7 @@ abstract class AlphabeticPager extends IndexPager {
                        return '';
                }
 
-               if( isset( $this->mNavigationBar ) ) {
+               if ( isset( $this->mNavigationBar ) ) {
                        return $this->mNavigationBar;
                }
 
@@ -749,7 +753,7 @@ abstract class AlphabeticPager extends IndexPager {
                        $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;
                }
@@ -757,14 +761,14 @@ abstract class AlphabeticPager extends IndexPager {
                $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(
@@ -774,7 +778,7 @@ abstract class AlphabeticPager extends IndexPager {
                        }
                }
 
-               if( $extra !== '' ) {
+               if ( $extra !== '' ) {
                        $extra = ' ' . $this->msg( 'parentheses' )->rawParams( $extra )->escaped();
                        $this->mNavigationBar .= $extra;
                }
@@ -784,8 +788,8 @@ abstract class AlphabeticPager extends IndexPager {
 
        /**
         * If this supports multiple order type messages, give the message key for
-        * enabling each one in getNavigationBar.  The return type is an associa-
-        * tive array whose keys must exactly match the keys of the array returned
+        * enabling each one in getNavigationBar.  The return type is an associative
+        * array whose keys must exactly match the keys of the array returned
         * by getIndexField(), and whose values are message keys.
         *
         * @return Array
@@ -857,7 +861,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
                        // 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--;
                        }
                }
@@ -904,7 +908,9 @@ abstract class TablePager extends IndexPager {
                }
 
                $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' ) ) {
@@ -922,16 +928,15 @@ abstract class TablePager extends IndexPager {
         */
        function getStartBody() {
                global $wgStylePath;
-               $tableClass = htmlspecialchars( $this->getTableClass() );
-               $sortClass = htmlspecialchars( $this->getSortHeaderClass() );
+               $sortClass = $this->getSortHeaderClass();
 
-               $s = "<table style='border:1px;' class=\"mw-datatable $tableClass\"><thead><tr>\n";
+               $s = '';
                $fields = $this->getFieldNames();
 
                # Make table header
                foreach ( $fields as $field => $name ) {
                        if ( strval( $name ) == '' ) {
-                               $s .= "<th>&#160;</th>\n";
+                               $s .= Html::rawElement( 'th', array(), '&#160;' ) . "\n";
                        } elseif ( $this->isFieldSortable( $field ) ) {
                                $query = array( 'sort' => $field, 'limit' => $this->mLimit );
                                if ( $field == $this->mSort ) {
@@ -950,20 +955,26 @@ abstract class TablePager extends IndexPager {
                                                $query['desc'] = '1';
                                                $alt = $this->msg( 'ascending_abbrev' )->escaped();
                                        }
-                                       $image = htmlspecialchars( "$wgStylePath/common/images/$image" );
+                                       $image = "$wgStylePath/common/images/$image";
                                        $link = $this->makeLink(
-                                               "<img width=\"12\" height=\"12\" alt=\"$alt\" src=\"$image\" />" .
-                                                       htmlspecialchars( $name ), $query );
-                                       $s .= "<th class=\"$sortClass\">$link</th>\n";
+                                               Html::element( 'img', array( 'width' => 12, 'height' => 12,
+                                                       'alt' => $alt, 'src' => $image ) ) . htmlspecialchars( $name ), $query );
+                                       $s .= Html::rawElement( 'th', array( 'class' => $sortClass ), $link ) . "\n";
                                } else {
-                                       $s .= '<th>' . $this->makeLink( htmlspecialchars( $name ), $query ) . "</th>\n";
+                                       $s .= Html::rawElement( 'th', array(),
+                                               $this->makeLink( htmlspecialchars( $name ), $query ) ) . "\n";
                                }
                        } else {
-                               $s .= '<th>' . htmlspecialchars( $name ) . "</th>\n";
+                               $s .= Html::element( 'th', array(), $name ) . "\n";
                        }
                }
-               $s .= "</tr></thead><tbody>\n";
-               return $s;
+
+               $tableClass = $this->getTableClass();
+               $ret = Html::openElement( 'table', array( 'style' => 'border:1px;', 'class' => "mw-datatable $tableClass" ) );
+               $ret .= Html::rawElement( 'thead', array(), Html::rawElement( 'tr', array(), "\n" . $s . "\n" ) );
+               $ret .= Html::openElement( 'tbody' ) . "\n";
+
+               return $ret;
        }
 
        /**
@@ -980,8 +991,9 @@ abstract class TablePager extends IndexPager {
         */
        function getEmptyBody() {
                $colspan = count( $this->getFieldNames() );
-               $msgEmpty = $this->msg( 'table_pager_empty' )->escaped();
-               return "<tr><td colspan=\"$colspan\">$msgEmpty</td></tr>\n";
+               $msgEmpty = $this->msg( 'table_pager_empty' )->text();
+               return Html::rawElement( 'tr', array(),
+                       Html::element( 'td', array( 'colspan' => $colspan ), $msgEmpty ) );
        }
 
        /**
@@ -991,7 +1003,7 @@ abstract class TablePager extends IndexPager {
         */
        function formatRow( $row ) {
                $this->mCurrentRow = $row; // In case formatValue etc need to know
-               $s = Xml::openElement( 'tr', $this->getRowAttrs( $row ) );
+               $s = Html::openElement( 'tr', $this->getRowAttrs( $row ) ) . "\n";
                $fieldNames = $this->getFieldNames();
 
                foreach ( $fieldNames as $field => $name ) {
@@ -1002,10 +1014,10 @@ abstract class TablePager extends IndexPager {
                                $formatted = '&#160;';
                        }
 
-                       $s .= Xml::tags( 'td', $this->getCellAttrs( $field, $value ), $formatted );
+                       $s .= Html::rawElement( 'td', $this->getCellAttrs( $field, $value ), $formatted ) . "\n";
                }
 
-               $s .= "</tr>\n";
+               $s .= Html::closeElement( 'tr' ) . "\n";
 
                return $s;
        }
@@ -1117,7 +1129,7 @@ abstract class TablePager extends IndexPager {
                        '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 ) );
@@ -1127,18 +1139,20 @@ abstract class TablePager extends IndexPager {
                $disabledTexts = array();
                foreach ( $labels as $type => $label ) {
                        $msgLabel = $this->msg( $label )->escaped();
-                       $linkTexts[$type] = "<img src=\"$path/{$images[$type]}\" alt=\"$msgLabel\"/><br />$msgLabel";
-                       $disabledTexts[$type] = "<img src=\"$path/{$disabledImages[$type]}\" alt=\"$msgLabel\"/><br />$msgLabel";
+                       $linkTexts[$type] = Html::element( 'img', array( 'src' => "$path/{$images[$type]}",
+                               'alt' => $msgLabel ) ) . "<br />$msgLabel";
+                       $disabledTexts[$type] = Html::element( 'img', array( 'src' => "$path/{$disabledImages[$type]}",
+                               'alt' => $msgLabel ) ) . "<br />$msgLabel";
                }
                $links = $this->getPagingLinks( $linkTexts, $disabledTexts );
 
-               $navClass = htmlspecialchars( $this->getNavClass() );
-               $s = "<table class=\"$navClass\"><tr>\n";
+               $s = Html::openElement( 'table', array( 'class' => $this->getNavClass() ) );
+               $s .= Html::openElement( 'tr' ) . "\n";
                $width = 100 / count( $links ) . '%';
                foreach ( $labels as $type => $label ) {
-                       $s .= "<td style='width:$width;'>{$links[$type]}</td>\n";
+                       $s .= Html::rawElement( 'td', array( 'style' => "width:$width;" ), $links[$type] ) . "\n";
                }
-               $s .= "</tr></table>\n";
+               $s .= Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n";
                return $s;
        }
 
@@ -1159,7 +1173,7 @@ abstract class TablePager extends IndexPager {
                        # 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 {
@@ -1188,9 +1202,7 @@ abstract class TablePager extends IndexPager {
                }
                $s = '';
                foreach ( $query as $name => $value ) {
-                       $encName = htmlspecialchars( $name );
-                       $encValue = htmlspecialchars( $value );
-                       $s .= "<input type=\"hidden\" name=\"$encName\" value=\"$encValue\"/>\n";
+                       $s .= Html::hidden( $name, $value ) . "\n";
                }
                return $s;
        }
@@ -1203,12 +1215,14 @@ abstract class TablePager extends IndexPager {
        function getLimitForm() {
                global $wgScript;
 
-               return Xml::openElement(
+               return Html::rawElement(
                        'form',
                        array(
                                'method' => 'get',
                                'action' => $wgScript
-                       ) ) . "\n" . $this->getLimitDropdown() . "</form>\n";
+                       ),
+                       "\n" . $this->getLimitDropdown()
+               ) . "\n";
        }
 
        /**