rendered paste body<?php
if ( !defined( 'MEDIAWIKI' ) ):
?>
<html><head><title>EditUser</title></head>
<body>
<h1>EditUser</h1>
<p>EditUser is a special page to modify some user settings.</p>
</body>
</html>
<?php
exit(1);
endif;
$wgExtensionFunctions[] = 'wfSetupEditUser';
$wgAvailableRights[] = 'edituser';
function wfSetupEditUser() {
global $wgMessageCache, $IP;
$wgMessageCache->addMessages( array(
'edituser' => 'Edit User',
));
require_once( "$IP/includes/SpecialPage.php" );
class EditUserPage extends SpecialPage {
function __construct() {
parent::__construct( 'EditUser', 'edituser' );
}
function execute() {
global $wgRequest, $wgUser;
$this->setHeaders();
if ( !$wgUser->isAllowed( 'edituser' ) ) {
$this->displayRestrictionError();
return;
}
$modifyuser = $wgRequest->getText( 'modifyuser' );
if ( $modifyuser ) {
$this->performUserModify();
}else{
$referringPage = '';
if ( $target = $wgRequest->getText( 'listusersname' )){
$referringPage = 'Listusers';
}else {
$target = $wgRequest->getText( 'targetusername' );
}
if ( $target ) {
$this->showUserSettingsForm($target, $referringPage);
} else {
$this->showGetUserForm();
}
}
}
function showUserSettingsForm($username, $referringPage) {
global $wgScript, $wgOut, $wgRequest;
$title = htmlspecialchars( $this->getTitle()->getPrefixedText() );
$action = htmlspecialchars( $wgScript ) . "?title=" . $title;
$validUser = false;
if ( strlen( $username ) > 0 ) {
$user = User::newFromName( $username );
$user->loadFromDatabase();
$userID = $user->mId;
$userRealName = $user->mRealName;
$userEMail = $user->mEmail;
if ( !is_object( $user ) || $userID == 0 ) {
$wgOut->addHTML( <<<EOT
<form method="post" action="$action">
<input type="hidden" name="title" value="{$title}" />
EditUser Error: Invalid Username<P>
<input type="submit" name="submit" value="OK" style="height: 23px; width: 50px" />
</form>
EOT
);
} else {
$validUser = true;
}
}
if ( $validUser) {
$pageOptions = '<input type="hidden" name="modifyuser" value="1" />';
if ( strlen($referringPage) > 0 ) {
$pageOptions .= "\n" . '<input type="hidden" name="referringpage" value="' . $referringPage . '" />';
$pageOptions .= "\n" . '<input type="hidden" name="limit" value="' . $wgRequest->getText('limit') . '" />';
$pageOptions .= "\n" . '<input type="hidden" name="offset" value="' . $wgRequest->getText('offset') . '" />';
}
$wgOut->addHTML( <<<EOT
<form method="post" action="$action">
<input type="hidden" name="title" value="{$title}" />
$pageOptions
<input type="hidden" name="modifyusername" value="{$username}" />
Settings for: <b>{$username}</b><P>
<table border="0">
<tr>
<td align="right">Real Name:</td>
<td align="left"><input type="text" size="30" name="realname" value="{$userRealName}"/>
</tr>
<tr>
<td align="right">EMail Address:</td>
<td align="left"><input type="text" size="30" name="emailaddr" value="{$userEMail}"/>
</tr>
<tr>
<td align="right"> </td>
<td align="left">(Password fields may be left blank if no change is desired.)</td>
</tr>
<tr>
<td align="right">New Password:</td>
<td align="left"><input type="password" size="20" name="newpassword"/>
</tr>
<tr>
<td align="right">Confirm Password:</td>
<td align="left"><input type="password" size="20" name="confirmpassword"/>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="OK" style="height: 23px; width: 50px" /></td>
</tr>
</table>
</form>
EOT
);
}
}
function showGetUserForm() {
global $wgScript, $wgOut;
$title = htmlspecialchars( $this->getTitle()->getPrefixedText() );
$action = htmlspecialchars( $wgScript ) . "?title=" . $title;
$wgOut->addHTML( <<<EOT
<form method="post" action="$action">
<input type="hidden" name="title" value="{$title}" />
<table border="0">
<tr>
<td align="right">Enter Username to modify:</td>
<td align="left"><input type="text" size="30" name="targetusername"/>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="OK" style="height: 23px; width: 50px" /></td>
</tr>
</table>
</form>
EOT
);
}
function performUserModify() {
global $wgRequest, $wgOut, $wgScript;
$title = htmlspecialchars( $this->getTitle()->getPrefixedText() );
$action = htmlspecialchars( $wgScript ) . "?title=" . $title;
$username = $wgRequest->getText( 'modifyusername' );
$userRealName = $wgRequest->getText( 'realname' );
$userEMail = $wgRequest->getText( 'emailaddr' );
$newpassword = $wgRequest->getText( 'newpassword' );
$passwordconfirm = $wgRequest->getText( 'confirmpassword' );
if ( strlen( $username ) > 0 ) {
$user = User::newFromName( $username );
$userID = $user->mId;
$user->loadFromDatabase();
if ( !is_object( $user ) || $userID == 0 ) {
$validUser = false;
$wgOut->addHTML( <<<EOT
<form method="post" action="$action">
<input type="hidden" name="title" value="{$title}" />
EditUser Error: Invalid Username<P>
<input type="submit" name="submit" value="OK" style="height: 23px; width: 50px" />
</form>
EOT
);
} else {
$validUser = true;
}
}
if ($validUser ) {
$saveSettings = false;
$passwordMismatch = false;
if ( strlen( $newpassword ) > 0 ) {
if( $newpassword == $passwordconfirm ) {
//Passwords match
$user->setPassword( $newpassword );
$saveSettings = true;
} else {
//Passwords DO NOT match
$passwordMismatch = true;
$wgOut->addHTML( <<<EOT
<form method="post" action="$action">
<input type="hidden" name="targetusername" value="{$username}" />
<input type="hidden" name="title" value="{$title}" />
EditUser Error: Passwords do not match<P>
<input type="submit" name="submit" value="OK" style="height: 23px; width: 50px" />
</form>
EOT
);
}
} // end if ( strlen( $newpassword ) > 0 )
if ( $passwordMismatch == false ) {
if ( $userRealName != $user->mRealName) {
$user->setRealName($userRealName);
$saveSettings = true;
}
if ( $userEMail != $user->mEmail) {
$user->setEmail($userEMail);
$saveSettings = true;
}
if ( isset($_REQUEST['referringpage']) ) {
if ( isset($_REQUEST['limit']) && strlen($wgRequest->getText('limit') > 0) ) {
$action = htmlspecialchars( $wgScript ) . "?title=Special:Listusers";
$action .= "&limit=" . $wgRequest->getText( 'limit' );
$action .= "&offset=" . $wgRequest->getText( 'offset' );
}else{
$action = htmlspecialchars( $wgScript ) . "/Special:Listusers";
$autoRedirect = '<input type="hidden" name="title" value="{$title}" />';
}
}
if ( $saveSettings ) {
$user->saveSettings();
$wgOut->addHTML( <<<EOT
<form method="post" action="$action">
$autoRedirect
EditUser: Successfully updated {$username}<P>
<input type="submit" name="submit" value="OK" style="height: 23px; width: 50px" />
</form>
EOT
);
} else{
$wgOut->addHTML( <<<EOT
<form method="post" action="$action">
$autoRedirect
EditUser: No changes were made
<P> <input type="submit" name="submit" value="OK" style="height: 23px; width: 50px" />
</form>
EOT
);
} // end if ( $saveSettings )
} // end if ( $passwordMismatch = false )
} // end if ($validUser )
} // end performUserModify()
function displayRestrictionError() {
global $wgOut;
$wgOut->addHTML( "EditUser Error: You are not authorized to use this function." );
}
}
SpecialPage::addPage( new EditUserPage );
}
?>