Fix navigation buttons on Special:Listfiles for first and last page
[lhc/web/wiklou.git] / includes / specials / SpecialListfiles.php
index f9caff6..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
@@ -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();
                        }
@@ -298,7 +309,8 @@ class ImageListPager extends TablePager {
        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;
 
@@ -315,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;
@@ -360,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();
                }
@@ -528,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;
+                               }
                        }
                }