2013-05-20 19:18:26 +02:00
|
|
|
<?php
|
|
|
|
|
2013-05-31 19:52:25 +02:00
|
|
|
final class DivinerLiveSymbol extends DivinerDAO
|
2013-06-06 17:36:51 +02:00
|
|
|
implements PhabricatorPolicyInterface, PhabricatorMarkupInterface {
|
2013-05-20 19:18:26 +02:00
|
|
|
|
|
|
|
protected $bookPHID;
|
|
|
|
protected $context;
|
|
|
|
protected $type;
|
|
|
|
protected $name;
|
|
|
|
protected $atomIndex;
|
|
|
|
protected $graphHash;
|
|
|
|
protected $identityHash;
|
2013-08-28 18:54:39 +02:00
|
|
|
protected $nodeHash;
|
2013-05-20 19:18:26 +02:00
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
protected $title;
|
Fix Diviner links to articles by title
Summary:
Ref T988. This fixes the biggest current problem with Diviner, which is dead links to articles.
In the new Diviner, articles can have both a "name" (derived from the file name, and used in the URI) and a "title" (optional, specified explicitly). For example, we have one document with the name "feedback" and the title "Give Feedback! Get Support!".
On disk, we want to use the name for the actual file where the text lives ("feedback.diviner"). We also want to use the name in the URI, to generate a clean URI and to allow us to retitle the document slightly without breaking links to it (for example, we renamed the "Backup" document to "Backups and Migrations").
However, when displaying the article we want to use the title.
Currently, you can //only// link to the name, not the title. This is inconvenient:
- We have a bunch of existing docs which link to titles.
- It's natural/intuitive to link to titles.
- Linking to titles makes it easier/cheaper to generate documentation, because we don't need to be able to resolve things at render time.
To remedy this, allow links to target either names or titles. If we miss on a name query, we'll do a title query. This is implemented with a slug hash to allow approximately correct titles (wrong case/spacing/punctuation, e.g.) and sidestep all the UTF8/column length issues.
(In the long run, atom resolution should theoretically be more sophistiated than it is now, and we should do render-time lookups on at least some documents to catch bad links. However, this is fairly complicated and a relatively advanced feature, and I think allowing links to titles is desirable no matter what.)
Test Plan: The user documentation book now has valid links to articles when the titles and names differ.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T988
Differential Revision: https://secure.phabricator.com/D8407
2014-03-05 21:07:26 +01:00
|
|
|
protected $titleSlugHash;
|
2013-06-04 20:15:34 +02:00
|
|
|
protected $groupName;
|
|
|
|
protected $summary;
|
|
|
|
protected $isDocumentable = 0;
|
|
|
|
|
2013-08-28 18:54:39 +02:00
|
|
|
private $book = self::ATTACHABLE;
|
|
|
|
private $atom = self::ATTACHABLE;
|
|
|
|
private $extends = self::ATTACHABLE;
|
2013-08-28 18:57:20 +02:00
|
|
|
private $children = self::ATTACHABLE;
|
2013-05-31 19:52:25 +02:00
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
public function getConfiguration() {
|
|
|
|
return array(
|
|
|
|
self::CONFIG_AUX_PHID => true,
|
|
|
|
self::CONFIG_TIMESTAMPS => false,
|
|
|
|
) + parent::getConfiguration();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generatePHID() {
|
2014-07-24 00:05:46 +02:00
|
|
|
return PhabricatorPHID::generateNewPHID(DivinerAtomPHIDType::TYPECONST);
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|
|
|
|
|
2013-05-31 19:52:25 +02:00
|
|
|
public function getBook() {
|
2013-08-28 18:54:39 +02:00
|
|
|
return $this->assertAttached($this->book);
|
2013-05-31 19:52:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachBook(DivinerLiveBook $book) {
|
|
|
|
$this->book = $book;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-06-01 00:14:39 +02:00
|
|
|
public function getAtom() {
|
2013-08-28 18:54:39 +02:00
|
|
|
return $this->assertAttached($this->atom);
|
2013-06-01 00:14:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attachAtom(DivinerLiveAtom $atom) {
|
|
|
|
$this->atom = DivinerAtom::newFromDictionary($atom->getAtomData());
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI() {
|
|
|
|
$parts = array(
|
|
|
|
'book',
|
|
|
|
$this->getBook()->getName(),
|
|
|
|
$this->getType(),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->getContext()) {
|
|
|
|
$parts[] = $this->getContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
$parts[] = $this->getName();
|
|
|
|
|
|
|
|
if ($this->getAtomIndex()) {
|
|
|
|
$parts[] = $this->getAtomIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
return '/'.implode('/', $parts).'/';
|
|
|
|
}
|
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
public function getSortKey() {
|
2014-03-11 01:59:13 +01:00
|
|
|
// Sort articles before other types of content. Then, sort atoms in a
|
|
|
|
// case-insensitive way.
|
|
|
|
return sprintf(
|
|
|
|
'%c:%s',
|
|
|
|
($this->getType() == DivinerAtom::TYPE_ARTICLE ? '0' : '1'),
|
|
|
|
phutil_utf8_strtolower($this->getTitle()));
|
2013-06-04 20:15:34 +02:00
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
public function save() {
|
|
|
|
|
|
|
|
// NOTE: The identity hash is just a sanity check because the unique tuple
|
|
|
|
// on this table is way way too long to fit into a normal UNIQUE KEY. We
|
|
|
|
// don't use it directly, but its existence prevents duplicate records.
|
|
|
|
|
|
|
|
if (!$this->identityHash) {
|
|
|
|
$this->identityHash = PhabricatorHash::digestForIndex(
|
|
|
|
serialize(
|
|
|
|
array(
|
|
|
|
'bookPHID' => $this->getBookPHID(),
|
|
|
|
'context' => $this->getContext(),
|
|
|
|
'type' => $this->getType(),
|
|
|
|
'name' => $this->getName(),
|
|
|
|
'index' => $this->getAtomIndex(),
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::save();
|
|
|
|
}
|
|
|
|
|
2013-06-04 20:15:34 +02:00
|
|
|
public function getTitle() {
|
|
|
|
$title = parent::getTitle();
|
|
|
|
if (!strlen($title)) {
|
|
|
|
$title = $this->getName();
|
|
|
|
}
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
Fix Diviner links to articles by title
Summary:
Ref T988. This fixes the biggest current problem with Diviner, which is dead links to articles.
In the new Diviner, articles can have both a "name" (derived from the file name, and used in the URI) and a "title" (optional, specified explicitly). For example, we have one document with the name "feedback" and the title "Give Feedback! Get Support!".
On disk, we want to use the name for the actual file where the text lives ("feedback.diviner"). We also want to use the name in the URI, to generate a clean URI and to allow us to retitle the document slightly without breaking links to it (for example, we renamed the "Backup" document to "Backups and Migrations").
However, when displaying the article we want to use the title.
Currently, you can //only// link to the name, not the title. This is inconvenient:
- We have a bunch of existing docs which link to titles.
- It's natural/intuitive to link to titles.
- Linking to titles makes it easier/cheaper to generate documentation, because we don't need to be able to resolve things at render time.
To remedy this, allow links to target either names or titles. If we miss on a name query, we'll do a title query. This is implemented with a slug hash to allow approximately correct titles (wrong case/spacing/punctuation, e.g.) and sidestep all the UTF8/column length issues.
(In the long run, atom resolution should theoretically be more sophistiated than it is now, and we should do render-time lookups on at least some documents to catch bad links. However, this is fairly complicated and a relatively advanced feature, and I think allowing links to titles is desirable no matter what.)
Test Plan: The user documentation book now has valid links to articles when the titles and names differ.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T988
Differential Revision: https://secure.phabricator.com/D8407
2014-03-05 21:07:26 +01:00
|
|
|
public function setTitle($value) {
|
|
|
|
$this->writeField('title', $value);
|
|
|
|
if (strlen($value)) {
|
|
|
|
$slug = DivinerAtomRef::normalizeTitleString($value);
|
|
|
|
$hash = PhabricatorHash::digestForIndex($slug);
|
|
|
|
$this->titleSlugHash = $hash;
|
|
|
|
} else {
|
|
|
|
$this->titleSlugHash = null;
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:54:39 +02:00
|
|
|
public function attachExtends(array $extends) {
|
|
|
|
assert_instances_of($extends, 'DivinerLiveSymbol');
|
|
|
|
$this->extends = $extends;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExtends() {
|
|
|
|
return $this->assertAttached($this->extends);
|
|
|
|
}
|
|
|
|
|
2013-08-28 18:57:20 +02:00
|
|
|
public function attachChildren(array $children) {
|
|
|
|
assert_instances_of($children, 'DivinerLiveSymbol');
|
|
|
|
$this->children = $children;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChildren() {
|
|
|
|
return $this->assertAttached($this->children);
|
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
|
2013-05-31 19:52:25 +02:00
|
|
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
|
|
|
|
|
|
|
public function getCapabilities() {
|
|
|
|
return $this->getBook()->getCapabilities();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getPolicy($capability) {
|
|
|
|
return $this->getBook()->getPolicy($capability);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
|
|
|
|
return $this->getBook()->hasAutomaticCapability($capability, $viewer);
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:43:41 +02:00
|
|
|
public function describeAutomaticCapability($capability) {
|
|
|
|
return pht('Atoms inherit the policies of the books they are part of.');
|
|
|
|
}
|
|
|
|
|
2013-06-06 17:36:51 +02:00
|
|
|
|
|
|
|
/* -( Markup Interface )--------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
public function getMarkupFieldKey($field) {
|
|
|
|
return $this->getPHID().':'.$field.':'.$this->getGraphHash();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function newMarkupEngine($field) {
|
2013-09-08 18:16:55 +02:00
|
|
|
return PhabricatorMarkupEngine::getEngine('diviner');
|
2013-06-06 17:36:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getMarkupText($field) {
|
|
|
|
return $this->getAtom()->getDocblockText();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function didMarkupText(
|
|
|
|
$field,
|
|
|
|
$output,
|
|
|
|
PhutilMarkupEngine $engine) {
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function shouldUseMarkupCache($field) {
|
2014-03-06 02:22:27 +01:00
|
|
|
return true;
|
2013-06-06 17:36:51 +02:00
|
|
|
}
|
|
|
|
|
2013-05-20 19:18:26 +02:00
|
|
|
}
|