From b195296778ee553c323ee517e86d573f05f79c36 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sun, 20 Nov 2011 11:29:56 +0000 Subject: [PATCH] =?utf8?q?In=20the=20spirit=20of=20r103745,=20guard=20agai?= =?utf8?q?nst=20invalid=20user=20names=20in=20SpecialContributions=20and?= =?utf8?q?=20SpecialDeletedContributions=20by=20checking=20for=20invalidit?= =?utf8?q?y=20early,=20then=20passing=20User=20objects=20around.=20Loosely?= =?utf8?q?=20based=20on=20S=C3=B8ren=20L=C3=B8vborg's=20patch=20on=20bug?= =?utf8?q?=2026854?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- includes/specials/SpecialContributions.php | 34 ++++++++----------- .../specials/SpecialDeletedContributions.php | 25 +++++++------- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/includes/specials/SpecialContributions.php b/includes/specials/SpecialContributions.php index cbf496f6a1..a86bb29b1d 100644 --- a/includes/specials/SpecialContributions.php +++ b/includes/specials/SpecialContributions.php @@ -74,21 +74,19 @@ class SpecialContributions extends SpecialPage { $this->opts['target'] = $target; $this->opts['topOnly'] = $request->getBool( 'topOnly' ); - $nt = Title::makeTitleSafe( NS_USER, $target ); - if( !$nt ) { + $userObj = User::newFromName( $target, false ); + if( !$userObj ) { $out->addHTML( $this->getForm() ); return; } - $id = User::idFromName( $nt->getText() ); + $nt = $userObj->getUserPage(); + $id = $userObj->getID(); if( $this->opts['contribs'] != 'newbie' ) { $target = $nt->getText(); - $out->addSubtitle( $this->contributionsSub( $nt, $id ) ); + $out->addSubtitle( $this->contributionsSub( $userObj ) ); $out->setHTMLTitle( $this->msg( 'pagetitle', wfMsgExt( 'contributions-title', array( 'parsemag' ), $target ) ) ); - $userObj = User::newFromName( $target, false ); - if ( is_object( $userObj ) ) { - $this->getSkin()->setRelevantUser( $userObj ); - } + $this->getSkin()->setRelevantUser( $userObj ); } else { $out->addSubtitle( $this->msg( 'sp-contributions-newbies-sub') ); $out->setHTMLTitle( $this->msg( 'pagetitle', wfMsg( 'sp-contributions-newbies-title' ) ) ); @@ -193,8 +191,7 @@ class SpecialContributions extends SpecialPage { if ( IP::isIPAddress( $target ) ) { $message = 'sp-contributions-footer-anon'; } else { - $userObj = User::newFromName( $target ); - if ( !$userObj || $userObj->isAnon() ) { + if ( $userObj->isAnon() ) { // No message for non-existing users return; } @@ -211,19 +208,18 @@ class SpecialContributions extends SpecialPage { /** * Generates the subheading with links - * @param $nt Title object for the target - * @param $id Integer: User ID for the target + * @param $userObj User object for the target * @return String: appropriately-escaped HTML to be output literally * @todo FIXME: Almost the same as getSubTitle in SpecialDeletedContributions.php. Could be combined. */ - protected function contributionsSub( $nt, $id ) { - if ( $id === null ) { - $user = htmlspecialchars( $nt->getText() ); + protected function contributionsSub( $userObj ) { + if ( $userObj->isAnon() ) { + $user = htmlspecialchars( $userObj->getName() ); } else { - $user = Linker::link( $nt, htmlspecialchars( $nt->getText() ) ); + $user = Linker::link( $userObj->getUserPage(), htmlspecialchars( $userObj->getName() ) ); } - $userObj = User::newFromName( $nt->getText(), /* check for username validity not needed */ false ); - $talk = $nt->getTalkPage(); + $nt = $userObj->getUserPage(); + $talk = $userObj->getTalkPage(); if( $talk ) { $tools = self::getUserLinks( $nt, $talk, $userObj, $this->getUser() ); $links = $this->getLang()->pipeList( $tools ); @@ -243,7 +239,7 @@ class SpecialContributions extends SpecialPage { $userObj->isAnon() ? 'sp-contributions-blocked-notice-anon' : 'sp-contributions-blocked-notice', - $nt->getText() # Support GENDER in 'sp-contributions-blocked-notice' + $userObj->getName() # Support GENDER in 'sp-contributions-blocked-notice' ), 'offset' => '' # don't use WebRequest parameter offset ) diff --git a/includes/specials/SpecialDeletedContributions.php b/includes/specials/SpecialDeletedContributions.php index d8e10638ee..9a853d066c 100644 --- a/includes/specials/SpecialDeletedContributions.php +++ b/includes/specials/SpecialDeletedContributions.php @@ -287,15 +287,16 @@ class DeletedContributionsPage extends SpecialPage { $options['limit'] = $request->getInt( 'limit', $wgQueryPageDefaultLimit ); $options['target'] = $target; - $nt = Title::makeTitleSafe( NS_USER, $target ); - if ( !$nt ) { + $userObj = User::newFromName( $target ); + if ( !$userObj ) { $out->addHTML( $this->getForm( '' ) ); return; } - $id = User::idFromName( $nt->getText() ); + $nt = $userObj->getUserPage(); + $id = $userObj->getID(); - $target = $nt->getText(); - $out->addSubtitle( $this->getSubTitle( $nt, $id ) ); + $target = $userObj->getName(); + $out->addSubtitle( $this->getSubTitle( $userObj ) ); if ( ( $ns = $request->getVal( 'namespace', null ) ) !== null && $ns !== '' ) { $options['namespace'] = intval( $ns ); @@ -336,18 +337,18 @@ class DeletedContributionsPage extends SpecialPage { /** * Generates the subheading with links - * @param $nt Title object for the target - * @param $id Integer: User ID for the target + * @param $userObj User object for the target * @return String: appropriately-escaped HTML to be output literally * @todo FIXME: Almost the same as contributionsSub in SpecialContributions.php. Could be combined. */ - function getSubTitle( $nt, $id ) { - if ( $id === null ) { - $user = htmlspecialchars( $nt->getText() ); + function getSubTitle( $userObj ) { + if ( $userObj->isAnon() ) { + $user = htmlspecialchars( $userObj->getName() ); } else { - $user = Linker::link( $nt, htmlspecialchars( $nt->getText() ) ); + $user = Linker::link( $userObj->getPage(), htmlspecialchars( $userObj->getText() ) ); } - $userObj = User::newFromName( $nt->getText(), /* check for username validity not needed */ false ); + $nt = $userObj->getUserPage(); + $id = $userObj->getID(); $talk = $nt->getTalkPage(); if( $talk ) { # Talk page link -- 2.20.1