Revert "Adding sanity check to Title::isRedirect()."
[lhc/web/wiklou.git] / includes / Pager.php
index 2673205..438a99a 100644 (file)
@@ -1,11 +1,30 @@
 <?php
 /**
- * @defgroup Pager Pager
+ * Efficient paging for SQL queries.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
  * @ingroup Pager
  */
 
+/**
+ * @defgroup Pager Pager
+ */
+
 /**
  * Basic pager interface.
  * @ingroup Pager
@@ -294,14 +313,14 @@ abstract class IndexPager extends ContextSource implements Pager {
                $join_conds = isset( $info['join_conds'] ) ? $info['join_conds'] : array();
                $sortColumns = array_merge( array( $this->mIndexField ), $this->mExtraSortFields );
                if ( $descending ) {
-                       $options['ORDER BY'] = implode( ',', $sortColumns );
+                       $options['ORDER BY'] = $sortColumns;
                        $operator = '>';
                } else {
                        $orderBy = array();
                        foreach ( $sortColumns as $col ) {
                                $orderBy[] = $col . ' DESC';
                        }
-                       $options['ORDER BY'] = implode( ',', $orderBy );
+                       $options['ORDER BY'] = $orderBy;
                        $operator = '<';
                }
                if ( $offset != '' ) {
@@ -366,9 +385,10 @@ abstract class IndexPager extends ContextSource implements Pager {
         * @param $text String: text displayed on the link
         * @param $query Array: associative array of paramter to be in the query string
         * @param $type String: value of the "rel" attribute
+        *
         * @return String: HTML fragment
         */
-       function makeLink($text, $query = null, $type=null) {
+       function makeLink( $text, array $query = null, $type = null ) {
                if ( $query === null ) {
                        return $text;
                }
@@ -382,6 +402,7 @@ abstract class IndexPager extends ContextSource implements Pager {
                if( $type ) {
                        $attrs['class'] = "mw-{$type}link";
                }
+
                return Linker::linkKnown(
                        $this->getTitle(),
                        $text,
@@ -472,7 +493,7 @@ abstract class IndexPager extends ContextSource implements Pager {
                }
 
                # Don't announce the limit everywhere if it's the default
-               $urlLimit = $this->mLimit == $this->mDefaultLimit ? '' : $this->mLimit;
+               $urlLimit = $this->mLimit == $this->mDefaultLimit ? null : $this->mLimit;
 
                if ( $this->mIsFirst ) {
                        $prev = false;
@@ -526,6 +547,7 @@ abstract class IndexPager extends ContextSource implements Pager {
        function getPagingLinks( $linkTexts, $disabledTexts = array() ) {
                $queries = $this->getPagingQueries();
                $links = array();
+
                foreach ( $queries as $type => $query ) {
                        if ( $query !== false ) {
                                $links[$type] = $this->makeLink(
@@ -539,6 +561,7 @@ abstract class IndexPager extends ContextSource implements Pager {
                                $links[$type] = $linkTexts[$type];
                        }
                }
+
                return $links;
        }
 
@@ -651,7 +674,9 @@ abstract class AlphabeticPager extends IndexPager {
         * @return String HTML
         */
        function getNavigationBar() {
-               if ( !$this->isNavigationBarShown() ) return '';
+               if ( !$this->isNavigationBarShown() ) {
+                       return '';
+               }
 
                if( isset( $this->mNavigationBar ) ) {
                        return $this->mNavigationBar;
@@ -679,13 +704,13 @@ abstract class AlphabeticPager extends IndexPager {
                $limitLinks = $this->getLimitLinks();
                $limits = $lang->pipeList( $limitLinks );
 
-               $this->mNavigationBar =
-                       "(" . $lang->pipeList(
+               $this->mNavigationBar = wfMessage( 'parentheses' )->rawParams(
+                       $lang->pipeList(
                                array( $pagingLinks['first'],
-                               $pagingLinks['last'] )
-                       ) . ") " .
+                                       $pagingLinks['last'] )
+                       ) )->escaped() . " " .
                        wfMsgHtml( 'viewprevnext', $pagingLinks['prev'],
-                       $pagingLinks['next'], $limits );
+                               $pagingLinks['next'], $limits );
 
                if( !is_array( $this->getIndexField() ) ) {
                        # Early return to avoid undue nesting
@@ -713,7 +738,8 @@ abstract class AlphabeticPager extends IndexPager {
                }
 
                if( $extra !== '' ) {
-                       $this->mNavigationBar .= " ($extra)";
+                       $extra = ' ' . wfMessage( 'parentheses' )->rawParams( $extra )->escaped();
+                       $this->mNavigationBar .= $extra;
                }
 
                return $this->mNavigationBar;
@@ -771,7 +797,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
                $limits = $this->getLanguage()->pipeList( $limitLinks );
                $firstLastLinks = wfMessage( 'parentheses' )->rawParams( "{$pagingLinks['first']}" .
                        wfMsgExt( 'pipe-separator' , 'escapenoentities' ) .
-                       "{$pagingLinks['last']}" )->escape();
+                       "{$pagingLinks['last']}" )->escaped();
 
                $this->mNavigationBar = $firstLastLinks . ' ' .
                        wfMsgHTML(
@@ -786,9 +812,11 @@ abstract class ReverseChronologicalPager extends IndexPager {
        function getDateCond( $year, $month ) {
                $year = intval( $year );
                $month = intval( $month );
+
                // Basic validity checks
                $this->mYear = $year > 0 ? $year : false;
                $this->mMonth = ( $month > 0 && $month < 13 ) ? $month : false;
+
                // Given an optional year and month, we need to generate a timestamp
                // to use as "WHERE rev_timestamp <= result"
                // Examples: year = 2006 equals < 20070101 (+000000)
@@ -797,6 +825,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
                if ( !$this->mYear && !$this->mMonth ) {
                        return;
                }
+
                if ( $this->mYear ) {
                        $year = $this->mYear;
                } else {
@@ -807,6 +836,7 @@ abstract class ReverseChronologicalPager extends IndexPager {
                                $year--;
                        }
                }
+
                if ( $this->mMonth ) {
                        $month = $this->mMonth + 1;
                        // For December, we want January 1 of the next year
@@ -819,14 +849,18 @@ abstract class ReverseChronologicalPager extends IndexPager {
                        $month = 1;
                        $year++;
                }
+
                // Y2K38 bug
                if ( $year > 2032 ) {
                        $year = 2032;
                }
+
                $ymd = (int)sprintf( "%04d%02d01", $year, $month );
+
                if ( $ymd > 20320101 ) {
                        $ymd = 20320101;
                }
+
                $this->mOffset = $this->mDb->timestamp( "${ymd}000000" );
        }
 }
@@ -894,7 +928,7 @@ abstract class TablePager extends IndexPager {
                                        $image = htmlspecialchars( "$wgStylePath/common/images/$image" );
                                        $link = $this->makeLink(
                                                "<img width=\"12\" height=\"12\" alt=\"$alt\" src=\"$image\" />" .
-                                               htmlspecialchars( $name ), $query );
+                                                       htmlspecialchars( $name ), $query );
                                        $s .= "<th class=\"$sortClass\">$link</th>\n";
                                } else {
                                        $s .= '<th>' . $this->makeLink( htmlspecialchars( $name ), $query ) . "</th>\n";