[pmwiki-users] Weird one for those that use the attachtable cookbook
Christopher Cox
chriscox at endlessnow.com
Thu Oct 15 16:13:24 PDT 2026
I've attached badboy2-php.txt
(:badboy2:)
Some text
(:badboy2end:)
with references enabled on attachtable, tell me what you discover if you have
that markup on BadBoy/PageOne and then you view attachtable on BadBoy/PageTwo.
On 10/15/26 4:40 PM, Christopher Cox wrote:
> On 10/15/26 3:26 PM, Petko Yotov wrote:
>> I still could not experience a duplication of the uploads/ directories, but
>> found something probably related.
>>
>> When Attachtable is configured to count the number of references for every
>> file, which is the default, it finds all other pages and calls MarkupToHTML
>> with the other $pagename for each page. This changes the global variable
>> $MarkupToHTML['pagename'] and from that point on, subsequent markups on the
>> page think they are on the last page Attachtable processed for the references.
>>
>> So if I have in HomePage:
>>
>> Attach:pic.jpg | picture exists and is shown
>>
>> (:attachlist:) works, shows files attached to HomePage
>>
>> (:attachtable:) works, shows files attached to HomePage, but the references
>> change $pagename to WikiSandbox
>>
>> Attach:pic.jpg | picture does not exists in WikiSandbox
>>
>> (:attachlist:) shows files attached to WikiSandbox
>>
>> (:attachtable:) shows files attached to WikiSandbox
>>
>>
>> After the first (:attachtable:), all links to uploads within Attach:,
>> (:attachtable:) and (:attachlist:) link to files attached to the last page the
>> first attachtable looked for file references. It just links to the other page,
>> does not seem to copy the other files to have them twice.
>>
>> A quick fix would be to define the default data fields excluding 'references',
>> in config.php:
>> $AttachtableDataFields = array('name', 'size', 'modtime', 'mimetype');
>
> Thanks, yep, that fixed (worked around) the issue for now. I tried making a
> very empty simulated cookbook, but, it didn't show the problem.. .sigh. So,
> this will do "for now" until I can fully debug my recipe.
>
> User error. But worked around for now.
>
>
>>
>> Alternatively, in the wiki page set (:attachtable data=name,size,modtime:)
>> without 'references'.
>>
>> Another quick fix could be to modify mu_FmtAttachtable() this way:
>> function mu_FmtAttachtable($m) {
>> \extract($GLOBALS["MarkupToHTML"]);
>> $out = \Keep(FmtAttachtable($pagename, $m[1]));
>> $GLOBALS["MarkupToHTML"]['pagename'] = $pagename;
>> return $out;
>> }
>>
>> I've added something similar in the core to push the current pagename to a
>> stack when starting, and at the end to pop it and reset
>> $MarkupToHTML['pagename']. This should work with attachtable and possibly
>> other markup functions that may call MarkupToHTML().
>>
>> This can be tested now with the pre-release and should be available in 2.7.7
>> in the next few days.
>>
>> Petko
>>
>
>
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users
-------------- next part --------------
<?php if (!defined('PmWiki')) exit();
$RecipeInfo['Badboy2']['Version'] = '2026-10-12';
Markup(
'badboy2',
'fulltext',
'/\\(:badboy2[ \t]*(.*?):\\)(.*?)\\(:badboy2end:\\)/si',
"BadBoy2Markup"
);
function BadBoy2Markup($m)
{
global $pagename;
global $FarmD;
global $UploadFileFmt;
@list($m0, $options, $sourceblock) = $m;
$sourceblock = preg_replace("/<:vspace>/", "", $sourceblock);
$sourceblock = preg_replace("/>/", ">", $sourceblock);
$sourceblock = preg_replace("/</", "<", $sourceblock);
$group = PageVar($pagename, '$Group');
$page = PageVar($pagename, '$Name');
/*
* Increment when recipe behavior changes.
*/
$version = '1';
/*
* Safe filename base.
*/
$name = preg_replace(
'/[^A-Za-z0-9._-]/',
'_',
"$group$page"
);
/*
* Used only to determine if a rerender is needed.
*/
$checkmd5 = md5(
$version .
$sourceblock
);
$dirpath =
$FarmD . '/' .
FmtPageName(
$UploadFileFmt,
$pagename
);
if (!file_exists($dirpath)) {
mkdir(
$dirpath,
0755,
true
);
}
/*
* Source file
*/
$sourcefile = MakeUploadName(
$pagename,
$name . '.txt'
);
$sourcepath =
$FarmD . '/' .
FmtPageName(
"$UploadFileFmt/$sourcefile",
$pagename
);
error_log("sourcepath: ".$sourcepath);
/*
* md5 tracking file
*/
$md5file = MakeUploadName(
$pagename,
$name . '.md5'
);
$md5filepath =
$FarmD . '/' .
FmtPageName(
"$UploadFileFmt/$md5file",
$pagename
);
/*
* Determine whether render is required.
*/
$rerender = true;
if (
file_exists($sourcefilepath) &&
file_exists($md5filepath)
) {
$storedmd5 = trim(
file_get_contents(
$md5filepath
)
);
if ($storedmd5 === $checkmd5) {
$rerender = false;
}
}
if ($rerender) {
file_put_contents(
$sourcepath,
$sourceblock
);
/*
* Save current checksum only on success.
*/
if (file_exists($outfilepath)) {
file_put_contents(
$md5filepath,
$checkmd5
);
}
}
if (file_exists($sourcepath)) {
return PRR(
"Attach:$group/$page/$sourcefile"
);
}
return PRR(
"Badboy2 failed.<br />"
. "Source: Attach:$group/$page/$sourcefile<br />"
);
}
More information about the pmwiki-users
mailing list