Fix navigation buttons on Special:Listfiles for first and last page
[lhc/web/wiklou.git] / includes / specials / SpecialListfiles.php
index 7484995..8e17015 100644 (file)
@@ -33,6 +33,7 @@ class SpecialListFiles extends IncludableSpecialPage {
                if ( $this->including() ) {
                        $userName = $par;
                        $search = '';
+                       $showAll = false;
                } else {
                        $userName = $this->getRequest()->getText( 'user', $par );
                        $search = $this->getRequest()->getText( 'ilsearch', '' );
@@ -67,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
@@ -120,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 ) {
@@ -128,7 +135,7 @@ class ImageListPager extends TablePager {
                $conds = array();
 
                if ( !is_null( $this->mUserName ) ) {
-                       $conds[ $prefix . '_user_text' ] = $this->mUserName;
+                       $conds[$prefix . '_user_text'] = $this->mUserName;
                }
 
                if ( $this->mSearch !== '' ) {
@@ -153,7 +160,7 @@ class ImageListPager extends TablePager {
        }
 
        /**
-        * @return Array
+        * @return array
         */
        function getFieldNames() {
                if ( !$this->mFieldNames ) {
@@ -163,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();
                        }
@@ -214,6 +226,7 @@ class ImageListPager extends TablePager {
                // for two different tables, without reimplementing
                // the pager class.
                $qi = $this->getQueryInfoReal( $this->mTableName );
+
                return $qi;
        }
 
@@ -224,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 ) {
@@ -289,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;
 
@@ -310,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;
@@ -324,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 ) {
@@ -337,7 +355,7 @@ class ImageListPager extends TablePager {
                $topRes2 = $res2->next();
                $resultArray = array();
                for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
-                       if ( strcmp( $topRes1->{ $this->mIndexField }, $topRes2->{ $this->mIndexField } ) > 0 ) {
+                       if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
                                if ( !$ascending ) {
                                        $resultArray[] = $topRes1;
                                        $topRes1 = $res1->next();
@@ -355,14 +373,21 @@ 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();
                }
+
                return new FakeResultWrapper( $resultArray );
        }
 
@@ -386,6 +411,20 @@ class ImageListPager extends TablePager {
                UserCache::singleton()->doQuery( $userIds, array( 'userpage' ), __METHOD__ );
        }
 
+       /**
+        * @param string $field
+        * @param string $value
+        * @return Message|string|int The return type depends on the value of $field:
+        *   - thumb: string
+        *   - img_timestamp: string
+        *   - img_name: string
+        *   - img_user_text: string
+        *   - img_size: string
+        *   - img_description: string
+        *   - count: int
+        *   - top: Message
+        * @throws MWException
+        */
        function formatValue( $field, $value ) {
                switch ( $field ) {
                        case 'thumb':
@@ -394,6 +433,7 @@ class ImageListPager extends TablePager {
                                // If statement for paranoia
                                if ( $file ) {
                                        $thumb = $file->transform( array( 'width' => 180, 'height' => 360 ) );
+
                                        return $thumb->toHtml( array( 'desc-link' => true ) );
                                } else {
                                        return htmlspecialchars( $value );
@@ -445,6 +485,8 @@ class ImageListPager extends TablePager {
                        case 'top':
                                // Messages: listfiles-latestversion-yes, listfiles-latestversion-no
                                return $this->msg( 'listfiles-latestversion-' . $value );
+                       default:
+                               throw new MWException( "Unknown field '$field'" );
                }
        }
 
@@ -476,6 +518,7 @@ class ImageListPager extends TablePager {
                        'checked' => $this->mShowAll,
                        'tabindex' => 4,
                ) );
+
                return Html::openElement( 'form',
                        array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listfiles-form' )
                ) .
@@ -504,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;
+                               }
                        }
                }