01087: Extend [[PmWiki/Conditional Markup]] (:if attachments:) to specify file names

Summary: Extend Conditional Markup (:if attachments:) to specify file names
Created: 2009-03-27 02:28
Status: Closed, added for 2.2.77
Category: Feature
From: simon
Assigned:
Priority: 421
Version: 2.2.0
OS: Any

Added for 2.2.77 in the format (:if attachments FILEPATTERNS PAGENAME:). --Petko June 13, 2015, at 10:30 AM

Description
Extend the (:if attachments:) conditional markup expression to allow the optional specification of one or more file descriptors, eg
(:if attachments ext='jpg,jpeg':)

or perhaps more generally

(:if attachments descriptor='*.jpg,*.jpeg':)

This would also apply to the pagelist if parameter.

See also PITS.01093 Enhance conditional markup to 'if attachments PAGENAME'.

The use I have for it is as follows:

>>comment<<
[[#randomimage]]
(:template default order=random count=1:)
(:template each:)
(:if attachments {=$FullName} ext='jpeg,jpg':)
(:thumblist {=$FullName} order=random count=1 px=128:)
(:ifend:)
[[#randomimageend]]
>><<

(:pagelist fmt=#randomimage list=normal count=4 group=pmwiki:)

(:template default order=random count=1:) (:template each:)

A condition for a list of files is an excellent idea and would not be hard to add, I'll think about it. For the Thumblist example you can use quiet=3 to suppress any warnings and to display nothing if the page has no attached pictures. --Petko March 27, 2009, at 03:38 AM

See this recipe. If it works for you, we may add it to the Cookbook and close this feature request. --Petko May 02, 2009, at 05:00 PM


Ambiguous parameters

Hi. I was considering adding this to the core, but I have a doubt. If the markup was like this:

  • (:if attachments Group.Page/*.jpg:) this is fine and clear enough
  • (:if attachments Group.Page/*:) this is fine and clear enough
  • (:if attachments *.jpg:) is this fine?
  • (:if attachments image.jpg:) is this fine?
  • (:if attachments Group.Page:) is this fine?

The last two commands are ambiguous -- is "X.Y" it a wiki page, or a file? Comments are welcome. --Petko July 02, 2009, at 09:22 AM

For the ambiguous cases the thought that springs to mind is syntax from other directives

  • (:if attachments image.jpg:) is fine
  • (:if attachments name=Group.Page:)

We also have cases that one might expect to work such as

  • (:if attachments Group/image.jpg:) which would refer to the home page of the group

Some other cases might be

  • (:if attachments image.jp?g:) no problems with this as "?" is not allowed in a page name
  • (:if attachments image.jpg image.jpeg:) multiple possible attachments, true if any are found
  • (:if attachments name Group.Page,Group2.Page2:) multiple pages, conditional markup syntax
  • (:if attachments name=Group.Page,Group2.Page2:) multiple pages, directive syntax
  • (:if attachments group Group,Group2 image.jpg image.jpeg:) multiple groups, multiple images on any pages in groups (perhaps not useful, but syntactically consistent)

(Actually looking at the ConditionalMarkup syntax makes me wonder if we should align the directive and conditional markup synatx, hmmmm, email list discussion perhaps)

note my original suggestion of "descriptor="

Simon July 02, 2009, at 03:56 PM

I'm afraid we'll leave all these complex conditional expressions for a cookbook recipe, until an actual need for many wikis is obvious. The markup I'm considering is this:
(:if attachments image.jpg Group.Page:) where
- Group.Page or just Page or Group. is optional, if omitted means the current page,
- image.jpg is optional, if omitted means "*" (any attachment), and could be:
i1.jpg,i2.jpg or *.jpg or *.jpg,*.png or *,-*.png or *.jpg,-1.jpg
With this variant, the current (:if attachments:) will continue to work as it does today. --Petko July 03, 2009, at 06:15 AM