<commit_before><?php

/*
 * Copyright 2012 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

final class PhabricatorFeedStoryManiphest
  extends PhabricatorFeedStory {

  public function getRequiredHandlePHIDs() {
    $data = $this->getStoryData();
    return array_filter(
      array(
        $this->getStoryData()->getAuthorPHID(),
        $data->getValue('taskPHID'),
        $data->getValue('ownerPHID'),
            ));
  }

  public function getRequiredObjectPHIDs() {
    return array(
      $this->getStoryData()->getAuthorPHID(),
                 );
  }

  public function renderView() {
    $data = $this->getStoryData();

    $view = new PhabricatorFeedStoryView();

    $line = $this->getLineForData($data);
    $view->setTitle($line);
    $view->setEpoch($data->getEpoch());

    $action = $data->getValue('action');
    switch ($action) {
      case ManiphestAction::ACTION_CREATE:
        $full_size = true;
        break;
      default:
        $full_size = false;
        break;
    }

    if ($full_size) {
      $view->setImage($this->getHandle($data->getAuthorPHID())->getImageURI());
      $content = $this->renderSummary($data->getValue('description'));
      $view->appendChild($content);
    } else {
      $view->setOneLineStory(true);
    }

    return $view;
  }

  public function renderNotificationView() {
    $data = $this->getStoryData();

    $view = new PhabricatorNotificationStoryView();

    $view->setTitle($this->getLineForData($data));
    $view->setEpoch($data->getEpoch());
    $view->setViewed($this->getHasViewed());

    return $view;
  }

  private function getLineForData($data) {
    $actor_phid = $data->getAuthorPHID();
    $owner_phid = $data->getValue('ownerPHID');
    $task_phid = $data->getValue('taskPHID');
    $action = $data->getValue('action');
    $description = $data->getValue('description');
    $comments = phutil_escape_html(
      phutil_utf8_shorten(
        $data->getValue('comments'),
        140));

    $actor_link = $this->linkTo($actor_phid);
    $task_link = $this->linkTo($task_phid);
    $owner_link = $this->linkTo($owner_phid);

    $verb = ManiphestAction::getActionPastTenseVerb($action);

    if (($action == ManiphestAction::ACTION_ASSIGN
        || $action == ManiphestAction::ACTION_REASSIGN)
        && !$owner_phid) {
      //double assignment since the action is diff in this case
      $verb = $action = 'placed up for grabs';
    }
    $one_line = "{$actor_link} {$verb} {$task_link}";

    switch ($action) {
      case ManiphestAction::ACTION_ASSIGN:
      case ManiphestAction::ACTION_REASSIGN:
        $one_line .= " to {$owner_link}";
        break;
      case ManiphestAction::ACTION_DESCRIPTION:
        $one_line .= " to {$description}";
        break;
    }

    if ($comments) {
      $one_line .= " \"{$comments}\"";
    }

    return $one_line;
  }
}<commit_msg>Minor, fix XSS in task description change notifications.<commit_after><?php

/*
 * Copyright 2012 Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

final class PhabricatorFeedStoryManiphest
  extends PhabricatorFeedStory {

  public function getRequiredHandlePHIDs() {
    $data = $this->getStoryData();
    return array_filter(
      array(
        $this->getStoryData()->getAuthorPHID(),
        $data->getValue('taskPHID'),
        $data->getValue('ownerPHID'),
      ));
  }

  public function getRequiredObjectPHIDs() {
    return array(
      $this->getStoryData()->getAuthorPHID(),
    );
  }

  public function renderView() {
    $data = $this->getStoryData();

    $view = new PhabricatorFeedStoryView();

    $line = $this->getLineForData($data);
    $view->setTitle($line);
    $view->setEpoch($data->getEpoch());

    $action = $data->getValue('action');
    switch ($action) {
      case ManiphestAction::ACTION_CREATE:
        $full_size = true;
        break;
      default:
        $full_size = false;
        break;
    }

    if ($full_size) {
      $view->setImage($this->getHandle($data->getAuthorPHID())->getImageURI());
      $content = $this->renderSummary($data->getValue('description'));
      $view->appendChild($content);
    } else {
      $view->setOneLineStory(true);
    }

    return $view;
  }

  public function renderNotificationView() {
    $data = $this->getStoryData();

    $view = new PhabricatorNotificationStoryView();

    $view->setTitle($this->getLineForData($data));
    $view->setEpoch($data->getEpoch());
    $view->setViewed($this->getHasViewed());

    return $view;
  }

  private function getLineForData($data) {
    $action = $data->getValue('action');

    $actor_phid = $data->getAuthorPHID();
    $actor_link = $this->linkTo($actor_phid);

    $task_phid = $data->getValue('taskPHID');
    $task_link = $this->linkTo($task_phid);

    $owner_phid = $data->getValue('ownerPHID');
    $owner_link = $this->linkTo($owner_phid);

    $verb = ManiphestAction::getActionPastTenseVerb($action);

    switch ($action) {
      case ManiphestAction::ACTION_ASSIGN:
      case ManiphestAction::ACTION_REASSIGN:
        if ($owner_phid) {
          $one_line = "{$actor_link} {$verb} to {$owner_link}";
        } else {
          $one_line = "{$actor_link} placed {$task_link} up for grabs";
        }
        break;
      default:
        $one_line = "{$actor_link} {$verb} {$task_link}";
        break;
    }

    return $one_line;
  }
}
{'fraction_non_alphanumeric': 0.14466489610998282, 'fraction_numerical': 0.0031245117950320263, 'mean_word_length': 3.2063074901445465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010789', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1938, 'n_words': 436}