Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2896349
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
43 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php
index 507ad4ef73..ce26384b35 100644
--- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php
+++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php
@@ -1,587 +1,586 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group aphront
*/
class AphrontDefaultApplicationConfiguration
extends AphrontApplicationConfiguration {
public function __construct() {
}
public function getApplicationName() {
return 'aphront-default';
}
public function getURIMap() {
return $this->getResourceURIMapRules() + array(
'/' => array(
'$' => 'PhabricatorDirectoryMainController',
),
'/directory/' => array(
'item/$'
=> 'PhabricatorDirectoryItemListController',
'item/edit/(?:(?P<id>\d+)/)?$'
=> 'PhabricatorDirectoryItemEditController',
'item/delete/(?P<id>\d+)/'
=> 'PhabricatorDirectoryItemDeleteController',
'category/$'
=> 'PhabricatorDirectoryCategoryListController',
'category/edit/(?:(?P<id>\d+)/)?$'
=> 'PhabricatorDirectoryCategoryEditController',
'category/delete/(?P<id>\d+)/'
=> 'PhabricatorDirectoryCategoryDeleteController',
),
'/file/' => array(
'$' => 'PhabricatorFileListController',
'upload/$' => 'PhabricatorFileUploadController',
'dropupload/$' => 'PhabricatorFileDropUploadController',
'(?P<view>info)/(?P<phid>[^/]+)/' => 'PhabricatorFileViewController',
'(?P<view>view)/(?P<phid>[^/]+)/' => 'PhabricatorFileViewController',
'(?P<view>download)/(?P<phid>[^/]+)/' => 'PhabricatorFileViewController',
'alt/(?P<key>[^/]+)/(?P<phid>[^/]+)/'
=> 'PhabricatorFileAltViewController',
'macro/' => array(
'$' => 'PhabricatorFileMacroListController',
'edit/(?:(?P<id>\d+)/)?$' => 'PhabricatorFileMacroEditController',
'delete/(?P<id>\d+)/$' => 'PhabricatorFileMacroDeleteController',
),
'proxy/$' => 'PhabricatorFileProxyController',
'xform/(?P<transform>[^/]+)/(?P<phid>[^/]+)/'
=> 'PhabricatorFileTransformController',
),
'/phid/' => array(
'$' => 'PhabricatorPHIDLookupController',
'list/$' => 'PhabricatorPHIDListController',
),
'/people/' => array(
'$' => 'PhabricatorPeopleListController',
'logs/$' => 'PhabricatorPeopleLogsController',
'edit/(?:(?P<id>\d+)/(?:(?P<view>\w+)/)?)?$'
=> 'PhabricatorPeopleEditController',
),
'/p/(?P<username>\w+)/(?:(?P<page>\w+)/)?$'
=> 'PhabricatorPeopleProfileController',
'/conduit/' => array(
'$' => 'PhabricatorConduitConsoleController',
'method/(?P<method>[^/]+)$' => 'PhabricatorConduitConsoleController',
'log/$' => 'PhabricatorConduitLogController',
'log/view/(?P<view>[^/]+)/$' => 'PhabricatorConduitLogController',
'token/$' => 'PhabricatorConduitTokenController',
),
'/api/(?P<method>[^/]+)$' => 'PhabricatorConduitAPIController',
'/D(?P<id>\d+)' => 'DifferentialRevisionViewController',
'/differential/' => array(
'$' => 'DifferentialRevisionListController',
'filter/(?P<filter>\w+)/$' => 'DifferentialRevisionListController',
'diff/' => array(
'(?P<id>\d+)/$' => 'DifferentialDiffViewController',
'create/$' => 'DifferentialDiffCreateController',
),
'changeset/$' => 'DifferentialChangesetViewController',
'revision/edit/(?:(?P<id>\d+)/)?$'
=> 'DifferentialRevisionEditController',
'comment/' => array(
'preview/(?P<id>\d+)/$' => 'DifferentialCommentPreviewController',
'save/$' => 'DifferentialCommentSaveController',
'inline/' => array(
'preview/(?P<id>\d+)/$' =>
'DifferentialInlineCommentPreviewController',
'edit/(?P<id>\d+)/$' => 'DifferentialInlineCommentEditController',
),
),
'subscribe/(?P<action>add|rem)/(?P<id>\d+)/$'
=> 'DifferentialSubscribeController',
),
'/typeahead/' => array(
'common/(?P<type>\w+)/$'
=> 'PhabricatorTypeaheadCommonDatasourceController',
),
'/mail/' => array(
'$' => 'PhabricatorMetaMTAListController',
'send/$' => 'PhabricatorMetaMTASendController',
'view/(?P<id>\d+)/$' => 'PhabricatorMetaMTAViewController',
'lists/$' => 'PhabricatorMetaMTAMailingListsController',
'lists/edit/(?:(?P<id>\d+)/)?$'
=> 'PhabricatorMetaMTAMailingListEditController',
'receive/$' => 'PhabricatorMetaMTAReceiveController',
'received/$' => 'PhabricatorMetaMTAReceivedListController',
'sendgrid/$' => 'PhabricatorMetaMTASendGridReceiveController',
),
'/login/' => array(
'$' => 'PhabricatorLoginController',
'email/$' => 'PhabricatorEmailLoginController',
'etoken/(?P<token>\w+)/$' => 'PhabricatorEmailTokenController',
'refresh/$' => 'PhabricatorRefreshCSRFController',
),
'/logout/$' => 'PhabricatorLogoutController',
'/oauth/' => array(
'(?P<provider>\w+)/' => array(
'login/$' => 'PhabricatorOAuthLoginController',
'diagnose/$' => 'PhabricatorOAuthDiagnosticsController',
'unlink/$' => 'PhabricatorOAuthUnlinkController',
),
),
'/xhprof/' => array(
'profile/(?P<phid>[^/]+)/$' => 'PhabricatorXHProfProfileController',
),
'/~/' => 'DarkConsoleController',
'/settings/' => array(
'(?:page/(?P<page>[^/]+)/)?$' => 'PhabricatorUserSettingsController',
),
'/maniphest/' => array(
'$' => 'ManiphestTaskListController',
'view/(?P<view>\w+)/$' => 'ManiphestTaskListController',
'task/' => array(
'create/$' => 'ManiphestTaskEditController',
'edit/(?P<id>\d+)/$' => 'ManiphestTaskEditController',
'descriptionchange/(?P<id>\d+)/$' =>
'ManiphestTaskDescriptionChangeController',
),
'transaction/' => array(
'save/' => 'ManiphestTransactionSaveController',
'preview/(?P<id>\d+)/$' => 'ManiphestTransactionPreviewController',
),
),
'/T(?P<id>\d+)$' => 'ManiphestTaskDetailController',
'/github-post-receive/(?P<id>\d+)/(?P<token>[^/]+)/$'
=> 'PhabricatorRepositoryGitHubPostReceiveController',
'/repository/' => array(
'$' => 'PhabricatorRepositoryListController',
'create/$' => 'PhabricatorRepositoryCreateController',
'edit/(?P<id>\d+)/(?:(?P<view>\w+)?/)?$' =>
'PhabricatorRepositoryEditController',
'delete/(?P<id>\d+)/$' => 'PhabricatorRepositoryDeleteController',
'project/(?P<id>\d+)/' =>
'PhabricatorRepositoryArcanistProjectEditController',
),
'/search/' => array(
'$' => 'PhabricatorSearchController',
'(?P<id>\d+)/$' => 'PhabricatorSearchController',
'attach/(?P<phid>[^/]+)/(?P<type>\w+)/(?:(?P<action>\w+)/)?$'
=> 'PhabricatorSearchAttachController',
'select/(?P<type>\w+)/$'
=> 'PhabricatorSearchSelectController',
'index/(?P<phid>[^/]+)/$' => 'PhabricatorSearchIndexController',
),
'/project/' => array(
'$' => 'PhabricatorProjectListController',
'edit/(?P<id>\d+)/$' => 'PhabricatorProjectProfileEditController',
'view/(?P<id>\d+)/(?:(?P<page>\w+)/)?$'
=> 'PhabricatorProjectProfileController',
'affiliation/(?P<id>\d+)/$'
=> 'PhabricatorProjectAffiliationEditController',
'create/$' => 'PhabricatorProjectCreateController',
),
'/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)$'
=> 'DiffusionCommitController',
'/diffusion/' => array(
'$' => 'DiffusionHomeController',
'(?P<callsign>[A-Z]+)/' => array(
'$' => 'DiffusionRepositoryController',
'repository/'.
'(?P<path>[^/]+)/'.
'$'
=> 'DiffusionRepositoryController',
'change/'.
'(?P<path>.*?)'.
'(?:[;](?P<commit>[a-z0-9]+))?'.
'$'
=> 'DiffusionChangeController',
'history/'.
'(?P<path>.*?)'.
'(?:[;](?P<commit>[a-z0-9]+))?'.
'$'
=> 'DiffusionHistoryController',
'browse/'.
'(?P<path>.*?)'.
'(?:[;](?P<commit>[a-z0-9]+))?'.
'(?:[$](?P<line>\d+))?'.
'$'
=> 'DiffusionBrowseController',
'diff/'.
'(?P<path>.*?)'.
'(?:[;](?P<commit>[a-z0-9]+))?'.
'$'
=> 'DiffusionDiffController',
'lastmodified/'.
'(?P<path>.*?)'.
'(?:[;](?P<commit>[a-z0-9]+))?'.
'$'
=> 'DiffusionLastModifiedController',
),
'services/' => array(
'path/' => array(
'complete/$' => 'DiffusionPathCompleteController',
'validate/$' => 'DiffusionPathValidateController',
),
),
'author/' => array(
'$' => 'DiffusionCommitListController',
'(?P<username>\w+)/$' => 'DiffusionCommitListController',
),
'symbol/(?P<name>[^/]+)/$' => 'DiffusionSymbolController',
),
'/daemon/' => array(
'task/(?P<id>\d+)/$' => 'PhabricatorWorkerTaskDetailController',
'log/' => array(
'$' => 'PhabricatorDaemonLogListController',
'combined/$' => 'PhabricatorDaemonCombinedLogController',
'(?P<id>\d+)/$' => 'PhabricatorDaemonLogViewController',
),
'timeline/$' => 'PhabricatorDaemonTimelineConsoleController',
'timeline/(?P<id>\d+)/$' => 'PhabricatorDaemonTimelineEventController',
'$' => 'PhabricatorDaemonConsoleController',
),
'/herald/' => array(
'$' => 'HeraldHomeController',
'view/(?P<view>[^/]+)/$' => 'HeraldHomeController',
'new/(?:(?P<type>[^/]+)/)?$' => 'HeraldNewController',
'rule/(?:(?P<id>\d+)/)?$' => 'HeraldRuleController',
'delete/(?P<id>\d+)/$' => 'HeraldDeleteController',
'test/$' => 'HeraldTestConsoleController',
'all/' => array(
'$' => 'HeraldAllRulesController',
'view/(?P<view>[^/]+)/$' => 'HeraldAllRulesController',
),
'transcript/$' => 'HeraldTranscriptListController',
'transcript/(?P<id>\d+)/(?:(?P<filter>\w+)/)?$'
=> 'HeraldTranscriptController',
),
'/uiexample/' => array(
'$' => 'PhabricatorUIExampleRenderController',
'view/(?P<class>[^/]+)/$' => 'PhabricatorUIExampleRenderController',
),
'/owners/' => array(
'$' => 'PhabricatorOwnersListController',
'view/(?P<view>[^/]+)/$' => 'PhabricatorOwnersListController',
'edit/(?P<id>\d+)/$' => 'PhabricatorOwnersEditController',
'new/$' => 'PhabricatorOwnersEditController',
'package/(?P<id>\d+)/$' => 'PhabricatorOwnersDetailController',
'delete/(?P<id>\d+)/$' => 'PhabricatorOwnersDeleteController',
),
'/xhpast/' => array(
'$' => 'PhabricatorXHPASTViewRunController',
'view/(?P<id>\d+)/$'
=> 'PhabricatorXHPASTViewFrameController',
'frameset/(?P<id>\d+)/$'
=> 'PhabricatorXHPASTViewFramesetController',
'input/(?P<id>\d+)/$'
=> 'PhabricatorXHPASTViewInputController',
'tree/(?P<id>\d+)/$'
=> 'PhabricatorXHPASTViewTreeController',
'stream/(?P<id>\d+)/$'
=> 'PhabricatorXHPASTViewStreamController',
),
'/status/$' => 'PhabricatorStatusController',
'/paste/' => array(
- '$' => 'PhabricatorPasteCreateController',
- 'list/' => 'PhabricatorPasteListController',
+ '$' => 'PhabricatorPasteListController',
+ 'filter/(?P<filter>\w+)/$' => 'PhabricatorPasteListController',
),
-
'/P(?P<id>\d+)$' => 'PhabricatorPasteViewController',
'/help/' => array(
'keyboardshortcut/$' => 'PhabricatorHelpKeyboardShortcutController',
),
'/countdown/' => array(
'$'
=> 'PhabricatorCountdownListController',
'(?P<id>\d+)/$'
=> 'PhabricatorCountdownViewController',
'edit/(?:(?P<id>\d+)/)?$'
=> 'PhabricatorCountdownEditController',
'delete/(?P<id>\d+)/$'
=> 'PhabricatorCountdownDeleteController'
),
'/feed/' => array(
'$' => 'PhabricatorFeedStreamController',
'public/$' => 'PhabricatorFeedPublicStreamController',
),
'/V(?P<id>\d+)$' => 'PhabricatorSlowvotePollController',
'/vote/' => array(
'(?:view/(?P<view>\w+)/)?$' => 'PhabricatorSlowvoteListController',
'create/' => 'PhabricatorSlowvoteCreateController',
),
// Match "/w/" with slug "/".
'/w(?P<slug>/)$' => 'PhrictionDocumentController',
// Match "/w/x/y/z/" with slug "x/y/z/".
'/w/(?P<slug>.+/)$' => 'PhrictionDocumentController',
'/phriction/' => array(
'$' => 'PhrictionListController',
'list/(?P<view>[^/]+)/$' => 'PhrictionListController',
'history(?P<slug>/)$' => 'PhrictionHistoryController',
'history/(?P<slug>.+/)$' => 'PhrictionHistoryController',
'edit/(?:(?P<id>\d+)/)?$' => 'PhrictionEditController',
'preview/$' => 'PhrictionDocumentPreviewController',
'diff/(?P<id>\d+)/$' => 'PhrictionDiffController',
),
'/calendar/' => array(
'$' => 'PhabricatorCalendarBrowseController',
),
);
}
protected function getResourceURIMapRules() {
return array(
'/res/' => array(
'(?P<package>pkg/)?(?P<hash>[a-f0-9]{8})/(?P<path>.+\.(?:css|js))$'
=> 'CelerityResourceController',
),
);
}
public function buildRequest() {
$request = new AphrontRequest($this->getHost(), $this->getPath());
$request->setRequestData($_GET + $_POST);
$request->setApplicationConfiguration($this);
return $request;
}
public function handleException(Exception $ex) {
// Always log the unhandled exception.
phlog($ex);
$class = phutil_escape_html(get_class($ex));
$message = phutil_escape_html($ex->getMessage());
if (PhabricatorEnv::getEnvConfig('phabricator.show-stack-traces')) {
$trace = $this->renderStackTrace($ex->getTrace());
} else {
$trace = null;
}
$content =
'<div class="aphront-unhandled-exception">'.
'<div class="exception-message">'.$message.'</div>'.
$trace.
'</div>';
$user = $this->getRequest()->getUser();
if (!$user) {
// If we hit an exception very early, we won't have a user.
$user = new PhabricatorUser();
}
$dialog = new AphrontDialogView();
$dialog
->setTitle('Unhandled Exception ("'.$class.'")')
->setClass('aphront-exception-dialog')
->setUser($user)
->appendChild($content);
if ($this->getRequest()->isAjax()) {
$dialog->addCancelButton('/', 'Close');
}
$response = new AphrontDialogResponse();
$response->setDialog($dialog);
return $response;
}
public function willSendResponse(AphrontResponse $response) {
$request = $this->getRequest();
$response->setRequest($request);
if ($response instanceof AphrontDialogResponse) {
if (!$request->isAjax()) {
$view = new PhabricatorStandardPageView();
$view->setRequest($request);
$view->appendChild(
'<div style="padding: 2em 0;">'.
$response->buildResponseString().
'</div>');
$response = new AphrontWebpageResponse();
$response->setContent($view->render());
return $response;
} else {
return id(new AphrontAjaxResponse())
->setContent(array(
'dialog' => $response->buildResponseString(),
));
}
} else if ($response instanceof AphrontRedirectResponse) {
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())
->setContent(
array(
'redirect' => $response->getURI(),
));
}
} else if ($response instanceof Aphront404Response) {
$failure = new AphrontRequestFailureView();
$failure->setHeader('404 Not Found');
$failure->appendChild(
'<p>The page you requested was not found.</p>');
$view = new PhabricatorStandardPageView();
$view->setTitle('404 Not Found');
$view->setRequest($this->getRequest());
$view->appendChild($failure);
$response = new AphrontWebpageResponse();
$response->setContent($view->render());
$response->setHTTPResponseCode(404);
return $response;
}
return $response;
}
public function build404Controller() {
return array(new Phabricator404Controller($this->getRequest()), array());
}
public function buildRedirectController($uri) {
return array(
new PhabricatorRedirectController($this->getRequest()),
array(
'uri' => $uri,
));
}
private function renderStackTrace($trace) {
$libraries = PhutilBootloader::getInstance()->getAllLibraries();
// TODO: Make this configurable?
$host = 'https://secure.phabricator.com';
$browse = array(
'arcanist' =>
$host.'/diffusion/ARC/browse/origin:master/src/',
'phutil' =>
$host.'/diffusion/PHU/browse/origin:master/src/',
'phabricator' =>
$host.'/diffusion/P/browse/origin:master/src/',
);
$rows = array();
$depth = count($trace);
foreach ($trace as $part) {
$lib = null;
$file = idx($part, 'file');
$relative = $file;
foreach ($libraries as $library) {
$root = phutil_get_library_root($library);
if (Filesystem::isDescendant($file, $root)) {
$lib = $library;
$relative = Filesystem::readablePath($file, $root);
break;
}
}
$where = '';
if (isset($part['class'])) {
$where .= $part['class'].'::';
}
if (isset($part['function'])) {
$where .= $part['function'].'()';
}
if ($file) {
if (isset($browse[$lib])) {
$file_name = phutil_render_tag(
'a',
array(
'href' => $browse[$lib].$relative.'$'.$part['line'],
'title' => $file,
'target' => '_blank',
),
phutil_escape_html($relative));
} else {
$file_name = phutil_render_tag(
'span',
array(
'title' => $file,
),
phutil_escape_html($relative));
}
$file_name = $file_name.' : '.(int)$part['line'];
} else {
$file_name = '<em>(Internal)</em>';
}
$rows[] = array(
$depth--,
phutil_escape_html($lib),
$file_name,
phutil_escape_html($where),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'Depth',
'Library',
'File',
'Where',
));
$table->setColumnClasses(
array(
'n',
'',
'',
'wide',
));
return
'<div class="exception-trace">'.
'<div class="exception-trace-header">Stack Trace</div>'.
$table->render().
'</div>';
}
}
diff --git a/src/applications/paste/controller/base/PhabricatorPasteController.php b/src/applications/paste/controller/base/PhabricatorPasteController.php
index 92eac1bba7..97a5fae593 100644
--- a/src/applications/paste/controller/base/PhabricatorPasteController.php
+++ b/src/applications/paste/controller/base/PhabricatorPasteController.php
@@ -1,44 +1,35 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
abstract class PhabricatorPasteController extends PhabricatorController {
public function buildStandardPageResponse($view, array $data) {
$page = $this->buildStandardPageView();
$page->setApplicationName('Paste');
$page->setBaseURI('/paste/');
$page->setTitle(idx($data, 'title'));
$page->setGlyph("\xE2\x9C\x8E");
- $page->setTabs(
- array(
- 'list' => array(
- 'href' => '/paste/list/',
- 'name' => 'Paste List',
- ),
- ),
- idx($data, 'tab'));
-
$page->appendChild($view);
$response = new AphrontWebpageResponse();
return $response->setContent($page->render());
}
}
diff --git a/src/applications/paste/controller/create/PhabricatorPasteCreateController.php b/src/applications/paste/controller/create/PhabricatorPasteCreateController.php
deleted file mode 100644
index 27aa6ef28a..0000000000
--- a/src/applications/paste/controller/create/PhabricatorPasteCreateController.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-
-/*
- * Copyright 2011 Facebook, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-class PhabricatorPasteCreateController extends PhabricatorPasteController {
-
- public function processRequest() {
-
- $request = $this->getRequest();
- $user = $request->getUser();
- $paste = new PhabricatorPaste();
-
- $error_view = null;
- $e_text = true;
-
- $fork = $request->getInt('fork');
-
- $paste_text = null;
- $paste_parent = null;
-
- if ($request->isFormPost()) {
- $errors = array();
- $title = $request->getStr('title');
-
- $paste_language = $request->getStr('language');
-
- $text = $request->getStr('text');
-
- if (!strlen($text)) {
- $e_text = 'Required';
- $errors[] = 'The paste may not be blank.';
- } else {
- $e_text = null;
- }
-
- $parent = id(new PhabricatorPaste())->loadOneWhere(
- 'phid = %s',
- $request->getStr('parent'));
-
- if ($parent) {
- $paste->setParentPHID($parent->getPHID());
- }
-
- $paste->setTitle($title);
-
- if (!$errors) {
- if ($paste_language == 'infer') {
- // If it's infer, store an empty string. Otherwise, store the
- // language name. We do this so we can refer to 'infer' elsewhere
- // in the code (such as default value) while retaining backwards
- // compatibility with old posts with no language stored.
- $paste_language = '';
- }
- $paste->setLanguage($paste_language);
-
- $paste_file = PhabricatorFile::newFromFileData(
- $text,
- array(
- 'name' => $title,
- 'mime-type' => 'text/plain; charset=utf-8',
- 'authorPHID' => $user->getPHID(),
- ));
- $paste->setFilePHID($paste_file->getPHID());
- $paste->setAuthorPHID($user->getPHID());
- $paste->save();
-
- return id(new AphrontRedirectResponse())
- ->setURI('/P'.$paste->getID());
- } else {
- $error_view = new AphrontErrorView();
- $error_view->setErrors($errors);
- $error_view->setTitle('A problem has occurred!');
- }
- } else {
- if ($fork) {
- $fork_paste = id(new PhabricatorPaste())->load($fork);
- if ($fork_paste) {
- $paste->setTitle('Fork of '.$fork_paste->getID().': '.
- $fork_paste->getTitle());
- $fork_file = id(new PhabricatorFile())->loadOneWhere(
- 'phid = %s',
- $fork_paste->getFilePHID());
- $paste_text = $fork_file->loadFileData();
- $paste_language = nonempty($fork_paste->getLanguage(), 'infer');
- $paste_parent = $fork_paste->getPHID();
- }
- } else {
- $paste_language = PhabricatorEnv::getEnvConfig(
- 'pygments.dropdown-default');
- }
- }
-
- $form = new AphrontFormView();
-
- $available_languages = PhabricatorEnv::getEnvConfig(
- 'pygments.dropdown-choices');
- asort($available_languages);
-
- $language_select = id(new AphrontFormSelectControl())
- ->setLabel('Language')
- ->setName('language')
- ->setValue($paste_language)
- ->setOptions($available_languages);
-
- $form
- ->setUser($user)
- ->setAction($request->getRequestURI()->getPath())
- ->addHiddenInput('parent', $paste_parent)
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setLabel('Title')
- ->setValue($paste->getTitle())
- ->setName('title'))
- ->appendChild($language_select)
- ->appendChild(
- id(new AphrontFormTextAreaControl())
- ->setLabel('Text')
- ->setError($e_text)
- ->setValue($paste_text)
- ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
- ->setName('text'))
- ->appendChild(
- id(new AphrontFormSubmitControl())
- ->addCancelButton('/paste/')
- ->setValue('Create Paste'));
-
- $panel = new AphrontPanelView();
- $panel->setWidth(AphrontPanelView::WIDTH_FORM);
- $panel->setHeader('Create a Paste');
- $panel->appendChild($form);
-
- return $this->buildStandardPageResponse(
- array(
- $error_view,
- $panel,
- ),
- array(
- 'title' => 'Paste Creation',
- 'tab' => 'create',
- ));
- }
-}
diff --git a/src/applications/paste/controller/create/__init__.php b/src/applications/paste/controller/create/__init__.php
deleted file mode 100644
index d0215f70f2..0000000000
--- a/src/applications/paste/controller/create/__init__.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-/**
- * This file is automatically generated. Lint this module to rebuild it.
- * @generated
- */
-
-
-
-phutil_require_module('phabricator', 'aphront/response/redirect');
-phutil_require_module('phabricator', 'applications/files/storage/file');
-phutil_require_module('phabricator', 'applications/paste/controller/base');
-phutil_require_module('phabricator', 'applications/paste/storage/paste');
-phutil_require_module('phabricator', 'infrastructure/env');
-phutil_require_module('phabricator', 'view/form/base');
-phutil_require_module('phabricator', 'view/form/control/select');
-phutil_require_module('phabricator', 'view/form/control/submit');
-phutil_require_module('phabricator', 'view/form/control/text');
-phutil_require_module('phabricator', 'view/form/control/textarea');
-phutil_require_module('phabricator', 'view/form/error');
-phutil_require_module('phabricator', 'view/layout/panel');
-
-phutil_require_module('phutil', 'utils');
-
-
-phutil_require_source('PhabricatorPasteCreateController.php');
diff --git a/src/applications/paste/controller/list/PhabricatorPasteListController.php b/src/applications/paste/controller/list/PhabricatorPasteListController.php
index e38a24a5ca..9cd4b638e0 100644
--- a/src/applications/paste/controller/list/PhabricatorPasteListController.php
+++ b/src/applications/paste/controller/list/PhabricatorPasteListController.php
@@ -1,114 +1,436 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class PhabricatorPasteListController extends PhabricatorPasteController {
+ private $filter;
+
+ private $errorView;
+ private $errorText;
+ private $paste;
+ private $pasteText;
+
+ private $offset;
+ private $pageSize;
+ private $author;
+
+ private function setFilter($filter) {
+ $this->filter = $filter;
+ return $this;
+ }
+ private function getFilter() {
+ return $this->filter;
+ }
+
+ private function setErrorView($error_view) {
+ $this->errorView = $error_view;
+ return $this;
+ }
+ private function getErrorView() {
+ return $this->errorView;
+ }
+
+ private function setErrorText($error_text) {
+ $this->errorText = $error_text;
+ return $this;
+ }
+ private function getErrorText() {
+ return $this->errorText;
+ }
+
+ private function setPaste(PhabricatorPaste $paste) {
+ $this->paste = $paste;
+ return $this;
+ }
+ private function getPaste() {
+ return $this->paste;
+ }
+
+ private function setPasteText($paste_text) {
+ $this->pasteText = $paste_text;
+ return $this;
+ }
+ private function getPasteText() {
+ return $this->pasteText;
+ }
+
+ private function setOffset($offset) {
+ $this->offset = $offset;
+ return $this;
+ }
+ private function getOffset() {
+ return $this->offset;
+ }
+
+ private function setPageSize($page_size) {
+ $this->pageSize = $page_size;
+ return $this;
+ }
+ private function getPageSize() {
+ return $this->pageSize;
+ }
+
+ private function setAuthor($author) {
+ $this->author = $author;
+ return $this;
+ }
+ private function getAuthor() {
+ return $this->author;
+ }
+
+ public function willProcessRequest(array $data) {
+ $this->setFilter(idx($data, 'filter', 'create'));
+ }
public function processRequest() {
$request = $this->getRequest();
+ $user = $request->getUser();
+ $paste_list = array();
+ $pager = null;
+
+ switch ($this->getFilter()) {
+ case 'create':
+ default:
+ // if we successfully create a paste, we redirect to view it
+ $created_paste_redirect = $this->processCreateRequest();
+ if ($created_paste_redirect) {
+ return $created_paste_redirect;
+ }
+ // if we didn't succeed or we weren't trying, load just a few
+ // recent pastes with NO pagination
+ $this->setOffset(0);
+ $this->setPageSize(10);
+ list($paste_list, $pager) = $this->loadPasteList();
+ break;
+
+ case 'my':
+ $this->setAuthor($user->getPHID());
+ $this->setOffset($request->getInt('page', 0));
+ list($paste_list, $pager) = $this->loadPasteList();
+ break;
+
+ case 'all':
+ $this->setOffset($request->getInt('page', 0));
+ list($paste_list, $pager) = $this->loadPasteList();
+ break;
+ }
+
+ $filters = array(
+ 'create' => array(
+ 'name' => 'Create Paste',
+ ),
+ 'my' => array(
+ 'name' => 'My Pastes',
+ ),
+ 'all' => array(
+ 'name' => 'All Pastes',
+ ),
+ );
+
+ $side_nav = new AphrontSideNavView();
+ foreach ($filters as $filter_key => $filter) {
+ $selected = $filter_key == $this->getFilter();
+ $side_nav->addNavItem(
+ phutil_render_tag(
+ 'a',
+ array(
+ 'href' => '/paste/filter/'.$filter_key.'/',
+ 'class' => $selected ? 'aphront-side-nav-selected': null,
+ ),
+ $filter['name'])
+ );
+ }
+
+ if ($this->getErrorView()) {
+ $side_nav->appendChild($this->getErrorView());
+ }
+
+ switch ($this->getFilter()) {
+ case 'create':
+ default:
+ $side_nav->appendChild($this->renderCreatePaste());
+ $see_all = phutil_render_tag(
+ 'a',
+ array(
+ 'href' => '/paste/filter/all',
+ ),
+ 'See all Pastes');
+ $header = "Recent Pastes · {$see_all}";
+ $side_nav->appendChild($this->renderPasteList($paste_list,
+ $header,
+ $pager = null));
+ break;
+ case 'my':
+ $header = 'Your Pastes';
+ $side_nav->appendChild($this->renderPasteList($paste_list,
+ $header,
+ $pager));
+ break;
+ case 'all':
+ $header = 'All Pastes';
+ $side_nav->appendChild($this->renderPasteList($paste_list,
+ $header,
+ $pager));
+ break;
+ }
+
+ return $this->buildStandardPageResponse(
+ $side_nav,
+ array(
+ 'title' => 'Paste',
+ )
+ );
+ }
+
+ private function processCreateRequest() {
+ $request = $this->getRequest();
+ $user = $request->getUser();
+ $fork = $request->getInt('fork');
+
+ $error_view = null;
+ $e_text = true;
+ $new_paste = new PhabricatorPaste();
+ $new_paste_text = null;
+ $new_paste_language = PhabricatorEnv::getEnvConfig(
+ 'pygments.dropdown-default');
+
+ if ($request->isFormPost()) {
+ $errors = array();
+
+ $text = $request->getStr('text');
+ if (!strlen($text)) {
+ $e_text = 'Required';
+ $errors[] = 'The paste may not be blank.';
+ } else {
+ $e_text = null;
+ }
+
+ $parent_phid = $request->getStr('parent');
+ if ($parent_phid) {
+ $parent = id(new PhabricatorPaste())->loadOneWhere('phid = %s',
+ $parent_phid);
+ if ($parent) {
+ $new_paste->setParentPHID($parent->getPHID());
+ }
+ }
+
+ $title = $request->getStr('title');
+ $new_paste->setTitle($title);
+
+ $new_paste_language = $request->getStr('language');
+
+ if (!$errors) {
+ if ($new_paste_language == 'infer') {
+ // If it's infer, store an empty string. Otherwise, store the
+ // language name. We do this so we can refer to 'infer' elsewhere
+ // in the code (such as default value) while retaining backwards
+ // compatibility with old posts with no language stored.
+ $new_paste_language = '';
+ }
+ $new_paste->setLanguage($new_paste_language);
+
+ $new_paste_file = PhabricatorFile::newFromFileData(
+ $text,
+ array(
+ 'name' => $title,
+ 'mime-type' => 'text/plain; charset=utf-8',
+ 'authorPHID' => $user->getPHID(),
+ ));
+ $new_paste->setFilePHID($new_paste_file->getPHID());
+ $new_paste->setAuthorPHID($user->getPHID());
+ $new_paste->save();
+
+ return id(new AphrontRedirectResponse())
+ ->setURI('/P'.$new_paste->getID());
+ } else {
+ $error_view = new AphrontErrorView();
+ $error_view->setErrors($errors);
+ $error_view->setTitle('A problem has occurred!');
+ }
+ } else if ($fork) {
+ $fork_paste = id(new PhabricatorPaste())->load($fork);
+ if ($fork_paste) {
+ $new_paste->setTitle('Fork of '.$fork_paste->getID().': '.
+ $fork_paste->getTitle());
+ $fork_file = id(new PhabricatorFile())->loadOneWhere(
+ 'phid = %s',
+ $fork_paste->getFilePHID());
+ $new_paste_text = $fork_file->loadFileData();
+ $new_paste_language = nonempty($fork_paste->getLanguage(), 'infer');
+ $new_paste->setParentPHID($fork_paste->getPHID());
+ }
+ }
+ $this->setErrorView($error_view);
+ $this->setErrorText($e_text);
+ $this->setPasteText($new_paste_text);
+ $new_paste->setLanguage($new_paste_language);
+ $this->setPaste($new_paste);
+ }
+
+ private function loadPasteList() {
+ $request = $this->getRequest();
$pager = new AphrontPagerView();
- $pager->setOffset($request->getInt('page'));
+ $pager->setOffset($this->getOffset());
+ if ($this->getPageSize()) {
+ $pager->setPageSize($this->getPageSize());
+ }
- $pastes = id(new PhabricatorPaste())->loadAllWhere(
- '1 = 1 ORDER BY id DESC LIMIT %d, %d',
- $pager->getOffset(),
- $pager->getPageSize() + 1);
+ if ($this->getAuthor()) {
+ $pastes = id(new PhabricatorPaste())->loadAllWhere(
+ 'authorPHID = %s ORDER BY id DESC LIMIT %d, %d',
+ $this->getAuthor(),
+ $pager->getOffset(),
+ $pager->getPageSize() + 1);
+ } else {
+ $pastes = id(new PhabricatorPaste())->loadAllWhere(
+ '1 = 1 ORDER BY id DESC LIMIT %d, %d',
+ $pager->getOffset(),
+ $pager->getPageSize() + 1);
+ }
$pastes = $pager->sliceResults($pastes);
$pager->setURI($request->getRequestURI(), 'page');
$phids = mpull($pastes, 'getAuthorPHID');
$handles = array();
if ($phids) {
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
}
- $rows = array();
+ $paste_list_rows = array();
foreach ($pastes as $paste) {
$handle = $handles[$paste->getAuthorPHID()];
- $rows[] = array(
+ $paste_list_rows[] = array(
phutil_escape_html('P'.$paste->getID()),
// TODO: Make this filter by user instead of going to their profile.
phutil_render_tag(
'a',
array(
'href' => '/p/'.$handle->getName().'/',
),
phutil_escape_html($handle->getName())),
phutil_escape_html($paste->getLanguage()),
phutil_render_tag(
'a',
array(
'href' => '/P'.$paste->getID(),
),
phutil_escape_html(
nonempty(
$paste->getTitle(),
'Untitled Masterwork P'.$paste->getID()))),
phutil_render_tag(
'a',
array(
'href' => PhabricatorFileURI::getViewURIForPHID(
$paste->getFilePHID()),
),
phutil_escape_html($paste->getFilePHID())),
);
}
- $table = new AphrontTableView($rows);
+ return array($paste_list_rows, $pager);
+ }
+
+ private function renderCreatePaste() {
+ $request = $this->getRequest();
+ $user = $request->getUser();
+
+ $new_paste = $this->getPaste();
+
+ $form = new AphrontFormView();
+
+ $available_languages = PhabricatorEnv::getEnvConfig(
+ 'pygments.dropdown-choices');
+ asort($available_languages);
+ $language_select = id(new AphrontFormSelectControl())
+ ->setLabel('Language')
+ ->setName('language')
+ ->setValue($new_paste->getLanguage())
+ ->setOptions($available_languages);
+
+ $form
+ ->setUser($user)
+ ->setAction($request->getRequestURI()->getPath())
+ ->addHiddenInput('parent', $new_paste->getParentPHID())
+ ->appendChild(
+ id(new AphrontFormTextControl())
+ ->setLabel('Title')
+ ->setValue($new_paste->getTitle())
+ ->setName('title'))
+ ->appendChild($language_select)
+ ->appendChild(
+ id(new AphrontFormTextAreaControl())
+ ->setLabel('Text')
+ ->setError($this->getErrorText())
+ ->setValue($this->getPasteText())
+ ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
+ ->setName('text'))
+ ->appendChild(
+ id(new AphrontFormSubmitControl())
+ ->addCancelButton('/paste/')
+ ->setValue('Create Paste'));
+
+ $create_panel = new AphrontPanelView();
+ $create_panel->setWidth(AphrontPanelView::WIDTH_FULL);
+ $create_panel->setHeader('Create a Paste');
+ $create_panel->appendChild($form);
+
+ return $create_panel;
+ }
+
+ private function renderPasteList($paste_list_rows,
+ $header,
+ $pager = null) {
+ $table = new AphrontTableView($paste_list_rows);
$table->setHeaders(
array(
'Paste ID',
'Author',
'Language',
'Title',
'File',
));
$table->setColumnClasses(
array(
null,
null,
null,
'wide pri',
null,
));
$panel = new AphrontPanelView();
$panel->setWidth(AphrontPanelView::WIDTH_FULL);
- $panel->setHeader("Paste");
- $panel->setCreateButton('Paste Something', '/paste/');
+ $panel->setHeader($header);
$panel->appendChild($table);
- $panel->appendChild($pager);
+ if ($pager) {
+ $panel->appendChild($pager);
+ }
- return $this->buildStandardPageResponse(
- $panel,
- array(
- 'title' => 'Paste List',
- 'tab' => 'list',
- )
- );
+ return $panel;
}
}
diff --git a/src/applications/paste/controller/list/__init__.php b/src/applications/paste/controller/list/__init__.php
index 76dd5f1fa1..3732b36750 100644
--- a/src/applications/paste/controller/list/__init__.php
+++ b/src/applications/paste/controller/list/__init__.php
@@ -1,21 +1,31 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
+phutil_require_module('phabricator', 'aphront/response/redirect');
+phutil_require_module('phabricator', 'applications/files/storage/file');
phutil_require_module('phabricator', 'applications/files/uri');
phutil_require_module('phabricator', 'applications/paste/controller/base');
phutil_require_module('phabricator', 'applications/paste/storage/paste');
phutil_require_module('phabricator', 'applications/phid/handle/data');
+phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/control/table');
+phutil_require_module('phabricator', 'view/form/base');
+phutil_require_module('phabricator', 'view/form/control/select');
+phutil_require_module('phabricator', 'view/form/control/submit');
+phutil_require_module('phabricator', 'view/form/control/text');
+phutil_require_module('phabricator', 'view/form/control/textarea');
+phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
+phutil_require_module('phabricator', 'view/layout/sidenav');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorPasteListController.php');
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Jan 19 2025, 22:56 (6 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1129629
Default Alt Text
(43 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment