There is currently no built-in function for retrieving the most popular pages. However, there is an Deki API function which can be invoked from DekiScript!
For this sample, we use uri.build to build the URI from the site.api URi. Then, we use web.xml to fetch the document from it (see what the XML looks like). Now, we iterate over all <page> elements in the document and print out foreach the link, title, and view count using xml.text.
DekiScript retrieves this information as the anonymous user (it does not pass on the context of the current user), so if your MindTouch is private, than this code snippet will return no pages.
<ul block="var pages = web.xml(uri.build(site.api, ['pages', 'popular'], {}))['page']">
<li foreach="var p in pages" where="__count < 10">{{ web.link(uri.build(site.uri, "index.php", { title: xml.text(p, 'path') ?? "" }), xml.text(p, 'title')) }} ({{ num.format(xml.text(p, 'metrics/metric.views'), '#,#00') }} views)</li>
</ul>
Sample output
This variation is designed to take advantage of the DekiScript innovations found in the 9.02 release. Create a DekiScript section in WYSIWYG mode and copy-paste the following code into it. No need to toggle to source mode!
var pages = wiki.api(site.api & 'pages/popular')['page'];
<ul>
foreach(var p in pages where __count < 10) {
<li>
web.link(site.uri & "index.php" & { title: xml.text(p, 'path') ?? "" }, xml.text(p, 'title'));
" (";
num.format(xml.text(p, 'metrics/metric.views'), '#,#00');
" views)";
</li>
}
</ul>
It's a good function but it does not work in my wiki. I pasted it but nothing occurs.
any ideas why this happens?
Thanks! edited 00:04, 6 Feb 2009
I have kilen woods v.8.08.2
regards! edited 15:23, 16 Apr 2009
I also used wiki.api(site.api) and it threw this:
content/body/ul, line 1, column 49: ")" expected
perhaps misunderstood, :S what do I change?
thanks!!