[pmwiki-users] How to export (:pagelist ...:) to a file e.g text/plain
Sinan Kaan Yerli
sinan at sinan.physics.metu.edu.tr
Wed Jan 30 05:16:37 CST 2013
Dear PmWiki Users,
As adviced by Peter I have tried to use RunMarkupRules() of toolbox.php
with no success. Probably I am not something obvious in the deep level
of PmWiki structure.
Below you will find what I have done with a minimal example. In the
action function (i.e HandleExport) I have tried both Peter's advice and
also tried just to dump the parsed HTML output. In Peter's advice,
"$Text" was empty; in MarkupToHTML I have received only "<" (1 byte).
In short, I couldn't manage to fill $Text with (:pagelist...:) parsed
and converted to #csv format.
As I said, probably I am missing something obvious. Any idea to fix it?
Thanks in advance.
Sinan.
-[In "Test/Export"]--------------------------------------------
[[{$FullName}?action=export|Export]]\\
(:if false:)
[[#csv]]
(:template first:)
>>pre<<
(:template each:)
{=$FileName} {{=$FullName}$:F1} {{=$FullName}$:F2}
(:template last:)
>><<
[[#csvend]]
(:ifend:)
(:pagelist group={$Group} list=normal fmt=#csv name=FILE*:)
-[In "Test/FILE*"]---------------------------------------------
-[(ignoring foxbegin/foxend and include statements)]-----------
(:F1 Value1:)
(:F2 Value2:)
-[In "local/config.php"]---------------------------------------
include_once("cookbook/toolbox.php");
$HandleActions['export'] = 'HandleExport';
function HandleExport($pagename, $auth = 'read')
{
# Check the page
$page = RetrieveAuthPage($pagename, $auth, false, READPAGE_CURRENT);
if (!$page) HandleBrowse($pagename, $auth);
# Collect the content
$Text = $page['text'];
# $output = RunMarkupRules($pagename, array('pagelist'), $Text, $opt);
# $output = MarkupToHTML($pagename, $Text);
# Dump back to page
if ($output != '')
{
$fname = FmtPageName('$Name',$pagename).'.txt';
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename="'.$fname.'"');
header("Content-Length: " . sizeof($output));
echo $output;
}
else
HandleBrowse($pagename, $auth);
}
---------------------------------------------------------------
(22/01/2013 21:45) Peter Bowers:
>On Tue, Jan 22, 2013 at 1:40 PM, Sinan Kaan Yerli <
>sinan at sinan.physics.metu.edu.tr> wrote:
>
>> * How could I redirect /this formatted/ output to a mimetype?
>> Do I have to introduce an ?action=export ...
>> If so how could I start the download of this data (i.e
>> download starts immediately without having a page to show).
>>
> [...]
>
>The thing is you probably don't want a full MarkupToHTML() because you're
>just looking for the text. You might want to take a look at toolbox.php
>and the RunMarkupRules() function there. This would enable you to run the
>"pagelist" rule to produce your dynamic download.
>
>So that leaves (purely untested and probably loaded with bugs):
>
>$HandleActions['export'] = 'HandleExport';
>function HandleExport($pagename, $auth = 'read')
>{
> $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
> if (!$page) Abort("?cannot read $pagename");
> $output = RunMarkupRules($pagename, array('pagelist'), $Text, $opt);
> header('Content-Type: application/download');
> header('Content-Disposition: attachment; filename="example.csv"');
> header("Content-Length: " . sizeof($output));
> echo $output; // I think this'll handle it. Sometimes people talk about
>the ob_* functions, but I usually try to avoid them.
>}
>
>-Peter
More information about the pmwiki-users
mailing list