ListFiles: Call Skin::setRelevantUser() when applicable
authorrillke <rillke@wikipedia.de>
Mon, 14 Mar 2016 05:28:04 +0000 (06:28 +0100)
committerUmherirrender <umherirrender_de.wp@web.de>
Sat, 19 Mar 2016 13:59:13 +0000 (13:59 +0000)
Also validate user name before calling `User::newFromName()`

Bug: T129825
Change-Id: I7481ab0fc1720e5e840f0d552934324f676c0241

includes/specials/SpecialListfiles.php

index 968af1e..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() );
                }
@@ -91,6 +93,13 @@ class ImageListPager extends TablePager {
 
        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>",
-                                       [
-                                               '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.
         *