Was this page helpful?

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 Display_a_list_of_files_attached_to_a_page

    1) dir300.release.note.txt
    Description: Simple description
    Date: Tue, 26 Oct 2010 07:48:35 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: SteveB
    Page: Display a list of files attached to a page

    2) dir300_v1.05_93gb.bin
    Description: Simple description
    Date: Tue, 26 Oct 2010 07:48:36 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: SteveB
    Page: Display a list of files attached to a page

    Was this page helpful?
    Tag page

    Files 2

    FileVersionSizeModified 
    Viewing 15 of 17 comments: view all
    Thanks a lot!
    It works Perfect!

    I wanna sort it by file Description, I did this way: list.sort(map.values( page.files ), 'desc') but it doesn't sort it,
    change the order but not on alphabetic way. what can I do?
    Thanks! edited 07:43, 13 Jul 2009
    Posted 12:10, 5 Feb 2009
    Gabriel, as I can see from the map values you can sort only by date or name...am I right, steve?
    Posted 02:20, 14 Jul 2009
    You can sort on any string, date, or numeric field using the second parameter. If you need something more complex, you can also use the 4th parameter which allows you to provide a comparison expression. For example, to sort the on the length of the names, you would do: list.sort(map.values( page.files ), _, _, '#$left.name - #$right.name'). The comparison expression should return a result < 0, if the left value is less than the right value; 0 if they are equal; and > 0 if the right value is greater.
    Posted 02:54, 14 Jul 2009
    @giulio, try this instead: list.sort(map.values( page.files ), _, _, 'string.compare($left.description, $right.description, true)'). The problem is probably that .description is a property and not a plain text field. I didn't test this code, so please report back if it works for you. Thx.
    Posted 02:57, 14 Jul 2009
    @SteveB, the code works perfect, thank you!
    Posted 03:25, 14 Jul 2009
    Thanks both of you for helping me!! but the code work just in a few pages, its weird :S, I paste the code in a few pages and it works great, just in 2 pages the code does not work. but now the number of the pages where the code does not work increased, just in a few pages works :s.
    this error show me:
    /content/body/div/p/span/span/span, function 'list.sort' failed
    can you help me? thanks! edited 06:52, 23 Jul 2009
    Posted 08:59, 15 Jul 2009
    @gabriel84: I had a similar problem on my wiki but it was due to some missing descriptions.
    Please, tell us also what version of mindtouch you're running. edited 05:54, 27 Jul 2009
    Posted 05:54, 27 Jul 2009
    I'm Running mindtouch 9.02.1
    Now it's working fine.
    thanks for your reply! edited 08:28, 29 Jul 2009
    Posted 08:28, 29 Jul 2009
    Some quick advice please. I am pasting in the script exactly as shown on this page, but I end up with an error message: /content/body/pre, line 1, column 2: "}" expected (click for details)
    I have checked the script multiple times, but can't see where the problem is. I'm sure it must be something simple - any advice? Thanks.
    Posted 17:33, 6 Aug 2009
    is there some way to filter just files, excluding Images and videos?
    thanks!!
    Posted 09:31, 17 Aug 2009
    Is there any way to show in the information listed about a file where in the wiki there are links to that file? Thanks.
    Posted 15:18, 12 Nov 2009
    @rumjs short answer is no. the database doesn't track incoming links for files. you would have to loop over all pages and check which ones have a reference to the file
    Posted 07:33, 13 Nov 2009
    I have a number of files attached to a page with the following naming scheme:
    file1
    file2
    file3
    .
    .
    file10
    file11
    etc etc
    How can I sort on the "mathematical" value of the numbers at the end of the filename, so that they display in order file1,file2,file3,file10,file11 - instead of file1,file10,file11,file2,file3 ?

    I guess it's quite simple, but I've not enough Dekiscript knowledge to figure it out yet!
    Posted 07:22, 3 Feb 2010
    Where exactly within the sample script above does one put the list.sort call? I would like to sort the list by date but have no clue where it goes. Thanks!
    Posted 12:52, 5 Feb 2010
    I just update to the newest version MindTouch Core v.9.08.3 and this function stopped working.
    I get this error:
    content/body/p/span, line 1, column 507: invalid XmlNode

    Any ideas to fix it? thanks!
    Posted 15:18, 12 Feb 2010
    Viewing 15 of 17 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by