mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 02:02:41 +01:00
ef85f49adc
Summary: This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory). We are removing the headers for these reasons: - It wastes space in editors, less code is visible in editor upon opening a file. - It brings noise to diff of the first change of any file every year. - It confuses Git file copy detection when creating small files. - We don't have an explicit license header in other files (JS, CSS, images, documentation). - Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new. This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook). Test Plan: Verified that the license survived only in LICENSE file and that it didn't modify externals. Reviewers: epriestley, davidrecordon Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2035 Differential Revision: https://secure.phabricator.com/D3886
114 lines
3 KiB
PHP
114 lines
3 KiB
PHP
<?php
|
|
|
|
final class PonderQuestionAskController extends PonderController {
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
|
|
$question = id(new PonderQuestion())
|
|
->setAuthorPHID($user->getPHID())
|
|
->setVoteCount(0)
|
|
->setAnswerCount(0)
|
|
->setHeat(0.0);
|
|
|
|
$errors = array();
|
|
$e_title = true;
|
|
if ($request->isFormPost()) {
|
|
$question->setTitle($request->getStr('title'));
|
|
$question->setContent($request->getStr('content'));
|
|
|
|
$len = phutil_utf8_strlen($question->getTitle());
|
|
if ($len < 1) {
|
|
$errors[] = pht('Title must not be empty.');
|
|
$e_title = pht('Required');
|
|
} else if ($len > 255) {
|
|
$errors[] = pht('Title is too long.');
|
|
$e_title = pht('Too Long');
|
|
}
|
|
|
|
if (!$errors) {
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
array(
|
|
'ip' => $request->getRemoteAddr(),
|
|
));
|
|
$question->setContentSource($content_source);
|
|
|
|
id(new PonderQuestionEditor())
|
|
->setQuestion($question)
|
|
->setActor($user)
|
|
->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
->setURI('/Q'.$question->getID());
|
|
}
|
|
}
|
|
|
|
$error_view = null;
|
|
if ($errors) {
|
|
$error_view = id(new AphrontErrorView())
|
|
->setTitle('Form Errors')
|
|
->setErrors($errors);
|
|
}
|
|
|
|
$header = id(new PhabricatorHeaderView())->setHeader(pht('Ask Question'));
|
|
|
|
$form = id(new AphrontFormView())
|
|
->setUser($user)
|
|
->setFlexible(true)
|
|
->appendChild(
|
|
id(new AphrontFormTextControl())
|
|
->setLabel(pht('Question'))
|
|
->setName('title')
|
|
->setValue($question->getTitle())
|
|
->setError($e_title))
|
|
->appendChild(
|
|
id(new PhabricatorRemarkupControl())
|
|
->setName('content')
|
|
->setID('content')
|
|
->setValue($question->getContent())
|
|
->setLabel(pht('Description')))
|
|
->appendChild(
|
|
id(new AphrontFormSubmitControl())
|
|
->setValue('Ask Away!'));
|
|
|
|
$preview =
|
|
'<div class="aphront-panel-flush">'.
|
|
'<div id="question-preview">'.
|
|
'<span class="aphront-panel-preview-loading-text">'.
|
|
pht('Loading question preview...').
|
|
'</span>'.
|
|
'</div>'.
|
|
'</div>';
|
|
|
|
Javelin::initBehavior(
|
|
'ponder-feedback-preview',
|
|
array(
|
|
'uri' => '/ponder/question/preview/',
|
|
'content' => 'content',
|
|
'preview' => 'question-preview',
|
|
'question_id' => null
|
|
));
|
|
|
|
$nav = $this->buildSideNavView($question);
|
|
$nav->selectFilter($question->getID() ? null : 'question/ask');
|
|
|
|
$nav->appendChild(
|
|
array(
|
|
$header,
|
|
$error_view,
|
|
$form,
|
|
$preview,
|
|
));
|
|
|
|
return $this->buildApplicationPage(
|
|
$nav,
|
|
array(
|
|
'device' => true,
|
|
'title' => 'Ask a Question',
|
|
)
|
|
);
|
|
}
|
|
|
|
}
|