/**
  * Show the special page
  *
  * @param mixed $par Parameter passed to the page
  */
 public function execute($par)
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgStatsDBEnabled, $wgJsMimeType;
     $this->setHeaders();
     $oAssetsManager = AssetsManager::getInstance();
     $sSrc = $oAssetsManager->getOneCommonURL('/extensions/wikia/UserRenameTool/js/NewUsernameUrlEncoder.js');
     $wgOut->addScript("<script type=\"{$wgJsMimeType}\" src=\"{$sSrc}\"></script>");
     if (wfReadOnly() || !$wgStatsDBEnabled) {
         $wgOut->readOnlyPage();
         wfProfileOut(__METHOD__);
         return;
     }
     if (!$wgUser->isAllowed('renameuser')) {
         wfProfileOut(__METHOD__);
         throw new PermissionsError('renameuser');
     }
     // Get the request data
     $oldusername = $wgRequest->getText('oldusername', $par);
     $newusername = $wgRequest->getText('newusername');
     $reason = $wgRequest->getText('reason');
     $token = $wgUser->getEditToken();
     $notifyRenamed = $wgRequest->getBool('notify_renamed', false);
     $confirmaction = false;
     if ($wgRequest->wasPosted() && $wgRequest->getInt('confirmaction')) {
         $confirmaction = true;
     }
     $warnings = array();
     $errors = array();
     $infos = array();
     if ($wgRequest->wasPosted() && $wgRequest->getText('token') !== '' && $wgUser->matchEditToken($wgRequest->getVal('token'))) {
         $process = new RenameUserProcess($oldusername, $newusername, $confirmaction, $reason);
         $status = $process->run();
         $warnings = $process->getWarnings();
         $errors = $process->getErrors();
         if ($status) {
             $infos[] = wfMessage('userrenametool-info-in-progress')->inContentLanguage()->text();
         }
     }
     $showConfirm = empty($errors) && empty($infos);
     // note: errors and infos beyond this point are non-blocking
     if (!empty($oldusername)) {
         $olduser = User::newFromName($oldusername);
         if ($olduser->getGlobalFlag('requested-rename', 0)) {
             $infos[] = wfMsg('userrenametool-requested-rename', $oldusername);
         } else {
             $errors[] = wfMsg('userrenametool-did-not-request-rename', $oldusername);
         }
         if ($olduser->getGlobalFlag('wasRenamed', 0)) {
             $errors[] = wfMsg('userrenametool-previously-renamed', $oldusername);
         }
     }
     $template = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $template->set_vars(array("submitUrl" => $wgTitle->getLocalUrl(), "oldusername" => $oldusername, "oldusername_hsc" => htmlspecialchars($oldusername), "newusername" => $newusername, "newusername_hsc" => htmlspecialchars($newusername), "reason" => $reason, "move_allowed" => $wgUser->isAllowed('move'), "confirmaction" => $confirmaction, "warnings" => $warnings, "errors" => $errors, "infos" => $infos, "show_confirm" => $showConfirm, "token" => $token, "notify_renamed" => $notifyRenamed));
     $text = $template->render("rename-form");
     $wgOut->addHTML($text);
     wfProfileOut(__METHOD__);
     return;
 }
 /**
  * execute
  *
  * entry point for TaskExecutor
  *
  * @access public
  * @author Federico "Lox" Lucignano <*****@*****.**>
  *
  * @param mixed $params default null - task data from wikia_tasks table
  *
  * @return boolean - status of operation
  */
 public function execute($params = null)
 {
     global $wgStatsDB, $wgStatsDBEnabled;
     //no working stats DB instance on devboxes
     if (!defined('ENV_DEVBOX') && !empty($wgStatsDBEnabled)) {
         $this->mParams = unserialize($params->task_arguments);
         $process = RenameUserProcess::newFromData(array_merge($this->mParams, array('local_task' => $this)));
         if (defined('ENV_DEVBOX')) {
             $process->addLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this);
         } else {
             $process->setLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this);
         }
         $process->addLog('Updating global shared database: stats');
         $dbw = wfGetDB(DB_MASTER, array(), $wgStatsDB);
         $dbw->begin();
         $tasks = $this->mParams['tasks'];
         $hookName = 'UserRename::Stats';
         $process->addLog("Broadcasting hook: {$hookName}");
         wfRunHooks($hookName, array($dbw, $this->mParams['rename_user_id'], $this->mParams['rename_old_name'], $this->mParams['rename_new_name'], $this, &$tasks));
         foreach ($tasks as $task) {
             $process->addLog("Updating stats: {$task['table']}:{$task['username_column']}");
             $process->renameInTable($dbw, $task['table'], $this->mParams['rename_user_id'], $this->mParams['rename_old_name'], $this->mParams['rename_new_name'], $task);
         }
         $hookName = 'UserRename::AfterStats';
         $process->addLog("Broadcasting hook: {$hookName}");
         wfRunHooks($hookName, array($dbw, $this->mParams['rename_user_id'], $this->mParams['rename_old_name'], $this->mParams['rename_new_name'], $this, &$tasks));
         $dbw->commit();
         $process->addLog('Finished updating shared database: stats');
     }
     return true;
 }
Example #3
0
 /**
  * Script entry point
  */
 public function execute()
 {
     global $wgUser;
     $wgUser = User::newFromName('WikiaBot');
     // get options
     $oldName = $this->getOption('old-username');
     $newName = $this->getOption('new-username');
     $reason = $this->getOption('reason', 'User rename');
     // set up the logger
     $logger = Wikia\Logger\WikiaLogger::instance();
     $logger->pushContext(['old-name' => $oldName, 'new-name' => $newName, 'reason' => $reason]);
     $logger->info(__CLASS__ . ': start');
     $renameProcess = new RenameUserProcess($oldName, $newName, true, $reason);
     $res = $renameProcess->run();
     if ($res !== true) {
         $logger->info(__CLASS__ . ': error', ['errors' => $renameProcess->getErrors(), 'warnings' => $renameProcess->getWarnings()]);
         $this->output("RenameUserProcess::run failed for {$oldName}\n");
         $this->output(json_encode(['errors' => $renameProcess->getErrors(), 'warnings' => $renameProcess->getWarnings()]));
         die(1);
     }
     $logger->info(__CLASS__ . ': done', ['task_id' => $renameProcess->getUserRenameTaskId()]);
     $this->output(sprintf("Renaming of '%s' to '%s' done, task_id is '%s'\n", $oldName, $newName, $renameProcess->getUserRenameTaskId()));
 }
 public static function newFromData($data)
 {
     wfProfileIn(__METHOD__);
     $o = new RenameUserProcess($data['rename_old_name'], $data['rename_new_name'], '', true);
     $mapping = array('mUserId' => 'rename_user_id', 'mOldUsername' => 'rename_old_name', 'mNewUsername' => 'rename_new_name', 'mFakeUserId' => 'rename_fake_user_id', 'mRequestorId' => 'requestor_id', 'mRequestorName' => 'requestor_name', 'mPhalanxBlockId' => 'phalanx_block_id', 'mReason' => 'reason', 'mLogTask' => 'local_task', 'mRenameIP' => 'rename_ip');
     foreach ($mapping as $property => $key) {
         if (array_key_exists($key, $data)) {
             $o->{$property} = $data[$key];
         }
     }
     // Quick hack to recover requestor name from its id
     if (!empty($o->mRequestorId) && empty($o->mRequestorName)) {
         $requestor = User::newFromId($o->mRequestorId);
         $o->mRequestorName = $requestor->getName();
     }
     $o->addLog("newFromData(): Requestor id={$o->mRequestorId} name={$o->mRequestorName}");
     wfProfileOut(__METHOD__);
     return $o;
 }
 /**
  * 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;
 }
 /**
  * Show the special page
  *
  * @param mixed $par Parameter passed to the page
  */
 public function execute($par)
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgStatsDBEnabled;
     $this->setHeaders();
     if (wfReadOnly() || !$wgStatsDBEnabled) {
         $wgOut->readOnlyPage();
         wfProfileOut(__METHOD__);
         return;
     }
     if (!$wgUser->isAllowed('renameuser')) {
         wfProfileOut(__METHOD__);
         throw new PermissionsError('renameuser');
     }
     // Get the request data
     $oldusername = $wgRequest->getText('oldusername', $par);
     $newusername = $wgRequest->getText('newusername');
     $reason = $wgRequest->getText('reason');
     $token = $wgUser->getEditToken();
     $notifyRenamed = $wgRequest->getBool('notify_renamed', false);
     $confirmaction = false;
     if ($wgRequest->wasPosted() && $wgRequest->getInt('confirmaction')) {
         $confirmaction = true;
     }
     $warnings = array();
     $errors = array();
     $infos = array();
     if ($wgRequest->wasPosted() && $wgRequest->getText('token') !== '' && $wgUser->matchEditToken($wgRequest->getVal('token'))) {
         $process = new RenameUserProcess($oldusername, $newusername, $confirmaction, $reason);
         $status = $process->run();
         $warnings = $process->getWarnings();
         $errors = $process->getErrors();
         if ($status) {
             $infos[] = wfMsgForContent('userrenametool-info-in-progress');
         }
     }
     $showConfirm = empty($errors) && empty($infos);
     // note: errors and infos beyond this point are non-blocking
     if (!empty($oldusername)) {
         $olduser = User::newFromName($oldusername);
         if ($olduser->getOption('requested-rename', 0)) {
             $infos[] = wfMsg('userrenametool-requested-rename', $oldusername);
         } else {
             $errors[] = wfMsg('userrenametool-did-not-request-rename', $oldusername);
         }
         if ($olduser->getOption('wasRenamed', 0)) {
             $errors[] = wfMsg('userrenametool-previously-renamed', $oldusername);
         }
         $phalanxMatches = PhalanxHelper::testBlock($oldusername);
         if ($phalanxMatches !== 'No matches found.') {
             $errors[] = Xml::tags('p', null, wfMsg('userrenametool-phalanx-matches', htmlspecialchars($oldusername))) . $phalanxMatches;
         }
     }
     if (!empty($newusername)) {
         $phalanxMatches = PhalanxHelper::testBlock($newusername);
         if ($phalanxMatches !== 'No matches found.') {
             $errors[] = Xml::tags('p', null, wfMsg('userrenametool-phalanx-matches', htmlspecialchars($newusername))) . $phalanxMatches;
         }
     }
     $template = new EasyTemplate(dirname(__FILE__) . '/templates/');
     $template->set_vars(array("submitUrl" => $wgTitle->getLocalUrl(), "oldusername" => $oldusername, "oldusername_hsc" => htmlspecialchars($oldusername), "newusername" => $newusername, "newusername_hsc" => htmlspecialchars($newusername), "reason" => $reason, "move_allowed" => $wgUser->isAllowed('move'), "confirmaction" => $confirmaction, "warnings" => $warnings, "errors" => $errors, "infos" => $infos, "show_confirm" => $showConfirm, "token" => $token, "notify_renamed" => $notifyRenamed));
     $text = $template->render("rename-form");
     $wgOut->addHTML($text);
     wfProfileOut(__METHOD__);
     return;
 }
