Exemplo n.º 1
0
 public static function eventlogWFPublicStatusChange($cityStatus, $cityId, $reason)
 {
     global $wgUser;
     $comment = wfMsgForContent('stafflog-wiki-status-change', RenameUserLogFormatter::getCommunityUser($wgUser->getName()), RenameUserLogFormatter::getCityLink($cityId), $cityStatus, $reason);
     // sadly, $type and $action have 10-character limit, hence 'wikifactor' and 'pubstatus'.
     self::log('wikifactor', 'pubstatus', $wgUser->getID(), $wgUser->getName(), '', '', $comment);
     return true;
 }
Exemplo n.º 2
0
 /**
  * @author Federico "Lox" Lucignano <*****@*****.**>
  * Performs action for cleaning up temporary data at the very end of a process
  */
 public function cleanup()
 {
     if ($this->mFakeUserId) {
         $this->addLog("Cleaning up process data in user option renameData for ID {$this->mFakeUserId}");
         $fakeUser = User::newFromId($this->mFakeUserId);
         $fakeUser->setGlobalAttribute('renameData', self::RENAME_TAG . '=' . $this->mNewUsername);
         $fakeUser->saveSettings();
         $fakeUser->saveToCache();
     }
     //TODO: Add a hook
     $hookName = 'UserRename::Cleanup';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mRequestorId, $this->mRequestorName, $this->mUserId, $this->mOldUsername, $this->mNewUsername));
     $tasks = array();
     if (isset($this->mGlobalTask)) {
         $tasks[] = $this->mGlobalTask->getID();
     }
     if (isset($this->mLogTask)) {
         $tasks[] = $this->mLogTask->getID();
     }
     $this->addMainLog("finish", RenameUserLogFormatter::finish($this->mRequestorName, $this->mOldUsername, $this->mNewUsername, $this->mReason, $tasks));
 }
