AttachLinks
Attach: links to display by default without the "Attach:" prefixQuestions answered by this recipe
How can I get Attach: links to display by default without the "Attach:" prefix?
Description
PmWiki version 2.5.10 or later:
Add one of the following lines to your config.php or local customization file:
# Hide Attach: prefix for existing uploads, keep for missing/pending uploads $EnableHideAttachPrefix = 1; # Hide Attach: prefix for existing and missing/pending uploads $EnableHideAttachPrefix = 2;
If you upgrade from the old version of the recipe to $EnableHideAttachPrefix, please remove the previous code (see below).
PmWiki versions before 2.5.10 (click to toggle)
Add the following lines to your config.php or local customization file:
- PHP4 - PHP7, PmWiki 2.2.56 or newer:
Markup('Attach', '>img', "/\\bAttach:([^\\s$UrlExcludeChars]*[^\\s.,?!$UrlExcludeChars])/", "MarkupAttachLink"); function MarkupAttachLink($m) { extract($GLOBALS["MarkupToHTML"]); # get $pagename return Keep(MakeLink($pagename,$m[0],$m[1]),'L'); } - PHP 5.4 or older:
Markup('Attach', '>img', "/\\bAttach:([^\\s$UrlExcludeChars]*[^\\s.,?!$UrlExcludeChars])/e", "Keep(MakeLink(\$pagename,'$0','$1'),'L')");
This will cause Attach:something.txt to appear as "something.txt".
To have the "Attach:" to still appear when creating a new attachment (but not for an existing attachment), also add
$LinkUploadCreateFmt = "<a class='createlinktext' href='\$LinkUpload'>Attach:\$LinkText</a><a class='createlink' href='\$LinkUpload'> Δ</a>";
After this modification, authors can still create links with the "Attach:" displayed by using the double-bracket form of link (i.e., [[Attach:somepage.txt]]).
Notes
This modification has been applied to the Cookbook group on pmwiki.org.
One may also use
[[Attach:somepage.txt | sometext]]
[[(Attach:)somefile.txt]]
to get the attachment link shown with another text.
Contributors
- Petko, update for PmWiki 2.5.10
- Petko, update for PHP 4 - PHP 7.2
- Dfaure, update for PHP 5.5+
- Pm, 2004-12-20
Comments
See discussion at AttachLinks-Talk
User notes +2: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.