[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/project/remarkup/ -> ProjectRemarkupRule.php (source)

   1  <?php
   2  
   3  final class ProjectRemarkupRule extends PhabricatorObjectRemarkupRule {
   4  
   5    protected function getObjectNamePrefix() {
   6      return '#';
   7    }
   8  
   9    protected function renderObjectRef($object, $handle, $anchor, $id) {
  10      if ($this->getEngine()->isTextMode()) {
  11        return '#'.$id;
  12      }
  13  
  14      return $handle->renderTag();
  15    }
  16  
  17    protected function getObjectIDPattern() {
  18      // NOTE: This explicitly does not match strings which contain only
  19      // digits, because digit strings like "#123" are used to reference tasks at
  20      // Facebook and are somewhat conventional in general.
  21  
  22      // The latter half of this rule matches monograms with internal periods,
  23      // like `#domain.com`, but does not match monograms with terminal periods,
  24      // because they're probably just puncutation.
  25  
  26      // Broadly, this will not match every possible project monogram, and we
  27      // accept some false negatives -- like `#1` or `#dot.` -- in order to avoid
  28      // a bunch of false positives on general use of the `#` character.
  29  
  30      // In other contexts, the PhabricatorProjectProjectPHIDType pattern is
  31      // controlling and these names should parse correctly.
  32  
  33      return '[^\s.\d!,:;{}#]+(?:[^\s!,:;{}#][^\s.!,:;{}#]+)*';
  34    }
  35  
  36    protected function loadObjects(array $ids) {
  37      $viewer = $this->getEngine()->getConfig('viewer');
  38  
  39      // Put the "#" back on the front of these IDs.
  40      $names = array();
  41      foreach ($ids as $id) {
  42        $names[] = '#'.$id;
  43      }
  44  
  45      // Issue a query by object name.
  46      $query = id(new PhabricatorObjectQuery())
  47        ->setViewer($viewer)
  48        ->withNames($names);
  49  
  50      $query->execute();
  51      $projects = $query->getNamedResults();
  52  
  53      // Slice the "#" off again.
  54      $result = array();
  55      foreach ($projects as $name => $project) {
  56        $result[substr($name, 1)] = $project;
  57      }
  58  
  59      return $result;
  60    }
  61  
  62  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1