<commit_before><?php

final class PhabricatorProjectProfileController
  extends PhabricatorProjectController {

  public function shouldAllowPublic() {
    return true;
  }

  public function handleRequest(AphrontRequest $request) {
    $user = $request->getUser();

    $query = id(new PhabricatorProjectQuery())
      ->setViewer($user)
      ->needMembers(true)
      ->needWatchers(true)
      ->needImages(true)
      ->needSlugs(true);
    $id = $request->getURIData('id');
    $slug = $request->getURIData('slug');
    if ($slug) {
      $query->withSlugs(array($slug));
    } else {
      $query->withIDs(array($id));
    }
    $project = $query->executeOne();
    if (!$project) {
      return new Aphront404Response();
    }
    if ($slug && $slug != $project->getPrimarySlug()) {
      return id(new AphrontRedirectResponse())
        ->setURI('/tag/'.$project->getPrimarySlug().'/');
    }

    $picture = $project->getProfileImageURI();
    require_celerity_resource('phabricator-profile-css');
    $tasks = $this->renderTasksPage($project);
    $content = phutil_tag_div('phabricator-project-layout', $tasks);

    $phid = $project->getPHID();
    $create_uri = '/maniphest/task/create/?projects='.$phid;
    $icon_new = id(new PHUIIconView())
      ->setIconFont('fa-plus');
    $button_add = id(new PHUIButtonView())
      ->setTag('a')
      ->setText(pht('New Task'))
      ->setHref($create_uri)
      ->setIcon($icon_new);

    $header = id(new PHUIHeaderView())
      ->setHeader($project->getName())
      ->setUser($user)
      ->setPolicyObject($project)
      ->setImage($picture)
      ->addActionLink($button_add);

    if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ACTIVE) {
      $header->setStatus('fa-check', 'bluegrey', pht('Active'));
    } else {
      $header->setStatus('fa-ban', 'red', pht('Archived'));
    }

    $actions = $this->buildActionListView($project);
    $properties = $this->buildPropertyListView($project, $actions);

    $object_box = id(new PHUIObjectBoxView())
      ->setHeader($header)
      ->addPropertyList($properties);

    $nav = $this->buildIconNavView($project);
    $nav->selectFilter("profile/{$id}/");
    $nav->appendChild($object_box);
    $nav->appendChild($content);

    return $this->buildApplicationPage(
      array(
        $nav,
      ),
      array(
        'title' => $project->getName(),
      ));
  }

  private function renderTasksPage(PhabricatorProject $project) {

    $user = $this->getRequest()->getUser();
    $limit = 50;

    $query = id(new ManiphestTaskQuery())
      ->setViewer($user)
      ->withAnyProjects(array($project->getPHID()))
      ->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
      ->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
      ->needProjectPHIDs(true)
      ->setLimit(($limit + 1));
    $tasks = $query->execute();
    $count = count($tasks);
    if ($count == ($limit + 1)) {
      array_pop($tasks);
    }

    $phids = mpull($tasks, 'getOwnerPHID');
    $phids = array_merge(
      $phids,
      array_mergev(mpull($tasks, 'getProjectPHIDs')));
    $phids = array_filter($phids);
    $handles = $this->loadViewerHandles($phids);

    $task_list = new ManiphestTaskListView();
    $task_list->setUser($user);
    $task_list->setTasks($tasks);
    $task_list->setHandles($handles);
    $task_list->setNoDataString(pht('This project has no open tasks.'));

    $phid = $project->getPHID();
    $view_uri = urisprintf(
      '/maniphest/?statuses=%s&allProjects=%s#R',
      implode(',', ManiphestTaskStatus::getOpenStatusConstants()),
      $phid);
    $icon = id(new PHUIIconView())
      ->setIconFont('fa-search');
    $button_view = id(new PHUIButtonView())
      ->setTag('a')
      ->setText(pht('View Query'))
      ->setHref($view_uri)
      ->setIcon($icon);

      $header = id(new PHUIHeaderView())
        ->addActionLink($button_view);

    if ($count > $limit) {
        $header->setHeader(pht('Highest Priority (some)'));
    } else {
        $header->setHeader(pht('Highest Priority (all)'));
    }

    $content = id(new PHUIObjectBoxView())
      ->setHeader($header)
      ->appendChild($task_list);

    return $content;
  }

  private function buildActionListView(PhabricatorProject $project) {
    $request = $this->getRequest();
    $viewer = $request->getUser();

    $id = $project->getID();

    $view = id(new PhabricatorActionListView())
      ->setUser($viewer)
      ->setObject($project)
      ->setObjectURI($request->getRequestURI());

    $can_edit = PhabricatorPolicyFilter::hasCapability(
      $viewer,
      $project,
      PhabricatorPolicyCapability::CAN_EDIT);

    $action = null;
    if (!$project->isUserMember($viewer->getPHID())) {
      $can_join = PhabricatorPolicyFilter::hasCapability(
        $viewer,
        $project,
        PhabricatorPolicyCapability::CAN_JOIN);

      $action = id(new PhabricatorActionView())
        ->setUser($viewer)
        ->setRenderAsForm(true)
        ->setHref('/project/update/'.$project->getID().'/join/')
        ->setIcon('fa-plus')
        ->setDisabled(!$can_join)
        ->setName(pht('Join Project'));
      $view->addAction($action);
    } else {
      $action = id(new PhabricatorActionView())
        ->setWorkflow(true)
        ->setHref('/project/update/'.$project->getID().'/leave/')
        ->setIcon('fa-times')<commit_msg>Add back edit project link on profile page<commit_after><?php

final class PhabricatorProjectProfileController
  extends PhabricatorProjectController {

  public function shouldAllowPublic() {
    return true;
  }

  public function handleRequest(AphrontRequest $request) {
    $user = $request->getUser();

    $query = id(new PhabricatorProjectQuery())
      ->setViewer($user)
      ->needMembers(true)
      ->needWatchers(true)
      ->needImages(true)
      ->needSlugs(true);
    $id = $request->getURIData('id');
    $slug = $request->getURIData('slug');
    if ($slug) {
      $query->withSlugs(array($slug));
    } else {
      $query->withIDs(array($id));
    }
    $project = $query->executeOne();
    if (!$project) {
      return new Aphront404Response();
    }
    if ($slug && $slug != $project->getPrimarySlug()) {
      return id(new AphrontRedirectResponse())
        ->setURI('/tag/'.$project->getPrimarySlug().'/');
    }

    $picture = $project->getProfileImageURI();
    require_celerity_resource('phabricator-profile-css');
    $tasks = $this->renderTasksPage($project);
    $content = phutil_tag_div('phabricator-project-layout', $tasks);

    $phid = $project->getPHID();
    $create_uri = '/maniphest/task/create/?projects='.$phid;
    $icon_new = id(new PHUIIconView())
      ->setIconFont('fa-plus');
    $button_add = id(new PHUIButtonView())
      ->setTag('a')
      ->setText(pht('New Task'))
      ->setHref($create_uri)
      ->setIcon($icon_new);

    $header = id(new PHUIHeaderView())
      ->setHeader($project->getName())
      ->setUser($user)
      ->setPolicyObject($project)
      ->setImage($picture)
      ->addActionLink($button_add);

    if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ACTIVE) {
      $header->setStatus('fa-check', 'bluegrey', pht('Active'));
    } else {
      $header->setStatus('fa-ban', 'red', pht('Archived'));
    }

    $actions = $this->buildActionListView($project);
    $properties = $this->buildPropertyListView($project, $actions);

    $object_box = id(new PHUIObjectBoxView())
      ->setHeader($header)
      ->addPropertyList($properties);

    $nav = $this->buildIconNavView($project);
    $nav->selectFilter("profile/{$id}/");
    $nav->appendChild($object_box);
    $nav->appendChild($content);

    return $this->buildApplicationPage(
      array(
        $nav,
      ),
      array(
        'title' => $project->getName(),
      ));
  }

  private function renderTasksPage(PhabricatorProject $project) {

    $user = $this->getRequest()->getUser();
    $limit = 50;

    $query = id(new ManiphestTaskQuery())
      ->setViewer($user)
      ->withAnyProjects(array($project->getPHID()))
      ->withStatuses(ManiphestTaskStatus::getOpenStatusConstants())
      ->setOrderBy(ManiphestTaskQuery::ORDER_PRIORITY)
      ->needProjectPHIDs(true)
      ->setLimit(($limit + 1));
    $tasks = $query->execute();
    $count = count($tasks);
    if ($count == ($limit + 1)) {
      array_pop($tasks);
    }

    $phids = mpull($tasks, 'getOwnerPHID');
    $phids = array_merge(
      $phids,
      array_mergev(mpull($tasks, 'getProjectPHIDs')));
    $phids = array_filter($phids);
    $handles = $this->loadViewerHandles($phids);

    $task_list = new ManiphestTaskListView();
    $task_list->setUser($user);
    $task_list->setTasks($tasks);
    $task_list->setHandles($handles);
    $task_list->setNoDataString(pht('This project has no open tasks.'));

    $phid = $project->getPHID();
    $view_uri = urisprintf(
      '/maniphest/?statuses=%s&allProjects=%s#R',
      implode(',', ManiphestTaskStatus::getOpenStatusConstants()),
      $phid);
    $icon = id(new PHUIIconView())
      ->setIconFont('fa-search');
    $button_view = id(new PHUIButtonView())
      ->setTag('a')
      ->setText(pht('View Query'))
      ->setHref($view_uri)
      ->setIcon($icon);

      $header = id(new PHUIHeaderView())
        ->addActionLink($button_view);

    if ($count > $limit) {
        $header->setHeader(pht('Highest Priority (some)'));
    } else {
        $header->setHeader(pht('Highest Priority (all)'));
    }

    $content = id(new PHUIObjectBoxView())
      ->setHeader($header)
      ->appendChild($task_list);

    return $content;
  }

  private function buildActionListView(PhabricatorProject $project) {
    $request = $this->getRequest();
    $viewer = $request->getUser();

    $id = $project->getID();

    $view = id(new PhabricatorActionListView())
      ->setUser($viewer)
      ->setObject($project)
      ->setObjectURI($request->getRequestURI());

    $can_edit = PhabricatorPolicyFilter::hasCapability(
      $viewer,
      $project,
      PhabricatorPolicyCapability::CAN_EDIT);

    $view->addAction(
      id(new PhabricatorActionView())
        ->setName(pht('Edit Project'))
        ->setIcon('fa-pencil')
        ->setHref($this->getApplicationURI("edit/{$id}/")));


    $action = null;
    if (!$project->isUserMember($viewer->getPHID())) {
      $can_join = PhabricatorPolicyFilter::hasCapability(
        $viewer,
        $project,
        PhabricatorPolicyCapability::CAN_JOIN);

      $action = id(new PhabricatorActionView())
        ->setUser($viewer)
        ->setRenderAsForm(true)
        ->setHref('/project/update/'.$project->getID().'/join/')
        ->setIcon('fa-plus')
        ->setDisabled(!$can_join)
        ->setName(pht('Join Project'));
      $view->addAction($action);
    } else {
      $action = id(new PhabricatorActionView())
        ->setWorkflow(true)
        ->setHref('/project/update/'.$project->getID().'/leave/')
        ->setIcon('fa-times')
{'fraction_non_alphanumeric': 0.17763397739701056, 'fraction_numerical': 0.0012759752096244987, 'mean_word_length': 3.2746396571873784, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 188, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1696791', 'n_tokens_mistral': 3618, 'n_tokens_neox': 3538, 'n_words': 519}