Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phame / controller / post / PhamePostHeaderPictureController.php
blob60075cc0772f169a4b6a85437bc2c0037813cbfc
1 <?php
3 final class PhamePostHeaderPictureController
4 extends PhamePostController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getViewer();
8 $id = $request->getURIData('id');
10 $post = id(new PhamePostQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->needHeaderImage(true)
14 ->requireCapabilities(
15 array(
16 PhabricatorPolicyCapability::CAN_VIEW,
17 PhabricatorPolicyCapability::CAN_EDIT,
19 ->executeOne();
20 if (!$post) {
21 return new Aphront404Response();
24 $post_uri = '/phame/post/view/'.$id;
26 $supported_formats = PhabricatorFile::getTransformableImageFormats();
27 $e_file = true;
28 $errors = array();
29 $delete_header = ($request->getInt('delete') == 1);
31 if ($request->isFormPost()) {
32 if ($request->getFileExists('header')) {
33 $file = PhabricatorFile::newFromPHPUpload(
34 $_FILES['header'],
35 array(
36 'authorPHID' => $viewer->getPHID(),
37 'canCDN' => true,
38 ));
39 } else if (!$delete_header) {
40 $e_file = pht('Required');
41 $errors[] = pht(
42 'You must choose a file when uploading a new post header.');
45 if (!$errors && !$delete_header) {
46 if (!$file->isTransformableImage()) {
47 $e_file = pht('Not Supported');
48 $errors[] = pht(
49 'This server only supports these image formats: %s.',
50 implode(', ', $supported_formats));
54 if (!$errors) {
55 if ($delete_header) {
56 $new_value = null;
57 } else {
58 $file->attachToObject($post->getPHID());
59 $new_value = $file->getPHID();
62 $xactions = array();
63 $xactions[] = id(new PhamePostTransaction())
64 ->setTransactionType(PhamePostHeaderImageTransaction::TRANSACTIONTYPE)
65 ->setNewValue($new_value);
67 $editor = id(new PhamePostEditor())
68 ->setActor($viewer)
69 ->setContentSourceFromRequest($request)
70 ->setContinueOnMissingFields(true)
71 ->setContinueOnNoEffect(true);
73 $editor->applyTransactions($post, $xactions);
75 return id(new AphrontRedirectResponse())->setURI($post_uri);
79 $title = pht('Edit Post Header');
81 $upload_form = id(new AphrontFormView())
82 ->setUser($viewer)
83 ->setEncType('multipart/form-data')
84 ->appendChild(
85 id(new AphrontFormFileControl())
86 ->setName('header')
87 ->setLabel(pht('Upload Header'))
88 ->setError($e_file)
89 ->setCaption(
90 pht('Supported formats: %s', implode(', ', $supported_formats))))
91 ->appendChild(
92 id(new AphrontFormCheckboxControl())
93 ->setName('delete')
94 ->setLabel(pht('Delete Header'))
95 ->addCheckbox(
96 'delete',
98 null,
99 null))
100 ->appendChild(
101 id(new AphrontFormSubmitControl())
102 ->addCancelButton($post_uri)
103 ->setValue(pht('Upload Header')));
105 $upload_box = id(new PHUIObjectBoxView())
106 ->setHeaderText(pht('Upload New Header'))
107 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
108 ->setForm($upload_form);
110 $crumbs = $this->buildApplicationCrumbs();
111 $crumbs->addTextCrumb(
112 $post->getTitle(),
113 $this->getApplicationURI('post/view/'.$id));
114 $crumbs->addTextCrumb(pht('Post Header'));
115 $crumbs->setBorder(true);
117 $header = id(new PHUIHeaderView())
118 ->setHeader(pht('Edit Post Header'))
119 ->setHeaderIcon('fa-camera');
121 $view = id(new PHUITwoColumnView())
122 ->setHeader($header)
123 ->setFooter(array(
124 $upload_box,
127 return $this->newPage()
128 ->setTitle($title)
129 ->setCrumbs($crumbs)
130 ->appendChild(
131 array(
132 $view,