Index: trunk/extensions/LookupUser/LookupUser.body.php |
— | — | @@ -42,7 +42,8 @@ |
43 | 43 | $this->showForm( $target ); |
44 | 44 | |
45 | 45 | if ( $target ) { |
46 | | - $this->showInfo( $target ); |
| 46 | + $emailUser = $wgRequest->getText( 'email_user' ); |
| 47 | + $this->showInfo( $target, $emailUser ); |
47 | 48 | } |
48 | 49 | } |
49 | 50 | |
— | — | @@ -59,7 +60,7 @@ |
60 | 61 | $username = wfMsg( 'username' ); |
61 | 62 | $inputformtop = wfMsg( 'lookupuser' ); |
62 | 63 | |
63 | | - $wgOut->addWikiMsg('lookupuser-intro'); |
| 64 | + $wgOut->addWikiMsg( 'lookupuser-intro' ); |
64 | 65 | |
65 | 66 | $wgOut->addHTML( <<<EOT |
66 | 67 | <fieldset> |
— | — | @@ -82,13 +83,81 @@ |
83 | 84 | /** |
84 | 85 | * Retrieves and shows the gathered info to the user |
85 | 86 | * @param $target Mixed: user whose info we're looking up |
| 87 | + * @param $emailUser String: e-mail address (like example@example.com) |
86 | 88 | */ |
87 | | - function showInfo( $target ) { |
88 | | - global $wgOut, $wgLang; |
89 | | - $user = User::newFromName( $target ); |
| 89 | + function showInfo( $target, $emailUser = '' ) { |
| 90 | + global $wgOut, $wgLang, $wgScript; |
| 91 | + |
| 92 | + $count = 0; |
| 93 | + $users = array(); |
| 94 | + $userTarget = ''; |
| 95 | + |
| 96 | + // Look for @ in username |
| 97 | + if( strpos( $target, '@' ) !== false ) { |
| 98 | + // Find username by email |
| 99 | + $emailUser = htmlspecialchars( $emailUser ); |
| 100 | + $dbr = wfGetDB( DB_SLAVE ); |
| 101 | + |
| 102 | + $res = $dbr->select( |
| 103 | + 'user', |
| 104 | + array( 'user_name' ), |
| 105 | + array( 'user_email' => $target ), |
| 106 | + __METHOD__ |
| 107 | + ); |
| 108 | + |
| 109 | + $loop = 0; |
| 110 | + foreach( $res as $row ) { |
| 111 | + if( $loop === 0 ) { |
| 112 | + $userTarget = $row->user_name; |
| 113 | + } |
| 114 | + if( !empty( $emailUser ) && ( $emailUser == $row->user_name ) ) { |
| 115 | + $userTarget = $emailUser; |
| 116 | + } |
| 117 | + $users[] = $row->user_name; |
| 118 | + $loop++; |
| 119 | + } |
| 120 | + $count = $loop; |
| 121 | + } |
| 122 | + |
| 123 | + $ourUser = ( !empty( $userTarget ) ) ? $userTarget : $target; |
| 124 | + $user = User::newFromName( $ourUser ); |
90 | 125 | if ( $user == null || $user->getId() == 0 ) { |
91 | 126 | $wgOut->addWikiText( '<span class="error">' . wfMsg( 'lookupuser-nonexistent', $target ) . '</span>' ); |
92 | 127 | } else { |
| 128 | + # Multiple matches? |
| 129 | + if ( $count > 1 ) { |
| 130 | + $options = array(); |
| 131 | + if( !empty( $users ) && is_array( $users ) ) { |
| 132 | + foreach( $users as $id => $userName ) { |
| 133 | + $options[] = Xml::option( $userName, $userName, ( $userName == $userTarget ) ); |
| 134 | + } |
| 135 | + } |
| 136 | + $selectForm = "\n" . Xml::openElement( 'select', array( 'id' => 'email_user', 'name' => 'email_user' ) ); |
| 137 | + $selectForm .= "\n" . implode( "\n", $options ) . "\n"; |
| 138 | + $selectForm .= Xml::closeElement( 'select' ) . "\n"; |
| 139 | + |
| 140 | + $wgOut->addHTML( |
| 141 | + Xml::openElement( 'fieldset' ) . "\n" . |
| 142 | + Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . "\n" . |
| 143 | + Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . "\n" . |
| 144 | + Html::hidden( 'target', $target ) . "\n" . |
| 145 | + Xml::openElement( 'table', array( 'border' => '0' ) ) . "\n" . |
| 146 | + Xml::openElement( 'tr' ) . "\n" . |
| 147 | + Xml::openElement( 'td', array( 'align' => 'right' ) ) . |
| 148 | + wfMsgHtml( 'lookupuser-foundmoreusers' ) . |
| 149 | + Xml::closeElement( 'td' ) . "\n" . |
| 150 | + Xml::openElement( 'td', array( 'align' => 'left' ) ) . "\n" . |
| 151 | + $selectForm . Xml::closeElement( 'td' ) . "\n" . |
| 152 | + Xml::openElement( 'td', array( 'colspan' => '2', 'align' => 'center' ) ) . |
| 153 | + Xml::submitButton( wfMsgHtml( 'go' ) ) . |
| 154 | + Xml::closeElement( 'td' ) . "\n" . |
| 155 | + Xml::closeElement( 'tr' ) . "\n" . |
| 156 | + Xml::closeElement( 'table' ) . "\n" . |
| 157 | + Xml::closeElement( 'form' ) . "\n" . |
| 158 | + Xml::closeElement( 'fieldset' ) |
| 159 | + ); |
| 160 | + } |
| 161 | + |
93 | 162 | $authTs = $user->getEmailAuthenticationTimestamp(); |
94 | 163 | if ( $authTs ) { |
95 | 164 | $authenticated = wfMsg( 'lookupuser-authenticated', $wgLang->timeanddate( $authTs ) ); |
Index: trunk/extensions/LookupUser/LookupUser.i18n.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | $messages['en'] = array( |
16 | 16 | 'lookupuser' => 'Look up user info', |
17 | 17 | 'lookupuser-desc' => '[[Special:LookupUser|Retrieve information]] about a user such as e-mail address and ID', |
18 | | - 'lookupuser-intro' => 'Enter a username to view the preferences of that user.', |
| 18 | + 'lookupuser-intro' => 'Enter a username to view the preferences of that user. E-mail address can also be used, and will show all accounts using that email.', |
19 | 19 | 'lookupuser-nonexistent' => 'Error: User does not exist', |
20 | 20 | 'lookupuser-authenticated' => 'authenticated on $1', |
21 | 21 | 'lookupuser-not-authenticated' => 'not authenticated', |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | 'lookupuser-touched' => 'User record last touched: $1', |
29 | 29 | 'lookupuser-info-authenticated' => 'E-mail authentication: $1', |
30 | 30 | 'lookupuser-useroptions' => 'User options:', |
| 31 | + 'lookupuser-foundmoreusers' => 'Found more than one user:', |
31 | 32 | 'right-lookupuser' => 'Look up user preferences', |
32 | 33 | ); |
33 | 34 | |
Index: trunk/extensions/LookupUser/LookupUser.php |
— | — | @@ -4,7 +4,7 @@ |
5 | 5 | * |
6 | 6 | * @file |
7 | 7 | * @ingroup Extensions |
8 | | - * @version 1.1 |
| 8 | + * @version 1.2 |
9 | 9 | * @author Tim Starling |
10 | 10 | * @copyright © 2006 Tim Starling |
11 | 11 | * @licence GNU General Public Licence |
— | — | @@ -19,14 +19,14 @@ |
20 | 20 | $wgExtensionCredits['specialpage'][] = array( |
21 | 21 | 'path' => __FILE__, |
22 | 22 | 'name' => 'Lookup User', |
23 | | - 'version' => '1.1', |
| 23 | + 'version' => '1.2', |
24 | 24 | 'author' => 'Tim Starling', |
25 | 25 | 'url' => 'http://www.mediawiki.org/wiki/Extension:LookupUser', |
26 | 26 | 'descriptionmsg' => 'lookupuser-desc', |
27 | 27 | ); |
28 | 28 | |
29 | 29 | // Set up the new special page |
30 | | -$dir = dirname(__FILE__) . '/'; |
| 30 | +$dir = dirname( __FILE__ ) . '/'; |
31 | 31 | $wgExtensionMessagesFiles['LookupUser'] = $dir . 'LookupUser.i18n.php'; |
32 | 32 | $wgExtensionAliasesFiles['LookupUser'] = $dir . 'LookupUser.alias.php'; |
33 | 33 | $wgAutoloadClasses['LookupUserPage'] = $dir . 'LookupUser.body.php'; |
— | — | @@ -45,13 +45,15 @@ |
46 | 46 | * if the user has 'lookupuser' permission |
47 | 47 | * @return true |
48 | 48 | */ |
49 | | -function efLoadLookupUserLink( $id, $nt, &$links ){ |
| 49 | +function efLoadLookupUserLink( $id, $nt, &$links ) { |
50 | 50 | global $wgUser; |
51 | 51 | if( $wgUser->isAllowed( 'lookupuser' ) ) { |
52 | | - $links[] = $wgUser->getSkin()->makeKnownLinkObj( |
53 | | - SpecialPage::getTitleFor( 'LookupUser' ), |
54 | | - wfMsgHtml( 'lookupuser' ), |
55 | | - '&target=' . urlencode( $nt->getText() ) ); |
| 52 | + $links[] = Linker::linkKnown( |
| 53 | + SpecialPage::getTitleFor( 'LookupUser' ), |
| 54 | + wfMsgHtml( 'lookupuser' ), |
| 55 | + array(), |
| 56 | + array( 'target' => $nt->getText() ) |
| 57 | + ); |
56 | 58 | } |
57 | 59 | return true; |
58 | 60 | } |