Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/storage/PhrictionDocument.php
<?php | <?php | ||||
/** | |||||
* @group phriction | |||||
*/ | |||||
final class PhrictionDocument extends PhrictionDAO | final class PhrictionDocument extends PhrictionDAO | ||||
implements | implements | ||||
PhabricatorPolicyInterface, | PhabricatorPolicyInterface, | ||||
PhabricatorSubscribableInterface, | PhabricatorSubscribableInterface, | ||||
PhabricatorFlaggableInterface, | PhabricatorFlaggableInterface, | ||||
PhabricatorTokenReceiverInterface { | PhabricatorTokenReceiverInterface { | ||||
protected $slug; | protected $slug; | ||||
protected $depth; | protected $depth; | ||||
protected $contentID; | protected $contentID; | ||||
protected $status; | protected $status; | ||||
private $contentObject = self::ATTACHABLE; | private $contentObject = self::ATTACHABLE; | ||||
private $ancestors = array(); | |||||
// TODO: This should be `self::ATTACHABLE`, but there are still a lot of call | // TODO: This should be `self::ATTACHABLE`, but there are still a lot of call | ||||
// sites which load PhrictionDocuments directly. | // sites which load PhrictionDocuments directly. | ||||
private $project = null; | private $project = null; | ||||
public function getConfiguration() { | public function getConfiguration() { | ||||
return array( | return array( | ||||
self::CONFIG_AUX_PHID => true, | self::CONFIG_AUX_PHID => true, | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public function attachProject(PhabricatorProject $project = null) { | ||||
$this->project = $project; | $this->project = $project; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function hasProject() { | public function hasProject() { | ||||
return (bool)$this->getProject(); | return (bool)$this->getProject(); | ||||
} | } | ||||
public function getAncestors() { | |||||
return $this->ancestors; | |||||
} | |||||
public function getAncestor($slug) { | |||||
return $this->assertAttachedKey($this->ancestors, $slug); | |||||
} | |||||
public function attachAncestor($slug, $ancestor) { | |||||
$this->ancestors[$slug] = $ancestor; | |||||
return $this; | |||||
} | |||||
public static function isProjectSlug($slug) { | public static function isProjectSlug($slug) { | ||||
$slug = PhabricatorSlug::normalize($slug); | $slug = PhabricatorSlug::normalize($slug); | ||||
$prefix = 'projects/'; | $prefix = 'projects/'; | ||||
if ($slug == $prefix) { | if ($slug == $prefix) { | ||||
// The 'projects/' document is not itself a project slug. | // The 'projects/' document is not itself a project slug. | ||||
return false; | return false; | ||||
} | } | ||||
return !strncmp($slug, $prefix, strlen($prefix)); | return !strncmp($slug, $prefix, strlen($prefix)); | ||||
Show All 19 Lines | return array( | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
); | ); | ||||
} | } | ||||
public function getPolicy($capability) { | public function getPolicy($capability) { | ||||
if ($this->hasProject()) { | if ($this->hasProject()) { | ||||
return $this->getProject()->getPolicy($capability); | return $this->getProject()->getPolicy($capability); | ||||
} | } | ||||
return PhabricatorPolicies::POLICY_USER; | return PhabricatorPolicies::POLICY_USER; | ||||
} | } | ||||
public function hasAutomaticCapability($capability, PhabricatorUser $user) { | public function hasAutomaticCapability($capability, PhabricatorUser $user) { | ||||
if ($this->hasProject()) { | if ($this->hasProject()) { | ||||
return $this->getProject()->hasAutomaticCapability($capability, $user); | return $this->getProject()->hasAutomaticCapability($capability, $user); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
public function describeAutomaticCapability($capability) { | public function describeAutomaticCapability($capability) { | ||||
if ($this->hasProject()) { | if ($this->hasProject()) { | ||||
return pht( | return pht( | ||||
"This is a project wiki page, and inherits the project's policies."); | "This is a project wiki page, and inherits the project's policies."); | ||||
} | } | ||||
switch ($capability) { | |||||
case PhabricatorPolicyCapability::CAN_VIEW: | |||||
return pht( | |||||
'To view a wiki document, you must also be able to view all '. | |||||
'of its parents.'); | |||||
} | |||||
return null; | return null; | ||||
} | } | ||||
/* -( PhabricatorSubscribableInterface )----------------------------------- */ | /* -( PhabricatorSubscribableInterface )----------------------------------- */ | ||||
public function isAutomaticallySubscribed($phid) { | public function isAutomaticallySubscribed($phid) { | ||||
Show All 19 Lines |