r101597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101596‎ | r101597 | r101598 >
Date:09:33, 2 November 2011
Author:neilk
Status:ok
Tags:
Comment:
none license and custom license basic interface. Set up LicenseInput to know about api, for preview
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.config.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizard.i18n.php (modified) (history)
  • /trunk/extensions/UploadWizard/UploadWizardHooks.php (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizard.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js (modified) (history)
  • /trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/UploadWizard.config.php
@@ -204,6 +204,13 @@
205205 'gfdl' => array(
206206 'msg' => 'mwe-upwiz-license-gfdl',
207207 'templates' => array( 'GFDL' )
 208+ ),
 209+ 'none' => array(
 210+ 'msg' => 'mwe-upwiz-license-none',
 211+ 'templates' => array( 'subst:uwl' )
 212+ ),
 213+ 'custom' => array(
 214+ 'msg' => 'mwe-upwiz-license-custom',
208215 )
209216 ),
210217
@@ -221,12 +228,11 @@
222229
223230 // checkbox selection of all licenses
224231 'licensesThirdParty' => array(
225 - 'type' => 'and',
 232+ 'type' => 'or',
226233 'licenseGroups' => array(
227234 array(
228 - 'head' => 'mwe-upwiz-license-none-applicable-head',
229 - 'subhead' => 'mwe-upwiz-license-none-applicable-subhead',
230 - 'special' => 'none'
 235+ 'head' => 'mwe-upwiz-license-none-head',
 236+ 'licenses' => array( 'none' )
231237 ),
232238 array(
233239 // This should be a list of all CC licenses we can reasonably expect to find around the web
@@ -272,15 +278,13 @@
273279 ),
274280 array(
275281 'head' => 'mwe-upwiz-license-custom-head',
276 - 'subhead' => 'mwe-upwiz-license-custom-subhead',
277 - 'special' => 'custom'
 282+ 'licenses' => array( 'custom' ),
 283+ 'prependTemplates' => array( 'custom-badness' )
278284 ),
279 -
280285 ),
281 - 'defaults' => array(),
 286+ 'defaults' => array( 'none' ),
282287 ),
283288
284 -
285289 // Default thumbnail width
286290 'thumbnailWidth' => 100,
287291
@@ -397,6 +401,6 @@
398402 'enableFormData' => true,
399403
400404 // should multi-file select be available in supporting browsers?
401 - 'enableMultiFileSelect' => true,
 405+ 'enableMultiFileSelect' => true
402406
403407 );
Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -311,6 +311,7 @@
312312 'mwe-upwiz-license-cc-by-2.5',
313313 'mwe-upwiz-license-cc-by-sa-2.0',
314314 'mwe-upwiz-license-cc-by-2.0',
 315+ 'mwe-upwiz-license-custom',
315316 'mwe-upwiz-license-fal',
316317 'mwe-upwiz-license-own-pd',
317318 'mwe-upwiz-license-pd-old-100',
@@ -339,9 +340,8 @@
340341 'mwe-upwiz-license-custom-head',
341342 'mwe-upwiz-license-custom-subhead',
342343 'mwe-upwiz-license-custom-preview',
343 - 'mwe-upwiz-license-none-applicable-head',
344 - 'mwe-upwiz-license-none-applicable-subhead',
345 - 'mwe-upwiz-license-none-applicable',
 344+ 'mwe-upwiz-license-none',
 345+ 'mwe-upwiz-license-none-head',
346346 'mwe-upwiz-license-confirm-remove',
347347 'mwe-upwiz-license-confirm-remove-title',
348348 'mwe-upwiz-license-external',
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -229,6 +229,7 @@
230230 'mwe-upwiz-license-cc-by-sa-2.0' => 'Creative Commons Attribution ShareAlike 2.0',
231231 'mwe-upwiz-license-cc-by-2.0' => 'Creative Commons Attribution 2.0',
232232 'mwe-upwiz-license-cc-zero' => 'Creative Commons CC0 Waiver (release all rights, like public domain)',
 233+ 'mwe-upwiz-license-custom' => 'The license is described by the following wikitext:',