Example #7
0
    $processData['rename_fake_user_id'] = (int) $options['rename-fake-user-id'];
}
if (!empty($options['requestor-id']) && is_numeric($options['requestor-id'])) {
    $processData['requestor_id'] = (int) $options['requestor-id'];
}
if (!empty($options['phalanx-block-id']) && is_numeric($options['phalanx-block-id'])) {
    $processData['phalanx_block_id'] = (int) $options['phalanx-block-id'];
}
if (!empty($options['reason'])) {
    $processData['reason'] = $options['reason'];
}
if (!empty($options['global-task-id']) && is_numeric($options['global-task-id'])) {
    $processData['global_task_id'] = (int) $options['global-task-id'];
}
require_once "{$IP}/extensions/wikia/UserRenameTool/SpecialRenameuser.php";
$process = RenameUserProcess::newFromData($processData);
$process->setLogDestination(RenameUserProcess::LOG_OUTPUT);
if ($taskId) {
    $runningTask = UserRenameLocalTask::newFromID($taskId);
    if (defined('ENV_DEVBOX')) {
        $process->addLogDestination(RenameUserProcess::LOG_BATCH_TASK, $runningTask);
    } else {
        $process->setLogDestination(RenameUserProcess::LOG_BATCH_TASK, $runningTask);
    }
}
$process->setRequestorUser();
try {
    if (isset($options['rename-ip-address'])) {
        $process->updateLocalIP();
    } else {
        $process->updateLocal();
 /**
  * execute
  *
  * entry point for TaskExecutor
  *
  * @access public
  * @author Federico "Lox" Lucignano <*****@*****.**>
  *
  * @param mixed $params default null - task data from wikia_tasks table
  *
  * @return boolean - status of operation
  */
 public function execute($params = null)
 {
     global $IP, $wgWikiaLocalSettingsPath, $wgWikiaAdminSettingsPath, $wgMaxShellMemory, $wgMaxShellTime;
     $wgMaxShellMemory = 0;
     $wgMaxShellTime = 0;
     $this->mParams = unserialize($params->task_arguments);
     $noErrors = true;
     $process = RenameUserProcess::newFromData(array_merge($this->mParams, array('local_task' => $this)));
     if (defined('ENV_DEVBOX')) {
         $process->addLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this);
     } else {
         $process->setLogDestination(RenameUserProcess::LOG_BATCH_TASK, $this);
     }
     //$process->setRequestorUser();
     $process->addLog('User rename local task start.');
     $oldUsername = $this->mParams['rename_old_name'];
     $newUsername = $this->mParams['rename_new_name'];
     $requestorID = (int) $this->mParams['requestor_id'];
     $notifyRenamed = $this->mParams['notify_renamed'];
     foreach ($this->mParams as $key => &$param) {
         if ($key == 'city_ids') {
             continue;
         }
         if (empty($param)) {
             $param = "'{$param}'";
         } else {
             $param = escapeshellarg($param);
         }
     }
     if (is_array($this->mParams['city_ids'])) {
         foreach ($this->mParams['city_ids'] as $cityId) {
             $process->addLog("Processing wiki with ID {$cityId}.");
             /**
              * execute maintenance script
              */
             $aconf = $wgWikiaAdminSettingsPath;
             if (defined('ENV_DEVBOX') && ENV_DEVBOX) {
                 $aconf = preg_replace("/\\.\\.\\//", "", $aconf);
             }
             $cmd = "SERVER_ID={$cityId} php {$IP}/maintenance/wikia/RenameUser_local.php " . "--rename-user-id {$this->mParams['rename_user_id']} --rename-old-name {$this->mParams['rename_old_name']} " . "--rename-new-name {$this->mParams['rename_new_name']} --rename-fake-user-id {$this->mParams['rename_fake_user_id']} " . "--phalanx-block-id {$this->mParams['phalanx_block_id']} " . "--task-id {$this->mTaskID} --requestor-id {$this->mParams['requestor_id']} --reason {$this->mParams['reason']} " . "--global-task-id {$this->mParams['global_task_id']} --conf {$wgWikiaLocalSettingsPath} --aconf {$aconf}";
             $this->addLog("Running {$cmd}");
             $exitCode = null;
             $output = wfShellExec($cmd, $exitCode);
             if ($exitCode == 1) {
                 $noErrors = false;
             }
             $this->addLog("--- Command output ---\n{$output}\n--- End of command output ---");
             $process->addLog("Finished processing wiki with ID {$cityId}.");
         }
     }
     $process->addLog("Cleaning up pre-process setup.");
     $process->cleanup();
     $process->addLog("Fetching email addresses for notification of completed process.");
     $requestorUser = User::newFromId($requestorID);
     //mark user as renamed
     $renamedUser = User::newFromName($newUsername);
     $renamedUser->setOption('wasRenamed', true);
     $renamedUser->saveSettings();
     //send e-mail to the user that rename process has finished
     $notify = array($requestorUser);
     if ($notifyRenamed) {
         $notify[] = $renamedUser;
     }
     foreach ($notify as $notifyUser) {
         if ($notifyUser->getEmail() != null) {
             $notifyUser->sendMail(wfMsgForContent('userrenametool-finished-email-subject', $oldUsername), wfMsgForContent('userrenametool-finished-email-body-text', $oldUsername, $newUsername), null, null, 'UserRenameProcessFinishedNotification', wfMsgForContent('userrenametool-finished-email-body-html', $oldUsername, $newUsername));
             $process->addLog("Notification sent.");
         } else {
             $process->addLog("Cannot send email, requestor user has no email address.");
         }
     }
     $process->addLog("User rename local task end.");
     return $noErrors;
 }