Fix r53270: drop &returntoquery parameter if empty, and prevent Special:Userlogin...
[lhc/web/wiklou.git] / includes / Pager.php
index 32bfec5..3f96251 100644 (file)
@@ -417,6 +417,14 @@ abstract class IndexPager implements Pager {
                return array( 'prev' => $prev, 'next' => $next, 'first' => $first, 'last' => $last );
        }
 
+       function isNavigationBarShown() {
+               if ( !$this->mQueryDone ) {
+                       $this->doQuery();
+               }
+               // Hide navigation by default if there is nothing to page
+               return !($this->mIsFirst && $this->mIsLast);
+       }
+
        /**
         * Get paging links. If a link is disabled, the item from $disabledTexts
         * will be used. If there is no such item, the unlinked text from
@@ -468,6 +476,7 @@ abstract class IndexPager implements Pager {
         *    fields => Field(s) for passing to Database::select(), may be *
         *    conds => WHERE conditions
         *    options => option array
+        *    join_conds => JOIN conditions
         */
        abstract function getQueryInfo();
 
@@ -516,6 +525,8 @@ abstract class AlphabeticPager extends IndexPager {
        function getNavigationBar() {
                global $wgLang;
 
+               if ( !$this->isNavigationBarShown() ) return '';
+
                if( isset( $this->mNavigationBar ) ) {
                        return $this->mNavigationBar;
                }
@@ -530,10 +541,10 @@ abstract class AlphabeticPager extends IndexPager {
 
                $pagingLinks = $this->getPagingLinks( $linkTexts );
                $limitLinks = $this->getLimitLinks();
-               $limits = implode( ' | ', $limitLinks );
+               $limits = $wgLang->pipeList( $limitLinks );
 
                $this->mNavigationBar =
-                       "({$pagingLinks['first']} | {$pagingLinks['last']}) " .
+                       "(" . $wgLang->pipeList( array( $pagingLinks['first'], $pagingLinks['last'] ) ) . ") " .
                        wfMsgHtml( 'viewprevnext', $pagingLinks['prev'],
                        $pagingLinks['next'], $limits );
 
@@ -549,7 +560,7 @@ abstract class AlphabeticPager extends IndexPager {
                        if( $first ) {
                                $first = false;
                        } else {
-                               $extra .= ' | ';
+                               $extra .= wfMsgExt( 'pipe-separator' , 'escapenoentities' );
                        }
 
                        if( $order == $this->mOrderType ) {
@@ -597,22 +608,24 @@ abstract class ReverseChronologicalPager extends IndexPager {
        function getNavigationBar() {
                global $wgLang;
 
+               if ( !$this->isNavigationBarShown() ) return '';
+
                if ( isset( $this->mNavigationBar ) ) {
                        return $this->mNavigationBar;
                }
                $nicenumber = $wgLang->formatNum( $this->mLimit );
                $linkTexts = array(
-                       'prev' => wfMsgExt( 'pager-newer-n', array( 'parsemag' ), $nicenumber ),
-                       'next' => wfMsgExt( 'pager-older-n', array( 'parsemag' ), $nicenumber ),
+                       'prev' => wfMsgExt( 'pager-newer-n', array( 'parsemag', 'escape' ), $nicenumber ),
+                       'next' => wfMsgExt( 'pager-older-n', array( 'parsemag', 'escape' ), $nicenumber ),
                        'first' => wfMsgHtml( 'histlast' ),
                        'last' => wfMsgHtml( 'histfirst' )
                );
 
                $pagingLinks = $this->getPagingLinks( $linkTexts );
                $limitLinks = $this->getLimitLinks();
-               $limits = implode( ' | ', $limitLinks );
+               $limits = $wgLang->pipeList( $limitLinks );
 
-               $this->mNavigationBar = "({$pagingLinks['first']} | {$pagingLinks['last']}) " .
+               $this->mNavigationBar = "({$pagingLinks['first']}" . wfMsgExt( 'pipe-separator' , 'escapenoentities' ) . "{$pagingLinks['last']}) " .
                        wfMsgHtml("viewprevnext", $pagingLinks['prev'], $pagingLinks['next'], $limits);
                return $this->mNavigationBar;
        }
@@ -745,27 +758,50 @@ abstract class TablePager extends IndexPager {
        }
 
        function formatRow( $row ) {
-               $class = $this->getRowClass( $row );
-               $s = "<tr class=\"$class\">\n";
+               $this->mCurrentRow = $row;      # In case formatValue etc need to know
+               $s = Xml::openElement( 'tr', $this->getRowAttrs($row) );
                $fieldNames = $this->getFieldNames();
-               $this->mCurrentRow = $row;  # In case formatValue needs to know
                foreach ( $fieldNames as $field => $name ) {
                        $value = isset( $row->$field ) ? $row->$field : null;
                        $formatted = strval( $this->formatValue( $field, $value ) );
                        if ( $formatted == '' ) {
                                $formatted = '&nbsp;';
                        }
-                       $class = 'TablePager_col_' . htmlspecialchars( $field );
-                       $s .= "<td class=\"$class\">$formatted</td>\n";
+                       $s .= Xml::tags( 'td', $this->getCellAttrs( $field, $value ), $formatted );
                }
                $s .= "</tr>\n";
                return $s;
        }
 
-       function getRowClass($row) {
+       /**
+        * Get a class name to be applied to the given row.
+        * @param object $row The database result row
+        */
+       function getRowClass( $row ) {
                return '';
        }
 
+       /**
+        * Get attributes to be applied to the given row.
+        * @param object $row The database result row
+        * @return associative array
+        */
+       function getRowAttrs( $row ) {
+               return array( 'class' => $this->getRowClass( $row ) );
+       }
+
+       /**
+        * Get any extra attributes to be applied to the given cell. Don't 
+        * take this as an excuse to hardcode styles; use classes and 
+        * CSS instead.  Row context is available in $this->mCurrentRow
+        * @param $field The column
+        * @param $value The cell contents
+        * @return associative array
+        */
+       function getCellAttrs( $field, $value ) {
+               return array( 'class' => 'TablePager_col_' . $field );
+       }
+
        function getIndexField() {
                return $this->mSort;
        }
@@ -787,6 +823,9 @@ abstract class TablePager extends IndexPager {
         */
        function getNavigationBar() {
                global $wgStylePath, $wgContLang;
+
+               if ( !$this->isNavigationBarShown() ) return '';
+
                $path = "$wgStylePath/common/images";
                $labels = array(
                        'first' => 'table_pager_first',
@@ -865,14 +904,15 @@ abstract class TablePager extends IndexPager {
         * Get a form containing a limit selection dropdown
         */
        function getLimitForm() {
+               global $wgScript;
+
                # Make the select with some explanatory text
-               $url = $this->getTitle()->escapeLocalURL();
                $msgSubmit = wfMsgHtml( 'table_pager_limit_submit' );
                return
-                       "<form method=\"get\" action=\"$url\">" .
+                       Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . "\n" .          
                        wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) .
                        "\n<input type=\"submit\" value=\"$msgSubmit\"/>\n" .
-                       $this->getHiddenFields( array('limit','title') ) .
+                       $this->getHiddenFields( array( 'limit' ) ) .
                        "</form>\n";
        }