Exemplo n.º 1
0
 /**
  * Do the whole dirty job of renaming user
  *
  * @return bool True if the process succeded
  */
 private function doRun()
 {
     global $wgMemc, $wgAuth;
     wfProfileIn(__METHOD__);
     $this->addLog("User rename global task start." . (!empty($this->mFakeUserId) ? ' Process is being repeated.' : null));
     $this->addLog("Renaming user {$this->mOldUsername} (ID {$this->mUserId}) to {$this->mNewUsername}");
     $hookName = 'RenameUser::Abort';
     $this->addLog("Broadcasting hook: {$hookName}");
     // Give other affected extensions a chance to validate or abort
     if (!wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername, &$this->mErrors))) {
         $this->addLog("Aborting procedure as requested by hook.");
         $this->addError(wfMessage('userrenametool-error-extension-abort')->inContentLanguage()->text());
         wfProfileOut(__METHOD__);
         return false;
     }
     //enumerate IDs for wikis the user has been active in
     $this->addLog("Searching for user activity on wikis.");
     $wikiIDs = RenameUserHelper::lookupRegisteredUserActivity($this->mUserId);
     $this->addLog("Found " . count($wikiIDs) . " wikis: " . implode(', ', $wikiIDs));
     $hookName = 'UserRename::BeforeAccountRename';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername));
     // delete the record from all the secondary clusters
     if (class_exists('ExternalUser_Wikia')) {
         ExternalUser_Wikia::removeFromSecondaryClusters($this->mUserId);
     }
     // rename the user on the shared cluster
     if (!$this->renameAccount()) {
         $this->addLog("Failed to rename the user on the primary cluster. Report the problem to the engineers.");
         $this->addError(wfMessage('userrenametool-error-cannot-rename-account')->inContentLanguage()->text());
         wfProfileOut(__METHOD__);
         return false;
     }
     $this->invalidateUser($this->mNewUsername);
     /*if not repeating the process
     		create a new account storing the old username and some extra information in the realname field
     		this avoids creating new accounts with the old name and let's resume/repeat the process in case is needed*/
     $this->addLog("Creating fake user account");
     $fakeUser = null;
     if (empty($this->mFakeUserId)) {
         global $wgAuth, $wgExternalAuthType;
         $fakeUser = User::newFromName($this->mOldUsername, 'creatable');
         if (!is_object($fakeUser)) {
             $this->addLog("Cannot create fake user: {$this->mOldUsername}");
             wfProfileOut(__METHOD__);
             return false;
         }
         $fakeUser->setPassword(null);
         $fakeUser->setEmail(null);
         $fakeUser->setRealName('');
         $fakeUser->setName($this->mOldUsername);
         if ($wgExternalAuthType) {
             ExternalUser_Wikia::addUser($fakeUser, '', '', '');
         } else {
             $fakeUser->addToDatabase();
         }
         $fakeUser->setGlobalAttribute('renameData', self::RENAME_TAG . '=' . $this->mNewUsername . ';' . self::PROCESS_TAG . '=' . '1');
         $fakeUser->setGlobalFlag('disabled', 1);
         $fakeUser->saveSettings();
         $this->mFakeUserId = $fakeUser->getId();
         $this->addLog("Created fake user account for {$fakeUser->getName()} with ID {$this->mFakeUserId} and renameData '{$fakeUser->getGlobalAttribute('renameData', '')}'");
     } else {
         $fakeUser = User::newFromId($this->mFakeUserId);
         $this->addLog("Fake user account already exists: {$this->mFakeUserId}");
     }
     $this->invalidateUser($this->mOldUsername);
     $hookName = 'UserRename::AfterAccountRename';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername));
     //process global tables
     $this->addLog("Initializing update of global shared DB's.");
     $this->updateGlobal();
     $callParams = array('requestor_id' => $this->mRequestorId, 'requestor_name' => $this->mRequestorName, 'rename_user_id' => $this->mUserId, 'rename_old_name' => $this->mOldUsername, 'rename_new_name' => $this->mNewUsername, 'rename_fake_user_id' => $this->mFakeUserId, 'phalanx_block_id' => $this->mPhalanxBlockId, 'reason' => $this->mReason);
     $task = (new UserRenameTask())->setPriority(\Wikia\Tasks\Queues\PriorityQueue::NAME);
     $task->call('renameUser', $wikiIDs, $callParams);
     $this->mUserRenameTaskId = $task->queue();
     wfProfileOut(__METHOD__);
     return true;
 }
