From 3d05cde537ff062035f642132ec0579458518f9e Mon Sep 17 00:00:00 2001 From: rillke Date: Mon, 14 Mar 2016 06:28:04 +0100 Subject: [PATCH] ListFiles: Call Skin::setRelevantUser() when applicable Also validate user name before calling `User::newFromName()` Bug: T129825 Change-Id: I7481ab0fc1720e5e840f0d552934324f676c0241 --- includes/specials/SpecialListfiles.php | 55 ++++++++++++++++++++------ 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/includes/specials/SpecialListfiles.php b/includes/specials/SpecialListfiles.php index 968af1e544..6c856e98af 100644 --- a/includes/specials/SpecialListfiles.php +++ b/includes/specials/SpecialListfiles.php @@ -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( - "
\n$1\n
", - [ - '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( + "
\n$1\n
", + [ + 'listfiles-userdoesnotexist', + wfEscapeWikiText( $userName ), + ] + ); + } + /** * Build the where clause of the query. * -- 2.20.1