@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add PhabricatorFileQuery

Summary: This doesn't do anything useful yet but Pholio needs to access Files and I wanted to get the groundwork in place for eventual policy-awareness.

Test Plan: Will use in Pholio.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D3829

+101 -2
+7 -1
src/__phutil_library_map__.php
··· 745 745 'PhabricatorFileListController' => 'applications/files/controller/PhabricatorFileListController.php', 746 746 'PhabricatorFileProxyController' => 'applications/files/controller/PhabricatorFileProxyController.php', 747 747 'PhabricatorFileProxyImage' => 'applications/files/storage/PhabricatorFileProxyImage.php', 748 + 'PhabricatorFileQuery' => 'applications/files/query/PhabricatorFileQuery.php', 748 749 'PhabricatorFileShortcutController' => 'applications/files/controller/PhabricatorFileShortcutController.php', 749 750 'PhabricatorFileSideNavView' => 'applications/files/view/PhabricatorFileSideNavView.php', 750 751 'PhabricatorFileStorageBlob' => 'applications/files/storage/PhabricatorFileStorageBlob.php', ··· 1932 1933 'PhabricatorFeedStoryUnknown' => 'PhabricatorFeedStory', 1933 1934 'PhabricatorFeedStoryView' => 'PhabricatorFeedView', 1934 1935 'PhabricatorFeedView' => 'AphrontView', 1935 - 'PhabricatorFile' => 'PhabricatorFileDAO', 1936 + 'PhabricatorFile' => 1937 + array( 1938 + 0 => 'PhabricatorFileDAO', 1939 + 1 => 'PhabricatorPolicyInterface', 1940 + ), 1936 1941 'PhabricatorFileController' => 'PhabricatorController', 1937 1942 'PhabricatorFileDAO' => 'PhabricatorLiskDAO', 1938 1943 'PhabricatorFileDataController' => 'PhabricatorFileController', ··· 1945 1950 'PhabricatorFileListController' => 'PhabricatorFileController', 1946 1951 'PhabricatorFileProxyController' => 'PhabricatorFileController', 1947 1952 'PhabricatorFileProxyImage' => 'PhabricatorFileDAO', 1953 + 'PhabricatorFileQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 1948 1954 'PhabricatorFileShortcutController' => 'PhabricatorFileController', 1949 1955 'PhabricatorFileSideNavView' => 'AphrontView', 1950 1956 'PhabricatorFileStorageBlob' => 'PhabricatorFileDAO',
+72
src/applications/files/query/PhabricatorFileQuery.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class PhabricatorFileQuery 20 + extends PhabricatorCursorPagedPolicyAwareQuery { 21 + 22 + private $ids; 23 + private $phids; 24 + 25 + public function withIDs(array $ids) { 26 + $this->ids = $ids; 27 + return $this; 28 + } 29 + 30 + public function withPHIDs(array $phids) { 31 + $this->phids = $phids; 32 + return $this; 33 + } 34 + 35 + public function loadPage() { 36 + $table = new PhabricatorFile(); 37 + $conn_r = $table->establishConnection('r'); 38 + 39 + $data = queryfx_all( 40 + $conn_r, 41 + 'SELECT * FROM %T f %Q %Q %Q', 42 + $table->getTableName(), 43 + $this->buildWhereClause($conn_r), 44 + $this->buildOrderClause($conn_r), 45 + $this->buildLimitClause($conn_r)); 46 + 47 + return $table->loadAllFromArray($data); 48 + } 49 + 50 + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 51 + $where = array(); 52 + 53 + $where[] = $this->buildPagingClause($conn_r); 54 + 55 + if ($this->ids) { 56 + $where[] = qsprintf( 57 + $conn_r, 58 + 'id IN (%Ld)', 59 + $this->ids); 60 + } 61 + 62 + if ($this->phids) { 63 + $where[] = qsprintf( 64 + $conn_r, 65 + 'phid IN (%Ls)', 66 + $this->phids); 67 + } 68 + 69 + return $this->formatWhereClause($where); 70 + } 71 + 72 + }
+22 -1
src/applications/files/storage/PhabricatorFile.php
··· 16 16 * limitations under the License. 17 17 */ 18 18 19 - final class PhabricatorFile extends PhabricatorFileDAO { 19 + final class PhabricatorFile extends PhabricatorFileDAO 20 + implements PhabricatorPolicyInterface { 20 21 21 22 const STORAGE_FORMAT_RAW = 'raw'; 22 23 ··· 499 500 public function generateSecretKey() { 500 501 return Filesystem::readRandomCharacters(20); 501 502 } 503 + 504 + 505 + /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ 506 + 507 + 508 + public function getCapabilities() { 509 + return array( 510 + PhabricatorPolicyCapability::CAN_VIEW, 511 + ); 512 + } 513 + 514 + public function getPolicy($capability) { 515 + // TODO: Implement proper per-object policies. 516 + return PhabricatorPolicies::POLICY_USER; 517 + } 518 + 519 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 520 + return false; 521 + } 522 + 502 523 }