AttachLinks

Summary: Get Attach: links to display by default without the "Attach:" prefix
Version: n/a
Prerequisites:
Status:
Maintainer: Petko
Discussion: AttachLinks-Talk
Categories: Uploads PHP72

Questions answered by this recipe

How can I get Attach: links to display by default without the "Attach:" prefix?

Description

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'>&nbsp;&Delta;</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]]
or [[(Attach:)somefile.txt]]

to get the attachment link shown with another text.

Contributors

  • 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.

Array
(
    [post_max_size] => 64M
    [$_POST keys] => 
    [$_REQUEST keys] => n
    [$_SERVER] => Array
        (
            [CONTEXT_DOCUMENT_ROOT] => /home/pmwiki/public_html
            [CONTEXT_PREFIX] => 
            [DOCUMENT_ROOT] => /home/pmwiki/public_html
            [GATEWAY_INTERFACE] => CGI/1.1
            [HTTPS] => on
            [HTTP_ACCEPT] => */*
            [HTTP_ACCEPT_ENCODING] => gzip, br, zstd, deflate
            [HTTP_COOKIE] => PHPSESSID=6thijj3lsnbf8molhjoejsg2p3
            [HTTP_HOST] => www.pmwiki.org
            [HTTP_REFERER] => https://www.pmwiki.org/wiki/Cookbook/AttachLinks,
            [HTTP_USER_AGENT] => Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
            [HTTP_X_HTTPS] => 1
            [PATH] => /bin:/usr/bin
            [PHP_INI_SCAN_DIR] => /opt/cpanel/ea-php70/root/etc:/opt/cpanel/ea-php70/root/etc/php.d:.
            [QUERY_STRING] => n=Cookbook%2fAttachLinks
            [REDIRECT_HTTPS] => on
            [REDIRECT_QUERY_STRING] => n=Cookbook%2fAttachLinks
            [REDIRECT_SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/AttachLinks
            [REDIRECT_SCRIPT_URL] => /wiki/Cookbook/AttachLinks
            [REDIRECT_SSL_TLS_SNI] => www.pmwiki.org
            [REDIRECT_STATUS] => 200
            [REDIRECT_UNIQUE_ID] => afRrMvcKtEfre9Lv0ifaOgAAAE0
            [REDIRECT_URL] => /wiki/Cookbook/AttachLinks
            [REMOTE_ADDR] => 216.73.216.25
            [REMOTE_PORT] => 39572
            [REQUEST_METHOD] => GET
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /wiki/Cookbook/AttachLinks
            [SCRIPT_FILENAME] => /home/pmwiki/public_html/index.php
            [SCRIPT_NAME] => /index.php
            [SCRIPT_URI] => https://www.pmwiki.org/wiki/Cookbook/AttachLinks
            [SCRIPT_URL] => /wiki/Cookbook/AttachLinks
            [SERVER_ADDR] => 23.254.203.248
            [SERVER_ADMIN] => webmaster@pmwiki.org
            [SERVER_NAME] => www.pmwiki.org
            [SERVER_PORT] => 443
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SIGNATURE] => 
            [SERVER_SOFTWARE] => Apache
            [SSL_TLS_SNI] => www.pmwiki.org
            [TZ] => America/Los_Angeles
            [UNIQUE_ID] => afRrMvcKtEfre9Lv0ifaOgAAAE0
            [PHP_SELF] => /index.php
            [REQUEST_TIME_FLOAT] => 1777625906.5966
            [REQUEST_TIME] => 1777625906
            [argv] => Array
                (
                    [0] => n=Cookbook%2fAttachLinks
                )

            [argc] => 1
        )

)