mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
MDL-53709 wiki: Return content size if includecontent=0
This commit is contained in:
parent
b611ade3ab
commit
31bfb00809
@ -537,16 +537,26 @@ class mod_wiki_external extends external_api {
|
||||
'firstpage' => $page->id == $firstpage->id
|
||||
);
|
||||
|
||||
if ($options['includecontent']) {
|
||||
// Refresh page cached content if needed.
|
||||
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
|
||||
if ($content = wiki_refresh_cachedcontent($page)) {
|
||||
$page = $content['page'];
|
||||
}
|
||||
// Refresh page cached content if needed.
|
||||
if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) {
|
||||
if ($content = wiki_refresh_cachedcontent($page)) {
|
||||
$page = $content['page'];
|
||||
}
|
||||
}
|
||||
list($cachedcontent, $contentformat) = external_format_text(
|
||||
$page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
|
||||
|
||||
list($retpage['cachedcontent'], $retpage['contentformat']) = external_format_text(
|
||||
$page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
|
||||
if ($options['includecontent']) {
|
||||
// Return the page content.
|
||||
$retpage['cachedcontent'] = $cachedcontent;
|
||||
$retpage['contentformat'] = $contentformat;
|
||||
} else {
|
||||
// Return the size of the content.
|
||||
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||
$retpage['contentsize'] = mb_strlen($cachedcontent, '8bit');
|
||||
} else {
|
||||
$retpage['contentsize'] = strlen($cachedcontent);
|
||||
}
|
||||
}
|
||||
|
||||
$returnedpages[] = $retpage;
|
||||
@ -586,6 +596,8 @@ class mod_wiki_external extends external_api {
|
||||
'firstpage' => new external_value(PARAM_BOOL, 'True if it\'s the first page.'),
|
||||
'cachedcontent' => new external_value(PARAM_RAW, 'Page contents.', VALUE_OPTIONAL),
|
||||
'contentformat' => new external_format_value('cachedcontent', VALUE_OPTIONAL),
|
||||
'contentsize' => new external_value(PARAM_INT, 'Size of page contents in bytes (doesn\'t include'.
|
||||
' size of attached files).', VALUE_OPTIONAL),
|
||||
), 'Pages'
|
||||
)
|
||||
),
|
||||
|
@ -629,11 +629,16 @@ class mod_wiki_external_testcase extends externallib_advanced_testcase {
|
||||
$result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
|
||||
$this->assertEquals($expectedpages, $result['pages']);
|
||||
|
||||
// Check that WS doesn't return page content if includecontent is false.
|
||||
unset($expectedpages[0]['cachedcontent']);
|
||||
unset($expectedpages[0]['contentformat']);
|
||||
unset($expectedpages[1]['cachedcontent']);
|
||||
unset($expectedpages[1]['contentformat']);
|
||||
// Check that WS doesn't return page content if includecontent is false, it returns the size instead.
|
||||
foreach ($expectedpages as $i => $expectedpage) {
|
||||
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||
$expectedpages[$i]['contentsize'] = mb_strlen($expectedpages[$i]['cachedcontent'], '8bit');
|
||||
} else {
|
||||
$expectedpages[$i]['contentsize'] = strlen($expectedpages[$i]['cachedcontent']);
|
||||
}
|
||||
unset($expectedpages[$i]['cachedcontent']);
|
||||
unset($expectedpages[$i]['contentformat']);
|
||||
}
|
||||
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id, 0, 0, array('sortby' => 'id', 'includecontent' => 0));
|
||||
$result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
|
||||
$this->assertEquals($expectedpages, $result['pages']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user