Index: trunk/extensions/UploadWizard/UploadWizard.config.php |
— | — | @@ -204,6 +204,13 @@ |
205 | 205 | 'gfdl' => array( |
206 | 206 | 'msg' => 'mwe-upwiz-license-gfdl', |
207 | 207 | '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', |
208 | 215 | ) |
209 | 216 | ), |
210 | 217 | |
— | — | @@ -221,12 +228,11 @@ |
222 | 229 | |
223 | 230 | // checkbox selection of all licenses |
224 | 231 | 'licensesThirdParty' => array( |
225 | | - 'type' => 'and', |
| 232 | + 'type' => 'or', |
226 | 233 | 'licenseGroups' => array( |
227 | 234 | 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' ) |
231 | 237 | ), |
232 | 238 | array( |
233 | 239 | // This should be a list of all CC licenses we can reasonably expect to find around the web |
— | — | @@ -272,15 +278,13 @@ |
273 | 279 | ), |
274 | 280 | array( |
275 | 281 | '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' ) |
278 | 284 | ), |
279 | | - |
280 | 285 | ), |
281 | | - 'defaults' => array(), |
| 286 | + 'defaults' => array( 'none' ), |
282 | 287 | ), |
283 | 288 | |
284 | | - |
285 | 289 | // Default thumbnail width |
286 | 290 | 'thumbnailWidth' => 100, |
287 | 291 | |
— | — | @@ -397,6 +401,6 @@ |
398 | 402 | 'enableFormData' => true, |
399 | 403 | |
400 | 404 | // should multi-file select be available in supporting browsers? |
401 | | - 'enableMultiFileSelect' => true, |
| 405 | + 'enableMultiFileSelect' => true |
402 | 406 | |
403 | 407 | ); |
Index: trunk/extensions/UploadWizard/UploadWizardHooks.php |
— | — | @@ -311,6 +311,7 @@ |
312 | 312 | 'mwe-upwiz-license-cc-by-2.5', |
313 | 313 | 'mwe-upwiz-license-cc-by-sa-2.0', |
314 | 314 | 'mwe-upwiz-license-cc-by-2.0', |
| 315 | + 'mwe-upwiz-license-custom', |
315 | 316 | 'mwe-upwiz-license-fal', |
316 | 317 | 'mwe-upwiz-license-own-pd', |
317 | 318 | 'mwe-upwiz-license-pd-old-100', |
— | — | @@ -339,9 +340,8 @@ |
340 | 341 | 'mwe-upwiz-license-custom-head', |
341 | 342 | 'mwe-upwiz-license-custom-subhead', |
342 | 343 | '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', |
346 | 346 | 'mwe-upwiz-license-confirm-remove', |
347 | 347 | 'mwe-upwiz-license-confirm-remove-title', |
348 | 348 | 'mwe-upwiz-license-external', |
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -229,6 +229,7 @@ |
230 | 230 | 'mwe-upwiz-license-cc-by-sa-2.0' => 'Creative Commons Attribution ShareAlike 2.0', |
231 | 231 | 'mwe-upwiz-license-cc-by-2.0' => 'Creative Commons Attribution 2.0', |
232 | 232 | '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:', |
233 | 234 | 'mwe-upwiz-license-fal' => 'Free Art License', |
234 | 235 | 'mwe-upwiz-license-own-pd' => 'Public domain (all rights waived with Creative Commons Zero license)', |
235 | 236 | 'mwe-upwiz-license-pd-old-100' => 'Author died more than 100 years ago', |
— | — | @@ -258,15 +259,12 @@ |
259 | 260 | 'mwe-upwiz-license-usgov-head' => '{{PLURAL:$1|This work was|These works were}} made by the United States government', |
260 | 261 | 'mwe-upwiz-license-misc' => 'Miscellaneous reasons', |
261 | 262 | |
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', |
268 | 264 | 'mwe-upwiz-license-custom-preview' => 'Preview', |
269 | 265 | |
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 | + |
271 | 269 | 'mwe-upwiz-license-confirm-remove' => 'Are you sure you want to remove {{PLURAL:$1|this upload|these uploads}}?', |
272 | 270 | 'mwe-upwiz-license-confirm-remove-title' => 'Confirm remove', |
273 | 271 | |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js |
— | — | @@ -44,9 +44,10 @@ |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * 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 |
49 | 50 | */ |
50 | | -mw.UploadWizardDeedOwnWork = function( uploadCount ) { |
| 51 | +mw.UploadWizardDeedOwnWork = function( uploadCount, api ) { |
51 | 52 | uploadCount = uploadCount ? uploadCount : 1; |
52 | 53 | |
53 | 54 | var _this = new mw.UploadWizardDeed(); |
— | — | @@ -66,7 +67,8 @@ |
67 | 68 | licenseInputDiv, |
68 | 69 | undefined, |
69 | 70 | mw.UploadWizard.config.licensesOwnWork, |
70 | | - _this.uploadCount |
| 71 | + _this.uploadCount, |
| 72 | + api |
71 | 73 | ); |
72 | 74 | } |
73 | 75 | |
— | — | @@ -87,7 +89,7 @@ |
88 | 90 | }, |
89 | 91 | |
90 | 92 | getLicenseWikiText: function() { |
91 | | - if ( _this.showCustomDiv && this.licenseInput.getWikiText() != '' ) { |
| 93 | + if ( _this.showCustomDiv && this.licenseInput.getWikiText() !== '' ) { |
92 | 94 | return this.licenseInput.getWikiText(); |
93 | 95 | } |
94 | 96 | else { |
— | — | @@ -239,8 +241,12 @@ |
240 | 242 | |
241 | 243 | }; |
242 | 244 | |
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 ) { |
245 | 251 | var _this = new mw.UploadWizardDeed(); |
246 | 252 | |
247 | 253 | _this.uploadCount = uploadCount ? uploadCount : 1; |
— | — | @@ -252,7 +258,9 @@ |
253 | 259 | _this.licenseInput = new mw.UploadWizardLicenseInput( licenseInputDiv, |
254 | 260 | undefined, |
255 | 261 | mw.UploadWizard.config.licensesThirdParty, |
256 | | - _this.uploadCount ); |
| 262 | + _this.uploadCount, |
| 263 | + api ); |
| 264 | + _this.licenseInput.setDefaultValues(); |
257 | 265 | |
258 | 266 | |
259 | 267 | return $j.extend( _this, mw.UploadWizardDeed.prototype, { |
— | — | @@ -336,7 +344,7 @@ |
337 | 345 | * @param {Array[UploadWizardDeed]} deeds |
338 | 346 | * @param {Array[UploadWizardUpload]} uploads that this applies to (this is just to make deleting and plurals work) |
339 | 347 | */ |
340 | | -mw.UploadWizardDeedChooser = function( selector, deeds, uploads ) { |
| 348 | +mw.UploadWizardDeedChooser = function( selector, deeds, uploads, api ) { |
341 | 349 | var _this = this; |
342 | 350 | _this.$selector = $j( selector ); |
343 | 351 | _this.uploads = mw.isDefined( uploads ) ? uploads : []; |
— | — | @@ -376,7 +384,7 @@ |
377 | 385 | _this.choose( deed ); |
378 | 386 | _this.selectDeedInterface( $deedInterface ); |
379 | 387 | $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).attr( 'checked', true ); |
380 | | - } |
| 388 | + }; |
381 | 389 | } |
382 | 390 | else { |
383 | 391 | $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).click( function() { |
— | — | @@ -443,16 +451,10 @@ |
444 | 452 | uploads: [], |
445 | 453 | |
446 | 454 | |
447 | | - // XXX it's impossible to choose the null deed if we stick with radio buttons, so that may be useless later |
448 | 455 | choose: function( deed ) { |
449 | 456 | var _this = this; |
450 | 457 | _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 ) { |
457 | 459 | $j( _this ).trigger( 'chooseDeed' ); |
458 | 460 | } |
459 | 461 | }, |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js |
— | — | @@ -1,5 +1,7 @@ |
2 | 2 | /** |
3 | 3 | * 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 | + * |
4 | 6 | * @param {String|jQuery} selector to place license input |
5 | 7 | * @param {Array} license key name(s) to activate by default |
6 | 8 | * @param {Array} configuration of licenseInput. Must have following properties |
— | — | @@ -8,13 +10,16 @@ |
9 | 11 | * 'licenses' => array of template string names (matching keys in mw.UploadWizard.config.licenses) |
10 | 12 | * optional: 'licenseGroups' => groups of licenses, with more explanation |
11 | 13 | * 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 |
13 | 16 | */ |
14 | 17 | |
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 ) { |
17 | 21 | var _this = this; |
18 | 22 | _this.count = count; |
| 23 | + _this.api = api; |
19 | 24 | |
20 | 25 | if ( ! ( mw.isDefined(config.type) |
21 | 26 | && mw.isDefined( config.defaults ) |
— | — | @@ -48,54 +53,38 @@ |
49 | 54 | * [ 'fooLicense' ] -> "{{pre}}{{pended}}{{fooLicense}}" |
50 | 55 | * 'filterTemplates' will filter Templates, as in "own work". If 'filterTemplate' was 'filter', then... |
51 | 56 | * [ '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. |
52 | 59 | * |
53 | 60 | */ |
54 | | - function appendLicenses( $el, config ) { |
| 61 | + function appendLicenses( $el, config, groupToggler ) { |
| 62 | + |
55 | 63 | if ( !mw.isDefined( config['licenses'] && typeof config['licenses'] === 'object' ) ) { |
56 | 64 | throw new Error( "improper license config" ); |
57 | 65 | } |
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] }; |
61 | 69 | _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 ); |
76 | 72 | |
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 ); |
85 | 74 | _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 ) ); |
93 | 88 | } |
94 | | - $el.append( |
95 | | - $input, |
96 | | - $j( '<label />' ).attr( { 'for': id } ).msg( messageKey, _this.count ).append( $icons ), |
97 | | - $j( '<br/>' ) |
98 | | - // XXX help? |
99 | | - ); |
100 | 89 | } |
101 | 90 | } ); |
102 | 91 | } |
— | — | @@ -103,6 +92,7 @@ |
104 | 93 | |
105 | 94 | if ( mw.isDefined( config['licenseGroups'] ) ) { |
106 | 95 | $j.each( config['licenseGroups'], function( i, group ) { |
| 96 | + var toggler; |
107 | 97 | var $group = $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license-group' ); |
108 | 98 | // if there is no header, just append licenses to the group div. |
109 | 99 | var $body = $group; |
— | — | @@ -114,34 +104,13 @@ |
115 | 105 | .msg( group.head, _this.count ) |
116 | 106 | ); |
117 | 107 | $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(); |
119 | 109 | } |
120 | 110 | if ( mw.isDefined( group['subhead'] ) ) { |
121 | 111 | $body.append( $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license-group-subhead' ).msg( group.subhead, _this.count ) ); |
122 | 112 | } |
123 | 113 | 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 ); |
146 | 115 | $body.append( $licensesDiv ); |
147 | 116 | _this.$selector.append( $group ); |
148 | 117 | } ); |
— | — | @@ -161,6 +130,31 @@ |
162 | 131 | mw.UploadWizardLicenseInput.prototype = { |
163 | 132 | count: 0, |
164 | 133 | |
| 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 | + |
165 | 159 | /** |
166 | 160 | * Sets the value(s) of a license input. This is a little bit klugey because it relies on an inverted dict, and in some |
167 | 161 | * cases we are now letting license inputs create multiple templates. |
— | — | @@ -172,15 +166,6 @@ |
173 | 167 | // 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 |
174 | 168 | // a radio button input. |
175 | 169 | |
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 | | - |
185 | 170 | if ( _this.type === 'radio' ) { |
186 | 171 | |
187 | 172 | // check if how many license names are set to true in the values requested. Should be 0 or 1 |
— | — | @@ -194,14 +179,14 @@ |
195 | 180 | } ); |
196 | 181 | |
197 | 182 | if ( trueCount === 0 ) { |
198 | | - setInputsIndividually(); |
| 183 | + _this.setInputsIndividually( values ); |
199 | 184 | } else if ( trueCount === 1 ) { |
200 | 185 | // set just one of the radio inputs and don't touch anything else |
201 | 186 | $j.each( _this.inputs, function( i, $input ) { |
202 | 187 | var licenseName = $input.data( 'licenseName' ); |
203 | 188 | // !! to ensure boolean. |
204 | 189 | if ( licenseName === trueLicenseName ) { |
205 | | - $input.attr( 'checked', true ); |
| 190 | + _this.setInput( $input, true ); |
206 | 191 | } |
207 | 192 | } ); |
208 | 193 | } else { |
— | — | @@ -209,7 +194,7 @@ |
210 | 195 | } |
211 | 196 | |
212 | 197 | } else if ( _this.type === 'checkbox' ) { |
213 | | - setInputsIndividually(); |
| 198 | + _this.setInputsIndividually( values ); |
214 | 199 | } else { |
215 | 200 | mw.log( "impossible? UploadWizardLicenseInput type neither radio nor checkbox" ); |
216 | 201 | } |
— | — | @@ -230,25 +215,31 @@ |
231 | 216 | }, |
232 | 217 | |
233 | 218 | /** |
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). |
235 | 223 | * @return string of wikitext (empty string if no inputs set) |
236 | 224 | */ |
237 | 225 | getWikiText: function() { |
| 226 | + var wikiTexts = this.getSelectedInputs().map( |
| 227 | + function() { |
| 228 | + return this.val() + "\n"; |
| 229 | + } |
| 230 | + ); |
238 | 231 | // 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( '' ); |
242 | 233 | }, |
243 | 234 | |
244 | 235 | /** |
245 | | - * Gets which inputs are checked |
| 236 | + * Gets which inputs have user-entered values |
246 | 237 | * @return {jQuery Array} of inputs |
247 | 238 | */ |
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'); } ); |
250 | 242 | }, |
251 | 243 | |
252 | | - |
253 | 244 | /** |
254 | 245 | * Check if a valid value is set, also look for incompatible choices. |
255 | 246 | * Side effect: if no valid value, add notes to the interface. Add listeners to interface, to revalidate and remove notes. |
— | — | @@ -284,9 +275,127 @@ |
285 | 276 | * @return boolean |
286 | 277 | */ |
287 | 278 | 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 |
289 | 397 | } |
290 | 398 | |
| 399 | + |
291 | 400 | }; |
292 | 401 | |
293 | 402 | } )( jQuery ); |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js |
— | — | @@ -274,22 +274,25 @@ |
275 | 275 | * @return {Array} |
276 | 276 | */ |
277 | 277 | 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 | + } |
279 | 289 | |
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 ) ); |
284 | 295 | } |
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 | + |
294 | 297 | return deeds; |
295 | 298 | }, |
296 | 299 | |
— | — | @@ -410,6 +413,7 @@ |
411 | 414 | */ |
412 | 415 | newUpload: function( file ) { |
413 | 416 | var _this = this; |
| 417 | + |
414 | 418 | if ( _this.uploads.length == _this.maxUploads ) { |
415 | 419 | return false; |
416 | 420 | } |
— | — | @@ -425,7 +429,7 @@ |
426 | 430 | $j( upload.ui.div ).bind( 'filenameAccepted', function(e) { _this.updateFileCounts(); e.stopPropagation(); } ); |
427 | 431 | $j( upload.ui.div ).bind( 'removeUploadEvent', function(e) { _this.removeUpload( upload ); e.stopPropagation(); } ); |
428 | 432 | $j( upload.ui.div ).bind( 'filled', function(e) { |
429 | | - _this.newUpload(); |
| 433 | + _this.newUpload(); // is this necessary? XXX XXX XXX |
430 | 434 | _this.setUploadFilled(upload); |
431 | 435 | e.stopPropagation(); |
432 | 436 | } ); |
— | — | @@ -1189,14 +1193,20 @@ |
1190 | 1194 | var $el = this; |
1191 | 1195 | var $contents = $el.find( '.mwe-upwiz-toggler-content' ).hide(); |
1192 | 1196 | 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 | + } ); |
1193 | 1205 | $toggle.click( function( e ) { |
1194 | 1206 | e.stopPropagation(); |
1195 | 1207 | if ( $toggle.hasClass( 'mwe-upwiz-toggler-open' ) ) { |
1196 | | - $contents.slideUp( 250 ); |
1197 | | - $toggle.removeClass( 'mwe-upwiz-toggler-open' ); |
| 1208 | + $el.data( 'close' )(); |
1198 | 1209 | } else { |
1199 | | - $contents.slideDown( 250 ); |
1200 | | - $toggle.addClass( 'mwe-upwiz-toggler-open' ); |
| 1210 | + $el.data( 'open' )(); |
1201 | 1211 | } |
1202 | 1212 | } ); |
1203 | 1213 | return this; |
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js |
— | — | @@ -422,7 +422,7 @@ |
423 | 423 | |
424 | 424 | _this.upload.deedChooser = new mw.UploadWizardDeedChooser( |
425 | 425 | _this.deedDiv, |
426 | | - mw.UploadWizard.prototype.getLicensingDeeds(), |
| 426 | + _this.upload.wizard.getLicensingDeeds(), |
427 | 427 | [ _this.upload ] |
428 | 428 | ); |
429 | 429 | |