EditUser

EditUser is a special page to modify some user settings.

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( << EditUser Error: Invalid Username

     EOT ); } else { $validUser = true; } } if ( $validUser) { $pageOptions = ''; if ( strlen($referringPage) > 0 ) { $pageOptions .= "\n" . ''; $pageOptions .= "\n" . ''; $pageOptions .= "\n" . ''; } $wgOut->addHTML( << $pageOptions Settings for: {$username}

Real Name:
EMail Address:
  (Password fields may be left blank if no change is desired.)
New Password:
Confirm Password:
EOT ); } } function showGetUserForm() { global $wgScript, $wgOut; $title = htmlspecialchars( $this->getTitle()->getPrefixedText() ); $action = htmlspecialchars( $wgScript ) . "?title=" . $title; $wgOut->addHTML( <<
Enter Username to modify:
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( << EditUser Error: Invalid Username

     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( << EditUser Error: Passwords do not match

     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 = ''; } } if ( $saveSettings ) { $user->saveSettings(); $wgOut->addHTML( << $autoRedirect EditUser: Successfully updated {$username}

     EOT ); } else{ $wgOut->addHTML( << $autoRedirect EditUser: No changes were made

     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 ); } ?>