Ticket #3011: Add attachments/uploads and attachments/file_quota to api/statusnet/config.(xml|json)

file_quota is adjusted from the defined value to take into account the maximum upload size limits in PHP, or cropped to 0 if uploads are disabled.
This can be used by client apps to determine maximum size for an attachment.
This commit is contained in:
Brion Vibber 2011-02-21 15:52:12 -08:00
parent 3fb4b92cd6
commit f3c822cc15
1 changed files with 18 additions and 3 deletions

View File

@ -59,7 +59,8 @@ class ApiStatusnetConfigAction extends ApiAction
'notice' => array('contentlimit'), 'notice' => array('contentlimit'),
'throttle' => array('enabled', 'count', 'timespan'), 'throttle' => array('enabled', 'count', 'timespan'),
'xmpp' => array('enabled', 'server', 'port', 'user'), 'xmpp' => array('enabled', 'server', 'port', 'user'),
'integration' => array('source') 'integration' => array('source'),
'attachments' => array('uploads', 'file_quota')
); );
/** /**
@ -96,7 +97,7 @@ class ApiStatusnetConfigAction extends ApiAction
foreach ($this->keys as $section => $settings) { foreach ($this->keys as $section => $settings) {
$this->elementStart($section); $this->elementStart($section);
foreach ($settings as $setting) { foreach ($settings as $setting) {
$value = common_config($section, $setting); $value = $this->setting($section, $setting);
if (is_array($value)) { if (is_array($value)) {
$value = implode(',', $value); $value = implode(',', $value);
} else if ($value === false || $value == '0') { } else if ($value === false || $value == '0') {
@ -125,7 +126,7 @@ class ApiStatusnetConfigAction extends ApiAction
$result[$section] = array(); $result[$section] = array();
foreach ($settings as $setting) { foreach ($settings as $setting) {
$result[$section][$setting] $result[$section][$setting]
= common_config($section, $setting); = $this->setting($section, $setting);
} }
} }
$this->initDocument('json'); $this->initDocument('json');
@ -143,6 +144,20 @@ class ApiStatusnetConfigAction extends ApiAction
} }
} }
function setting($section, $key) {
$result = common_config($section, $key);
if ($key == 'file_quota') {
// hack: adjust for the live upload limit
if (common_config($section, 'uploads')) {
$max = ImageFile::maxFileSizeInt();
} else {
$max = 0;
}
return min($result, $max);
}
return $result;
}
/** /**
* Return true if read only. * Return true if read only.
* *