@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 PhabricatorAuthMessage
4 extends PhabricatorAuthDAO
5 implements
6 PhabricatorApplicationTransactionInterface,
7 PhabricatorPolicyInterface,
8 PhabricatorDestructibleInterface {
9
10 protected $messageKey;
11 protected $messageText;
12
13 private $messageType = self::ATTACHABLE;
14
15 public static function initializeNewMessage(
16 PhabricatorAuthMessageType $type) {
17
18 return id(new self())
19 ->setMessageKey($type->getMessageTypeKey())
20 ->attachMessageType($type);
21 }
22
23 protected function getConfiguration() {
24 return array(
25 self::CONFIG_AUX_PHID => true,
26 self::CONFIG_COLUMN_SCHEMA => array(
27 'messageKey' => 'text64',
28 'messageText' => 'text',
29 ),
30 self::CONFIG_KEY_SCHEMA => array(
31 'key_type' => array(
32 'columns' => array('messageKey'),
33 'unique' => true,
34 ),
35 ),
36 ) + parent::getConfiguration();
37 }
38
39 public function getPHIDType() {
40 return PhabricatorAuthMessagePHIDType::TYPECONST;
41 }
42
43 public function getObjectName() {
44 return pht('Auth Message %d', $this->getID());
45 }
46
47 public function getURI() {
48 return urisprintf('/auth/message/%s/', $this->getID());
49 }
50
51 public function attachMessageType(PhabricatorAuthMessageType $type) {
52 $this->messageType = $type;
53 return $this;
54 }
55
56 public function getMessageType() {
57 return $this->assertAttached($this->messageType);
58 }
59
60 public function getMessageTypeDisplayName() {
61 return $this->getMessageType()->getDisplayName();
62 }
63
64 public static function loadMessage(
65 PhabricatorUser $viewer,
66 $message_key) {
67 return id(new PhabricatorAuthMessageQuery())
68 ->setViewer($viewer)
69 ->withMessageKeys(array($message_key))
70 ->executeOne();
71 }
72
73 public static function loadMessageText(
74 PhabricatorUser $viewer,
75 $message_key) {
76
77 $message = self::loadMessage($viewer, $message_key);
78 if ($message) {
79 $message_text = $message->getMessageText();
80 if (strlen($message_text)) {
81 return $message_text;
82 }
83 }
84
85 $message_type = PhabricatorAuthMessageType::newFromKey($message_key);
86
87 return $message_type->getDefaultMessageText();
88 }
89
90
91/* -( PhabricatorPolicyInterface )----------------------------------------- */
92
93
94 public function getCapabilities() {
95 return array(
96 PhabricatorPolicyCapability::CAN_VIEW,
97 PhabricatorPolicyCapability::CAN_EDIT,
98 );
99 }
100
101 public function getPolicy($capability) {
102 switch ($capability) {
103 case PhabricatorPolicyCapability::CAN_VIEW:
104 return PhabricatorPolicies::getMostOpenPolicy();
105 default:
106 return false;
107 }
108 }
109
110 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
111 switch ($capability) {
112 case PhabricatorPolicyCapability::CAN_VIEW:
113 // Even if an install doesn't allow public users, you can still view
114 // auth messages: otherwise, we can't do things like show you
115 // guidance on the login screen.
116 return true;
117 default:
118 return false;
119 }
120 }
121
122/* -( PhabricatorApplicationTransactionInterface )------------------------- */
123
124
125 public function getApplicationTransactionEditor() {
126 return new PhabricatorAuthMessageEditor();
127 }
128
129 public function getApplicationTransactionTemplate() {
130 return new PhabricatorAuthMessageTransaction();
131 }
132
133
134/* -( PhabricatorDestructibleInterface )----------------------------------- */
135
136
137 public function destroyObjectPermanently(
138 PhabricatorDestructionEngine $engine) {
139 $this->delete();
140 }
141
142}