diff options
author | Brion Vibber <brion@pobox.com> | 2010-12-02 10:56:44 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-12-02 13:41:56 -0800 |
commit | aa96c3c1d9823382e9e6de0da5084fcc111f2ee5 (patch) | |
tree | 06846b7b32f718d3e62a212fc60924d2f6008668 /classes/File_redirection.php | |
parent | c4f67f76476a4ca608bcf2fc860ad5ef889d269d (diff) |
Fix for tickets #2917, #2262: user URL shortening options not being applied in non-web channels
common_shorten_links() can only access the web session's logged-in user, so never properly took user options into effect for posting via XMPP, API, mail, etc.
Adds an optional $user parameter on common_shorten_links(), and a $user->shortenLinks() as a clearer interface for that.
Tweaked some lower-level functions so $user gets passed down -- making the $notice_id param previously there for saving URLs at notice save time generalized a little.
Note also ticket #2919: there's a lot of duplicate code calling the shortening, checking the length, and reporting near-identical error messages. These should be consolidated to aid in code and translation maintenance.
Diffstat (limited to 'classes/File_redirection.php')
-rw-r--r-- | classes/File_redirection.php | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/classes/File_redirection.php b/classes/File_redirection.php index 4ee43026b..53c15bf8b 100644 --- a/classes/File_redirection.php +++ b/classes/File_redirection.php @@ -187,13 +187,14 @@ class File_redirection extends Memcached_DataObject * may be saved. * * @param string $long_url + * @param User $user whose shortening options to use; defaults to the current web session user * @return string */ - function makeShort($long_url) { + function makeShort($long_url, $user=null) { $canon = File_redirection::_canonUrl($long_url); - $short_url = File_redirection::_userMakeShort($canon); + $short_url = File_redirection::_userMakeShort($canon, $user); // Did we get one? Is it shorter? if (!empty($short_url) && mb_strlen($short_url) < mb_strlen($long_url)) { @@ -203,8 +204,8 @@ class File_redirection extends Memcached_DataObject } } - function _userMakeShort($long_url) { - $short_url = common_shorten_url($long_url); + function _userMakeShort($long_url, User $user=null) { + $short_url = common_shorten_url($long_url, $user); if (!empty($short_url) && $short_url != $long_url) { $short_url = (string)$short_url; // store it |