(Translated by https://www.hiragana.jp/)
r15275 MediaWiki - Code Review archive

r15275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15274‎ | r15275 | r15276 >
Date:10:57, 3 July 2006
Author:tstarling
Status:old
Tags:
Comment:
1.6-style special page to retrieve user details
Modified paths:
  • /trunk/extensions/LookupUser (added) (history)
  • /trunk/extensions/LookupUser/LookupUser.php (added) (history)

Diff [purge]

Index: trunk/extensions/LookupUser/LookupUser.php
@@ -0,0 +1,125 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ):
 5+?>
 6+<html><head><title>LookupUser</title></head>
 7+<body>
 8+<h1>LookupUser</h1>
 9+<p>LookupUser is a special page to retrieve information about a user such as email address and ID.</p>
 10+</body>
 11+</html>
 12+<?php
 13+exit(1);
 14+endif;
 15+
 16+$wgExtensionFunctions[] = 'wfSetupLookupUser';
 17+$wgAvailableRights[] = 'lookupuser';
 18+
 19+function wfSetupLookupUser() {
 20+ global $wgMessageCache, $IP;
 21+
 22+ $wgMessageCache->addMessages( array(
 23+ 'lookupuser' => 'Look up user info',
 24+ 'lookupuser_username' => 'Username:',
 25+ 'lookupuser_nonexistent' => 'User does not exist',
 26+ 'lookupuser_authenticated' => 'authenticated on $1',
 27+ 'lookupuser_not_authenticated' => 'not authenticated',
 28+ 'lookupuser_info' =>
 29+'* Name: $1
 30+* User ID: $2
 31+* Email address: $3
 32+* Real name: $4
 33+* Registration date: $5
 34+* User record last touched: $6
 35+* Email authentication: $7
 36+
 37+User options:
 38+
 39+$8
 40+',
 41+ ));
 42+
 43+ require_once( "$IP/includes/SpecialPage.php" );
 44+
 45+ class LookupUserPage extends SpecialPage {
 46+ function __construct() {
 47+ parent::__construct( 'LookupUser', 'lookupuser' );
 48+ }
 49+
 50+ function execute( $subpage ) {
 51+ global $wgRequest, $wgUser;
 52+
 53+ $this->setHeaders();
 54+
 55+ if ( !$wgUser->isAllowed( 'lookupuser' ) ) {
 56+ $this->displayRestrictionError();
 57+ return;
 58+ }
 59+
 60+ if ( $subpage ) {
 61+ $target = $subpage;
 62+ } else {
 63+ $target = $wgRequest->getText( 'target' );
 64+ }
 65+ $this->showForm( $target );
 66+ if ( $target ) {
 67+ $this->showInfo( $target );
 68+ }
 69+ }
 70+
 71+ function showForm( $target ) {
 72+ global $wgOut;
 73+ $title = $this->getTitle();
 74+ $action = htmlspecialchars( $title->getLocalURL() );
 75+ $target = htmlspecialchars( $target );
 76+ $username = htmlspecialchars( wfMsg( 'lookupuser_username' ) );
 77+
 78+ $wgOut->addHTML( <<<EOT
 79+<form method="get" action="$action">
 80+<table border="0">
 81+<tr>
 82+<td align="right">$username</td>
 83+<td align="left"><input type="text" size="50" name="target" value="$target" />
 84+</tr>
 85+<tr>
 86+<td colspan="2" align="center"><input type="submit" name="submit" value="OK" /></td>
 87+</tr>
 88+</table>
 89+</form>
 90+EOT
 91+ );
 92+ }
 93+
 94+ function showInfo( $target ) {
 95+ global $wgOut, $wgLang;
 96+ $user = User::newFromName( $target );
 97+ if ( $user->getId() == 0 ) {
 98+ $wgOut->addWikiText( wfMsg( 'lookupuser_nonexistent', $target ) );
 99+ } else {
 100+ $authTs = $user->getEmailAuthenticationTimestamp();
 101+ if ( $authTs ) {
 102+ $authenticated = wfMsg( 'lookupuser_authenticated', $wgLang->timeanddate( $authTs ) );
 103+ } else {
 104+ $authenticated = wfMsg( 'lookupuser_not_authenticated' );
 105+ }
 106+ $optionsString = '';
 107+ foreach ( $user->mOptions as $name => $value ) {
 108+ $optionsString .= "$name = $value <br>";
 109+ }
 110+ $wgOut->addWikiText( wfMsg( 'lookupuser_info',
 111+ $user->getName(),
 112+ $user->getId(),
 113+ $user->getEmail(),
 114+ $user->getRealName(),
 115+ $wgLang->timeanddate( $user->mRegistration ),
 116+ $wgLang->timeanddate( $user->mTouched ),
 117+ $authenticated,
 118+ $optionsString
 119+ ));
 120+ }
 121+ }
 122+ }
 123+
 124+ SpecialPage::addPage( new LookupUserPage );
 125+}
 126+?>