Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / specials / SpecialListfiles.php
index 9a73a25..6c856e9 100644 (file)
@@ -52,6 +52,8 @@ class SpecialListFiles extends IncludableSpecialPage {
                if ( $this->including() ) {
                        $out->addParserOutputContent( $pager->getBodyOutput() );
                } else {
+                       $user = $pager->getRelevantUser();
+                       $this->getSkin()->setRelevantUser( $user );
                        $pager->getForm();
                        $out->addParserOutputContent( $pager->getFullOutput() );
                }
@@ -69,7 +71,7 @@ class SpecialListFiles extends IncludableSpecialPage {
                $user = User::newFromName( $search );
                if ( !$user ) {
                        // No prefix suggestion for invalid user
-                       return array();
+                       return [];
                }
                // Autocomplete subpage as user list - public to allow caching
                return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
@@ -87,10 +89,17 @@ class ImageListPager extends TablePager {
        protected $mFieldNames = null;
 
        // Subclasses should override buildQueryConds instead of using $mQueryConds variable.
-       protected $mQueryConds = array();
+       protected $mQueryConds = [];
 
        protected $mUserName = null;
 
+       /**
+        * The relevant user
+        *
+        * @var User|null
+        */
+       protected $mUser = null;
+
        protected $mSearch = '';
 
        protected $mIncluding = false;
@@ -108,20 +117,18 @@ class ImageListPager extends TablePager {
 
                if ( $userName !== null && $userName !== '' ) {
                        $nt = Title::newFromText( $userName, NS_USER );
-                       $user = User::newFromName( $userName, false );
-                       if ( !is_null( $nt ) ) {
+                       if ( is_null( $nt ) ) {
+                               $this->outputUserDoesNotExist( $userName );
+                       } else {
                                $this->mUserName = $nt->getText();
+                               $user = User::newFromName( $this->mUserName, false );
+                               if ( $user ) {
+                                       $this->mUser = $user;
+                               }
+                               if ( !$user || ( $user->isAnon() && !User::isIP( $user->getName() ) ) ) {
+                                       $this->outputUserDoesNotExist( $userName );
+                               }
                        }
-                       if ( !$user || ( $user->isAnon() && !User::isIP( $user->getName() ) ) ) {
-                               $this->getOutput()->wrapWikiMsg(
-                                       "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
-                                       array(
-                                               'listfiles-userdoesnotexist',
-                                               wfEscapeWikiText( $userName ),
-                                       )
-                               );
-                       }
-
                }
 
                if ( $search !== '' && !$this->getConfig()->get( 'MiserMode' ) ) {
@@ -149,6 +156,30 @@ class ImageListPager extends TablePager {
                parent::__construct( $context );
        }
 
+       /**
+        * Get the user relevant to the ImageList
+        *
+        * @return User|null
+        */
+       function getRelevantUser() {
+               return $this->mUser;
+       }
+
+       /**
+        * Add a message to the output stating that the user doesn't exist
+        *
+        * @param string $userName Unescaped user name
+        */
+       protected function outputUserDoesNotExist( $userName ) {
+               $this->getOutput()->wrapWikiMsg(
+                       "<div class=\"mw-userpage-userdoesnotexist error\">\n$1\n</div>",
+                       [
+                               'listfiles-userdoesnotexist',
+                               wfEscapeWikiText( $userName ),
+                       ]
+               );
+       }
+
        /**
         * Build the where clause of the query.
         *
@@ -158,7 +189,7 @@ class ImageListPager extends TablePager {
         */
        protected function buildQueryConds( $table ) {
                $prefix = $table === 'image' ? 'img' : 'oi';
-               $conds = array();
+               $conds = [];
 
                if ( !is_null( $this->mUserName ) ) {
                        $conds[$prefix . '_user_text'] = $this->mUserName;
@@ -190,12 +221,12 @@ class ImageListPager extends TablePager {
         */
        function getFieldNames() {
                if ( !$this->mFieldNames ) {
-                       $this->mFieldNames = array(
+                       $this->mFieldNames = [
                                'img_timestamp' => $this->msg( 'listfiles_date' )->text(),
                                'img_name' => $this->msg( 'listfiles_name' )->text(),
                                'thumb' => $this->msg( 'listfiles_thumb' )->text(),
                                'img_size' => $this->msg( 'listfiles_size' )->text(),
-                       );
+                       ];
                        if ( is_null( $this->mUserName ) ) {
                                // Do not show username if filtering by username
                                $this->mFieldNames['img_user_text'] = $this->msg( 'listfiles_user' )->text();
@@ -218,7 +249,7 @@ class ImageListPager extends TablePager {
                if ( $this->mIncluding ) {
                        return false;
                }
-               $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
+               $sortable = [ 'img_timestamp', 'img_name', 'img_size' ];
                /* For reference, the indicies we can use for sorting are:
                 * On the image table: img_usertext_timestamp, img_size, img_timestamp
                 * On oldimage: oi_usertext_timestamp, oi_name_timestamp
@@ -269,7 +300,7 @@ class ImageListPager extends TablePager {
        protected function getQueryInfoReal( $table ) {
                $prefix = $table === 'oldimage' ? 'oi' : 'img';
 
-               $tables = array( $table );
+               $tables = [ $table ];
                $fields = array_keys( $this->getFieldNames() );
 
                if ( $table === 'oldimage' ) {
@@ -288,7 +319,7 @@ class ImageListPager extends TablePager {
                $fields[] = $prefix . '_user AS img_user';
                $fields[array_search( 'thumb', $fields )] = $prefix . '_name AS thumb';
 
-               $options = $join_conds = array();
+               $options = $join_conds = [];
 
                # Depends on $wgMiserMode
                # Will also not happen if mShowAll is true.
@@ -305,21 +336,21 @@ class ImageListPager extends TablePager {
 
                        $dbr = wfGetDB( DB_SLAVE );
                        if ( $dbr->implicitGroupby() ) {
-                               $options = array( 'GROUP BY' => 'img_name' );
+                               $options = [ 'GROUP BY' => 'img_name' ];
                        } else {
                                $columnlist = preg_grep( '/^img/', array_keys( $this->getFieldNames() ) );
-                               $options = array( 'GROUP BY' => array_merge( array( 'img_user' ), $columnlist ) );
+                               $options = [ 'GROUP BY' => array_merge( [ 'img_user' ], $columnlist ) ];
                        }
-                       $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) );
+                       $join_conds = [ 'oldimage' => [ 'LEFT JOIN', 'oi_name = img_name' ] ];
                }
 
-               return array(
+               return [
                        'tables' => $tables,
                        'fields' => $fields,
                        'conds' => $this->buildQueryConds( $table ),
                        'options' => $options,
                        'join_conds' => $join_conds
-               );
+               ];
        }
 
        /**
@@ -381,7 +412,7 @@ class ImageListPager extends TablePager {
                $res2->rewind();
                $topRes1 = $res1->next();
                $topRes2 = $res2->next();
-               $resultArray = array();
+               $resultArray = [];
                for ( $i = 0; $i < $limit && $topRes1 && $topRes2; $i++ ) {
                        if ( strcmp( $topRes1->{$this->mIndexField}, $topRes2->{$this->mIndexField} ) > 0 ) {
                                if ( !$ascending ) {
@@ -429,13 +460,13 @@ class ImageListPager extends TablePager {
        }
 
        function doBatchLookups() {
-               $userIds = array();
+               $userIds = [];
                $this->mResult->seek( 0 );
                foreach ( $this->mResult as $row ) {
                        $userIds[] = $row->img_user;
                }
                # Do a link batch query for names and userpages
-               UserCache::singleton()->doQuery( $userIds, array( 'userpage' ), __METHOD__ );
+               UserCache::singleton()->doQuery( $userIds, [ 'userpage' ], __METHOD__ );
        }
 
        /**
@@ -455,13 +486,13 @@ class ImageListPager extends TablePager {
        function formatValue( $field, $value ) {
                switch ( $field ) {
                        case 'thumb':
-                               $opt = array( 'time' => wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) );
+                               $opt = [ 'time' => wfTimestamp( TS_MW, $this->mCurrentRow->img_timestamp ) ];
                                $file = RepoGroup::singleton()->getLocalRepo()->findFile( $value, $opt );
                                // If statement for paranoia
                                if ( $file ) {
-                                       $thumb = $file->transform( array( 'width' => 180, 'height' => 360 ) );
+                                       $thumb = $file->transform( [ 'width' => 180, 'height' => 360 ] );
 
-                                       return $thumb->toHtml( array( 'desc-link' => true ) );
+                                       return $thumb->toHtml( [ 'desc-link' => true ] );
                                } else {
                                        return htmlspecialchars( $value );
                                }
@@ -482,7 +513,7 @@ class ImageListPager extends TablePager {
                                                htmlspecialchars( $filePage->getText() )
                                        );
                                        $download = Xml::element( 'a',
-                                               array( 'href' => wfLocalFile( $filePage )->getURL() ),
+                                               [ 'href' => wfLocalFile( $filePage )->getUrl() ],
                                                $imgfile
                                        );
                                        $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped();
@@ -493,7 +524,7 @@ class ImageListPager extends TablePager {
                                                $deleteMsg = $this->msg( 'listfiles-delete' )->escaped();
 
                                                $delete = Linker::linkKnown(
-                                                       $filePage, $deleteMsg, array(), array( 'action' => 'delete' )
+                                                       $filePage, $deleteMsg, [], [ 'action' => 'delete' ]
                                                );
                                                $delete = $this->msg( 'parentheses' )->rawParams( $delete )->escaped();
 
@@ -531,17 +562,17 @@ class ImageListPager extends TablePager {
        }
 
        function getForm() {
-               $fields = array();
-               $fields['limit'] = array(
+               $fields = [];
+               $fields['limit'] = [
                        'type' => 'select',
                        'name' => 'limit',
                        'label-message' => 'table_pager_limit_label',
                        'options' => $this->getLimitSelectList(),
                        'default' => $this->mLimit,
-               );
+               ];
 
                if ( !$this->getConfig()->get( 'MiserMode' ) ) {
-                       $fields['ilsearch'] = array(
+                       $fields['ilsearch'] = [
                                'type' => 'text',
                                'name' => 'ilsearch',
                                'id' => 'mw-ilsearch',
@@ -549,11 +580,11 @@ class ImageListPager extends TablePager {
                                'default' => $this->mSearch,
                                'size' => '40',
                                'maxlength' => '255',
-                       );
+                       ];
                }
 
                $this->getOutput()->addModules( 'mediawiki.userSuggest' );
-               $fields['user'] = array(
+               $fields['user'] = [
                        'type' => 'text',
                        'name' => 'user',
                        'id' => 'mw-listfiles-user',
@@ -562,15 +593,15 @@ class ImageListPager extends TablePager {
                        'size' => '40',
                        'maxlength' => '255',
                        'cssclass' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
-               );
+               ];
 
-               $fields['ilshowall'] = array(
+               $fields['ilshowall'] = [
                        'type' => 'check',
                        'name' => 'ilshowall',
                        'id' => 'mw-listfiles-show-all',
                        'label-message' => 'listfiles-show-all',
                        'default' => $this->mShowAll,
-               );
+               ];
 
                $query = $this->getRequest()->getQueryValues();
                unset( $query['title'] );