How do I... Display a list of files attached to a page?

Table of contents
  1. 1. Sample Output

This is a working DekiScript block to list the files attached to the Extensions page.

{{
var page = wiki.getpage( '/MindTouch_Deki/Extensions' );

if( #map.values( page.files ) == 0 ) {
    web.html( "<p>No files are attached to page " .. page.name .. "</p>" );
}
else {
    web.html( "<p>" .. #map.values( page.files ) .. " files are attached to page " .. page.name .. "</p>" );
    foreach( var file in map.values( page.files ) ) {
        web.html(
            "<p>" ..
            __count + 1 .. ") <b>" .. file.name .. "</b><br />" ..
            "<i>Description:</i> " .. file.description .. "<br />" ..
            "<i>Date:</i> " .. file.date .. "<br />" ..
            "<i>Size:</i> " .. file.size .. " bytes<br />" ..
            "<i>URI:</i> <a href='" .. file.uri .. "'>" .. file.uri .. "</a><br />" ..
            "<i>API:</i> <a href='" .. file.api .. "'>" .. file.api .. "</a><br />" ..
            "<i>Mime:</i> " .. file.mime .. "<br />" ..
            "<i>Author:</i> " .. file.author .. "<br />" ..
            "<i>Page:</i> " .. file.page .. "<br />" ..
            "</p>"
        );
    }
}
}}

Sample Output

2 files are attached to page How_do_I..._Display_a_list_of_files_attached_to_a_page?

1) dir300_v1.05_93gb.bin
Description: Simple description
Date: Sat, 02 May 2009 16:32:44 GMT
Size: 2416768 bytes
URI: http://developer.mindtouch.com/@api/deki/files/4307/=dir300_v1.05_93gb.bin
API: http://developer.mindtouch.com/@api/deki/files/4307
Mime: text/plain
Author: aldago
Page: How do I... Display a list of files attached to a page?

2) dir300.release.note.txt
Description: Simple description
Date: Sat, 02 May 2009 16:32:13 GMT
Size: 30865 bytes
URI: http://developer.mindtouch.com/@api/deki/files/4306/=dir300.release.note.txt
API: http://developer.mindtouch.com/@api/deki/files/4306
Mime: text/plain
Author: aldago
Page: How do I... Display a list of files attached to a page?

Tag page

Files 2

FileSizeDateAttached by 
 dir300.release.note.txt
Simple description
30.14 kB16:32, 2 May 2009aldagoActions
 dir300_v1.05_93gb.bin
Simple description
2.3 MB16:32, 2 May 2009aldagoActions
Viewing 3 of 3 comments: view all
Hi,
good function!
Is there any way to sort it by Name or date?
regards!
Posted 16:37, 5 Feb 2009
Yes, just add a call to list.sort, like this: list.sort(map.values( page.files ), 'name')
Posted 17:04, 5 Feb 2009
Thanks a lot!
It works Perfect!

regards!!
Posted 20:10, 5 Feb 2009
Viewing 3 of 3 comments: view all
You must login to post a comment.