Exemplo n.º 2
0
 public function renameIPAddress()
 {
     wfProfileIn(__METHOD__);
     if (!$this->checkRequest()) {
         wfProfileOut(__METHOD__);
         return;
     }
     $ipAddr = $this->request->getVal('user');
     if (!IP::isIPAddress($ipAddr)) {
         $this->response->setVal('success', false);
         $this->response->setVal('errorMsg', wfMessage('coppatool-invalid-ip')->plain());
         wfProfileOut(__METHOD__);
         return;
     }
     $ipAddr = IP::sanitizeIP($ipAddr);
     $newIpAddr = '0.0.0.0';
     $wikiIDs = RenameUserHelper::lookupIPActivity($ipAddr);
     $taskParams = ['requestor_id' => $this->wg->User->getID(), 'requestor_name' => $this->wg->User->getName(), 'rename_user_id' => 0, 'rename_old_name' => $ipAddr, 'rename_new_name' => $newIpAddr, 'rename_ip' => true, 'notify_renamed' => false, 'reason' => wfMessage('coppatool-reason')->plain()];
     $task = (new UserRenameTask())->setPriority(\Wikia\Tasks\Queues\PriorityQueue::NAME);
     $task->call('renameUser', $wikiIDs, $taskParams);
     $taskID = $task->queue();
     $this->response->setVal('success', true);
     $this->response->setVal('resultMsg', wfMessage('coppatool-rename-ip-success', $taskID)->plain());
     wfProfileOut(__METHOD__);
 }
 /**
  * Do the whole dirty job of renaming user
  *
  * @return bool True if the process succeded
  */
 private function doRun()
 {
     global $wgMemc, $wgAuth;
     $this->addLog("User rename global task start." . (!empty($this->mFakeUserId) ? ' Process is being repeated.' : null));
     $this->addLog("Renaming user {$this->mOldUsername} (ID {$this->mUserId}) to {$this->mNewUsername}");
     $hookName = 'RenameUser::Abort';
     $this->addLog("Broadcasting hook: {$hookName}");
     // Give other affected extensions a chance to validate or abort
     if (!wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername, &$this->mErrors))) {
         $this->addLog("Aborting procedure as requested by hook.");
         $this->addError(wfMsgForContent('userrenametool-error-extension-abort'));
         wfProfileOut(__METHOD__);
         return false;
     }
     //enumerate IDs for wikis the user has been active in
     $this->addLog("Searching for user activity on wikis.");
     $wikiIDs = RenameUserHelper::lookupRegisteredUserActivity($this->mUserId);
     $this->addLog("Found " . count($wikiIDs) . " wikis: " . implode(', ', $wikiIDs));
     $hookName = 'UserRename::BeforeAccountRename';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername));
     //rename the user account across clusters
     $clusters = WikiFactory::getClusters();
     foreach ($clusters as $clusterName) {
         if (!$this->renameAccount($clusterName)) {
             $this->addLog("Renaming user account on cluster {$clusterName} resulted in a failure.");
             //if main shared DB, rename operation failed and not repeating then something's wrong dude...
             if ($clusterName === RenameUserHelper::CLUSTER_DEFAULT && empty($this->mFakeUserId)) {
                 $this->addLog("Cluster {$clusterName} is the main shared DB, aborting.");
                 $this->addError(wfMsgForContent('userrenametool-error-cannot-rename-account'));
                 wfProfileOut(__METHOD__);
                 return false;
             }
         }
     }
     $this->invalidateUser($this->mNewUsername);
     /*if not repeating the process
     		create a new account storing the old username and some extra information in the realname field
     		this avoids creating new accounts with the old name and let's resume/repeat the process in case is needed*/
     $this->addLog("Creating fake user account");
     $fakeUser = null;
     if (empty($this->mFakeUserId)) {
         //IMPORTANT: thi extension is meant to be enabled only on community central
         $fakeUser = User::createNew($this->mOldUsername);
         $fakeUser->setOption('renameData', self::RENAME_TAG . '=' . $this->mNewUsername . ';' . self::PROCESS_TAG . '=' . '1');
         $fakeUser->saveToCache();
         $this->mFakeUserId = $fakeUser->getId();
         $this->addLog("Created fake user account with ID {$this->mFakeUserId} and renameData '{$fakeUser->getOption('renameData', '')}'");
     } else {
         $fakeUser = User::newFromId($this->mFakeUserId);
         $this->addLog("Fake user account already exists: {$this->mFakeUserId}");
     }
     $this->invalidateUser($this->mOldUsername);
     //Block the user from logging in before logging him out
     $this->addLog("Creating a Phalanx block for the user.");
     if (empty($this->mPhalanxBlockId)) {
         $this->mPhalanxBlockId = PhalanxHelper::save(array('text' => $this->mNewUsername, 'exact' => 1, 'case' => 1, 'regex' => 0, 'timestamp' => wfTimestampNow(), 'expire' => null, 'author_id' => $this->mRequestorId, 'reason' => 'User rename process requested', 'lang' => null, 'type' => Phalanx::TYPE_USER), false);
         if (!$this->mPhalanxBlockId) {
             $this->addLog("Creation of the block failed.");
             $this->addError(wfMsgForContent('userrenametool-error-cannot-create-block'));
             wfProfileOut(__METHOD__);
             return false;
         } else {
             $fakeUser->setOption('renameData', $fakeUser->getOption('renameData', '') . ';' . self::PHALANX_BLOCK_TAG . '=' . $this->mPhalanxBlockId);
             $fakeUser->saveSettings();
             $this->addLog("Block created with ID {$this->mPhalanxBlockId}.");
         }
     } else {
         $this->addLog("Block with ID {$this->mPhalanxBlockId} already exists.");
     }
     $hookName = 'UserRename::AfterAccountRename';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mUserId, $this->mOldUsername, $this->mNewUsername));
     //process global tables
     $this->addLog("Initializing update of global shared DB's.");
     $this->updateGlobal();
     // create a new task for the Task Manager to handle all the global tables
     $this->addLog("Setting up a task for processing global DB");
     $task = new UserRenameGlobalTask();
     $task->createTask(array('rename_user_id' => $this->mUserId, 'rename_old_name' => $this->mOldUsername, 'rename_new_name' => $this->mNewUsername, 'tasks' => self::$mStatsDefaults), TASK_QUEUED);
     $this->addLog("Task created with ID " . $task->getID());
     $this->addLog("Setting up a task for processing local DB's");
     //create a new task for the Task Manager to handle all the local tables per each wiki
     $task = new UserRenameLocalTask();
     $task->createTask(array('city_ids' => $wikiIDs, 'requestor_id' => $this->mRequestorId, 'requestor_name' => $this->mRequestorName, 'rename_user_id' => $this->mUserId, 'rename_old_name' => $this->mOldUsername, 'rename_new_name' => $this->mNewUsername, 'rename_fake_user_id' => $this->mFakeUserId, 'phalanx_block_id' => $this->mPhalanxBlockId, 'reason' => $this->mReason, 'global_task_id' => $this->mGlobalTask->getID()), TASK_QUEUED);
     $this->addLog("Task created with ID " . $task->getID());
     $this->addLog("User rename global task end.");
     wfProfileOut(__METHOD__);
     return true;
 }