Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/aphront/request/AphrontRequest.php b/src/aphront/request/AphrontRequest.php
index 118119e6a2..d7f5fe8be5 100644
--- a/src/aphront/request/AphrontRequest.php
+++ b/src/aphront/request/AphrontRequest.php
@@ -1,317 +1,318 @@
<?php
/*
* Copyright 2012 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.
*/
/**
*
* @task data Accessing Request Data
*
* @group aphront
*/
final class AphrontRequest {
const TYPE_AJAX = '__ajax__';
const TYPE_FORM = '__form__';
const TYPE_CONDUIT = '__conduit__';
private $host;
private $path;
private $requestData;
private $user;
private $env;
private $applicationConfiguration;
final public function __construct($host, $path) {
$this->host = $host;
$this->path = $path;
}
final public function setApplicationConfiguration(
$application_configuration) {
$this->applicationConfiguration = $application_configuration;
return $this;
}
final public function getApplicationConfiguration() {
return $this->applicationConfiguration;
}
final public function getPath() {
return $this->path;
}
final public function getHost() {
return $this->host;
}
/* -( Accessing Request Data )--------------------------------------------- */
/**
* @task data
*/
final public function setRequestData(array $request_data) {
$this->requestData = $request_data;
return $this;
}
/**
* @task data
*/
final public function getRequestData() {
return $this->requestData;
}
/**
* @task data
*/
final public function getInt($name, $default = null) {
if (isset($this->requestData[$name])) {
return (int)$this->requestData[$name];
} else {
return $default;
}
}
/**
* @task data
*/
final public function getBool($name, $default = null) {
if (isset($this->requestData[$name])) {
if ($this->requestData[$name] === 'true') {
return true;
} else if ($this->requestData[$name] === 'false') {
return false;
} else {
return (bool)$this->requestData[$name];
}
} else {
return $default;
}
}
/**
* @task data
*/
final public function getStr($name, $default = null) {
if (isset($this->requestData[$name])) {
$str = (string)$this->requestData[$name];
// Normalize newline craziness.
$str = str_replace(
array("\r\n", "\r"),
array("\n", "\n"),
$str);
return $str;
} else {
return $default;
}
}
/**
* @task data
*/
final public function getArr($name, $default = array()) {
if (isset($this->requestData[$name]) &&
is_array($this->requestData[$name])) {
return $this->requestData[$name];
} else {
return $default;
}
}
/**
* @task data
*/
final public function getStrList($name, $default = array()) {
if (!isset($this->requestData[$name])) {
return $default;
}
$list = $this->getStr($name);
$list = preg_split('/[,\n]/', $list);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
$list = array_values($list);
return $list;
}
/**
* @task data
*/
final public function getExists($name) {
return array_key_exists($name, $this->requestData);
}
final public function isHTTPPost() {
return ($_SERVER['REQUEST_METHOD'] == 'POST');
}
final public function isAjax() {
return $this->getExists(self::TYPE_AJAX);
}
final public function isConduit() {
return $this->getExists(self::TYPE_CONDUIT);
}
public static function getCSRFTokenName() {
return '__csrf__';
}
public static function getCSRFHeaderName() {
return 'X-Phabricator-Csrf';
}
final public function validateCSRF() {
$token_name = self::getCSRFTokenName();
$token = $this->getStr($token_name);
// No token in the request, check the HTTP header which is added for Ajax
// requests.
if (empty($token)) {
// PHP mangles HTTP headers by uppercasing them and replacing hyphens with
// underscores, then prepending 'HTTP_'.
$php_index = self::getCSRFHeaderName();
$php_index = strtoupper($php_index);
$php_index = str_replace('-', '_', $php_index);
$php_index = 'HTTP_'.$php_index;
$token = idx($_SERVER, $php_index);
}
$valid = $this->getUser()->validateCSRFToken($token);
if (!$valid) {
// Add some diagnostic details so we can figure out if some CSRF issues
// are JS problems or people accessing Ajax URIs directly with their
// browsers.
if ($token) {
$token_info = "with an invalid CSRF token";
} else {
$token_info = "without a CSRF token";
}
if ($this->isAjax()) {
$more_info = "(This was an Ajax request, {$token_info}.)";
} else {
$more_info = "(This was a web request, {$token_info}.)";
}
// This should only be able to happen if you load a form, pull your
// internet for 6 hours, and then reconnect and immediately submit,
// but give the user some indication of what happened since the workflow
// is incredibly confusing otherwise.
throw new AphrontCSRFException(
"The form you just submitted did not include a valid CSRF token. ".
"This token is a technical security measure which prevents a ".
"certain type of login hijacking attack. However, the token can ".
"become invalid if you leave a page open for more than six hours ".
"without a connection to the internet. To fix this problem: reload ".
"the page, and then resubmit it.\n\n".
$more_info);
}
return true;
}
final public function isFormPost() {
$post = $this->getExists(self::TYPE_FORM) &&
$this->isHTTPPost();
if (!$post) {
return false;
}
return $this->validateCSRF();
}
final public function getCookie($name, $default = null) {
return idx($_COOKIE, $name, $default);
}
final public function clearCookie($name) {
$this->setCookie($name, '', time() - (60 * 60 * 24 * 30));
}
final public function setCookie($name, $value, $expire = null) {
// Ensure cookies are only set on the configured domain.
$base_uri = PhabricatorEnv::getEnvConfig('phabricator.base-uri');
$base_uri = new PhutilURI($base_uri);
$base_domain = $base_uri->getDomain();
$base_protocol = $base_uri->getProtocol();
// The "Host" header may include a port number; if so, ignore it. We can't
// use PhutilURI since there's no URI scheme.
list($actual_host) = explode(':', $this->getHost(), 2);
if ($base_domain != $actual_host) {
throw new Exception(
"This install of Phabricator is configured as '{$base_domain}' but ".
"you are accessing it via '{$actual_host}'. Access Phabricator via ".
"the primary configured domain.");
}
if ($expire === null) {
$expire = time() + (60 * 60 * 24 * 365 * 5);
}
$is_secure = ($base_protocol == 'https');
setcookie(
$name,
$value,
$expire,
$path = '/',
$base_domain,
$is_secure,
$http_only = true);
}
final public function setUser($user) {
$this->user = $user;
return $this;
}
final public function getUser() {
return $this->user;
}
final public function getRequestURI() {
$get = $_GET;
unset($get['__path__']);
- return id(new PhutilURI($this->getPath()))->setQueryParams($get);
+ $path = phutil_escape_uri($this->getPath());
+ return id(new PhutilURI($path))->setQueryParams($get);
}
final public function isDialogFormPost() {
return $this->isFormPost() && $this->getStr('__dialog__');
}
final public function getRemoteAddr() {
return $_SERVER['REMOTE_ADDR'];
}
}
diff --git a/src/aphront/request/__init__.php b/src/aphront/request/__init__.php
index 7e0a7e8115..61fb9f861c 100644
--- a/src/aphront/request/__init__.php
+++ b/src/aphront/request/__init__.php
@@ -1,16 +1,17 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'aphront/exception/csrf');
phutil_require_module('phabricator', 'infrastructure/env');
+phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'parser/uri');
phutil_require_module('phutil', 'utils');
phutil_require_source('AphrontRequest.php');
diff --git a/src/applications/chatlog/controller/channellog/PhabricatorChatLogChannelLogController.php b/src/applications/chatlog/controller/channellog/PhabricatorChatLogChannelLogController.php
index bcf1d35a0f..2f89b40a49 100644
--- a/src/applications/chatlog/controller/channellog/PhabricatorChatLogChannelLogController.php
+++ b/src/applications/chatlog/controller/channellog/PhabricatorChatLogChannelLogController.php
@@ -1,86 +1,95 @@
<?php
/*
* Copyright 2012 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.
*/
final class PhabricatorChatLogChannelLogController
extends PhabricatorChatLogController {
private $channel;
public function willProcessRequest(array $data) {
$this->channel = $data['channel'];
}
public function processRequest() {
- $request = $this->getRequest();
- $user = $request->getUser();
+ $request = $this->getRequest();
+ $user = $request->getUser();
+ $offset = $request->getInt('offset', 0);
+ $page_size = 1000;
+ $pager = new AphrontPagerView();
+ $request_uri = $request->getRequestURI();
+ $pager->setURI($request_uri, 'offset');
+ $pager->setPageSize($page_size);
+ $pager->setOffset($offset);
$query = new PhabricatorChatLogQuery();
$query->withChannels(array($this->channel));
- $query->setLimit(1000);
- $logs = $query->execute();
+ $logs = $query->executeWithPager($pager);
require_celerity_resource('phabricator-chatlog-css');
$last_author = null;
$last_epoch = null;
$row_idx = 0;
$row_colors = array(
'normal',
'alternate',
);
$out = array();
$out[] = '<table class="phabricator-chat-log">';
foreach ($logs as $log) {
$this_author = $log->getAuthor();
$this_epoch = $log->getEpoch();
if (($this_author !== $last_author) ||
($this_epoch - (60 * 5) > $last_epoch)) {
++$row_idx;
$out[] = '<tr class="initial '.$row_colors[$row_idx % 2].'">';
$out[] = '<td class="timestamp">'.
phabricator_datetime($log->getEpoch(), $user).'</td>';
$author = $log->getAuthor();
$author = phutil_utf8_shorten($author, 18);
$out[] = '<td class="author">'.
phutil_escape_html($author).'</td>';
} else {
$out[] = '<tr class="'.$row_colors[$row_idx % 2].'">';
$out[] = '<td class="similar" colspan="2"></td>';
}
$out[] = '<td class="message">'.
phutil_escape_html($log->getMessage()).'</td>';
$out[] = '</tr>';
$last_author = $this_author;
$last_epoch = $this_epoch;
}
$out[] = '</table>';
return $this->buildStandardPageResponse(
- implode("\n", $out),
+ array(
+ implode("\n", $out),
+ $pager
+ ),
array(
'title' => 'Channel Log',
));
}
}
diff --git a/src/applications/chatlog/controller/channellog/__init__.php b/src/applications/chatlog/controller/channellog/__init__.php
index ca4927c293..0dfed22523 100644
--- a/src/applications/chatlog/controller/channellog/__init__.php
+++ b/src/applications/chatlog/controller/channellog/__init__.php
@@ -1,18 +1,19 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/chatlog/controller/base');
phutil_require_module('phabricator', 'applications/chatlog/query');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
+phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');
phutil_require_source('PhabricatorChatLogChannelLogController.php');
diff --git a/src/applications/chatlog/query/PhabricatorChatLogQuery.php b/src/applications/chatlog/query/PhabricatorChatLogQuery.php
index f15454a11b..9a52e37ee1 100644
--- a/src/applications/chatlog/query/PhabricatorChatLogQuery.php
+++ b/src/applications/chatlog/query/PhabricatorChatLogQuery.php
@@ -1,80 +1,64 @@
<?php
/*
* Copyright 2012 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.
*/
-final class PhabricatorChatLogQuery {
-
+final class PhabricatorChatLogQuery extends PhabricatorOffsetPagedQuery {
private $channels;
- private $limit;
-
public function withChannels(array $channels) {
$this->channels = $channels;
return $this;
}
- public function setLimit($limit) {
- $this->limit = $limit;
- return $this;
- }
-
public function execute() {
- $table = new PhabricatorChatLogEvent();
+ $table = new PhabricatorChatLogEvent();
$conn_r = $table->establishConnection('r');
$where_clause = $this->buildWhereClause($conn_r);
-
- $limit_clause = '';
- if ($this->limit) {
- $limit_clause = qsprintf(
- $conn_r,
- 'LIMIT %d',
- $this->limit);
- }
+ $limit_clause = $this->buildLimitClause($conn_r);
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T e %Q ORDER BY epoch ASC %Q',
$table->getTableName(),
$where_clause,
$limit_clause);
$logs = $table->loadAllFromArray($data);
return $logs;
}
private function buildWhereClause($conn_r) {
$where = array();
if ($this->channels) {
$where[] = qsprintf(
$conn_r,
'channel IN (%Ls)',
$this->channels);
}
if ($where) {
$where = 'WHERE ('.implode(') AND (', $where).')';
} else {
$where = '';
}
return $where;
}
-
}
diff --git a/src/applications/chatlog/query/__init__.php b/src/applications/chatlog/query/__init__.php
index 6af86c96a0..5afb603820 100644
--- a/src/applications/chatlog/query/__init__.php
+++ b/src/applications/chatlog/query/__init__.php
@@ -1,14 +1,15 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/chatlog/storage/event');
+phutil_require_module('phabricator', 'infrastructure/query/offsetpaged');
phutil_require_module('phabricator', 'storage/qsprintf');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_source('PhabricatorChatLogQuery.php');

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jul 29, 8:06 AM (3 w, 20 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
188329
Default Alt Text
(16 KB)

Event Timeline