233234 'mwe-upwiz-license-fal' => 'Free Art License',
234235 'mwe-upwiz-license-own-pd' => 'Public domain (all rights waived with Creative Commons Zero license)',
235236 'mwe-upwiz-license-pd-old-100' => 'Author died more than 100 years ago',
@@ -258,15 +259,12 @@
259260 'mwe-upwiz-license-usgov-head' => '{{PLURAL:$1|This work was|These works were}} made by the United States government',
260261 'mwe-upwiz-license-misc' => 'Miscellaneous reasons',
261262
262 - 'mwe-upwiz-license-custom-head' => 'Experts only: enter the code for a license not shown here',
263 - 'mwe-upwiz-license-custom-subhead' => 'Enter wikitext that will add a license template to your uploads.',
264 -
265 - 'mwe-upwiz-license-none-applicable-head' => 'I don\'t know',
266 - 'mwe-upwiz-license-none-applicable-subhead' => 'Please explain where you got the image. If it is not published under a suitable license it will be deleted without further notice.',
267 -
 263+ 'mwe-upwiz-license-custom-head' => 'Another reason not mentioned above',
268264 'mwe-upwiz-license-custom-preview' => 'Preview',
269265
270 - 'mwe-upwiz-license-none-applicable' => 'Abandon {{PLURAL:$1|this upload|these uploads}} without publishing',
 266+ 'mwe-upwiz-license-none-head' => 'I found it on the Internet -- I\'m not sure',
 267+ 'mwe-upwiz-license-none' => 'Upload {{PLURAL:$1|this file|these files}} without copyright information for now. I understand the image may be deleted.',
 268+
271269 'mwe-upwiz-license-confirm-remove' => 'Are you sure you want to remove {{PLURAL:$1|this upload|these uploads}}?',
272270 'mwe-upwiz-license-confirm-remove-title' => 'Confirm remove',
273271
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js
@@ -44,9 +44,10 @@
4545
4646 /**
4747 * Set up the form and deed object for the deed option that says these uploads are all the user's own work.
48 - * XXX these deeds are starting to turn into jquery fns
 48+ * @param {Number} integer count of uploads that this deed refers to (useful for message pluralization)
 49+ * @param {mw.Api} api object - useful for doing previews
4950 */
50 -mw.UploadWizardDeedOwnWork = function( uploadCount ) {
 51+mw.UploadWizardDeedOwnWork = function( uploadCount, api ) {
5152 uploadCount = uploadCount ? uploadCount : 1;
5253
5354 var _this = new mw.UploadWizardDeed();
@@ -66,7 +67,8 @@
6768 licenseInputDiv,
6869 undefined,
6970 mw.UploadWizard.config.licensesOwnWork,
70 - _this.uploadCount
 71+ _this.uploadCount,
 72+ api
7173 );
7274 }
7375
@@ -87,7 +89,7 @@
8890 },
8991
9092 getLicenseWikiText: function() {
91 - if ( _this.showCustomDiv && this.licenseInput.getWikiText() != '' ) {
 93+ if ( _this.showCustomDiv && this.licenseInput.getWikiText() !== '' ) {
9294 return this.licenseInput.getWikiText();
9395 }
9496 else {
@@ -239,8 +241,12 @@
240242
241243 };
242244
243 -// XXX these deeds are starting to turn into jquery fns
244 -mw.UploadWizardDeedThirdParty = function( uploadCount ) {
 245+/**
 246+ * Set up the form and deed object for the deed option that says these uploads are the work of a third party.
 247+ * @param {Number} integer count of uploads that this deed refers to (useful for message pluralization)
 248+ * @param {mw.Api} api object - useful for doing previews
 249+ */
 250+mw.UploadWizardDeedThirdParty = function( uploadCount, api ) {
245251 var _this = new mw.UploadWizardDeed();
246252
247253 _this.uploadCount = uploadCount ? uploadCount : 1;
@@ -252,7 +258,9 @@
253259 _this.licenseInput = new mw.UploadWizardLicenseInput( licenseInputDiv,
254260 undefined,
255261 mw.UploadWizard.config.licensesThirdParty,
256 - _this.uploadCount );
 262+ _this.uploadCount,
 263+ api );
 264+ _this.licenseInput.setDefaultValues();
257265
258266
259267 return $j.extend( _this, mw.UploadWizardDeed.prototype, {
@@ -336,7 +344,7 @@
337345 * @param {Array[UploadWizardDeed]} deeds
338346 * @param {Array[UploadWizardUpload]} uploads that this applies to (this is just to make deleting and plurals work)
339347 */
340 -mw.UploadWizardDeedChooser = function( selector, deeds, uploads ) {
 348+mw.UploadWizardDeedChooser = function( selector, deeds, uploads, api ) {
341349 var _this = this;
342350 _this.$selector = $j( selector );
343351 _this.uploads = mw.isDefined( uploads ) ? uploads : [];
@@ -376,7 +384,7 @@
377385 _this.choose( deed );
378386 _this.selectDeedInterface( $deedInterface );
379387 $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).attr( 'checked', true );
380 - }
 388+ };
381389 }
382390 else {
383391 $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).click( function() {
@@ -443,16 +451,10 @@
444452 uploads: [],
445453
446454
447 - // XXX it's impossible to choose the null deed if we stick with radio buttons, so that may be useless later
448455 choose: function( deed ) {
449456 var _this = this;
450457 _this.deed = deed;
451 - if ( deed === mw.UploadWizardNullDeed ) {
452 - $j( _this ).trigger( 'chooseNullDeed' );
453 - _this.$selector
454 - .find( 'input.mwe-accept-deed' )
455 - .attr( 'checked', false );
456 - } else {
 458+ if ( deed !== mw.UploadWizardNullDeed ) {
457459 $j( _this ).trigger( 'chooseDeed' );
458460 }
459461 },
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js
@@ -1,5 +1,7 @@
22 /**
33 * Create a group of radio buttons for licenses. N.b. the licenses are named after the templates they invoke.
 4+ * Note that this is very anti-MVC. The values are held only in the actual form elements themselves.
 5+ *
46 * @param {String|jQuery} selector to place license input
57 * @param {Array} license key name(s) to activate by default
68 * @param {Array} configuration of licenseInput. Must have following properties
@@ -8,13 +10,16 @@
911 * 'licenses' => array of template string names (matching keys in mw.UploadWizard.config.licenses)
1012 * optional: 'licenseGroups' => groups of licenses, with more explanation
1113 * optional: 'special' => String -- indicates, don't put licenses here, instead use a special widget
12 - * @param {Numbe} count of the things we are licensing (it matters to some texts)
 14+ * @param {Number} count of the things we are licensing (it matters to some texts)
 15+ * @param {mw.Api} api object; useful for previews
1316 */
1417
15 -( function( $j ) {
16 -mw.UploadWizardLicenseInput = function( selector, values, config, count ) {
 18+( function( $j, undefined ) {
 19+
 20+mw.UploadWizardLicenseInput = function( selector, values, config, count, api ) {
1721 var _this = this;
1822 _this.count = count;
 23+ _this.api = api;
1924
2025 if ( ! ( mw.isDefined(config.type)
2126 && mw.isDefined( config.defaults )
@@ -48,54 +53,38 @@
4954 * [ 'fooLicense' ] -> "{{pre}}{{pended}}{{fooLicense}}"
5055 * 'filterTemplates' will filter Templates, as in "own work". If 'filterTemplate' was 'filter', then...
5156 * [ 'fooLicense', 'barLicense' ] -> {{filter|fooLicense|barLicense}}
 57+ * @param {jQuery} optional - jquery-wrapped element created by $j.fn.collapseToggle(), which has 'close' and 'open'
 58+ * methods in its data.
5259 *
5360 */
54 - function appendLicenses( $el, config ) {
 61+ function appendLicenses( $el, config, groupToggler ) {
 62+
5563 if ( !mw.isDefined( config['licenses'] && typeof config['licenses'] === 'object' ) ) {
5664 throw new Error( "improper license config" );
5765 }
58 - $j.each( config['licenses'], function( i, name ) {
59 - if ( mw.isDefined( mw.UploadWizard.config.licenses[name] ) ) {
60 - var license = { name: name, props: mw.UploadWizard.config.licenses[name] };
 66+ $j.each( config['licenses'], function( i, licenseName ) {
 67+ if ( mw.isDefined( mw.UploadWizard.config.licenses[licenseName] ) ) {
 68+ var license = { name: licenseName, props: mw.UploadWizard.config.licenses[licenseName] };
6169 _this.licenses.push( license );
62 - var templates = mw.isDefined( license.props['templates'] ) ? license.props.templates.slice(0) : [ license.name ];
63 - var origTemplateString = templates.join( '|' );
64 - if ( mw.isDefined( config['prependTemplates'] ) ) {
65 - $j.each( config['prependTemplates'], function( i, template ) {
66 - templates.unshift( template );
67 - } );
68 - }
69 - if ( mw.isDefined( config['filterTemplate'] ) ) {
70 - templates.unshift( config['filterTemplate'] );
71 - templates = [ templates.join( '|' ) ];
72 - }
73 - // using inputs length to ensure that you can have two options which deliver same result,
74 - // but the label association still works
75 - var id = _this.name + '_' + templates.join('_') + '_' + _this.inputs.length;
 70+
 71+ var templates = _this.getTemplatesForLicense( license );
7672
77 - // the value is literal wikitext; turn template names (or template names + args) into wikitext templates
78 - var value = ( $j.map( templates, function( t ) { return '{{' + t + '}}'; } ) ).join( '' );
79 - // IE6 is idiotic about radio buttons; you have to create them as HTML or clicks aren't recorded
80 - var $input = $j( '<input id="' + id + '" name="' + _this.name + '" type="' + _this.type + '" value="' + value + '" />' );
81 - $input.click( function() { _this.$selector.trigger( 'changeLicenses' ); } );
82 - // this is added so that setValues() can find one (or more) checkboxes to check - represent values without wikitext
83 - $input.data( 'templateString', origTemplateString );
84 - $input.data( 'licenseName', name );
 73+ var $input = _this.getInputElement( templates, config );
8574 _this.inputs.push( $input );
86 -
87 - var messageKey = mw.isDefined( license.props['msg'] ) ? license.props.msg : '[missing msg for ' + license.name + ']';
88 - var $icons = $j( '<span></span>' );
89 - if ( mw.isDefined( license.props['icons'] ) ) {
90 - $j.each( license.props.icons, function( i, icon ) {
91 - $icons.append( $j( '<span></span>' ).addClass( 'mwe-upwiz-license-icon mwe-upwiz-' + icon + '-icon' ) );
92 - } );
 75+
 76+ var $label = _this.getInputElementLabel( license, $input );
 77+ $el.append( $input, $label, $j( '<br/>' ) );
 78+ // TODO add popup help?
 79+
 80+ // this is so we can tell if a particular license ought to be set in setValues()
 81+ $input.data( 'licenseName', licenseName );
 82+
 83+ // this is so if a single input in a group changes, we open the entire "toggler" that was hiding them
 84+ $input.data( 'groupToggler', groupToggler );
 85+
 86+ if ( licenseName === 'custom' ) {
 87+ $el.append( _this.getInputElementRelatedTextarea( $input ) );
9388 }
94 - $el.append(
95 - $input,
96 - $j( '<label />' ).attr( { 'for': id } ).msg( messageKey, _this.count ).append( $icons ),
97 - $j( '<br/>' )
98 - // XXX help?
99 - );
10089 }
10190 } );
10291 }
@@ -103,6 +92,7 @@
10493
10594 if ( mw.isDefined( config['licenseGroups'] ) ) {
10695 $j.each( config['licenseGroups'], function( i, group ) {
 96+ var toggler;
10797 var $group = $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license-group' );
10898 // if there is no header, just append licenses to the group div.
10999 var $body = $group;
@@ -114,34 +104,13 @@
115105 .msg( group.head, _this.count )
116106 );
117107 $body = $j( '<div></div>' ).addClass( 'mwe-upwiz-toggler-content' ).css( { 'marginBottom': '1em' } );
118 - $group.append( $head, $body ).collapseToggle();
 108+ toggler = $group.append( $head, $body ).collapseToggle();
119109 }
120110 if ( mw.isDefined( group['subhead'] ) ) {
121111 $body.append( $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license-group-subhead' ).msg( group.subhead, _this.count ) );
122112 }
123113 var $licensesDiv = $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license' );
124 - if ( mw.isDefined( group['special'] ) ) {
125 - switch ( group['special'] ) {
126 - case 'custom':
127 - $licensesDiv.append(
128 - $j( '<div></div>' ).css( { 'width': '100%' } ).append(
129 - $j( '<div></div>' ).css( { 'float': 'right', 'width': '9em', 'padding-left': '1em' } ).append(
130 - $j( '<span></span>' ).button( { label: gM( 'mwe-upwiz-license-custom-preview' ) } ).css( { 'width': '8em' } )
131 - ),
132 - $j( '<div></div>' ).css( { 'margin-right': '10em' } ).append(
133 - $j( '<textarea></textarea>' ).growTextArea().css( { 'width': '100%' } )
134 - ),
135 - $j( '<div></div>' ).css( { 'clear':'both' } )
136 - )
137 - );
138 - break;
139 - case 'none':
140 - default:
141 - break;
142 - }
143 - } else {
144 - appendLicenses( $licensesDiv, group );
145 - }
 114+ appendLicenses( $licensesDiv, group, toggler );
146115 $body.append( $licensesDiv );
147116 _this.$selector.append( $group );
148117 } );
@@ -161,6 +130,31 @@
162131 mw.UploadWizardLicenseInput.prototype = {
163132 count: 0,
164133
 134+ // Set the input value. If it is part of a group, and this is being turned on, pop open the group so we can see this input.
 135+ setInput: function( $input, val ) {
 136+ var _this = this;
 137+ var oldVal = $input.attr( 'checked' );
 138+ // !! to ensure boolean.
 139+ var bool = !!val;
 140+ $input.attr( 'checked', bool );
 141+ if ( bool !== oldVal ) {
 142+ _this.$selector.trigger( 'changeLicenses' );
 143+ }
 144+ // pop open the 'toggle' group if is now on. Do nothing if it is now off.
 145+ if ( bool && $input.data( 'groupToggler' ) ) {
 146+ $input.data( 'groupToggler' ).data( 'open' )();
 147+ }
 148+ },
 149+
 150+ // this works fine for blanking all of a radio input, or for checking/unchecking individual checkboxes
 151+ setInputsIndividually: function( values ) {
 152+ var _this = this;
 153+ $j.each( _this.inputs, function( i, $input ) {
 154+ var licenseName = $input.data( 'licenseName' );
 155+ _this.setInput( $input, values[licenseName] );
 156+ } );
 157+ },
 158+
165159 /**
166160 * Sets the value(s) of a license input. This is a little bit klugey because it relies on an inverted dict, and in some
167161 * cases we are now letting license inputs create multiple templates.
@@ -172,15 +166,6 @@
173167 // is set to false! Unfortunately the incoming data structure is a key-val object so we have to make extra sure it makes sense for
174168 // a radio button input.
175169
176 - // this works fine for blanking all of a radio input, or for checking/unchecking individual checkboxes
177 - function setInputsIndividually() {
178 - $j.each( _this.inputs, function( i, $input ) {
179 - var licenseName = $input.data( 'licenseName' );
180 - // !! to ensure boolean.
181 - $input.attr( 'checked', !!values[licenseName] );
182 - } );
183 - }
184 -
185170 if ( _this.type === 'radio' ) {
186171
187172 // check if how many license names are set to true in the values requested. Should be 0 or 1
@@ -194,14 +179,14 @@
195180 } );
196181
197182 if ( trueCount === 0 ) {
198 - setInputsIndividually();
 183+ _this.setInputsIndividually( values );
199184 } else if ( trueCount === 1 ) {
200185 // set just one of the radio inputs and don't touch anything else
201186 $j.each( _this.inputs, function( i, $input ) {
202187 var licenseName = $input.data( 'licenseName' );
203188 // !! to ensure boolean.
204189 if ( licenseName === trueLicenseName ) {
205 - $input.attr( 'checked', true );
 190+ _this.setInput( $input, true );
206191 }
207192 } );
208193 } else {
@@ -209,7 +194,7 @@
210195 }
211196
212197 } else if ( _this.type === 'checkbox' ) {
213 - setInputsIndividually();
 198+ _this.setInputsIndividually( values );
214199 } else {
215200 mw.log( "impossible? UploadWizardLicenseInput type neither radio nor checkbox" );
216201 }
@@ -230,25 +215,31 @@
231216 },
232217
233218 /**
234 - * Gets the wikitext associated with all checked inputs
 219+ * Gets the wikitext associated with all selected inputs.
 220+ * Anything from a text input is automatically suspect, because it might not be valid. So we append a template to double check.
 221+ * This is a bit of a hack, in the ideal case we'd make all the inputs into objects that returned their own wikitext, but
 222+ * it is easier to extend the current interface (which assumes form input value is all we want).
235223 * @return string of wikitext (empty string if no inputs set)
236224 */
237225 getWikiText: function() {
 226+ var wikiTexts = this.getSelectedInputs().map(
 227+ function() {
 228+ return this.val() + "\n";
 229+ }
 230+ );
238231 // need to use makeArray because a jQuery-returned set of things won't have .join
239 - return $j.makeArray(
240 - this.getCheckedInputs().map( function() { return this.val(); } )
241 - ).join( "" );
 232+ return $j.makeArray( wikiTexts ).join( '' );
242233 },
243234
244235 /**
245 - * Gets which inputs are checked
 236+ * Gets which inputs have user-entered values
246237 * @return {jQuery Array} of inputs
247238 */
248 - getCheckedInputs: function() {
249 - return $j( this.inputs ).filter( function() { return this.is( ':checked' ); } );
 239+ getSelectedInputs: function() {
 240+ // not sure why filter(':checked') doesn't work
 241+ return $j( this.inputs ).filter( function(i, $x) { return $x.is(':checked'); } );
250242 },
251243
252 -
253244 /**
254245 * Check if a valid value is set, also look for incompatible choices.
255246 * Side effect: if no valid value, add notes to the interface. Add listeners to interface, to revalidate and remove notes.
@@ -284,9 +275,127 @@
285276 * @return boolean
286277 */
287278 isSet: function() {
288 - return this.getCheckedInputs().length > 0;
 279+ return this.getSelectedInputs().length > 0;
 280+ },
 281+
 282+ /**
 283+ * Given a license name, return template names
 284+ * Note we return copies, so as not to perturb the configuration itself
 285+ * @param {String} license name
 286+ * @return {Array} of strings of template names
 287+ */
 288+ getTemplatesForLicense: function( license ) {
 289+ return mw.isDefined( license.props['templates'] ) ? license.props.templates.slice(0) : [ license.name ];
 290+ },
 291+
 292+ /**
 293+ * License templates are these abstract ideas like cc-by-sa. In general they map directly to a license template.
 294+ * However, configuration for a particular option can add other templates or transform the templates,
 295+ * such as wrapping templates in an outer "self" template for own-work
 296+ * @param {Array} of license template names
 297+ * @param {Object}, license input configuration
 298+ * @return {String} of wikitext
 299+ */
 300+ getWikiTextForTemplates: function( templates, config ) {
 301+ if ( mw.isDefined( config['prependTemplates'] ) ) {
 302+ $j.each( config['prependTemplates'], function( i, template ) {
 303+ templates.unshift( template );
 304+ } );
 305+ }
 306+ if ( mw.isDefined( config['filterTemplate'] ) ) {
 307+ templates.unshift( config['filterTemplate'] );
 308+ templates = [ templates.join( '|' ) ];
 309+ }
 310+ return $j.map( templates, function(t) { return '{{' + t + '}}'; } ).join( '' );
 311+ },
 312+
 313+ /**
 314+ * Return a radio button or checkbox with appropriate values, depending on config
 315+ * @param {Array} of template strings
 316+ * @param {Object} config for this license input
 317+ * @return {jQuery} wrapped input
 318+ */
 319+ getInputElement: function( templates, config ) {
 320+ var _this = this;
 321+
 322+ var attrs = {
 323+ id: _this.name + '_' + _this.inputs.length, // unique id
 324+ name: _this.name, // name of input, shared among all checkboxes or radio buttons.
 325+ type: _this.type, // kind of input
 326+ value: _this.getWikiTextForTemplates( templates, config )
 327+ };
 328+
 329+ var inputHtml = '<input ' +
 330+ $j.map( attrs, function(val, key) {
 331+ return key + '="' + val.toString().replace( '"', '' ) + '"';
 332+ } ).join( " " )
 333+ + ' />';
 334+
 335+ // Note we aren't using $('<input>').attr( { ... } ) . We construct a string of HTML.
 336+ // IE6 is idiotic about radio buttons; you have to create them as HTML or clicks aren't recorded
 337+ return $j( inputHtml ).click( function() {
 338+ _this.$selector.trigger( 'changeLicenses' );
 339+ } );
 340+ },
 341+
 342+ /**
 343+ * Get a label for the form element
 344+ * @param {Object} license definition from global config. Will tell us the messages, and maybe icons.
 345+ * @param {jQuery} wrapped input
 346+ * @return {jQuery} wrapped label referring to that input, with appropriate HTML, decorations, etc.
 347+ */
 348+ getInputElementLabel: function( license, $input ) {
 349+ var messageKey = mw.isDefined( license.props['msg'] ) ? license.props.msg : '[missing msg for ' + license.name + ']';
 350+ var $icons = $j( '<span></span>' );
 351+ if ( mw.isDefined( license.props['icons'] ) ) {
 352+ $j.each( license.props.icons, function( i, icon ) {
 353+ $icons.append( $j( '<span></span>' ).addClass( 'mwe-upwiz-license-icon mwe-upwiz-' + icon + '-icon' ) );
 354+ } );
 355+ }
 356+ return $j( '<label />' )
 357+ .attr( { 'for': $input.attr('id') } )
 358+ .msg( messageKey, this.count )
 359+ .append( $icons );
 360+ },
 361+
 362+ /**
 363+ * Given an input, return another textarea to be appended below.
 364+ * When text entered here, auto-selects the input.
 365+ * @param {jQuery} wrapped input
 366+ * @return {jQuery} wrapped textarea
 367+ */
 368+ getInputElementRelatedTextarea: function( $input ) {
 369+ var _this = this;
 370+
 371+ var $textarea = $j( '<textarea></textarea>' )
 372+ .attr( { id: $input.attr( 'id' ) + '_custom' } )
 373+ .growTextArea()
 374+ .focus( function() { _this.setInput( $input, true ); } )
 375+ .css( {
 376+ 'width': '100%',
 377+ 'font-family': 'monospace'
 378+ } );
 379+
 380+ var $button = $j( '<span></span>' )
 381+ .button( { label: gM( 'mwe-upwiz-license-custom-preview' ) } )
 382+ .css( { 'width': '8em' } )
 383+ .click( function() { _this.showPreview( $textarea.val() ); } );
 384+
 385+ return $j( '<div></div>' ).css( { 'width': '100%' } ).append(
 386+ $j( '<div></div>' ).css( { 'float': 'right', 'width': '9em', 'padding-left': '1em' } ).append( $button ),
 387+ $j( '<div></div>' ).css( { 'margin-right': '10em' } ).append( $textarea ),
 388+ $j( '<div></div>' ).css( { 'clear':'both' } )
 389+ );
 390+ },
 391+
 392+ /**
 393+ * Preview license
 394+ */
 395+ showPreview: function() {
 396+ // do stuff with this.api
289397 }
290398
 399+
291400 };
292401
293402 } )( jQuery );
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js
@@ -274,22 +274,25 @@
275275 * @return {Array}
276276 */
277277 getLicensingDeeds: function( uploadsLength ) {
278 - var deeds = [];
 278+ var deeds = [],
 279+ doOwnWork = false,
 280+ doThirdParty = false;
 281+
 282+ if ( mw.UploadWizard.config.ownWorkOption === 'choice' ) {
 283+ doOwnWork = doThirdParty = true;
 284+ } else if ( mw.UploadWizard.config.ownWorkOption === 'own' ) {
 285+ doOwnWork = true;
 286+ } else {
 287+ doThirdParty = true;
 288+ }
279289
280 - if ( mw.UploadWizard.config.ownWorkOption == 'choice' ) {
281 - // these deeds are standard
282 - deeds.push( new mw.UploadWizardDeedOwnWork( uploadsLength ) );
283 - deeds.push( new mw.UploadWizardDeedThirdParty( uploadsLength ) );
 290+ if ( doOwnWork ) {
 291+ deeds.push( new mw.UploadWizardDeedOwnWork( uploadsLength, this.api ) );
 292+ }
 293+ if ( doThirdParty ) {
 294+ deeds.push( new mw.UploadWizardDeedThirdParty( uploadsLength, this.api ) );
284295 }
285 - else {
286 - if ( mw.UploadWizard.config.ownWorkOption == 'own' ) {
287 - deeds.push( new mw.UploadWizardDeedOwnWork( uploadsLength ) );
288 - }
289 - else {
290 - deeds.push( new mw.UploadWizardDeedThirdParty( uploadsLength ) );
291 - }
292 - }
293 -
 296+
294297 return deeds;
295298 },
296299
@@ -410,6 +413,7 @@
411414 */
412415 newUpload: function( file ) {
413416 var _this = this;
 417+
414418 if ( _this.uploads.length == _this.maxUploads ) {
415419 return false;
416420 }
@@ -425,7 +429,7 @@
426430 $j( upload.ui.div ).bind( 'filenameAccepted', function(e) { _this.updateFileCounts(); e.stopPropagation(); } );
427431 $j( upload.ui.div ).bind( 'removeUploadEvent', function(e) { _this.removeUpload( upload ); e.stopPropagation(); } );
428432 $j( upload.ui.div ).bind( 'filled', function(e) {
429 - _this.newUpload();
 433+ _this.newUpload(); // is this necessary? XXX XXX XXX
430434 _this.setUploadFilled(upload);
431435 e.stopPropagation();
432436 } );
@@ -1189,14 +1193,20 @@
11901194 var $el = this;
11911195 var $contents = $el.find( '.mwe-upwiz-toggler-content' ).hide();
11921196 var $toggle = $el.find( '.mwe-upwiz-toggler' ).addClass( 'mwe-upwiz-more-options' );
 1197+ $el.data( 'open', function() {
 1198+ $contents.slideDown( 250 );
 1199+ $toggle.addClass( 'mwe-upwiz-toggler-open' );
 1200+ } );
 1201+ $el.data( 'close', function() {
 1202+ $contents.slideUp( 250 );
 1203+ $toggle.removeClass( 'mwe-upwiz-toggler-open' );
 1204+ } );
11931205 $toggle.click( function( e ) {
11941206 e.stopPropagation();
11951207 if ( $toggle.hasClass( 'mwe-upwiz-toggler-open' ) ) {
1196 - $contents.slideUp( 250 );
1197 - $toggle.removeClass( 'mwe-upwiz-toggler-open' );
 1208+ $el.data( 'close' )();
11981209 } else {
1199 - $contents.slideDown( 250 );
1200 - $toggle.addClass( 'mwe-upwiz-toggler-open' );
 1210+ $el.data( 'open' )();
12011211 }
12021212 } );
12031213 return this;
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
@@ -422,7 +422,7 @@
423423
424424 _this.upload.deedChooser = new mw.UploadWizardDeedChooser(
425425 _this.deedDiv,
426 - mw.UploadWizard.prototype.getLicensingDeeds(),
 426+ _this.upload.wizard.getLicensingDeeds(),
427427 [ _this.upload ]
428428 );
429429

Status & tagging log