1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-23 12:09:12 +01:00

Use phutil_tag in Setup issue stuff

Summary: These are pretty straightforward, they just have a fair amount of instructional text with inline markup.

Test Plan: Added and viewed a UIExample.

Reviewers: vrana

Reviewed By: vrana

CC: aran

Maniphest Tasks: T2432

Differential Revision: https://secure.phabricator.com/D4686
This commit is contained in:
epriestley 2013-01-29 11:29:56 -08:00
parent 39221b1d3f
commit fb59101cde
5 changed files with 125 additions and 86 deletions

View file

@ -1254,6 +1254,7 @@ phutil_register_library_map(array(
'PhabricatorSetupCheckStorage' => 'applications/config/check/PhabricatorSetupCheckStorage.php', 'PhabricatorSetupCheckStorage' => 'applications/config/check/PhabricatorSetupCheckStorage.php',
'PhabricatorSetupCheckTimezone' => 'applications/config/check/PhabricatorSetupCheckTimezone.php', 'PhabricatorSetupCheckTimezone' => 'applications/config/check/PhabricatorSetupCheckTimezone.php',
'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php', 'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php',
'PhabricatorSetupIssueExample' => 'applications/uiexample/examples/PhabricatorSetupIssueExample.php',
'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php', 'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php',
'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php', 'PhabricatorSlowvoteChoice' => 'applications/slowvote/storage/PhabricatorSlowvoteChoice.php',
'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php', 'PhabricatorSlowvoteComment' => 'applications/slowvote/storage/PhabricatorSlowvoteComment.php',
@ -2652,6 +2653,7 @@ phutil_register_library_map(array(
'PhabricatorSetupCheckPath' => 'PhabricatorSetupCheck', 'PhabricatorSetupCheckPath' => 'PhabricatorSetupCheck',
'PhabricatorSetupCheckStorage' => 'PhabricatorSetupCheck', 'PhabricatorSetupCheckStorage' => 'PhabricatorSetupCheck',
'PhabricatorSetupCheckTimezone' => 'PhabricatorSetupCheck', 'PhabricatorSetupCheckTimezone' => 'PhabricatorSetupCheck',
'PhabricatorSetupIssueExample' => 'PhabricatorUIExample',
'PhabricatorSetupIssueView' => 'AphrontView', 'PhabricatorSetupIssueView' => 'AphrontView',
'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO', 'PhabricatorSlowvoteChoice' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO', 'PhabricatorSlowvoteComment' => 'PhabricatorSlowvoteDAO',

View file

@ -59,9 +59,10 @@ final class PhabricatorSetupCheckBaseURI extends PhabricatorSetupCheck {
->setSummary($summary) ->setSummary($summary)
->setMessage($message) ->setMessage($message)
->addCommand( ->addCommand(
csprintf( hsprintf(
'<tt>phabricator/ $</tt> '. '<tt>phabricator/ $</tt> %s',
'./bin/config set phabricator.base-uri %s', csprintf(
$base_uri_guess)); './bin/config set phabricator.base-uri %s',
$base_uri_guess)));
} }
} }

View file

@ -79,7 +79,7 @@ final class PhabricatorSetupCheckDatabase extends PhabricatorSetupCheck {
->setName(pht('Setup MySQL Schema')) ->setName(pht('Setup MySQL Schema'))
->setMessage($message) ->setMessage($message)
->setIsFatal(true) ->setIsFatal(true)
->addCommand('<tt>phabricator/ $</tt> ./bin/storage upgrade'); ->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade'));
} }
} }
} }

View file

@ -16,7 +16,8 @@ final class PhabricatorSetupIssueView extends AphrontView {
public function render() { public function render() {
$issue = $this->getIssue(); $issue = $this->getIssue();
$description = phutil_tag( $description = array();
$description[] = phutil_tag(
'div', 'div',
array( array(
'class' => 'setup-issue-instructions', 'class' => 'setup-issue-instructions',
@ -25,25 +26,25 @@ final class PhabricatorSetupIssueView extends AphrontView {
$configs = $issue->getPHPConfig(); $configs = $issue->getPHPConfig();
if ($configs) { if ($configs) {
$description .= $this->renderPHPConfig($configs); $description[] = $this->renderPHPConfig($configs);
} }
$configs = $issue->getPhabricatorConfig(); $configs = $issue->getPhabricatorConfig();
if ($configs) { if ($configs) {
$description .= $this->renderPhabricatorConfig($configs); $description[] = $this->renderPhabricatorConfig($configs);
} }
$commands = $issue->getCommands(); $commands = $issue->getCommands();
if ($commands) { if ($commands) {
$run_these = pht("Run these %d command(s):", count($commands)); $run_these = pht("Run these %d command(s):", count($commands));
$description .= phutil_tag( $description[] = phutil_tag(
'div', 'div',
array( array(
'class' => 'setup-issue-config', 'class' => 'setup-issue-config',
), ),
array( array(
phutil_render_tag('p', array(), $run_these), phutil_tag('p', array(), $run_these),
phutil_render_tag('pre', array(), implode("\n", $commands)), phutil_tag('pre', array(), array_interleave("\n", $commands)),
)); ));
} }
@ -52,11 +53,11 @@ final class PhabricatorSetupIssueView extends AphrontView {
$install_these = pht( $install_these = pht(
"Install these %d PHP extension(s):", count($extensions)); "Install these %d PHP extension(s):", count($extensions));
$install_info = pht( $install_info = phutil_safe_html(pht(
"You can usually install a PHP extension using <tt>apt-get</tt> or ". "You can usually install a PHP extension using <tt>apt-get</tt> or ".
"<tt>yum</tt>. Common package names are ". "<tt>yum</tt>. Common package names are ".
"<tt>php-<em>extname</em></tt> or <tt>php5-<em>extname</em></tt>. ". "<tt>php-<em>extname</em></tt> or <tt>php5-<em>extname</em></tt>. ".
"Try commands like these:"); "Try commands like these:"));
// TODO: We should do a better job of detecting how to install extensions // TODO: We should do a better job of detecting how to install extensions
// on the current system. // on the current system.
@ -65,6 +66,7 @@ final class PhabricatorSetupIssueView extends AphrontView {
"$ sudo yum install php-<em>extname</em> # Red Hat / Derivatives", "$ sudo yum install php-<em>extname</em> # Red Hat / Derivatives",
); );
$install_commands = implode("\n", $install_commands); $install_commands = implode("\n", $install_commands);
$install_commands = phutil_safe_html($install_commands);
$fallback_info = pht( $fallback_info = pht(
"If those commands don't work, try Google. The process of installing ". "If those commands don't work, try Google. The process of installing ".
@ -75,19 +77,20 @@ final class PhabricatorSetupIssueView extends AphrontView {
$restart_info = pht( $restart_info = pht(
"After installing new PHP extensions, <strong>restart your webserver ". "After installing new PHP extensions, <strong>restart your webserver ".
"for the changes to take effect</strong>."); "for the changes to take effect</strong>.");
$restart_info = phutil_safe_html($restart_info);
$description .= phutil_tag( $description[] = phutil_tag(
'div', 'div',
array( array(
'class' => 'setup-issue-config', 'class' => 'setup-issue-config',
), ),
array( array(
phutil_render_tag('p', array(), $install_these), phutil_tag('p', array(), $install_these),
phutil_render_tag('pre', array(), implode("\n", $extensions)), phutil_tag('pre', array(), implode("\n", $extensions)),
phutil_render_tag('p', array(), $install_info), phutil_tag('p', array(), $install_info),
phutil_render_tag('pre', array(), $install_commands), phutil_tag('pre', array(), $install_commands),
phutil_render_tag('p', array(), $fallback_info), phutil_tag('p', array(), $fallback_info),
phutil_render_tag('p', array(), $restart_info), phutil_tag('p', array(), $restart_info),
)); ));
} }
@ -111,7 +114,12 @@ final class PhabricatorSetupIssueView extends AphrontView {
array( array(
'class' => 'setup-issue', 'class' => 'setup-issue',
), ),
array($name, $description, $next)); $this->renderHTMLView(
array(
$name,
$description,
$next,
)));
} }
private function renderPhabricatorConfig(array $configs) { private function renderPhabricatorConfig(array $configs) {
@ -124,32 +132,11 @@ final class PhabricatorSetupIssueView extends AphrontView {
"The current Phabricator configuration has these %d value(s):", "The current Phabricator configuration has these %d value(s):",
count($configs))); count($configs)));
$table = array(); $dict = array();
foreach ($configs as $key) { foreach ($configs as $key) {
$table[] = '<tr>'; $dict[$key] = PhabricatorEnv::getUnrepairedEnvConfig($key);
$table[] = '<th>'.phutil_escape_html($key).'</th>';
$value = PhabricatorEnv::getUnrepairedEnvConfig($key);
if ($value === null) {
$value = '<em>null</em>';
} else if ($value === false) {
$value = '<em>false</em>';
} else if ($value === true) {
$value = '<em>true</em>';
} else {
$value = phutil_escape_html(
PhabricatorConfigJSON::prettyPrintJSON($value));
}
$table[] = '<td>'.$value.'</td>';
$table[] = '</tr>';
} }
$table = $this->renderValueTable($dict);
$table = phutil_tag(
'table',
array(
),
new PhutilSafeHTML(implode("\n", $table)));
$options = PhabricatorApplicationConfigOptions::loadAllOptions(); $options = PhabricatorApplicationConfigOptions::loadAllOptions();
@ -164,12 +151,11 @@ final class PhabricatorSetupIssueView extends AphrontView {
$update = array(); $update = array();
foreach ($configs as $key) { foreach ($configs as $key) {
$cmd = '<tt>phabricator/ $</tt> ./bin/config set '. $update[] = hsprintf(
phutil_escape_html($key).' '. '<tt>phabricator/ $</tt> ./bin/config set %s <em>value</em>',
'<em>value</em>'; $key);
$update[] = $cmd;
} }
$update = phutil_render_tag('pre', array(), implode("\n", $update)); $update = phutil_tag('pre', array(), array_interleave("\n", $update));
} else { } else {
$update = array(); $update = array();
foreach ($configs as $config) { foreach ($configs as $config) {
@ -182,11 +168,11 @@ final class PhabricatorSetupIssueView extends AphrontView {
'href' => '/config/edit/'.$config.'/?issue='.$issue->getIssueKey(), 'href' => '/config/edit/'.$config.'/?issue='.$issue->getIssueKey(),
), ),
pht('Edit %s', $config)); pht('Edit %s', $config));
$update[] = '<li>'.$link.'</li>'; $update[] = phutil_tag('li', array(), $link);
} }
if ($update) { if ($update) {
$update = '<ul>'.implode("\n", $update).'</ul>'; $update = phutil_tag('ul', array(), $update);
$update_info = phutil_render_tag( $update_info = phutil_tag(
'p', 'p',
array(), array(),
pht("You can update these %d value(s) here:", count($configs))); pht("You can update these %d value(s) here:", count($configs)));
@ -196,12 +182,12 @@ final class PhabricatorSetupIssueView extends AphrontView {
} }
} }
return phutil_render_tag( return phutil_tag(
'div', 'div',
array( array(
'class' => 'setup-issue-config', 'class' => 'setup-issue-config',
), ),
self::renderSingleView( self::renderHTMLView(
array( array(
$table_info, $table_info,
$table, $table,
@ -218,32 +204,12 @@ final class PhabricatorSetupIssueView extends AphrontView {
"The current PHP configuration has these %d value(s):", "The current PHP configuration has these %d value(s):",
count($configs))); count($configs)));
$table = array(); $dict = array();
foreach ($configs as $key) { foreach ($configs as $key) {
$table[] = '<tr>'; $dict[$key] = ini_get($key);
$table[] = '<th>'.phutil_escape_html($key).'</th>';
$value = ini_get($key);
if ($value === null) {
$value = '<em>null</em>';
} else if ($value === false) {
$value = '<em>false</em>';
} else if ($value === true) {
$value = '<em>true</em>';
} else if ($value === '') {
$value = '<em>(empty string)</em>';
} else {
$value = phutil_escape_html($value);
}
$table[] = '<td>'.$value.'</td>';
$table[] = '</tr>';
} }
$table = phutil_tag( $table = $this->renderValueTable($dict);
'table',
array(),
new PhutilSafeHTML(implode("\n", $table)));
ob_start(); ob_start();
phpinfo(); phpinfo();
@ -270,41 +236,42 @@ final class PhabricatorSetupIssueView extends AphrontView {
} }
} }
$info = array();
if (!$ini_loc) { if (!$ini_loc) {
$info = phutil_tag( $info[] = phutil_tag(
'p', 'p',
array(), array(),
pht( pht(
"To update these %d value(s), edit your PHP configuration file.", "To update these %d value(s), edit your PHP configuration file.",
count($configs))); count($configs)));
} else { } else {
$info = phutil_tag( $info[] = phutil_tag(
'p', 'p',
array(), array(),
pht( pht(
"To update these %d value(s), edit your PHP configuration file, ". "To update these %d value(s), edit your PHP configuration file, ".
"located here:", "located here:",
count($configs))); count($configs)));
$info .= phutil_tag( $info[] = phutil_tag(
'pre', 'pre',
array(), array(),
$ini_loc); $ini_loc);
} }
if ($more_loc) { if ($more_loc) {
$info .= phutil_tag( $info[] = phutil_tag(
'p', 'p',
array(), array(),
pht( pht(
"PHP also loaded these configuration file(s):", "PHP also loaded these configuration file(s):",
count($more_loc))); count($more_loc)));
$info .= phutil_tag( $info[] = phutil_tag(
'pre', 'pre',
array(), array(),
implode("\n", $more_loc)); implode("\n", $more_loc));
} }
$info .= phutil_tag( $info[] = phutil_tag(
'p', 'p',
array(), array(),
phutil_safe_html(pht( phutil_safe_html(pht(
@ -312,7 +279,7 @@ final class PhabricatorSetupIssueView extends AphrontView {
'<a href="%s">PHP Documentation</a>.', '<a href="%s">PHP Documentation</a>.',
'http://php.net/manual/ini.list.php'))); 'http://php.net/manual/ini.list.php')));
$info .= phutil_tag( $info[] = phutil_tag(
'p', 'p',
array(), array(),
phutil_safe_html(pht( phutil_safe_html(pht(
@ -324,7 +291,38 @@ final class PhabricatorSetupIssueView extends AphrontView {
array( array(
'class' => 'setup-issue-config', 'class' => 'setup-issue-config',
), ),
array($table_info, $table, $info)); $this->renderHTMLView(
array(
$table_info,
$table,
$info,
)));
}
private function renderValueTable(array $dict) {
$rows = array();
foreach ($dict as $key => $value) {
$cols = array(
phutil_tag('th', array(), $key),
phutil_tag('td', array(), $this->renderValueForDisplay($value)),
);
$rows[] = phutil_tag('tr', array(), $cols);
}
return phutil_tag('table', array(), $rows);
}
private function renderValueForDisplay($value) {
if ($value === null) {
return phutil_tag('em', array(), 'null');
} else if ($value === false) {
return phutil_tag('em', array(), 'false');
} else if ($value === true) {
return phutil_tag('em', array(), 'true');
} else if ($value === '') {
return phutil_tag('em', array(), 'empty string');
} else {
return PhabricatorConfigJSON::prettyPrintJSON($value);
}
} }
} }

View file

@ -0,0 +1,38 @@
<?php
final class PhabricatorSetupIssueExample extends PhabricatorUIExample {
public function getName() {
return 'Setup Issue';
}
public function getDescription() {
return 'Setup errors and warnings.';
}
public function renderExample() {
$request = $this->getRequest();
$user = $request->getUser();
$issue = id(new PhabricatorSetupIssue())
->setShortName(pht('Short Name'))
->setName(pht('Name'))
->setSummary(pht('Summary'))
->setMessage(pht('Message'))
->setIssueKey('example.key')
->addCommand('$ # Add Command')
->addCommand(hsprintf('<tt>$</tt> %s', '$ ls -1 > /dev/null'))
->addPHPConfig('php.config.example')
->addPhabricatorConfig('test.value')
->addPHPExtension('libexample');
// NOTE: Since setup issues may be rendered before we can build the page
// chrome, they don't explicitly include resources.
require_celerity_resource('setup-issue-css');
$view = id(new PhabricatorSetupIssueView())
->setIssue($issue);
return $view;
}
}