mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Web editor/browser for image macros
Summary: Restores the old "pokedex" feature and allows easy definition of new macros. Only good can come of this! Critical feature!! Test Plan: nyancat Reviewed By: tuomaspelkonen Reviewers: aran, bh, tomo, jungejason, tuomaspelkonen CC: aran, tuomaspelkonen Differential Revision: 220
This commit is contained in:
parent
72dec7cd25
commit
b75960c578
12 changed files with 919 additions and 555 deletions
|
@ -160,11 +160,13 @@ foreach ($package_spec as $name => $package) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
ksort($runtime_map);
|
||||
$runtime_map = var_export($runtime_map, true);
|
||||
$runtime_map = preg_replace('/\s+$/m', '', $runtime_map);
|
||||
$runtime_map = preg_replace('/array \(/', 'array(', $runtime_map);
|
||||
|
||||
ksort($package_map['packages']);
|
||||
ksort($package_map['reverse']);
|
||||
$package_map = var_export($package_map, true);
|
||||
$pacakge_map = preg_replace('/\s+$/m', '', $package_map);
|
||||
$package_map = preg_replace('/array \(/', 'array(', $package_map);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -307,6 +307,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFileDAO' => 'applications/files/storage/base',
|
||||
'PhabricatorFileImageMacro' => 'applications/files/storage/imagemacro',
|
||||
'PhabricatorFileListController' => 'applications/files/controller/list',
|
||||
'PhabricatorFileMacroDeleteController' => 'applications/files/controller/macrodelete',
|
||||
'PhabricatorFileMacroEditController' => 'applications/files/controller/macroedit',
|
||||
'PhabricatorFileMacroListController' => 'applications/files/controller/macrolist',
|
||||
'PhabricatorFileStorageBlob' => 'applications/files/storage/storageblob',
|
||||
'PhabricatorFileURI' => 'applications/files/uri',
|
||||
'PhabricatorFileUploadController' => 'applications/files/controller/upload',
|
||||
|
@ -712,6 +715,9 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFileDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorFileImageMacro' => 'PhabricatorFileDAO',
|
||||
'PhabricatorFileListController' => 'PhabricatorFileController',
|
||||
'PhabricatorFileMacroDeleteController' => 'PhabricatorFileController',
|
||||
'PhabricatorFileMacroEditController' => 'PhabricatorFileController',
|
||||
'PhabricatorFileMacroListController' => 'PhabricatorFileController',
|
||||
'PhabricatorFileStorageBlob' => 'PhabricatorFileDAO',
|
||||
'PhabricatorFileUploadController' => 'PhabricatorFileController',
|
||||
'PhabricatorFileViewController' => 'PhabricatorFileController',
|
||||
|
|
|
@ -55,6 +55,11 @@ class AphrontDefaultApplicationConfiguration
|
|||
'(?P<view>info)/(?P<phid>[^/]+)/' => 'PhabricatorFileViewController',
|
||||
'(?P<view>view)/(?P<phid>[^/]+)/' => 'PhabricatorFileViewController',
|
||||
'(?P<view>download)/(?P<phid>[^/]+)/' => 'PhabricatorFileViewController',
|
||||
'macro/' => array(
|
||||
'$' => 'PhabricatorFileMacroListController',
|
||||
'edit/(?:(?P<id>\d+)/)?$' => 'PhabricatorFileMacroEditController',
|
||||
'delete/(?P<id>\d+)/$' => 'PhabricatorFileMacroDeleteController',
|
||||
),
|
||||
),
|
||||
'/phid/' => array(
|
||||
'$' => 'PhabricatorPHIDLookupController',
|
||||
|
|
|
@ -25,6 +25,18 @@ abstract class PhabricatorFileController extends PhabricatorController {
|
|||
$page->setBaseURI('/file/');
|
||||
$page->setTitle(idx($data, 'title'));
|
||||
$page->setGlyph("\xE2\x87\xAA");
|
||||
$page->setTabs(
|
||||
array(
|
||||
'files' => array(
|
||||
'name' => 'Files',
|
||||
'href' => '/file/',
|
||||
),
|
||||
'macros' => array(
|
||||
'name' => 'Image Macros',
|
||||
'href' => '/file/macro/',
|
||||
),
|
||||
),
|
||||
idx($data, 'tab'));
|
||||
$page->appendChild($view);
|
||||
|
||||
$response = new AphrontWebpageResponse();
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?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 PhabricatorFileMacroDeleteController extends PhabricatorFileController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$macro = id(new PhabricatorFileImageMacro())->load($this->id);
|
||||
if (!$macro) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
if ($request->isDialogFormPost()) {
|
||||
$macro->delete();
|
||||
return id(new AphrontRedirectResponse())->setURI('/file/macro/');
|
||||
}
|
||||
|
||||
$dialog = new AphrontDialogView();
|
||||
$dialog
|
||||
->setUser($request->getUser())
|
||||
->setTitle('Really delete macro?')
|
||||
->appendChild(
|
||||
'<p>Really delete the much-beloved image macro "'.
|
||||
phutil_escape_html($macro->getName()).'"? It will be sorely missed.'.
|
||||
'</p>')
|
||||
->setSubmitURI('/file/macro/delete/'.$this->id.'/')
|
||||
->addSubmitButton('Delete')
|
||||
->addCancelButton('/file/macro/');
|
||||
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
}
|
20
src/applications/files/controller/macrodelete/__init__.php
Normal file
20
src/applications/files/controller/macrodelete/__init__.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'aphront/response/dialog');
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/imagemacro');
|
||||
phutil_require_module('phabricator', 'view/dialog');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorFileMacroDeleteController.php');
|
|
@ -0,0 +1,124 @@
|
|||
<?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 PhabricatorFileMacroEditController extends PhabricatorFileController {
|
||||
|
||||
private $id;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->id = idx($data, 'id');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
if ($this->id) {
|
||||
$macro = id(new PhabricatorFileImageMacro())->load($this->id);
|
||||
if (!$macro) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
} else {
|
||||
$macro = new PhabricatorFileImageMacro();
|
||||
}
|
||||
|
||||
$errors = array();
|
||||
$e_name = true;
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request->isFormPost()) {
|
||||
|
||||
$macro->setName($request->getStr('name'));
|
||||
|
||||
if (!strlen($macro->getName())) {
|
||||
$errors[] = 'Macro name is required.';
|
||||
$e_name = 'Required';
|
||||
} else if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) {
|
||||
$errors[] = 'Macro must be at least three characters long and contain '.
|
||||
'only lowercase letters, digits, hyphen and underscore.';
|
||||
$e_name = 'Invalid';
|
||||
} else {
|
||||
$e_name = null;
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
idx($_FILES, 'file'),
|
||||
array(
|
||||
'name' => $request->getStr('name'),
|
||||
));
|
||||
$macro->setFilePHID($file->getPHID());
|
||||
|
||||
try {
|
||||
$macro->save();
|
||||
return id(new AphrontRedirectResponse())->setURI('/file/macro/');
|
||||
} catch (AphrontQueryDuplicateKeyException $ex) {
|
||||
$errors[] = 'Macro name is not unique!';
|
||||
$e_name = 'Duplicate';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
$error_view = new AphrontErrorView();
|
||||
$error_view->setTitle('Form Errors');
|
||||
$error_view->setErrors($errors);
|
||||
} else {
|
||||
$error_view = null;
|
||||
}
|
||||
|
||||
$form = new AphrontFormView();
|
||||
$form->setAction('/file/macro/edit/');
|
||||
$form->setUser($request->getUser());
|
||||
|
||||
$form
|
||||
->setEncType('multipart/form-data')
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('Name')
|
||||
->setName('name')
|
||||
->setValue($macro->getName())
|
||||
->setCaption('This word or phrase will be replaced with the image.')
|
||||
->setError($e_name))
|
||||
->appendChild(
|
||||
id(new AphrontFormFileControl())
|
||||
->setLabel('File')
|
||||
->setName('file')
|
||||
->setError(true))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Save Image Macro')
|
||||
->addCancelButton('/file/macro/'));
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
if ($macro->getID()) {
|
||||
$panel->setHeader('Edit Image Macro');
|
||||
} else {
|
||||
$panel->setHeader('Create Image Macro');
|
||||
}
|
||||
|
||||
$panel->appendChild($form);
|
||||
$panel->setWidth(AphrontPanelView::WIDTH_FORM);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array($error_view, $panel),
|
||||
array(
|
||||
'title' => 'Edit Image Macro',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
24
src/applications/files/controller/macroedit/__init__.php
Normal file
24
src/applications/files/controller/macroedit/__init__.php
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/404');
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/file');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/imagemacro');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
phutil_require_module('phabricator', 'view/form/control/file');
|
||||
phutil_require_module('phabricator', 'view/form/control/submit');
|
||||
phutil_require_module('phabricator', 'view/form/control/text');
|
||||
phutil_require_module('phabricator', 'view/form/error');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorFileMacroEditController.php');
|
|
@ -0,0 +1,89 @@
|
|||
<?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 PhabricatorFileMacroListController extends PhabricatorFileController {
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$pager->setOffset($request->getInt('page'));
|
||||
|
||||
$macros = id(new PhabricatorFileImageMacro())->loadAllWhere(
|
||||
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
||||
$pager->getOffset(),
|
||||
$pager->getPageSize() + 1);
|
||||
|
||||
$macros = $pager->sliceResults($macros);
|
||||
$pager->setURI($request->getRequestURI(), 'page');
|
||||
|
||||
$rows = array();
|
||||
foreach ($macros as $macro) {
|
||||
$src = PhabricatorFileURI::getViewURIForPHID($macro->getFilePHID());
|
||||
$rows[] = array(
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/file/macro/edit/'.$macro->getID().'/',
|
||||
),
|
||||
phutil_escape_html($macro->getName())),
|
||||
phutil_render_tag(
|
||||
'img',
|
||||
array(
|
||||
'src' => $src,
|
||||
)),
|
||||
javelin_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/file/macro/delete/'.$macro->getID().'/',
|
||||
'sigil' => 'workflow',
|
||||
'class' => 'grey small button',
|
||||
),
|
||||
'Delete'),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setHeaders(
|
||||
array(
|
||||
'Name',
|
||||
'Image',
|
||||
'',
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'pri',
|
||||
'wide thumb',
|
||||
'action',
|
||||
));
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->appendChild($table);
|
||||
$panel->setHeader('Image Macros');
|
||||
$panel->setCreateButton('New Image Macro', '/file/macro/edit/');
|
||||
$panel->appendChild($pager);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$panel,
|
||||
array(
|
||||
'title' => 'Image Macros',
|
||||
'tab' => 'macros',
|
||||
));
|
||||
}
|
||||
}
|
21
src/applications/files/controller/macrolist/__init__.php
Normal file
21
src/applications/files/controller/macrolist/__init__.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/files/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/files/storage/imagemacro');
|
||||
phutil_require_module('phabricator', 'applications/files/uri');
|
||||
phutil_require_module('phabricator', 'infrastructure/javelin/markup');
|
||||
phutil_require_module('phabricator', 'view/control/pager');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorFileMacroListController.php');
|
|
@ -86,3 +86,8 @@
|
|||
color: #888888;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.aphront-table-view td.thumb img {
|
||||
max-width: 64px;
|
||||
max-height: 64px;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue