[Home]WikiPatches/ImageTagsAlt

UseModWiki | WikiPatches | RecentChanges | Preferences

Decription

This patch allows to refer images not only with full URL but:

The first option is recognized by the URL - the missing protocol part and the path without the root slash (/) at the beginning of URL. The relative path is appended to the path from the new global variable $ImageUrl?. URL for the second option must start with the slash (/) and for the third one with the protocol specification (http:, https: or ftp:).

Moreover, a horizontal alignment can be prescribed by optional prefix delimited by semicolon (;). Without alignment specification is the image horizontally centered on the page. With alignment it is formatted according to the specified value (there are "left", "right", "top" and "texttop" and "middle" supported in HTML).

The whole image reference is enclosed in brackets - I see it better than the solution in the first WikiPatches/ImageTags patch. This syntax can be supported also in free links, which have the same syntax, and then we can have unified syntax for textual and graphic hyperlinks. It can be also extended on named anchors, because the syntax is also similar. At last, but not least, the syntax @x@ of the first patch clashes with another patch for automatic creation of e-mail hyperlinks (WikiPatches/AutoMailto).

Examples

Here we are some examples of the syntax of references:

 [image.png]                  - it will be searched in the $ImageUrl directory
 [common/image.png]           - it will be searched in the $ImageUrl/common directory
 [/images/image.png]          - it will be searched in the /images directory
 [http://localhost/image.png] - it will be searched on the specified URL

Any type of the reference can be prefixed by alignment, for example:

 [image.png]      - it will be centered on the page
 [left;image.png] - it will be left-aligned

The original way to include an image (writing its complete URL) remains unchanged, to maintain backward compatibility, after application of this patch.

Patch

The patch is similar to the first one I mentioned above except for he syntax of the reference. The steps to get it working follow:

A new configuration variable $ImageUrl? must be created in the first section of variables (and also declared in the first "use vars qw" section above):

 $LogoUrl     = "/Wiki/wiki.gif"; # URL for site logo ("" for no logo)
 $ImageUrl    = "/Wiki/Images/";  # path to image files for relative links inside []

A new method for image tag construction can be inserted anywhere, here for example in front of the subroutine WikiToHTML:

 sub GetImageTag {
   my ($image, $align) = @_ ;
 
   $image = $ImageUrl . $image if $image !~ /^(http:|https:|ftp:|\/).+\.$ImageExtensions$/;
   return defined($align) ? '<img align="' . $align . '" src="' . $image . '"> '
                           : '<center><img src="' . $image . '"></center> '
 }
 
 sub WikiToHTML {

Translation of the reference syntax belongs to the subroutine CommonMarkup but it is not important where exactly it will be inserted; it is sensible to put it near to code, which expands the other squere-bracketed rules:

     s/$RFCPattern/&StoreRFC($1)/geo;
     s/$ISBNPattern/&StoreISBN($1)/geo;
     s/\[(?:(\w+);)?\s*(\S+\.$ImageExtensions)\s*\]/&GetImageTag($2, $1)/gei;
     if ($ThinLine) {
       s/--------+/<hr noshade size="5">/g;

--FerdinandPrantl


Does this clobber the feature of linking to an image without displaying it inline? For example: [1]


Maybe it is just all the other patches I applied, but I had much better luck with the following:

sub StoreImageTag {
    my ($image, $align) = @_ ;

    $image = $ImageUrl . $image if $image !~ /^(http:|https:|ftp:|\/).+\.$ImageExtensions$/;
    return &StoreRaw(defined($align) ? '<img align="' . $align . '" src="' . $image . '"> '
        : '<center><img src="' . $image . '"></center> ');
 }

(note the StoreRaw function call) and the regular expression:

s/\[(?:(\w+);)?\s*(\S+\.$ImageExtensions)\s*\]/&StoreImageTag($2, $1)/geo;


I've taken the above patch and modified it to allow basic CSS attribute:value pairs. You can find the code at http://www.mcs.vuw.ac.nz/~db/FishBrainWiki?WikiHacking/Images

- DanielBallinger?


UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited October 16, 2007 2:13 am by MarkusLude (diff)
Search: