Skip to content

Commit

Permalink
ListFiles: Call Skin::setRelevantUser() when applicable
Browse files Browse the repository at this point in the history
Also validate user name before calling `User::newFromName()`

Bug: T129825
Change-Id: I7481ab0fc1720e5e840f0d552934324f676c0241
  • Loading branch information
Rillke authored and umherirrender committed Mar 19, 2016
1 parent e464eff commit 3d05cde
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions includes/specials/SpecialListfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function execute( $par ) {
if ( $this->including() ) {
$out->addParserOutputContent( $pager->getBodyOutput() );
} else {
$user = $pager->getRelevantUser();
$this->getSkin()->setRelevantUser( $user );
$pager->getForm();
$out->addParserOutputContent( $pager->getFullOutput() );
}
Expand Down Expand Up @@ -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;
Expand All @@ -108,20 +117,18 @@ function __construct( IContextSource $context, $userName = null, $search = '',

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' ) ) {
Expand Down Expand Up @@ -149,6 +156,30 @@ function __construct( IContextSource $context, $userName = null, $search = '',
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.
*
Expand Down

0 comments on commit 3d05cde

Please sign in to comment.