Name

file

Type

input

Synopsis

Using file uploads

Description

Use a form to upload one or multiple files.

Parameters

input type="file"

target* : Name of the File page to be created

id* : This must always be unique, that is, it can only occur once on a page. Do not include a hyphen ("-"), underscore ("_"), or any special characters (also no spaces).

action* : defaults to upload. Read more below on using this to convert docx documents to pages in the wiki.

name* : As with any input field, a name is mandatory

pagecontent: Text content to be added on the File Page. If you are using convertfrom then any images uploading during the convert will get the pagecontent.

comment: Text to show in recent changes or contributions list

force : Force images to a certain format (png, jpg or gif). When using this option, any file uploaded that is not supported will be uploaded as is.

error_id : Id of a DOM Element where error notices will be shown

verbose_id : Id of a DOM element where information about the file is shown

use_label : Doesn't require a value. When an input field has a label attached to it, then the label will become the upload button and the input field will be hidden

dropzone : Doesn't require a value. Will turn the verbose div into an additional file drop zone. If you also use_label, then the label will become the dropzone.

parsecontent: Will force FlexForm to insert values from other form fields inside the pagecontent field. Use square brackets, like [fieldname], where values should be inserted.

template : If you want to store a template call inside the content of the File page, you can template=<name of your template> in combination with parsecontent. [flexform-template] inside your content field will be replaced by {{<name of your template and [/flexform-template] will be replaced by }}. See example 3 on the examples page.

*= a required variable

The target is basically the name you want to use to store the file or files. It recognizes [mwrandom], [filename] and other form fields, by using their name with square brackets around them (see example). pagecontent can also hold form variables.

action="convertfrom:????"

Pandoc

The action argument defaults to upload. If you use action="convertfrom:????" and you have Pandoc installed on your system, FlexForm will convert a document and create it as a page in the Wiki. target will then be used as a Page Title. Depending on your version of Pandoc, the results might differ. convertfrom allows all Pandoc to MediaWiki text conversions. docx would be a good example : action="convertfrom:docx". Any images uploaded during the convert can have their content of their filepages be filled using pagecontent. Since version 2.2.9 you can also add an argument slot="<name of slot>" to have the converted Document be save to a specific slot on the target page, instead of the main slot. Keep in mind, MediaWiki slots need to be defined in your LocalSettings.

Excel ( since version 2.2.9 )

You can also use action="convertfrom:xls" or action="convertfrom:xlsx". This allows for converting an Excel xls or xlsx file to JSON. Images are not supported. The argument slot is supported. This conversion is not done using Pandoc and thus will work without having Pandoc installed. (just make sure you run composer update after you update FlexForm).

An excel document like this :

options description HitCounter WSStats More
$wgDisableCounters automatically show hitcounts on a page and Special page yes no WSStats allows for adding this to a page using parser function
$wgHitcounterUpdateFreq frequency of counters update yes no WSStats uses MW DB abstraction layer to update hitcount. The approach is different
skip_user_groups Skip certain user groups in counting no yes
count_all_usergroups Count pages independend of a user group no yes

Will result in the following JSON:

[
    {
        "options": "$wgDisableCounters",
        "description": "automatically show hitcounts on a page and Special page",
        "HitCounter": "yes",
        "WSStats": "no",
        "More": "WSStats allows for adding this to a page using parser function"
    },
    {
        "options": "$wgHitcounterUpdateFreq",
        "description": "frequency of counters update",
        "HitCounter": "yes",
        "WSStats": "no",
        "More": "WSStats uses MW DB abstraction layer to update hitcount. The approach is different"
    },
    {
        "options": "skip_user_groups",
        "description": "Skip certain user groups in counting",
        "HitCounter": "no",
        "WSStats": "yes"
    },
    {
        "options": "count_all_usergroups",
        "description": "Count pages independend of a user group",
        "HitCounter": "no",
        "WSStats": "yes"
    }
]


HTMLtoImage

You can also use the field input to upload an image created from part of the page shown where the form is rendered.

Basically, you tell FlexForm you want to render a part of your screen as an image and upload it to the wiki.

The syntax is the same as above, but it only needs : target, name and pagecontent. The other arguments are ignored. Additionally it needs an argument called presentor="canvas" and it needs the ID of the element you want to convert to an image: canvas_source_id.

By default the image will always be a .jpg file. We plan to support png if this is requested.

For example you have a DIV element with id="content-to-convert". Within this DIV you have content you want to convert to an image an upload to the Wiki.

A FlexForm to utilize this would look something like this :

<div id="content-to-convert" style="width:500px">
  <h1>Test Screenshot</h1>
  <p>Lots of other content here</p>
</div>

<form>
  <input type="file" presentor="canvas" id="canvasUpload" target="testCanvasFile.jpg" pagecontent="testing" canvas_source_id="content-to-convert"  />
  <input type="submit" value="upload" />
</form>

You cannot use both file uploads in one form.

Note

An input type="file" always needs a unique ID! ( do not use "-", "_", any special characters ( also no spaces ) ).

A form that needs to upload files needs this argument : enctype="multipart/form-data". The argument needs to be added to the Form tag, not the input tag. See also : https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/enctype

As FlexForm first handles File Upload, it will add the files processed to use in an _edit or a _create. Every file upload field needs a name attribute and once a file has been uploaded you can use them in an edit or create in the following format :

  • FFUploadedFile-UploadName-<name attribute of input field> : Will hold the original file name uploaded
  • FFUploadedFile-UploadBase-<name attribute of input field> : Will hold the original file name uploaded without the extension
  • FFUploadedFile-NewName-<name attribute of input field> : Will hold the name of the file as it is uploaded into the Wiki ( Without the File: prefix )

If you use a multiple file upload, then the above values will all be , separated.

Links

https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/enctype

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file

https://pandoc.org/