@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhrictionDocumentPolicyCodex
4 extends PhabricatorPolicyCodex {
5
6 public function getPolicySpecialRuleDescriptions() {
7 $object = $this->getObject();
8 $strongest_policy = $this->getStrongestPolicy();
9
10 $rules = array();
11 $rules[] = $this->newRule()
12 ->setDescription(
13 pht('To view a wiki document, you must also be able to view all '.
14 'of its ancestors. The most-restrictive view policy of this '.
15 'document\'s ancestors is "%s".',
16 $strongest_policy->getShortName()))
17 ->setCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW));
18
19 $rules[] = $this->newRule()
20 ->setDescription(
21 pht('To edit a wiki document, you must also be able to view all '.
22 'of its ancestors.'))
23 ->setCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT));
24
25 return $rules;
26 }
27
28 public function getDefaultPolicy() {
29 $ancestors = $this->getObject()->getAncestors();
30 if ($ancestors) {
31 $root = head($ancestors);
32 } else {
33 $root = $this->getObject();
34 }
35
36 $root_policy_phid = $root->getPolicy($this->getCapability());
37
38 return id(new PhabricatorPolicyQuery())
39 ->setViewer($this->getViewer())
40 ->withPHIDs(array($root_policy_phid))
41 ->executeOne();
42 }
43
44 private function getStrongestPolicy() {
45 $ancestors = $this->getObject()->getAncestors();
46 $ancestors[] = $this->getObject();
47
48 $strongest_policy = $this->getDefaultPolicy();
49 foreach ($ancestors as $ancestor) {
50 $ancestor_policy_phid = $ancestor->getPolicy($this->getCapability());
51
52 $ancestor_policy = id(new PhabricatorPolicyQuery())
53 ->setViewer($this->getViewer())
54 ->withPHIDs(array($ancestor_policy_phid))
55 ->executeOne();
56
57 if ($ancestor_policy->isStrongerThan($strongest_policy)) {
58 $strongest_policy = $ancestor_policy;
59 }
60 }
61
62 return $strongest_policy;
63 }
64
65}