Example #1
0
 public static function removeSingleBlock()
 {
     global $wgRequest;
     $id = $wgRequest->getInt('id');
     if (empty($id)) {
         return false;
     }
     return PhalanxHelper::removeFilter($id);
 }
 public function actionBlockAccountGroup($groupId)
 {
     wfProfileIn(__METHOD__);
     if (!$this->wg->User->isAllowed('phalanx')) {
         $this->displayRestrictionError($this->user);
         $this->skipRendering();
         wfProfileOut(__METHOD__);
         return false;
     }
     if (!class_exists('Phalanx')) {
         // TODO display some error
         $this->skipRendering();
         wfProfileOut(__METHOD__);
         return false;
     }
     $data = array('text' => $groupId, 'exact' => false, 'case' => false, 'regex' => false, 'timestamp' => wfTimestampNow(), 'expire' => null, 'author_id' => $this->wg->User->getId(), 'reason' => 'cookie-based block via AccountCreationTracker', 'lang' => 'all', 'type' => Phalanx::TYPE_COOKIE);
     $status = PhalanxHelper::save($data);
     wfProfileOut(__METHOD__);
     return $status;
 }
Example #3
0
 public static function onDeletePhalanxBlock($block_id)
 {
     wfProfileIn(__METHOD__);
     $ret = PhalanxHelper::removeFilter($block_id, false);
     wfProfileOut(__METHOD__);
     return $ret['error'] == true ? false : true;
 }
 /**
  * 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;
 }
 /**
  * @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));
 }
 /**
  * AJAX creation/update
  */
 public static function setBlock()
 {
     global $wgRequest, $wgUser;
     wfProfileOut(__METHOD__);
     $id = $wgRequest->getVal('id', false);
     // only set for update
     $filter = $wgRequest->getText('wpPhalanxFilter');
     $filterbulk = $wgRequest->getText('wpPhalanxFilterBulk');
     $regex = $wgRequest->getCheck('wpPhalanxFormatRegex') ? 1 : 0;
     $exact = $wgRequest->getCheck('wpPhalanxFormatExact') ? 1 : 0;
     $case = $wgRequest->getCheck('wpPhalanxFormatCase') ? 1 : 0;
     $expiry = $wgRequest->getText('wpPhalanxExpire');
     $types = $wgRequest->getArray('wpPhalanxType');
     $reason = $wgRequest->getText('wpPhalanxReason');
     $lang = $wgRequest->getVal('wpPhalanxLanguages', null);
     $typemask = 0;
     foreach ($types as $type) {
         $typemask |= $type;
     }
     //validation
     if (empty($filter) && empty($filterbulk) || empty($typemask)) {
         wfProfileOut(__METHOD__);
         return array('error' => true, 'text' => wfMsg('phalanx-block-failure'));
     }
     if ($lang == 'all') {
         $lang = null;
     }
     if ($expiry != 'infinite') {
         $expire = strtotime($expiry);
         if ($expire < 0 || $expire === false) {
             wfProfileOut(__METHOD__);
             return false;
         }
         $expire = wfTimestamp(TS_MW, $expire);
     } else {
         $expire = null;
     }
     $data = array('text' => $filter, 'exact' => $exact, 'case' => $case, 'regex' => $regex, 'timestamp' => wfTimestampNow(), 'expire' => $expire, 'author_id' => $wgUser->getId(), 'reason' => $reason, 'lang' => $lang, 'type' => $typemask);
     if (empty($filterbulk)) {
         //single mode
         if (!$id) {
             $status = PhalanxHelper::save($data);
             $reason = $status ? wfMsg('phalanx-block-success') : wfMsg('phalanx-block-failure');
         } else {
             $data['id'] = $id;
             $status = PhalanxHelper::update($data);
             $reason = $status ? wfMsg('phalanx-modify-success') : wfMsg('phalanx-block-failure');
         }
     } else {
         // non-empty bulk field
         $bulkdata = explode("\n", $filterbulk);
         if (count($bulkdata)) {
             $reasons = array('s' => 0, 'f' => 0);
             foreach ($bulkdata as $bulkrow) {
                 $bulkrow = trim($bulkrow);
                 $data['text'] = $bulkrow;
                 $bstatus = PhalanxHelper::save($data);
                 if ($bstatus) {
                     $reasons['s']++;
                 } else {
                     $reasons['f']++;
                 }
             }
             $status = true;
             $reason = "[" . $reasons['s'] . "] success and [" . $reasons['f'] . "] fails";
         } else {
             $status = false;
             $reason = "nothing to block";
         }
     }
     wfProfileOut(__METHOD__);
     return array('error' => !$status, 'text' => $reason);
 }