From 87370f0cb18aab5d2c5f7d1325f47692fa39ad90 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 6 Oct 2013 22:35:26 +0200 Subject: [PATCH] URL shortening can now be disabled for the 'maxurllength' Also, URL shortening now consistently uses 'maxurllength'... --- CONFIGURE | 10 +++++----- actions/apistatusnetconfig.php | 2 +- actions/urlsettings.php | 6 +++--- classes/User_urlshortener_prefs.php | 2 +- lib/default.php | 2 +- lib/util.php | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CONFIGURE b/CONFIGURE index c5fac78730..d41f64b44f 100644 --- a/CONFIGURE +++ b/CONFIGURE @@ -794,14 +794,14 @@ external: external links in notices. One of three values: 'sometimes', url --- -Everybody loves URL shorteners. These are some options for fine-tuning -how and when the server shortens URLs. +These are some options for fine-tuning how and when the server will +shorten URLs. shortener: URL shortening service to use by default. Users can override - individually. 'ur1.ca' by default. -maxlength: If an URL is strictly longer than this limit, it will be + individually. 'internal' by default. +maxurllength: If an URL is strictly longer than this limit, it will be shortened. Note that the URL shortener service may return an - URL longer than this limit. Defaults to 25. Users can + URL longer than this limit. Defaults to 100. Users can override. If set to 0, all URLs will be shortened. maxnoticelength: If a notice is strictly longer than this limit, all URLs in the notice will be shortened. Users can override. diff --git a/actions/apistatusnetconfig.php b/actions/apistatusnetconfig.php index a58c5d3dfa..33ac32a7da 100644 --- a/actions/apistatusnetconfig.php +++ b/actions/apistatusnetconfig.php @@ -61,7 +61,7 @@ class ApiStatusnetConfigAction extends ApiAction 'xmpp' => array('enabled', 'server', 'port', 'user'), 'integration' => array('source'), 'attachments' => array('uploads', 'file_quota'), - 'url' => array('maxlength', 'maxnoticelength'), + 'url' => array('maxurllength', 'maxnoticelength'), ); /** diff --git a/actions/urlsettings.php b/actions/urlsettings.php index 837d4df1d0..dd1218bc14 100644 --- a/actions/urlsettings.php +++ b/actions/urlsettings.php @@ -136,7 +136,7 @@ class UrlsettingsAction extends SettingsAction (!is_null($this->arg('maxurllength'))) ? $this->arg('maxurllength') : User_urlshortener_prefs::maxUrlLength($user), // TRANS: Field title in URL settings in profile. - _('URLs longer than this will be shortened, 0 means always shorten.')); + _('URLs longer than this will be shortened, -1 means never shorten because a URL is long.')); $this->elementEnd('li'); $this->elementStart('li'); $this->input('maxnoticelength', @@ -145,7 +145,7 @@ class UrlsettingsAction extends SettingsAction (!is_null($this->arg('maxnoticelength'))) ? $this->arg('maxnoticelength') : User_urlshortener_prefs::maxNoticeLength($user), // TRANS: Field title in URL settings in profile. - _('URLs in notices longer than this will always be shortened, -1 means shorten only if notice text exceeds maximum length.')); + _('URLs in notices longer than this will always be shortened, -1 means only shorten if the full post exceeds maximum length.')); $this->elementEnd('li'); $this->elementEnd('ul'); // TRANS: Button text for saving "Other settings" in profile. @@ -183,7 +183,7 @@ class UrlsettingsAction extends SettingsAction $maxurllength = $this->trimmed('maxurllength'); - if (!Validate::number($maxurllength, array('min' => 0))) { + if (!Validate::number($maxurllength, array('min' => -1))) { // TRANS: Client exception thrown when the maximum URL settings value is invalid in profile URL settings. throw new ClientException(_('Invalid number for maximum URL length.')); } diff --git a/classes/User_urlshortener_prefs.php b/classes/User_urlshortener_prefs.php index 146c8b8087..a9a70112c7 100755 --- a/classes/User_urlshortener_prefs.php +++ b/classes/User_urlshortener_prefs.php @@ -58,7 +58,7 @@ class User_urlshortener_prefs extends Managed_DataObject static function maxUrlLength($user) { - $def = common_config('url', 'maxlength'); + $def = common_config('url', 'maxurllength'); $prefs = self::getPrefs($user); diff --git a/lib/default.php b/lib/default.php index 16f384e1c2..68b4518bfa 100644 --- a/lib/default.php +++ b/lib/default.php @@ -343,7 +343,7 @@ $default = 'external' => 'sometimes'), // Options: 'sometimes', 'never', default = 'sometimes' 'url' => array('shortener' => 'internal', - 'maxlength' => 100, + 'maxurllength' => 100, 'maxnoticelength' => -1), 'http' => // HTTP client settings when contacting other sites array('ssl_cafile' => false, // To enable SSL cert validation, point to a CA bundle (eg '/usr/lib/ssl/certs/ca-certificates.crt') diff --git a/lib/util.php b/lib/util.php index c9500d7222..fdd678abdb 100644 --- a/lib/util.php +++ b/lib/util.php @@ -2155,7 +2155,7 @@ function common_shorten_url($long_url, User $user=null, $force = false) // $force forces shortening even if it's not strictly needed // I doubt URL shortening is ever 'strictly' needed. - ESP - if (mb_strlen($long_url) < $maxUrlLength && !$force) { + if (($maxUrlLength == -1 || mb_strlen($long_url) < $maxUrlLength) && !$force) { return $long_url; }