In the spirit of r103745, guard against invalid user names in SpecialContributions...
authorRoan Kattouw <catrope@users.mediawiki.org>
Sun, 20 Nov 2011 11:29:56 +0000 (11:29 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Sun, 20 Nov 2011 11:29:56 +0000 (11:29 +0000)
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php

index cbf496f..a86bb29 100644 (file)
@@ -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
                                        )
index d8e1063..9a853d0 100644 (file)
@@ -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