/**
  * @param array $data
  * @return Status
  */
 public function onSubmit(array $data)
 {
     $wiki = $this->isGlobalUser() ? null : wfWikiID();
     $reason = isset($data['reason']) ? $data['reason'] : null;
     $safeName = User::getCanonicalName($data['newname'], 'creatable');
     $request = new GlobalRenameRequest();
     $request->setName($this->getUser()->getName());
     $request->setWiki($wiki);
     $request->setNewName($safeName);
     $request->setReason($reason);
     if ($request->save()) {
         $status = Status::newGood();
         if (isset($data['email'])) {
             $user = $this->getUser();
             $user->setEmail($data['email']);
             $user->saveSettings();
             $status = $user->sendConfirmationMail('set');
         }
     } else {
         $status = Status::newFatal($this->msg('globalrenamerequest-save-error'));
     }
     return $status;
 }
 protected function doResolveRequest($approved, $data)
 {
     $request = GlobalRenameRequest::newFromId($data['rid']);
     $oldUser = User::newFromName($request->getName());
     if ($request->userIsGlobal() || $request->getWiki() === wfWikiId()) {
         $notifyEmail = MailAddress::newFromUser($oldUser);
     } else {
         $notifyEmail = $this->getRemoteUserMailAddress($request->getWiki(), $request->getName());
     }
     $newUser = User::newFromName($request->getNewName(), 'creatable');
     $status = new Status();
     $session = $this->getContext()->exportSession();
     if ($approved) {
         if ($request->userIsGlobal()) {
             // Trigger a global rename job
             $globalRenameUser = new GlobalRenameUser($this->getUser(), $oldUser, CentralAuthUser::getInstance($oldUser), $newUser, CentralAuthUser::getInstance($newUser), new GlobalRenameUserStatus($newUser->getName()), 'JobQueueGroup::singleton', new GlobalRenameUserDatabaseUpdates(), new GlobalRenameUserLogger($this->getUser()), $session);
             $status = $globalRenameUser->rename($data);
         } else {
             // If the user is local-only:
             // * rename the local user using LocalRenameUserJob
             // * create a global user attached only to the local wiki
             $job = new LocalRenameUserJob(Title::newFromText('Global rename job'), array('from' => $oldUser->getName(), 'to' => $newUser->getName(), 'renamer' => $this->getUser()->getName(), 'movepages' => true, 'suppressredirects' => true, 'promotetoglobal' => true, 'reason' => $data['reason'], 'session' => $session));
             JobQueueGroup::singleton($request->getWiki())->push($job);
             // Now log it
             $this->logPromotionRename($oldUser->getName(), $request->getWiki(), $newUser->getName(), $data['reason']);
             $status = Status::newGood();
         }
     }
     if ($status->isGood()) {
         $request->setStatus($approved ? GlobalRenameRequest::APPROVED : GlobalRenameRequest::REJECTED);
         $request->setCompleted(wfTimestampNow());
         $request->setPerformer(CentralAuthUser::getInstance($this->getUser())->getId());
         $request->setComments($data['comments']);
         if ($request->save()) {
             // Send email to the user about the change in status.
             if ($approved) {
                 $subject = $this->msg('globalrenamequeue-email-subject-approved')->inContentLanguage()->text();
                 $body = $this->msg('globalrenamequeue-email-body-approved', array($oldUser->getName(), $newUser->getName()))->inContentLanguage()->text();
             } else {
                 $subject = $this->msg('globalrenamequeue-email-subject-rejected')->inContentLanguage()->text();
                 $body = $this->msg('globalrenamequeue-email-body-rejected', array($oldUser->getName(), $newUser->getName(), $request->getComments()))->inContentLanguage()->text();
             }
             if ($notifyEmail !== null && $notifyEmail->address) {
                 $type = $approved ? 'approval' : 'rejection';
                 wfDebugLog('CentralAuthRename', "Sending {$type} email to User:{$oldUser->getName()}/{$notifyEmail->address}");
                 $this->sendNotificationEmail($notifyEmail, $subject, $body);
             }
         } else {
             $status->fatal('globalrenamequeue-request-savefailed');
         }
     }
     return $status;
 }
コード例 #3
0
 /**
  * @param $user User
  * @param $abortError
  * @return bool
  */
 static function onAbortNewAccount($user, &$abortError)
 {
     global $wgCentralAuthPreventUnattached;
     global $wgCentralAuthEnableGlobalRenameRequest;
     $centralUser = CentralAuthUser::getInstance($user);
     if ($centralUser->exists() || $centralUser->renameInProgressOn(wfWikiID())) {
         $abortError = wfMessage('centralauth-account-exists')->text();
         return false;
     }
     if ($wgCentralAuthPreventUnattached && !$centralUser->exists() && $centralUser->listUnattached()) {
         // If no global account exists and there are unattached accounts,
         // don't let a new unattached account get created. We'll pretend
         // that the name is already taken, because someone will eventually
         // get it. See bug 67901.
         $abortError = wfMessage('centralauth-account-unattached-exists')->text();
         return false;
     }
     // Block account creation if name is a pending rename request
     if ($wgCentralAuthEnableGlobalRenameRequest && GlobalRenameRequest::nameHasPendingRequest($user->getName())) {
         $abortError = wfMessage('centralauth-account-rename-exists')->text();
         return false;
     }
     return true;
 }