Exemplo n.º 3
0
 /**
  * Marshal & execute the RenameUserProcess functions to rename a user
  *
  * @param array $wikiCityIds
  * @param array $params
  *		requestor_id => ID of the user requesting this rename action
  *		requestor_name => Name of the user requesting this rename action
  *		rename_user_id => ID of the user to rename
  *		rename_old_name => Current username of the user to rename
  *		rename_new_name => New username for the user to rename
  *		reason => Reason for requesting username change
  *		rename_fake_user_id => Repeated rename process special case (TODO: Don't know what this is)
  *		phalanx_block_id => Phalanx login block ID
  * @return bool
  */
 public function renameUser(array $wikiCityIds, array $params)
 {
     global $IP;
     $renameIP = !empty($params['rename_ip']);
     $loadBalancerFactory = wfGetLBFactory();
     $process = RenameUserProcess::newFromData($params);
     $process->setLogDestination(\RenameUserProcess::LOG_BATCH_TASK, $this);
     $process->setRequestorUser();
     $noErrors = true;
     // ComSup wants the StaffLogger to keep track of renames...
     $this->staffLog('start', $params, \RenameUserLogFormatter::start($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $params['reason'], [$this->getTaskId()]));
     try {
         foreach ($wikiCityIds as $cityId) {
             /**
              * execute maintenance script
              */
             $cmd = sprintf("SERVER_ID=%s php {$IP}/maintenance/wikia/RenameUser_local.php", $cityId);
             $opts = ['rename-user-id' => $params['rename_user_id'], 'requestor-id' => $params['requestor_id'], 'reason' => $params['reason']];
             if ($renameIP) {
                 $opts['rename-old-name'] = $params['rename_old_name'];
                 $opts['rename-new-name'] = $params['rename_new_name'];
             } else {
                 $opts['rename-old-name-enc'] = rawurlencode($params['rename_old_name']);
                 $opts['rename-new-name-enc'] = rawurlencode($params['rename_new_name']);
                 $opts['rename-fake-user-id'] = $params['rename_fake_user_id'];
                 $opts['phalanx-block-id'] = $params['phalanx_block_id'];
             }
             foreach ($opts as $opt => $val) {
                 $cmd .= sprintf(' --%s %s', $opt, escapeshellarg($val));
             }
             if ($renameIP) {
                 $cmd .= ' --rename-ip-address';
             }
             $exitCode = null;
             $output = wfShellExec($cmd, $exitCode);
             $logMessage = sprintf("Rename user %s to %s on city id %s", $params['rename_old_name'], $params['rename_new_name'], $cityId);
             $logContext = ['command' => $cmd, 'exitStatus' => $exitCode, 'output' => $output];
             if ($exitCode > 0) {
                 $this->error($logMessage, $logContext);
                 $noErrors = false;
             } else {
                 $this->info($logMessage, $logContext);
             }
             $this->staffLog('log', $params, \RenameUserLogFormatter::wiki($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $cityId, $params['reason'], $exitCode > 0));
             $loadBalancerFactory->forEachLBCallMethod('commitMasterChanges');
             $loadBalancerFactory->forEachLBCallMethod('closeAll');
         }
     } catch (Exception $e) {
         $noErrors = false;
         $this->error("error while renaming user", ['message' => $e->getMessage(), 'stack' => $e->getTraceAsString()]);
     }
     // clean up pre-process setup
     $process->cleanup();
     $this->notifyUser(\User::newFromId($params['requestor_id']), $params['rename_old_name'], $params['rename_new_name']);
     if (!$renameIP) {
         //mark user as renamed
         $renamedUser = \User::newFromName($params['rename_new_name']);
         $renamedUser->setGlobalFlag('wasRenamed', true);
         $renamedUser->saveSettings();
         if ($params['notify_renamed']) {
             //send e-mail to the user that rename process has finished
             $this->notifyUser($renamedUser, $params['rename_old_name'], $params['rename_new_name']);
         }
     }
     if ($noErrors) {
         $this->staffLog('finish', $params, \RenameUserLogFormatter::finish($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $params['reason'], [$this->getTaskId()]));
     } else {
         $this->staffLog('fail', $params, \RenameUserLogFormatter::fail($params['requestor_name'], $params['rename_old_name'], $params['rename_new_name'], $params['reason'], [$this->getTaskId()]));
     }
     return $noErrors;
 }
 /**
  * @author Federico "Lox" Lucignano <*****@*****.**>
  * Performs action for cleaning up temporary data at the very end of a process
  */
 public function cleanup()
 {
     //remove phalanx user block
     if ($this->mPhalanxBlockId) {
         $ret = PhalanxHelper::removeFilter($this->mPhalanxBlockId, false);
         if ($ret['error'] == true) {
             $this->addLog("Error removing Phalanx user block with ID {$this->mPhalanxBlockId}");
         } else {
             $this->addLog("Phalanx user block with ID {$this->mPhalanxBlockId} has been removed");
         }
     }
     if ($this->mFakeUserId) {
         $this->addLog("Cleaning up process data in user option renameData for ID {$this->mFakeUserId}");
         $fakeUser = User::newFromId($this->mFakeUserId);
         $fakeUser->setOption('renameData', self::RENAME_TAG . '=' . $this->mNewUsername);
         $fakeUser->saveSettings();
         $fakeUser->saveToCache();
     }
     //TODO: Add a hook
     $hookName = 'UserRename::Cleanup';
     $this->addLog("Broadcasting hook: {$hookName}");
     wfRunHooks($hookName, array($this->mRequestorId, $this->mRequestorName, $this->mUserId, $this->mOldUsername, $this->mNewUsername));
     $tasks = array();
     if (isset($this->mGlobalTask)) {
         $tasks[] = $this->mGlobalTask->getID();
     }
     if (isset($this->mLogTask)) {
         $tasks[] = $this->mLogTask->getID();
     }
     $this->addMainLog("finish", RenameUserLogFormatter::finish($this->mRequestorName, $this->mOldUsername, $this->mNewUsername, $this->mReason, $tasks));
 }