Jump to content

Topic on Extension talk:SimpleBatchUpload

Notes on how to emulate file folders or upload files as "attachments" to pages

4
Revansx (talkcontribs)

It is common to want to document multiple projects that contain supporting files with very general filenames (like "readme.txt" or "image1.jpg", etc..). Most people use local file systems to organize and store their files using folders. This allows the file system to hold multiple versions of files with common filenames (like "readme.txt" or "image1.jpg", etc..) in different folders. The problem arises when one wishes to migrate these project file stores to a Mediawiki server. As Mediawiki uses a "flat" file system (meaning that all file names in the wiki must be unique), this means that there can be only one uploaded file named "readme.txt". This is problematic for sites that wish to use the wiki to store files from multiple project and multiple users.

The solution presented here is one that uses SimpleBatchUpload (and some other supporting extensions) to achieve the following goals:

  1. Enable users to upload files as "attachments" to a specific wiki article (i.e. Foo)
  2. Enable pages where files have been uploaded to query those files and display them in the page as the set of files that are "attached" to the page.

This effectively allows each wiki page to function as a traditional "file folder" might in a local file system.

Extension Used: We are using SimpleBatchUpload to provide "in-page" uploading of files with options for altering the filenames of upload files as well as creating new file pages with default text, but here are some other essential extensions need to make this all possible:

  • SMW - enables the use of semantics to store data in pages and provides the ability to queries the semantic data anywhere else in the wiki with inline queries
  • SRF - Adds additional types of SMW result formats providing a very wide range of display possibilities
  • SESP - makes intrinsic properties available to SMW
  • Variables - allows users to define and display variables in pages
  • MediaFunctions - provide access to file properties and file metadata of various media files

Here's how we do it:

First define a page variable called "PagePrefix" that is a concatenation of the wiki ID and the Page ID

{{#vardefine:PagePrefix|{{MediaWiki:SitePrefix}}{{PAGEID}}-}}

where {{MediaWiki:SitePrefix}} is a very short string like "MyWiki" (this just gives a reference to the wiki database that the page ID is in reference to)


Then add the batchupload function into a page with the "rename" option as follows:

{{#batchupload:Uploads|+rename= !^({{#var:PagePrefix}}[./+]*)?!iu -->{{#var:PagePrefix}}}}

The !^(@@@@@@@[./+]*)?!iu is a regex string the looks for files that already begin with "@@@@@@@" so that it does not prepend the same prefix again and again when uploading newer versions of an existing file.

When using the rename option, SimpleBatchUpload provides a textarea input box that allows the user to tailor the expression. For the way we are using this feature We personally don't like giving the users the opportunity to mess with regex and upload page text so we hide it from the users by including the following in our Mediawiki:Common.css

textarea#wfUploadDescription { display: none; visibility: hidden; }
label[for="wfUploadDescription"] { display: none; visibility: hidden; } 

We look forward to a day when the extension is updated to make it an option to display the SimpleBatchUpload parameters

Next note the "Uploads" parameter in the batchupload command, this adds the text {{Uploads}} to the uploaded files wiki page. You can develop the "Uploads" template to do lots of interesting things with Semantic Mediawiki or Cargo that will allow the file page to be querried elsewhere in the wiki (including the page where the file was uploaded).

In the page that includes the batchupload function we also add the following:

Page Has File Folder Size

{{#vardefine:HasFileFolderSize|{{#ask:[[Category:Uploads]][[~*{{#var:PagePrefix}}*]]|?Has file size#-|format=sum}}}}

Page Has Num Of Files

{{#vardefine:HasNumOfFiles|{{#ask:[[Category:Uploads]][[~*{{#var:PagePrefix}}*]]|format=count}}}}

Page has the following files:

{{#ask:[[Category:Uploads]][[~*{{#var:PagePrefix}}*]]
|?Has file size
|?Creation date
|?Modification date
|?Page author
|?MIME Type
|?Page creator
|?Has Description
|?Number of revisions
|?Has file ext
|format=template
|template=PagePrefix - Result Row
|introtemplate=PagePrefix - Result Top
|outrotemplate=PagePrefix - Result Bot
|userparam={{#var:PagePrefix}}
|link=none
|limit=200
|default=no files
}}

We often include the following note to the users:

To avoid filename duplications, files uploaded here will be given the prefix "{{#var:PagePrefix}}"

In the end, you can develop a very nice "file folder" system or "page attachment" system for your wiki that will make adoption of the wiki MUCH more intuitive and friendly for non-wiki minded people.

GregRundlett (talkcontribs)

This is a great write-up, and use-case thank you!

Revansx (talkcontribs)

@GregRundlett - Thanks! .. we're working on a MW File Folder Project page that documents the whole thing and include a link to an XML file of wiki pages that one can use to import all our pages at once and have the system running quickly. I'll link that page here when it's made.

InnerCitadel (talkcontribs)

Thanks for sharing. I've tried to replicate (unsuccessfully), would you mind sharing a few more details to make it fully work? What is in you Template:Uploads template. Do you put [[Category:Uploads]] ? What is in your other templates (page prefex templates)?

Reply to "Notes on how to emulate file folders or upload files as "attachments" to pages"