<commit_before><?php

final class DiffusionBlameController extends DiffusionController {

  public function shouldAllowPublic() {
    return true;
  }

  public function handleRequest(AphrontRequest $request) {
    $response = $this->loadDiffusionContext();
    if ($response) {
      return $response;
    }

    $viewer = $this->getViewer();
    $drequest = $this->getDiffusionRequest();
    $repository = $drequest->getRepository();

    $blame = $this->loadBlame();

    $identifiers = array_fuse($blame);
    if ($identifiers) {
      $commits = id(new DiffusionCommitQuery())
        ->setViewer($viewer)
        ->withRepository($repository)
        ->withIdentifiers($identifiers)
        ->execute();
      $commits = mpull($commits, null, 'getCommitIdentifier');
    } else {
      $commits = array();
    }

    $commit_map = mpull($commits, 'getCommitIdentifier', 'getPHID');

    $revisions = array();
    $revision_map = array();
    if ($commits) {
      $revision_ids = id(new DifferentialRevision())
        ->loadIDsByCommitPHIDs(array_keys($commit_map));
      if ($revision_ids) {
        $revisions = id(new DifferentialRevisionQuery())
          ->setViewer($viewer)
          ->withIDs($revision_ids)
          ->execute();
        $revisions = mpull($revisions, null, 'getID');
      }

      foreach ($revision_ids as $commit_phid => $revision_id) {
        // If the viewer can't actually see this revision, skip it.
        if (!isset($revisions[$revision_id])) {
          continue;
        }
        $revision_map[$commit_map[$commit_phid]] = $revision_id;
      }
    }

    $base_href = (string)$drequest->generateURI(
      array(
        'action' => 'browse',
        'stable' => true,
      ));

    $skip_text = pht('Skip Past This Commit');
    $skip_icon = id(new PHUIIconView())
      ->setIcon('fa-backward');

    Javelin::initBehavior('phabricator-tooltips');

    $handle_phids = array();
    foreach ($commits as $commit) {
      $author_phid = $commit->getAuthorPHID();
      if ($author_phid) {
        $handle_phids[] = $author_phid;
      }
    }

    foreach ($revisions as $revision) {
      $handle_phids[] = $revision->getAuthorPHID();
    }

    $handles = $viewer->loadHandles($handle_phids);

    $map = array();
    foreach ($identifiers as $identifier) {
      $revision_id = idx($revision_map, $identifier);
      if ($revision_id) {
        $revision = idx($revisions, $revision_id);
      } else {
        $revision = null;
      }

      $skip_href = $base_href.'?before='.$identifier;

      $skip_link = javelin_tag(
        'a',
        array(
          'href'  => $skip_href,
          'sigil' => 'has-tooltip',
          'meta'  => array(
            'tip'     => $skip_text,
            'align'   => 'E',
            'size'    => 300,
          ),
        ),
        $skip_icon);

      $commit = $commits[$identifier];

      $author_phid = $commit->getAuthorPHID();
      if (!$author_phid && $revision) {
        $author_phid = $revision->getAuthorPHID();
      }

      if (!$author_phid) {
        // This means we couldn't identify an author for the commit or the
        // revision. We just render a blank for alignment.
        $author_style = null;
        $author_href = null;
        $author_sigil = null;
        $author_meta = null;
      } else {
        $author_src = $handles[$author_phid]->getImageURI();
        $author_style = 'background-image: url('.$author_src.');';
        $author_href = $handles[$author_phid]->getURI();
        $author_sigil = 'has-tooltip';
        $author_meta = array(
          'tip' => $handles[$author_phid]->getName(),
          'align' => 'E',
        );
      }

      $author_link = javelin_tag(
        $author_href ? 'a' : 'span',
        array(
          'class' => 'phabricator-source-blame-author',
          'style' => $author_style,
          'href' => $author_href,
          'sigil' => $author_sigil,
          'meta' => $author_meta,
        ));

      $commit_link = javelin_tag(
        'a',
        array(
          'href' => $commit->getURI(),
          'sigil' => 'has-tooltip',
          'meta'  => array(
            'tip'   => $this->renderCommitTooltip($commit, $handles),
            'align' => 'E',
            'size'  => 600,
          ),
        ),
        $commit->getLocalName());

      $info = array(
        $author_link,
        $commit_link,
      );

      if ($revision) {
        $revision_link = phutil_tag(
          'a',
          array(
            'href' => $revision->getURI(),
            'sigil' => 'has-tooltip',
            'meta'  => array(
              'tip'   => $this->renderRevisionTooltip($revision, $handles),
              'align' => 'E',
              'size'  => 600,
            ),
          ),
          $revision->getMonogram());


        $info = array(
          $info,
          ' / ',
          $revision_link,
        );
      }

      $data = array(
        'skip' => $skip_link,
        'info' => hsprintf('%s', $info),
      );

      $map[$identifier] = $data;
    }
<commit_msg>Use javelin_tag(), not phutil_tag(), to render revision blame tooltips properly<commit_after><?php

final class DiffusionBlameController extends DiffusionController {

  public function shouldAllowPublic() {
    return true;
  }

  public function handleRequest(AphrontRequest $request) {
    $response = $this->loadDiffusionContext();
    if ($response) {
      return $response;
    }

    $viewer = $this->getViewer();
    $drequest = $this->getDiffusionRequest();
    $repository = $drequest->getRepository();

    $blame = $this->loadBlame();

    $identifiers = array_fuse($blame);
    if ($identifiers) {
      $commits = id(new DiffusionCommitQuery())
        ->setViewer($viewer)
        ->withRepository($repository)
        ->withIdentifiers($identifiers)
        ->execute();
      $commits = mpull($commits, null, 'getCommitIdentifier');
    } else {
      $commits = array();
    }

    $commit_map = mpull($commits, 'getCommitIdentifier', 'getPHID');

    $revisions = array();
    $revision_map = array();
    if ($commits) {
      $revision_ids = id(new DifferentialRevision())
        ->loadIDsByCommitPHIDs(array_keys($commit_map));
      if ($revision_ids) {
        $revisions = id(new DifferentialRevisionQuery())
          ->setViewer($viewer)
          ->withIDs($revision_ids)
          ->execute();
        $revisions = mpull($revisions, null, 'getID');
      }

      foreach ($revision_ids as $commit_phid => $revision_id) {
        // If the viewer can't actually see this revision, skip it.
        if (!isset($revisions[$revision_id])) {
          continue;
        }
        $revision_map[$commit_map[$commit_phid]] = $revision_id;
      }
    }

    $base_href = (string)$drequest->generateURI(
      array(
        'action' => 'browse',
        'stable' => true,
      ));

    $skip_text = pht('Skip Past This Commit');
    $skip_icon = id(new PHUIIconView())
      ->setIcon('fa-backward');

    Javelin::initBehavior('phabricator-tooltips');

    $handle_phids = array();
    foreach ($commits as $commit) {
      $author_phid = $commit->getAuthorPHID();
      if ($author_phid) {
        $handle_phids[] = $author_phid;
      }
    }

    foreach ($revisions as $revision) {
      $handle_phids[] = $revision->getAuthorPHID();
    }

    $handles = $viewer->loadHandles($handle_phids);

    $map = array();
    foreach ($identifiers as $identifier) {
      $revision_id = idx($revision_map, $identifier);
      if ($revision_id) {
        $revision = idx($revisions, $revision_id);
      } else {
        $revision = null;
      }

      $skip_href = $base_href.'?before='.$identifier;

      $skip_link = javelin_tag(
        'a',
        array(
          'href'  => $skip_href,
          'sigil' => 'has-tooltip',
          'meta'  => array(
            'tip'     => $skip_text,
            'align'   => 'E',
            'size'    => 300,
          ),
        ),
        $skip_icon);

      $commit = $commits[$identifier];

      $author_phid = $commit->getAuthorPHID();
      if (!$author_phid && $revision) {
        $author_phid = $revision->getAuthorPHID();
      }

      if (!$author_phid) {
        // This means we couldn't identify an author for the commit or the
        // revision. We just render a blank for alignment.
        $author_style = null;
        $author_href = null;
        $author_sigil = null;
        $author_meta = null;
      } else {
        $author_src = $handles[$author_phid]->getImageURI();
        $author_style = 'background-image: url('.$author_src.');';
        $author_href = $handles[$author_phid]->getURI();
        $author_sigil = 'has-tooltip';
        $author_meta = array(
          'tip' => $handles[$author_phid]->getName(),
          'align' => 'E',
        );
      }

      $author_link = javelin_tag(
        $author_href ? 'a' : 'span',
        array(
          'class' => 'phabricator-source-blame-author',
          'style' => $author_style,
          'href' => $author_href,
          'sigil' => $author_sigil,
          'meta' => $author_meta,
        ));

      $commit_link = javelin_tag(
        'a',
        array(
          'href' => $commit->getURI(),
          'sigil' => 'has-tooltip',
          'meta'  => array(
            'tip' => $this->renderCommitTooltip($commit, $handles),
            'align' => 'E',
            'size' => 600,
          ),
        ),
        $commit->getLocalName());

      $info = array(
        $author_link,
        $commit_link,
      );

      if ($revision) {
        $revision_link = javelin_tag(
          'a',
          array(
            'href' => $revision->getURI(),
            'sigil' => 'has-tooltip',
            'meta'  => array(
              'tip' => $this->renderRevisionTooltip($revision, $handles),
              'align' => 'E',
              'size' => 600,
            ),
          ),
          $revision->getMonogram());

        $info = array(
          $info,
          ' / ',
          $revision_link,
        );
      }

      $data = array(
        'skip' => $skip_link,
        'info' => hsprintf('%s', $info),
      );

      $map[$identifier] = $data;
    }

{'fraction_non_alphanumeric': 0.15783274440518258, 'fraction_numerical': 0.0017667844522968198, 'mean_word_length': 2.0243395666369843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 121, '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': '2370160', 'n_tokens_mistral': 3299, 'n_tokens_neox': 3205, 'n_words': 593}