User:MarkEldridge/My Spin on CharlesC's Generic File Template

My Spin on The Generic File TemplateEdit

CharlesC has a talk page discussing the Generic File Template, and another person submitted what was the precursor of the following template.

This version makes things a bit easier for users, because the parameters are fewer, but is a bit more work for the admin in setting up. I found with the original script users were making mistakes and putting the wrong extension with the wrong file. This just takes the extension they use on the filename, and parses that out to get the icon.

Icons Used in this template:

  • doc.png
  • xls.png
  • ppt.png
  • pdf.png
  • zip.png
  • Click_for_more_info.png (which is similar to the info icon that CharlesC had. I just renamed it because it seemed to be more informative when you hover.

Note: You require ParserFunctions StringFunctions to be set up correctly for this to work. Basically I took the solution above, and rewrote it to parse the end of the filename, to look for various extensions. I use that to lookup the appropriate icon. The downside is you need an if statement for each doc type you wish to represent.

Be sure to edit your LocalSettings.php and add the file extensions to set:

$wgAllowExternalImages = true;

and include all the extensions you will be using in your:

$wgFileExtensions = array( 'png', 'jpg', 'jpeg', 'doc', 'xls', 'ppt', 'pdf', 'zip' );

For more instructions see CharlesCs page.

Here is my version of the Generic File Template:

  • This works for mixes of upper and lower case extensions. eg) .PdF .PDf .pdf .PDF etc
  • The template is LONG, and can not include any spaces in the extension determination. A copy and paste should work fine.
  • Create your Template:file template and use the following.
http://mysite/wiki/images/icons/{{#ifexpr:{{#rpos:{{lc:{{{1}}}}}|.zip}} > 0 |zip.png|}}{{#ifexpr:{{#rpos:{{lc:{{{1}}}}}|.doc}} > 0 |doc.png|}}{{#ifexpr:{{#rpos:{{lc:{{{1}}}}}|.xls}} > 0 |xls.png|}}{{#ifexpr:{{#rpos:{{lc:{{{1}}}}}|.ppt}} > 0 |ppt.png|}}{{#ifexpr:{{#rpos:{{lc:{{{1}}}}}|.pdf}} > 0 |pdf.png|}} [[media:{{{1}}}|{{{2}}}]] <span class="plainlinks">[{{SERVER}}{{localurl:image:{{{1}}}}} http://mysite/wiki/images/icons/Click_for_more_info.png]</span>

So to use this you just need to use:

 {{file|sheet.xls|My xls spreadsheet}}
 {{file|document.doc|My doc file}}
 {{file|myadobething.pdf|My pdf document}}