Wikipedia:File upload wizard/doc

{{pp-semi-indef}}

This page provides documentation for the experimental Wikipedia:File Upload Wizard, which is currently in testing stage.

Architecture

The wizard consists of one normal wiki page, currently located at Wikipedia:File Upload Wizard, a page of client-side Javascript code, currently at MediaWiki:FileUploadWizard.js, and a corresponding .css page, currently at MediaWiki:FileUploadWizard.css. Almost all of the text content used by the wizard (forms, prompts, warnings etc.) is contained as standard wikitext in the main page, inside hidden

-elements and nested tables. Interactive elements that cannot be created by normal wiki text (
elements, buttons, input text fields, dropdowns boxes etc.) are created by the Javascript when the page loads. Empty elements in the wikitext mark the positions where they will be inserted. To activate the Javascript, the wikipage must be loaded with a withJS= parameter.

The Javascript code has been tested with the Firefox 10.0 browser so far. It makes some use of the jQuery library, which is commonly used in Wikipedia scripts. Data used during the input and upload process are stored in a Javascript object named window.fuw. A representation of the input data present at any given time during the input process is cached in window.fuw.opts, and data representing the current status of various warning conditions (e.g. bad filenames, missing target articles etc.) are stored in window.fuw.warn.

The most important functions of the script are:

;fuwGlobal()

:The constructor function of the global window.fuw object, executed once when the page loads. It creates the interactive form elements (buttons, text fields etc.) and sets the initial visibility of the main form area.

;fuwUpdateOptions()

:The onChange event handler shared by most of the input elements. It collects the input from all currently active input fields, updates the cached contents of the window.fuw.opts object from it, and switches visibility and enabled/disabled status for the various subsections of the questionnaire in response to the current status of the option radio-buttons. It also shows and hides various warning messages in response to the result of previous validation routines stored in window.fuw.warn.

;fuw.validateInput()

:Called at the end of each fuwUpdateOptions(), this function determines whether the current state of input data is complete and sufficient for uploading. The fuwUpdateOptions() function will enable or disable the submit button in response to this validation. (Possible alternative: keep the submit button always enabled and run validateInput() only when it's clicked, showing a warning message if false. Which is more user-friendly?)

;fuw.collectInput()

:This function collects the input data from the window.fuw.opts object and assembles a set of window.fuw.descFields from them, representing the strings that are to be written into the fields of the description template.

;fuw.formatOutput()

:Called immediately after collectInput(), before uploading. This function assembles the code of the actual description page from the window.fuw.descFields object and the license tags, and prepares it for upload, either in local upload mode or in Commons upload mode. For local upload, it writes the resulting values into the hidden elements of the TargetForm, from where they are submitted to the API. In Commons mode, the description wikitext is assembled into a parameter string to be appended to the URL for the Commons Special:Upload page, pre-loading the value into the standard Commons upload form.

In the current testing version, this function is also called at the end of each fuwUpdateOptions() call, in order to maintain a constant preview of the output for testing purposes. In the final version, it will be sufficient to have it called only once, from the onClick event of the submit button (after validateInput() has returned true).

Server interaction

The questionnaire page currently contains three separate elements. The first, , is the one that is actually used for uploading. The only overt element contained in it is the file selection box. All other upload parameters are present in the form of elements, whose values are filled in prior to uploading by the fuw.collectInput() function.

The upload is done via a standard form.submit() from this target form, with the form's action set to the //en.wikipedia.org/w/api.php interface. The API's return message is diverted into a hidden