summaryrefslogtreecommitdiff
path: root/classes/File.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-05-27 14:57:32 -0700
committerBrion Vibber <brion@pobox.com>2010-05-27 14:57:32 -0700
commit696aeea113b88fd0f6b7c4c88eebc2f4f369d245 (patch)
treec16f91a270c2989f8e6b3799b2dfa3e39698f565 /classes/File.php
parentcc25ec175530a691686087db4c23a1a28ffd1b62 (diff)
parent2f2fa100715f9c09b2b91a2d1afddacf7b7f16db (diff)
Merge branch 'testing' of gitorious.org:statusnet/mainline into 0.9.x
Conflicts: lib/language.php plugins/OpenID/finishaddopenid.php
Diffstat (limited to 'classes/File.php')
-rw-r--r--classes/File.php22
1 files changed, 19 insertions, 3 deletions
diff --git a/classes/File.php b/classes/File.php
index c9477f5f1..0cd31075d 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -116,7 +116,11 @@ class File extends Memcached_DataObject
return false;
}
- function processNew($given_url, $notice_id=null) {
+ /**
+ * @fixme refactor this mess, it's gotten pretty scary.
+ * @param bool $followRedirects
+ */
+ function processNew($given_url, $notice_id=null, $followRedirects=true) {
if (empty($given_url)) return -1; // error, no url to process
$given_url = File_redirection::_canonUrl($given_url);
if (empty($given_url)) return -1; // error, no url to process
@@ -124,6 +128,10 @@ class File extends Memcached_DataObject
if (empty($file)) {
$file_redir = File_redirection::staticGet('url', $given_url);
if (empty($file_redir)) {
+ // @fixme for new URLs this also looks up non-redirect data
+ // such as target content type, size, etc, which we need
+ // for File::saveNew(); so we call it even if not following
+ // new redirects.
$redir_data = File_redirection::where($given_url);
if (is_array($redir_data)) {
$redir_url = $redir_data['url'];
@@ -134,11 +142,19 @@ class File extends Memcached_DataObject
throw new ServerException("Can't process url '$given_url'");
}
// TODO: max field length
- if ($redir_url === $given_url || strlen($redir_url) > 255) {
+ if ($redir_url === $given_url || strlen($redir_url) > 255 || !$followRedirects) {
$x = File::saveNew($redir_data, $given_url);
$file_id = $x->id;
} else {
- $x = File::processNew($redir_url, $notice_id);
+ // This seems kind of messed up... for now skipping this part
+ // if we're already under a redirect, so we don't go into
+ // horrible infinite loops if we've been given an unstable
+ // redirect (where the final destination of the first request
+ // doesn't match what we get when we ask for it again).
+ //
+ // Seen in the wild with clojure.org, which redirects through
+ // wikispaces for auth and appends session data in the URL params.
+ $x = File::processNew($redir_url, $notice_id, /*followRedirects*/false);
$file_id = $x->id;
File_redirection::saveNew($redir_data, $file_id, $given_url);
}