Fix navigation buttons on Special:Listfiles for first and last page
[lhc/web/wiklou.git] / includes / specials / SpecialListfiles.php
index 9f0d127..8e17015 100644 (file)
@@ -68,14 +68,20 @@ class SpecialListFiles extends IncludableSpecialPage {
  * @ingroup SpecialPage Pager
  */
 class ImageListPager extends TablePager {
-       var $mFieldNames = null;
+       protected $mFieldNames = null;
+
        // Subclasses should override buildQueryConds instead of using $mQueryConds variable.
-       var $mQueryConds = array();
-       var $mUserName = null;
-       var $mSearch = '';
-       var $mIncluding = false;
-       var $mShowAll = false;
-       var $mTableName = 'image';
+       protected $mQueryConds = array();
+
+       protected $mUserName = null;
+
+       protected $mSearch = '';
+
+       protected $mIncluding = false;
+
+       protected $mShowAll = false;
+
+       protected $mTableName = 'image';
 
        function __construct( IContextSource $context, $userName = null, $search = '',
                $including = false, $showAll = false
@@ -121,7 +127,7 @@ class ImageListPager extends TablePager {
         * Build the where clause of the query.
         *
         * Replaces the older mQueryConds member variable.
-        * @param $table String Either "image" or "oldimage"
+        * @param string $table Either "image" or "oldimage"
         * @return array The query conditions.
         */
        protected function buildQueryConds( $table ) {
@@ -154,7 +160,7 @@ class ImageListPager extends TablePager {
        }
 
        /**
-        * @return Array
+        * @return array
         */
        function getFieldNames() {
                if ( !$this->mFieldNames ) {
@@ -164,9 +170,14 @@ class ImageListPager extends TablePager {
                                'img_name' => $this->msg( 'listfiles_name' )->text(),
                                'thumb' => $this->msg( 'listfiles_thumb' )->text(),
                                'img_size' => $this->msg( 'listfiles_size' )->text(),
-                               'img_user_text' => $this->msg( 'listfiles_user' )->text(),
-                               'img_description' => $this->msg( 'listfiles_description' )->text(),
                        );
+                       if ( is_null( $this->mUserName ) ) {
+                               // Do not show username if filtering by username
+                               $this->mFieldNames['img_user_text'] = $this->msg( 'listfiles_user' )->text();
+                       }
+                       // img_description down here, in order so that its still after the username field.
+                       $this->mFieldNames['img_description'] = $this->msg( 'listfiles_description' )->text();
+
                        if ( !$wgMiserMode && !$this->mShowAll ) {
                                $this->mFieldNames['count'] = $this->msg( 'listfiles_count' )->text();
                        }
@@ -226,7 +237,7 @@ class ImageListPager extends TablePager {
         *
         * This is a bit hacky.
         *
-        * @param $table String Either 'image' or 'oldimage'
+        * @param string $table Either 'image' or 'oldimage'
         * @return array Query info
         */
        protected function getQueryInfoReal( $table ) {
@@ -291,11 +302,15 @@ class ImageListPager extends TablePager {
         * @note $asc is named $descending in IndexPager base class. However
         *   it is true when the order is ascending, and false when the order
         *   is descending, so I renamed it to $asc here.
+        * @param int $offset
+        * @param int $limit
+        * @param bool $asc
         */
        function reallyDoQuery( $offset, $limit, $asc ) {
                $prevTableName = $this->mTableName;
                $this->mTableName = 'image';
-               list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo( $offset, $limit, $asc );
+               list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
+                       $this->buildQueryInfo( $offset, $limit, $asc );
                $imageRes = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
                $this->mTableName = $prevTableName;
 
@@ -312,7 +327,8 @@ class ImageListPager extends TablePager {
                }
                $this->mIndexField = 'oi_' . substr( $this->mIndexField, 4 );
 
-               list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo( $offset, $limit, $asc );
+               list( $tables, $fields, $conds, $fname, $options, $join_conds ) =
+                       $this->buildQueryInfo( $offset, $limit, $asc );
                $oldimageRes = $this->mDb->select( $tables, $fields, $conds, $fname, $options, $join_conds );
 
                $this->mTableName = $prevTableName;
@@ -326,10 +342,10 @@ class ImageListPager extends TablePager {
         *
         * Note: This will throw away some results
         *
-        * @param $res1 ResultWrapper
-        * @param $res2 ResultWrapper
-        * @param $limit int
-        * @param $ascending boolean See note about $asc in $this->reallyDoQuery
+        * @param ResultWrapper $res1
+        * @param ResultWrapper $res2
+        * @param int $limit
+        * @param bool $ascending See note about $asc in $this->reallyDoQuery
         * @return FakeResultWrapper $res1 and $res2 combined
         */
        protected function combineResult( $res1, $res2, $limit, $ascending ) {
@@ -357,11 +373,17 @@ class ImageListPager extends TablePager {
                                }
                        }
                }
+
+               // @codingStandardsIgnoreStart Squiz.WhiteSpace.SemicolonSpacing.Incorrect
                for ( ; $i < $limit && $topRes1; $i++ ) {
+                       // @codingStandardsIgnoreEnd
                        $resultArray[] = $topRes1;
                        $topRes1 = $res1->next();
                }
+
+               // @codingStandardsIgnoreStart Squiz.WhiteSpace.SemicolonSpacing.Incorrect
                for ( ; $i < $limit && $topRes2; $i++ ) {
+                       // @codingStandardsIgnoreEnd
                        $resultArray[] = $topRes2;
                        $topRes2 = $res2->next();
                }
@@ -525,7 +547,9 @@ class ImageListPager extends TablePager {
                if ( !is_null( $this->mUserName ) ) {
                        # Append the username to the query string
                        foreach ( $queries as &$query ) {
-                               $query['user'] = $this->mUserName;
+                               if ( $query !== false ) {
+                                       $query['user'] = $this->mUserName;
+                               }
                        }
                }