r99326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99325‎ | r99326 | r99327 >
Date:23:13, 8 October 2011
Author:ashley
Status:ok (Comments)
Tags:
Comment:
LookupUser: integrate Wikia code (by Adrian Wieczorek and Piotr Molski) which allows searching for users via an email address, bump version number and change non-static usage of Linker to static
Modified paths:
  • /trunk/extensions/LookupUser/LookupUser.body.php (modified) (history)
  • /trunk/extensions/LookupUser/LookupUser.i18n.php (modified) (history)
  • /trunk/extensions/LookupUser/LookupUser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LookupUser/LookupUser.body.php
@@ -42,7 +42,8 @@
4343 $this->showForm( $target );
4444
4545 if ( $target ) {
46 - $this->showInfo( $target );
 46+ $emailUser = $wgRequest->getText( 'email_user' );
 47+ $this->showInfo( $target, $emailUser );
4748 }
4849 }
4950
@@ -59,7 +60,7 @@
6061 $username = wfMsg( 'username' );
6162 $inputformtop = wfMsg( 'lookupuser' );
6263
63 - $wgOut->addWikiMsg('lookupuser-intro');
 64+ $wgOut->addWikiMsg( 'lookupuser-intro' );
6465
6566 $wgOut->addHTML( <<<EOT
6667 <fieldset>
@@ -82,13 +83,81 @@
8384 /**
8485 * Retrieves and shows the gathered info to the user
8586 * @param $target Mixed: user whose info we're looking up
 87+ * @param $emailUser String: e-mail address (like example@example.com)
8688 */
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 );
90125 if ( $user == null || $user->getId() == 0 ) {
91126 $wgOut->addWikiText( '<span class="error">' . wfMsg( 'lookupuser-nonexistent', $target ) . '</span>' );
92127 } 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+
93162 $authTs = $user->getEmailAuthenticationTimestamp();
94163 if ( $authTs ) {
95164 $authenticated = wfMsg( 'lookupuser-authenticated', $wgLang->timeanddate( $authTs ) );
Index: trunk/extensions/LookupUser/LookupUser.i18n.php
@@ -14,7 +14,7 @@
1515 $messages['en'] = array(
1616 'lookupuser' => 'Look up user info',
1717 '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.',
1919 'lookupuser-nonexistent' => 'Error: User does not exist',
2020 'lookupuser-authenticated' => 'authenticated on $1',
2121 'lookupuser-not-authenticated' => 'not authenticated',
@@ -27,6 +27,7 @@
2828 'lookupuser-touched' => 'User record last touched: $1',
2929 'lookupuser-info-authenticated' => 'E-mail authentication: $1',
3030 'lookupuser-useroptions' => 'User options:',
 31+ 'lookupuser-foundmoreusers' => 'Found more than one user:',
3132 'right-lookupuser' => 'Look up user preferences',
3233 );
3334
Index: trunk/extensions/LookupUser/LookupUser.php
@@ -4,7 +4,7 @@
55 *
66 * @file
77 * @ingroup Extensions
8 - * @version 1.1
 8+ * @version 1.2
99 * @author Tim Starling
1010 * @copyright © 2006 Tim Starling
1111 * @licence GNU General Public Licence
@@ -19,14 +19,14 @@
2020 $wgExtensionCredits['specialpage'][] = array(
2121 'path' => __FILE__,
2222 'name' => 'Lookup User',
23 - 'version' => '1.1',
 23+ 'version' => '1.2',
2424 'author' => 'Tim Starling',
2525 'url' => 'http://www.mediawiki.org/wiki/Extension:LookupUser',
2626 'descriptionmsg' => 'lookupuser-desc',
2727 );
2828
2929 // Set up the new special page
30 -$dir = dirname(__FILE__) . '/';
 30+$dir = dirname( __FILE__ ) . '/';
3131 $wgExtensionMessagesFiles['LookupUser'] = $dir . 'LookupUser.i18n.php';
3232 $wgExtensionAliasesFiles['LookupUser'] = $dir . 'LookupUser.alias.php';
3333 $wgAutoloadClasses['LookupUserPage'] = $dir . 'LookupUser.body.php';
@@ -45,13 +45,15 @@
4646 * if the user has 'lookupuser' permission
4747 * @return true
4848 */
49 -function efLoadLookupUserLink( $id, $nt, &$links ){
 49+function efLoadLookupUserLink( $id, $nt, &$links ) {
5050 global $wgUser;
5151 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+ );
5658 }
5759 return true;
5860 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r105127complete message documentationcervidae21:03, 4 December 2011

Comments

#Comment by Siebrand (talk | contribs)   23:34, 8 October 2011

Please add message documentation for the newly added messages. Thanks.

Status & tagging log