r66730 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66729‎ | r66730 | r66731 >
Date:18:57, 21 May 2010
Author:neilk
Status:deferred
Tags:
Comment:
deed selector radio button interface
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.i18n.php (modified) (history)
  • /trunk/extensions/UploadWizard/js/mw.UploadWizard.js (modified) (history)
  • /trunk/extensions/UploadWizard/styles/uploadWizard.css (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/styles/uploadWizard.css
@@ -338,7 +338,7 @@
339339 margin-left: 24px;
340340 }
341341
342 -.mwe-upwiz-deed-name {
 342+.mwe-upwiz-deed.selected .mwe-upwiz-deed-name {
343343 font-weight: bold;
344344 }
345345
@@ -466,7 +466,7 @@
467467 }
468468
469469 .mwe-upwiz-deed-form-internal {
470 - padding: 5px 0px 20px 20px;
 470+ padding: 5px 0px 20px 40px;
471471 }
472472
473473
@@ -503,3 +503,8 @@
504504 a.mwe-upwiz-tooltip-link {
505505 cursor: pointer;
506506 }
 507+
 508+.mwe-error {
 509+ color: #ff0000;
 510+ display: none;
 511+}
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -33,8 +33,12 @@
3434 'mwe-upwiz-upload' => 'Upload',
3535 'mwe-upwiz-upload-count' => '$1 {{PLURAL:$1|file|files}} of $2 {{PLURAL:$2|file|files}} uploaded',
3636 'mwe-upwiz-progressbar-uploading' => 'uploading',
37 - 'mwe-upwiz-remaining' => '$1 {{PLURAL:$1|file|files}} remaining',
38 - 'mwe-upwiz-deeds-intro' => "Thank you! Now we need to set a license for these files, so everyone can legally view or modify them. First, we will have to know where you got them.",
 37+ 'mwe-upwiz-secs-remaining' => '$1 {{PLURAL:$1|second|seconds}} remaining',
 38+ 'mwe-upwiz-mins-secs-remaining' => '$1 {{PLURAL:$1|minute|minutes}} $2 {{PLURAL:$2|second|seconds}} remaining',
 39+ 'mwe-upwiz-hrs-mins-secs-remaining' => '$1 {{PLURAL:$1|hour|hours}} $2 {{PLURAL:$2|minute|minutes}} $3 {{PLURAL:$3|second|seconds}} remaining',
 40+ 'mwe-upwiz-deeds-intro' => "This site requires you to set a license for uploaded files, so everyone can legally reuse them for any purpose.",
 41+ 'mwe-upwiz-deeds-macro-prompt' => "Set a license for {{PLURAL:$1|the above file|all the above files}}:",
 42+ 'mwe-upwiz-deeds-custom-prompt' => "Or:",
3943 'mwe-upwiz-details-intro' => 'Now we need some basic information about the files.',
4044 'mwe-upwiz-source-ownwork' => '{{PLURAL:$1|This file is|These files are}} my own work.',
4145 'mwe-upwiz-source-ownwork-assert' => 'I, $2, the copyright holder of {{PLURAL:$1|this work|these works}}, hereby grant anyone the right to use {{PLURAL:$1|this work|these works}} for any purpose, as long as they credit me and share derivative work under the same terms.',
@@ -46,7 +50,7 @@
4751 'mwe-upwiz-source-thirdparty-custom-multiple-intro' => 'If all files have the same source, author, and copyright status, you may enter them only once for all of them.',
4852 'mwe-upwiz-source-thirdparty-license' => 'The copyright holder of {{PLURAL:$1|this work|these works}} published {{PLURAL:$1|it|them}} under the following license(s):',
4953 'mwe-upwiz-source-thirdparty-accept' => 'OK',
50 - 'mwe-upwiz-source-custom' => 'Did you know? You can <a href="$1">customize</a> the default options you see here.',
 54+ 'mwe-upwiz-source-custom' => 'Choose licenses for each file individually on the next page.',
5155 'mwe-upwiz-more-options' => 'more options...',
5256 'mwe-upwiz-fewer-options' => 'fewer options...',
5357 'mwe-upwiz-desc' => 'Description in',
@@ -92,7 +96,6 @@
9397 'mwe-upwiz-upload-another' => 'Upload more files',
9498 'mwe-prevent-close' => 'Your files are still uploading. Are you sure you want to navigate away from this page?',
9599 'mwe-upwiz-files-complete' => 'Your files finished uploading!',
96 - 'mwe-upwiz-deeds-later' => 'Set deeds and licenses for each file individually on the next page',
97100 'mwe-upwiz-tooltip-author' => 'The name of the person who took the photo, or painted the picture, drew the drawing, etc.',
98101 'mwe-upwiz-tooltip-source' => 'Where this digital file came from -- could be a URL, or a book or publication',
99102 'mwe-upwiz-tooltip-sign' => 'You can use your wiki user name or your real name. In both cases, this will be linked to your wiki user page',
@@ -104,6 +107,7 @@
105108 'mwe-upwiz-file-need-start' => 'Please press this button to start your uploads.',
106109 'mwe-upwiz-file-need-complete' => 'Please wait until all files have finished uploading.',
107110 'mwe-upwiz-deeds-need-deed' => 'Please explain where you got {{PLURAL:$1|this file|these files}} and how this site can use {{PLURAL:$1|it|them}}, by selecting one of the options.',
 111+ 'mwe-upwiz-deeds-need-license' => 'Please select a license.'
108112 );
109113
110114 /** Message documentation (Message documentation)
Index: trunk/extensions/UploadWizard/js/mw.UploadWizard.js
@@ -184,7 +184,7 @@
185185 * @param values (optional) array of license key names to activate by default
186186 * @param change (optional) function to execute when any value changes
187187 */
188 -mw.UploadWizardLicenseInput = function( div, values ) {
 188+mw.UploadWizardLicenseInput = function( selector, values ) {
189189 var _this = this;
190190
191191 _this.change = function() {};
@@ -202,14 +202,15 @@
203203
204204 _this.inputs = [];
205205
206 - $div = $j( div );
 206+ _this.$selector = $j( selector );
 207+ _this.$selector.append( $j( '<div class="mwe-error"></div>' ) );
207208 $j.each( _this.licenses, function( key, data ) {
208209 var id = 'license_' + key + '_' + c;
209210 var input = $j( '<input />' )
210211 .attr( { id: id, type: 'checkbox', value: key } )
211212 .click( function() { _this.change() } );
212213 data.input = input.get(0);
213 - $div.append(
 214+ _this.$selector.append(
214215 data.input,
215216 $j( '<label />' ).attr( { 'for': id } ).html( data.text ),
216217 $j( '<br/>' )
@@ -278,6 +279,26 @@
279280 },
280281
281282 /**
 283+ * Check if a valid value is set,
 284+ * Side effect: add notes to the interface if no valid value
 285+ * @return boolean; true if a value set, false otherwise
 286+ */
 287+ validate: function() {
 288+ var isValid = this.isSet();
 289+ if (!isValid) {
 290+ var $errorEl = this.$selector.find( '.mwe-error' )
 291+ $errorEl.html( gM( 'mwe-upwiz-deeds-need-license' ) ).show();
 292+ var $inputs = _this.$selector.find( 'input[type=checkbox]' )
 293+ $inputs.bind( 'click.hideError', function() {
 294+ $errorEl.hide();
 295+ $inputs.unbind( 'click.hideError' );
 296+ } )
 297+ }
 298+ return isValid;
 299+ },
 300+
 301+
 302+ /**
282303 * Returns true if any license is set
283304 * @return boolean
284305 */
@@ -1093,16 +1114,13 @@
10941115 var _this = this;
10951116 _this.copyrightInfoFieldset.show();
10961117 _this.upload.wizardDeedChooser = _this.upload.deedChooser;
1097 - _this.upload.deedChooser = new mw.UploadWizardDeedChooser( _this.deedDiv );
 1118+ _this.upload.deedChooser = new mw.UploadWizardDeedChooser(
 1119+ _this.deedDiv,
 1120+ [ new mw.UploadWizardDeedOwnWork(),
 1121+ new mw.UploadWizardDeedThirdParty() ]
 1122+ );
10981123 },
10991124
1100 - useDeedChooser: function( deedChooser ) {
1101 - var _this = this;
1102 - _this.upload.deedChooser = deedChooser;
1103 - _this.deedDiv.empty();
1104 - },
1105 -
1106 -
11071125 /**
11081126 * Sets the filename from the title plus this upload's extension.
11091127 */
@@ -1865,11 +1883,18 @@
18661884 _this.startUploads();
18671885 } );
18681886
 1887+
 1888+ // handler for next button
18691889 $j( '#mwe-upwiz-stepdiv-file .mwe-upwiz-button-next').click( function() {
 1890+ // check if there is an upload at all
18701891 if ( _this.uploads.length === 0 ) {
18711892 alert( gM( 'mwe-upwiz-file-need-file' ) );
18721893 return;
18731894 }
 1895+
 1896+
 1897+ // check if all uploads are finished. The upload with the most advanced state
 1898+ // will be copied to 'overallState'
18741899 var overallState = 'new';
18751900 $j.each( _this.uploads, function( i, upload ) {
18761901 if ( upload.state == 'transporting' ) {
@@ -1878,111 +1903,97 @@
18791904 overallState = 'transported';
18801905 }
18811906 } );
 1907+
 1908+ // if uploads aren't initiated or finished uploading, throw up errors, otherwise, let's
 1909+ // go to the next step.
18821910 if ( overallState == 'new' ) {
18831911 alert( gM( 'mwe-upwiz-file-need-start' ) );
18841912 } else if ( overallState == 'transporting' ) {
18851913 alert( gM( 'mwe-upwiz-file-need-complete' ) );
18861914 } else if ( overallState == 'transported' ) {
 1915+
 1916+
 1917+ // okay all uploads are done, we're ready to go to the next step
 1918+
 1919+ // do some last minute prep before advancing to the DEEDS page
 1920+
 1921+ // these deeds are standard
 1922+ var deeds = [
 1923+ new mw.UploadWizardDeedOwnWork( _this.uploads.length ),
 1924+ new mw.UploadWizardDeedThirdParty( _this.uploads.length ),
 1925+ ];
 1926+
 1927+ // if we have multiple uploads, also give them the option to set
 1928+ // licenses individually
 1929+ if ( _this.uploads.length > 1 ) {
 1930+ var customDeed = $j.extend( new mw.UploadWizardDeed(), {
 1931+ validate: function() { return true; },
 1932+ $formFields: null,
 1933+ name: 'custom',
 1934+ } );
 1935+ deeds.push( customDeed );
 1936+ }
 1937+
 1938+ _this.deedChooser = new mw.UploadWizardDeedChooser(
 1939+ '#mwe-upwiz-deeds',
 1940+ deeds,
 1941+ _this.uploads.length );
 1942+
 1943+ $j( '<div>' ).html( gM( 'mwe-upwiz-deeds-macro-prompt' ) )
 1944+ .insertBefore ( _this.deedChooser.$selector.find( '.mwe-upwiz-deed-ownwork' ) );
 1945+
 1946+ if ( _this.uploads.length > 1 ) {
 1947+ $j( '<div style="margin-top: 1em">' ).html( gM( 'mwe-upwiz-deeds-custom-prompt' ) )
 1948+ .insertBefore( _this.deedChooser.$selector.find( '.mwe-upwiz-deed-custom' ) );
 1949+ }
 1950+
18871951 _this.moveToStep( 'deeds' );
 1952+
18881953 } else {
 1954+ // should never happen, since all the state names are well known
 1955+ // compare with the 'makeTransitioner' call for the upload page
18891956 alert( "error: could not recognize state of uploads: " + overallState );
18901957 }
18911958
18921959 } );
18931960
 1961+
18941962 // DEEDS div
1895 - _this.deedChooser = new mw.UploadWizardDeedChooser( '#mwe-upwiz-deeds' );
18961963
1897 - var customDeed = $j.extend( new mw.UploadWizardDeed(), {
1898 - isReady: function() { return true; },
1899 - setQuantity: function() { return; }
1900 - } );
1901 -
1902 - $j( '#mwe-upwiz-deeds-custom' ).append(
1903 - $j( '<div id="mwe-upwiz-deeds-later-div" />' )
1904 - .hide()
1905 - .append( $j( '<label>' )
1906 - .append(
1907 - $j( '<input id="mwe-upwiz-deeds-later" '
1908 - + 'type="checkbox" value="deeds-later" class="mwe-accept-deed" />')
1909 - .click( function() {
1910 - if ( $j( this ).is( ':checked' ) ) {
1911 - _this.deedChooser.showDeedChoice();
1912 - _this.deedChooser.choose( customDeed );
1913 - //_this.deedChooser.trigger( 'isReady' );
1914 - } else {
1915 - _this.deedChooser.choose( mw.UploadWizardNullDeed );
1916 - }
1917 - } ),
1918 - $j( '<span />').append( gM( 'mwe-upwiz-deeds-later' ) )
1919 - )
1920 - )
1921 - );
1922 -
1923 - $j( _this.deedChooser ).bind( 'setQuantityEvent', function() {
1924 - mw.log( "checking this deedchooser count " + _this.deedChooser.count );
1925 - if ( _this.deedChooser.count > 1 ) {
1926 - $j( '#mwe-upwiz-deeds-later-div' ).show();
1927 - } else {
1928 - $j( '#mwe-upwiz-deeds-later-div' ).hide();
1929 - }
1930 - } );
1931 -
1932 - // XXX mediawiki PLURAL
19331964 $j( '#mwe-upwiz-deeds-intro' ).html( gM( 'mwe-upwiz-deeds-intro' ) );
19341965
19351966 $j( '#mwe-upwiz-stepdiv-deeds .mwe-upwiz-button-next').click( function() {
1936 - if ( $j( '#mwe-upwiz-deeds-later-checkbox' ).is( ':checked' )
1937 - ||
1938 - _this.deedChooser.isReady() ) {
1939 - _this.moveToStep('details');
1940 - } else {
1941 - _this.deedChooser.deed.showValidationTips();
1942 - }
1943 - } );
 1967+ if ( _this.deedChooser.validate() ) {
19441968
1945 - // XXX perhaps we should defer this until we click next
1946 - $j( _this.deedChooser ).bind( 'chooseDeed', function() {
1947 - var isCustom = ( _this.deedChooser.deed === customDeed );
1948 - $j.each( _this.uploads, function( i, upload ) {
1949 - if (isCustom) {
1950 - upload.details.useCustomDeedChooser();
1951 - } else {
1952 - upload.details.useDeedChooser( _this.deedChooser );
1953 - }
1954 - } );
1955 - } );
 1969+ var isCustom = ( _this.deedChooser.deed.name == 'later' );
 1970+
 1971+ $j.each( _this.uploads, function( i, upload ) {
 1972+ if ( isCustom ) {
 1973+ upload.details.useCustomDeedChooser();
 1974+ } else {
 1975+ upload.deedChooser = _this.deedChooser;
 1976+ }
 1977+ } );
19561978
1957 - // XXX perhaps we should defer this until we click next
1958 - $j( _this.deedChooser ).bind( 'chooseNullDeed', function() {
1959 - $j.each( _this.uploads, function( i, upload ) {
1960 - upload.details.deedChooser = _this.deedChooser;
1961 - } );
1962 - // $j( '#mwe-upwiz-stepdiv-deeds' ).disableNextButton();
 1979+ _this.moveToStep('details');
 1980+ }
19631981 } );
19641982
1965 - /*
1966 - // XXX figure out some way to make them ready / unready
1967 - // timeout after input, check for readiness, then trigger event?
1968 - $j( _this.deedChooser ).bind( 'isReady', function() {
1969 - $j( '#mwe-upwiz-stepdiv-deeds' ).enableNextButton();
1970 - } );
19711983
1972 - $j( _this.deedChooser ).bind( 'isNotReady', function() {
1973 - $j( '#mwe-upwiz-stepdiv-deeds' ).disableNextButton();
1974 - } );
1975 -*/
1976 -
1977 -
19781984 // DETAILS div
 1985+
19791986 $j( '#mwe-upwiz-stepdiv-details .mwe-upwiz-button-next' ).click( function() {
19801987 _this.detailsSubmit( function() {
19811988 _this.prefillThanksPage();
19821989 _this.moveToStep('thanks');
19831990 } );
19841991 } );
 1992+
 1993+
19851994
1986 - // add one to start
 1995+ // WIZARD
 1996+
 1997+ // add one upload field to start (this is the big one that asks you to upload something)
19871998 var upload = _this.newUpload( '#mwe-upwiz-add-file' );
19881999
19892000 // "select" the first step - highlight, make it visible, hide all others
@@ -2086,12 +2097,7 @@
20872098 _this.updateFileCounts();
20882099
20892100 upload.deedPreview = new mw.UploadWizardDeedPreview( upload );
2090 -
2091 - // this will modify upload, so it has a .deedChooser property.
2092 - // We use a method to so we notify deedChooser that it has a new upload -- interface
2093 - // will change based on quantity etc. Maybe we could be clever with bind here.
2094 - _this.deedChooser.attach( upload );
2095 -
 2101+
20962102 // set up details
20972103 upload.details = new mw.UploadWizardDetails( upload, $j( '#mwe-upwiz-macro-files' ));
20982104 },
@@ -2108,9 +2114,6 @@
21092115 removeUpload: function( upload ) {
21102116 var _this = this;
21112117 $j( upload ).unbind(); // everything
2112 - if ( upload.deedChooser ) {
2113 - upload.deedChooser.detach( upload );
2114 - }
21152118 upload.details.div.remove();
21162119 upload.thanksDiv.remove();
21172120
@@ -2421,116 +2424,294 @@
24222425 };
24232426
24242427 mw.UploadWizardNullDeed = $j.extend( new mw.UploadWizardDeed(), {
2425 - isReady: function() { return false; },
 2428+ validate: function() {
 2429+ alert( gM( 'mwe-upwiz-deeds-need-deed', _this.uploads.length ) );
 2430+ return false;
 2431+ }
 2432+} );
24262433
2427 - setQuantity: function() { return; },
 2434+
 2435+/**
 2436+ * Set up the form and deed object for the deed option that says these uploads are all the user's own work.
 2437+ */
 2438+mw.UploadWizardDeedOwnWork = function( uploadCount ) {
 2439+ uploadCount = uploadCount ? uploadCount : 1;
24282440
2429 - showValidationTips: function() {
2430 - alert( gM( 'mwe-upwiz-deeds-need-deed', _this.uploads.length ) );
 2441+ var _this = new mw.UploadWizardDeed();
 2442+
 2443+ _this.authorInput = $j( '<input />')
 2444+ .attr( { name: "author" } )
 2445+ .addClass( 'mwe-upwiz-sign' );
 2446+
 2447+ var licenseInputDiv = $j( '<div class="mwe-upwiz-deed-license"></div>' );
 2448+ _this.licenseInput = new mw.UploadWizardLicenseInput( licenseInputDiv );
 2449+ _this.licenseInput.setDefaultValues();
 2450+
 2451+ var $standardCheckbox, $customCheckbox;
 2452+
 2453+ $standardCheckbox = $j( '<input type="checkbox" class="mwe-accept-deed mwe-checkbox-hang-indent" />' ).click( function() {
 2454+ if ( $j( this ).is( ':checked' ) ) {
 2455+ $customCheckbox.attr( 'checked', false );
 2456+ _this.licenseInput.setDefaultValues();
 2457+ }
 2458+ } );
 2459+
 2460+ $customCheckbox = $j( '<input type="checkbox" class="mwe-accept-deed mwe-checkbox-hang-indent" />' ).click( function() {
 2461+ if ( $j( this ).is( ':checked' ) ) {
 2462+ $standardCheckbox.attr( 'checked', false );
 2463+ }
 2464+ } );
 2465+
 2466+ var $standardDiv = $j( '<div />' ).append(
 2467+ $standardCheckbox,
 2468+
 2469+ $j( '<p class="mwe-checkbox-hang-indent-text"/>' )
 2470+ .html( gM( 'mwe-upwiz-source-ownwork-assert',
 2471+ uploadCount,
 2472+ '<input name="author" class="mwe-upwiz-sign" />' )
 2473+ ),
 2474+
 2475+ $j( '<p class="mwe-checkbox-hang-indent-text mwe-small-print" />' ).html(
 2476+ gM ( 'mwe-upwiz-source-ownwork-assert-note' )
 2477+ )
 2478+ );
 2479+
 2480+ var $toggleDiv = $j('<div />');
 2481+
 2482+ var $customDiv = $j('<div/>').append(
 2483+ $customCheckbox,
 2484+
 2485+ $j( '<p class="mwe-checkbox-hang-indent-text" />' )
 2486+ .html( gM( 'mwe-upwiz-source-ownwork-assert-custom',
 2487+ uploadCount,
 2488+ '<span class="mwe-custom-author-input"></span>' ) ),
 2489+
 2490+ licenseInputDiv
 2491+ );
 2492+
 2493+ _this.$formFields = $j( '<div class="mwe-upwiz-deed-form-internal" />' ).append(
 2494+ $standardDiv, $toggleDiv, $customDiv
 2495+ );
 2496+
 2497+ mw.UploadWizardUtil.makeFadingToggler( $standardDiv, $toggleDiv, $customDiv );
 2498+
 2499+ // if they select 'fewer options', and they have selected the deed in there, we should unselect it
 2500+ $toggleDiv.bind( 'close', function(e) {
 2501+ e.stopPropagation();
 2502+ if ( $customCheckbox.is( ':checked' ) ) {
 2503+ $customCheckbox.attr( 'checked', false );
 2504+ }
 2505+ } );
 2506+
 2507+ // have to add the author input this way -- gM() will flatten it to a string and we'll lose it as a dom object
 2508+ _this.$formFields.find( '.mwe-custom-author-input' ).append( _this.authorInput );
 2509+
 2510+ // synchronize both username signatures
 2511+ // set initial value to configured username
 2512+ // if one changes all the others change (keyup event)
 2513+ //
 2514+ // also set tooltips ( the title, tipsy() )
 2515+ _this.$formFields.find( '.mwe-upwiz-sign' )
 2516+ .attr( {
 2517+ title: gM( 'mwe-upwiz-tooltip-sign' ),
 2518+ value: mw.getConfig( 'userName' )
 2519+ } )
 2520+ .tipsyPlus()
 2521+ .keyup( function() {
 2522+ var thisInput = this;
 2523+ var thisVal = $j( thisInput ).val();
 2524+ $j.each( $j( '.mwe-upwiz-sign' ), function( i, input ) {
 2525+ if (thisInput !== input) {
 2526+ $j( input ).val( thisVal );
 2527+ }
 2528+ } );
 2529+ } );
 2530+
 2531+ return $j.extend( _this, {
 2532+
 2533+ name: 'ownwork',
 2534+
 2535+ /**
 2536+ * Is this correctly set, with side effects of causing errors to show in interface.
 2537+ * @return boolean true if valid, false if not
 2538+ */
 2539+ validate: function() {
 2540+ return (
 2541+ ( $j( _this.selector ).find( '.mwe-accept-deed' ).is( ':checked' ) !== 0 )
 2542+ &&
 2543+ licenseInput.isSet()
 2544+ );
 2545+ },
 2546+
 2547+ getSourceWikiText: function() {
 2548+ return '{{own}}';
 2549+ },
 2550+
 2551+ getAuthorWikiText: function() {
 2552+ return "[[User:" + mw.getConfig('userName') + '|' + $j( authorInput ).val() + ']]';
 2553+ },
 2554+
 2555+
 2556+ getLicenseWikiText: function() {
 2557+ var wikiText = '{{self';
 2558+ $j.each( licenseInput.getTemplates(), function( i, template ) {
 2559+ wikiText += '|' + template;
 2560+ } );
 2561+ wikiText += '}}';
 2562+ return wikiText;
 2563+ }
 2564+
 2565+ } );
 2566+
 2567+};
 2568+
 2569+
 2570+mw.UploadWizardDeedThirdParty = function( uploadCount ) {
 2571+ uploadCount = uploadCount ? uploadCount : 1;
 2572+
 2573+ var _this = new mw.UploadWizardDeed();
 2574+
 2575+ _this.sourceInput = $j('<textarea class="mwe-source mwe-long-textarea" name="source" rows="1" cols="40"></textarea>' )
 2576+ .growTextArea()
 2577+ .attr( 'title', gM( 'mwe-upwiz-tooltip-source' ) )
 2578+ .tipsyPlus();
 2579+ _this.authorInput = $j('<textarea class="mwe-author mwe-long-textarea" name="author" rows="1" cols="40"></textarea>' )
 2580+ .growTextArea()
 2581+ .attr( 'title', gM( 'mwe-upwiz-tooltip-author' ) )
 2582+ .tipsyPlus();
 2583+ licenseInputDiv = $j( '<div class="mwe-upwiz-deed-license"></div>' );
 2584+ _this.licenseInput = new mw.UploadWizardLicenseInput( licenseInputDiv );
 2585+ _this.licenseInput.setDefaultValues();
 2586+
 2587+ _this.$formFields = $j( '<div class="mwe-upwiz-deed-form-internal"/>' );
 2588+
 2589+ if ( uploadCount > 1 ) {
 2590+ _this.$formFields.append( $j( '<div />' ).append( gM( 'mwe-upwiz-source-thirdparty-custom-multiple-intro' ) ) );
24312591 }
2432 -} );
24332592
 2593+ _this.$formFields.append (
 2594+ $j( '<div class="mwe-upwiz-source-thirdparty-custom-multiple-intro" />' ),
 2595+ $j( '<div class="mwe-upwiz-thirdparty-fields" />' )
 2596+ .append( $j( '<label for="source"/>' ).text( gM( 'mwe-upwiz-source' ) ),
 2597+ _this.sourceInput ),
 2598+ $j( '<div class="mwe-upwiz-thirdparty-fields" />' )
 2599+ .append( $j( '<label for="author"/>' ).text( gM( 'mwe-upwiz-author' ) ),
 2600+ _this.authorInput ),
 2601+ $j( '<div class="mwe-upwiz-thirdparty-license" />' )
 2602+ .append( gM( 'mwe-upwiz-source-thirdparty-license', uploadCount ) ),
 2603+ licenseInputDiv
 2604+ );
24342605
 2606+ return $j.extend( _this, mw.UploadWizardDeed.prototype, {
 2607+ name: 'thirdparty',
24352608
 2609+ validate: function() {
 2610+ return (! mw.isEmpty( $j( this.sourceInput ).val() ) )
 2611+ && (! mw.isEmpty( $j( this.authorInput ).val() ) )
 2612+ && this.licenseInput.isSet()
 2613+ }
 2614+ } );
 2615+}
24362616
24372617
 2618+
 2619+
24382620 /**
24392621 * @param selector where to put this deed chooser
24402622 * @param isPlural whether this chooser applies to multiple files (changes messaging mostly)
24412623 */
2442 -mw.UploadWizardDeedChooser = function( selector ) {
 2624+mw.UploadWizardDeedChooser = function( selector, deeds, uploadCount ) {
24432625 var _this = this;
2444 - _this.selector = selector;
2445 - _this.deed = mw.UploadWizardNullDeed;
 2626+ _this.$selector = $j( selector );
 2627+ _this.uploadCount = uploadCount ? uploadCount : 1;
 2628+
24462629
2447 - items = [];
2448 - $j.each( [ 'ownwork', 'thirdparty' ], function (i, key) {
2449 - var item =
2450 - '<div class="mwe-upwiz-macro-deed-' + key + ' mwe-upwiz-deed">'
 2630+ _this.$selector.append( '<div class="mwe-error"></div>' );
 2631+
 2632+ // name for radio button set
 2633+ _this.name = 'deedChooser' + (mw.UploadWizardDeedChooser.prototype.widgetCount++).toString();
 2634+
 2635+ $j.each( deeds, function (i, deed) {
 2636+ var id = _this.name + '-' + deed.name;
 2637+
 2638+ var $deedInterface = $j(
 2639+ '<div class="mwe-upwiz-deed mwe-upwiz-deed-' + deed.name + '">'
24512640 + '<div class="mwe-upwiz-deed-option-title">'
2452 - + '<span class="mwe-upwiz-deed-header mwe-closed">'
2453 - + '<a class="mwe-upwiz-deed-header-link mwe-upwiz-deed-name"></a>'
 2641+ + '<span class="mwe-upwiz-deed-header">'
 2642+ + '<input id="' + id +'" name="' + _this.name + '" type="radio" value="' + deed.name + '">'
 2643+ + '<label for="' + id + '" class="mwe-upwiz-deed-name">'
 2644+ + gM( 'mwe-upwiz-source-' + deed.name, _this.uploadCount )
 2645+ + '</label>'
 2646+ + '</input>'
24542647 + '</span>'
2455 - + '<span class="mwe-upwiz-deed-header mwe-open" style="display: none;">'
2456 - + '<span class="mwe-upwiz-deed-name"></span>'
2457 - + ' <a class="mwe-upwiz-macro-deeds-return">' + gM( 'mwe-upwiz-change' ) + '</a>'
2458 - + '</span>'
 2648+ // + ' <a class="mwe-upwiz-macro-deeds-return">' + gM( 'mwe-upwiz-change' ) + '</a>'
24592649 + '</div>'
2460 - + '<div class="mwe-upwiz-deed-form"></div>'
 2650+ + '<div class="mwe-upwiz-deed-form">'
24612651 + '</div>'
2462 - items.push(item);
2463 - } );
 2652+ );
24642653
2465 - $j( selector ).html( items.join('') );
 2654+ var $deedSelector = _this.$selector.append( $deedInterface );
24662655
 2656+ $deedInterface.find( '.mwe-upwiz-deed-form' ).append( deed.$formFields );
 2657+
 2658+ $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).click( function() {
 2659+ if ( $j( this ).is(':checked' ) ) {
 2660+ _this.choose( deed );
 2661+ _this.showDeed( $deedInterface );
 2662+ }
 2663+ } );
 2664+
 2665+ } );
 2666+
 2667+ /*
24672668 $j( '.mwe-upwiz-macro-deeds-return' ).click( function() {
24682669 _this.choose( mw.UploadWizardNullDeed );
24692670 _this.showDeedChoice();
24702671 } );
 2672+ */
24712673
24722674 _this.choose( mw.UploadWizardNullDeed );
24732675 _this.showDeedChoice();
24742676
2475 - // set up the deed interfaces
2476 - _this.deeds = {
2477 - 'ownwork' : _this.setupDeedOwnWork(),
2478 - 'thirdparty' : _this.setupDeedThirdParty()
2479 - };
24802677
2481 - _this.setQuantity();
24822678 };
24832679
24842680
24852681 mw.UploadWizardDeedChooser.prototype = {
24862682
2487 - isReady: function() {
2488 - return ( typeof this.deed !== 'undefined' && this.deed.isReady() );
2489 - },
 2683+ /**
 2684+ * How many deed choosers there are (important for creating unique ids, element names)
 2685+ */
 2686+ widgetCount: 0,
24902687
2491 - count: 0,
2492 -
2493 - attach: function( upload ) {
2494 - var _this = this;
2495 - upload.deedChooser = _this;
2496 - _this.count++;
2497 - _this.setQuantity();
2498 - },
2499 -
2500 - detach: function( upload ) {
2501 - _this.count--;
2502 - _this.setQuantity();
2503 - },
2504 -
2505 - // modify various interface strings depending on singular, multiple deeds
2506 - // XXX use PLURAL when possible
2507 - setQuantity: function() {
2508 - var _this = this;
2509 - mw.log( "setting quantity of deed to " + _this.count );
2510 - $j.each( [ 'ownwork', 'thirdparty' ], function (i, key) {
2511 -
2512 - // fix the deed title that opens and closes
2513 - $j( _this.selector )
2514 - .find( '.mwe-upwiz-macro-deed-' + key)
2515 - .find( '.mwe-upwiz-deed-name' )
2516 - .html( gM( 'mwe-upwiz-source-' + key, _this.count ) );
2517 -
2518 - // any other internal strings in the deed
2519 - if ( _this.deeds[key] ) {
2520 - _this.deeds[key].setQuantity( _this.count );
 2688+ /**
 2689+ * Check if this form is filled out correctly, with side effects of showing error messages if invalid
 2690+ * @return boolean; true if valid, false if not
 2691+ */
 2692+ validate: function() {
 2693+ var valid = (typeof this.deed === 'undefined') || this.deed.validate();
 2694+ if (!valid) {
 2695+ if ( ( typeof this.deed === 'undefined' ) || this.deed === mw.UploadWizardNullDeed ) { /* highlight the main choices */
 2696+ /* this.selector.find( 'input[type=checkbox]. .mwe-/* add general select-a-deed message */
 2697+ alert( "no deed selected" );
25212698 }
2522 -
2523 - } );
2524 - $j( _this ).trigger( 'setQuantityEvent' );
2525 -
 2699+ }
 2700+ return valid;
25262701 },
25272702
 2703+ /**
 2704+ * How many uploads this deed controls
 2705+ */
 2706+ uploadCount: 0,
 2707+
 2708+
25282709 choose: function( deed ) {
25292710 var _this = this;
25302711 _this.deed = deed;
25312712 if ( deed === mw.UploadWizardNullDeed ) {
25322713 $j( _this ).trigger( 'chooseNullDeed' );
25332714 //_this.trigger( 'isNotReady' );
2534 - $j( _this.selector )
 2715+ _this.$selector
25352716 .find( 'input.mwe-accept-deed' )
25362717 .attr( 'checked', false )
25372718 } else {
@@ -2540,285 +2721,37 @@
25412722
25422723 /**
25432724 * Go back to original source choice.
2544 - * Assumed that we are in details mode.
25452725 */
25462726 showDeedChoice: function() {
2547 - var _this = this;
2548 - $j( _this.selector ).find( '.mwe-upwiz-deed-header.mwe-open' ).hide();
2549 - $j( _this.selector ).find( '.mwe-upwiz-deed-header.mwe-closed' ).show();
2550 - $j( _this.selector ).find( '.mwe-upwiz-deed' ).maskSafeShow();
2551 - $j( _this.selector ).find( '.mwe-upwiz-deed-form' ).maskSafeHide();
2552 - },
 2727+ var $allDeeds = this.$selector.find( '.mwe-upwiz-deed' );
 2728+ this.deselectDeed( $allDeeds );
 2729+ // $allDeeds.fadeTo( 'fast', 1.0 ); //maskSafeShow();
 2730+ },
25532731
2554 - /**
2555 - * From the deed choice page, show a particular deed
 2732+ /**
 2733+ * From the deed choices, make a choice fade to the background a bit, hide the extended form
25562734 */
2557 - showDeed: function( deedSelector ) {
2558 - $j( deedSelector ).find( '.mwe-upwiz-deed-header.mwe-open' ).show();
2559 - $j( deedSelector ).find( '.mwe-upwiz-deed-header.mwe-closed' ).hide();
2560 - $j( deedSelector ).siblings().maskSafeHide();
2561 - $j( deedSelector ).find( '.mwe-upwiz-deed-form' ).maskSafeShow();
 2735+ deselectDeed: function( $deedSelector ) {
 2736+ $deedSelector.removeClass( 'selected' );
 2737+ // $deedSelector.find( 'a.mwe-upwiz-macro-deeds-return' ).hide();
 2738+ $deedSelector.find( '.mwe-upwiz-deed-form' ).slideUp( 500 ); //.maskSafeHide();
25622739 },
2563 -
 2740+
25642741 /**
2565 - * Set up the form and deed object for the deed option that says these uploads are all the user's own work.
 2742+ * From the deed choice page, show a particular deed
25662743 */
2567 - setupDeedOwnWork: function() {
2568 - mw.log("setupdeed own work");
2569 - var _this = this;
 2744+ showDeed: function( $deedSelector ) {
 2745+ var $otherDeeds = $deedSelector.siblings().filter( '.mwe-upwiz-deed' );
 2746+ this.deselectDeed( $otherDeeds );
 2747+ // $siblings.fadeTo( 'fast', 0.5 ) // maskSafeHide();
25702748
2571 - var authorInput = $j( '<input />')
2572 - .attr( { name: "author" } )
2573 - .addClass( 'mwe-upwiz-sign' );
2574 -
2575 - var licenseInputDiv = $j( '<div class="mwe-upwiz-deed-license"></div>' );
2576 - var licenseInput = new mw.UploadWizardLicenseInput( licenseInputDiv );
2577 - licenseInput.setDefaultValues();
2578 -
2579 - var ownWorkDeed = $j.extend( new mw.UploadWizardDeed(), {
2580 -
2581 - licenseInput: licenseInput,
2582 -
2583 - isReady: function() {
2584 - return (
2585 - ( $j( _this.selector ).find( '.mwe-accept-deed' ).is( ':checked' ) !== 0 )
2586 - &&
2587 - licenseInput.isSet()
2588 - );
2589 - },
2590 -
2591 - getSourceWikiText: function() {
2592 - return '{{own}}';
2593 - },
2594 -
2595 - getAuthorWikiText: function() {
2596 - return "[[User:" + mw.getConfig('userName') + '|' + $j( authorInput ).val() + ']]';
2597 - },
2598 -
2599 -
2600 - getLicenseWikiText: function() {
2601 - var wikiText = '{{self';
2602 - $j.each ( licenseInput.getTemplates(), function( i, template ) {
2603 - wikiText += '|' + template;
2604 - } );
2605 - wikiText += '}}';
2606 - return wikiText;
2607 - },
2608 -
2609 - createInterface: function( deedChooser ) {
2610 - var _this = this;
2611 - _this.deedChooser = deedChooser;
2612 -
2613 - var standardDiv = $j( '<div />' )
2614 - .append(
2615 - $j( '<input />')
2616 - .attr( { type: 'checkbox' } )
2617 - .click( function() {
2618 - if ( $j( this ).is( ':checked' ) ) {
2619 - $j( deedChooser.selector )
2620 - .find( '.mwe-upwiz-deed-accept-ownwork-custom' )
2621 - .attr( 'checked', false );
2622 - _this.licenseInput.setDefaultValues();
2623 - deedChooser.choose( ownWorkDeed );
2624 - } else {
2625 - deedChooser.choose( mw.UploadWizardNullDeed );
2626 - }
2627 - } )
2628 - .addClass( 'mwe-upwiz-deed-accept-ownwork-default mwe-accept-deed mwe-checkbox-hang-indent' ),
2629 -
2630 - // text added in setQuantit
2631 - $j( '<p class="mwe-upwiz-source-ownwork-assert mwe-checkbox-hang-indent-text"/>' ),
2632 -
2633 - $j( '<p />' )
2634 - .addClass( 'mwe-checkbox-hang-indent-text' )
2635 - .addClass( 'mwe-small-print' )
2636 - .html( gM ( 'mwe-upwiz-source-ownwork-assert-note' ) )
2637 - );
2638 -
2639 - var toggleDiv = $j('<div />');
2640 -
2641 - var customDiv = $j('<div/>')
2642 - .append(
2643 - $j( '<input />')
2644 - .attr( { type: 'checkbox' } )
2645 - .click( function() {
2646 - if ( $j( this ).is( ':checked' ) ) {
2647 - $j( deedChooser.selector )
2648 - .find( '.mwe-upwiz-deed-accept-ownwork-default' )
2649 - .attr( 'checked', false )
2650 - deedChooser.choose( ownWorkDeed );
2651 - } else {
2652 - deedChooser.choose( mw.UploadWizardNullDeed );
2653 - }
2654 - } )
2655 - .addClass( 'mwe-upwiz-deed-accept-ownwork-custom mwe-accept-deed mwe-checkbox-hang-indent' ),
2656 - $j( '<p class="mwe-upwiz-source-ownwork-assert-custom mwe-checkbox-hang-indent-text" />' ),
2657 - licenseInputDiv
2658 - );
2659 -
2660 - $j( deedChooser.selector ).find( '.mwe-upwiz-macro-deed-ownwork .mwe-upwiz-deed-form' )
2661 - .append( $j( '<div class="mwe-upwiz-deed-form-internal" />' )
2662 - .append( standardDiv,
2663 - toggleDiv,
2664 - customDiv )
2665 - );
2666 -
2667 -
2668 -
2669 - mw.UploadWizardUtil.makeFadingToggler( standardDiv, toggleDiv, customDiv );
2670 -
2671 - // if they select 'fewer options', and they have selected the deed in there, we should unselect it
2672 - $j( toggleDiv ).bind( 'close', function(e) {
2673 - e.stopPropagation();
2674 - if ( $j( deedChooser.selector ).find( '.mwe-upwiz-deed-accept-ownwork-custom' ).is( ':checked' ) ) {
2675 - $j( deedChooser.selector )
2676 - .find( '.mwe-upwiz-deed-accept-ownwork-custom' )
2677 - .attr( 'checked', false );
2678 - deedChooser.choose( mw.UploadWizardNullDeed );
2679 - }
2680 - } );
2681 -
2682 - _this.count = 1;
2683 - _this.setQuantity();
2684 -
2685 -
2686 - },
2687 -
2688 -
2689 - setQuantity: function() {
2690 - var _this = this;
2691 - $j( _this.deedChooser.selector )
2692 - .find( 'p.mwe-upwiz-source-ownwork-assert' )
2693 - .html( gM( 'mwe-upwiz-source-ownwork-assert',
2694 - _this.count,
2695 - '<input name="author" class="mwe-upwiz-sign" />' )
2696 - );
2697 -
2698 - $j( _this.deedChooser.selector )
2699 - .find( 'p.mwe-upwiz-source-ownwork-assert-custom' )
2700 - .html( gM( 'mwe-upwiz-source-ownwork-assert-custom',
2701 - _this.count,
2702 - '<span class="mwe-custom-author-input"></span>' ) );
2703 -
2704 - // have to add the author input this way -- gM() will flatten it to a string and we'll lose it as a dom object
2705 - $j( _this.deedChooser.selector ).find( '.mwe-custom-author-input' ).append( authorInput );
2706 -
2707 - // synchronize both username signatures
2708 - // set initial value to configured username
2709 - // if one changes all the others change (keyup event)
2710 - //
2711 - // also set tooltips ( the title, tipsy() )
2712 - $j( _this.deedChooser.selector ).find( '.mwe-upwiz-sign' )
2713 - .attr( {
2714 - title: gM( 'mwe-upwiz-tooltip-sign' ),
2715 - value: mw.getConfig( 'userName' )
2716 - } )
2717 - .tipsyPlus()
2718 - .keyup( function() {
2719 - var thisInput = this;
2720 - var thisVal = $j( thisInput ).val();
2721 - $j.each( $j( '.mwe-upwiz-sign' ), function( i, input ) {
2722 - if (thisInput !== input) {
2723 - $j( input ).val( thisVal );
2724 - }
2725 - } );
2726 - } );
2727 -
2728 -
2729 - }
2730 - } );
2731 -
2732 - ownWorkDeed.createInterface( _this );
2733 -
2734 - $j( _this.selector ).find( '.mwe-upwiz-macro-deed-ownwork .mwe-upwiz-deed-header-link').click(
2735 - function() {
2736 - _this.showDeed( $j( _this.selector ).find( '.mwe-upwiz-macro-deed-ownwork' ) );
2737 - }
2738 - );
2739 -
2740 - return ownWorkDeed;
2741 -
 2749+ $deedSelector
 2750+ .addClass('selected')
 2751+ .fadeTo( 'fast', 1.0 )
 2752+ .find( '.mwe-upwiz-deed-form' ).slideDown( 500 ); // maskSafeShow();
 2753+ // $deedSelector.find( 'a.mwe-upwiz-macro-deeds-return' ).show();
27422754 },
27432755
2744 - setupDeedThirdParty: function() {
2745 - var _this = this;
2746 - var sourceInput = $j('<textarea class="mwe-source mwe-long-textarea" name="source" rows="1" cols="40"></textarea>' )
2747 - .growTextArea()
2748 - .attr( 'title', gM( 'mwe-upwiz-tooltip-source' ) )
2749 - .tipsyPlus();
2750 - var authorInput = $j('<textarea class="mwe-author mwe-long-textarea" name="author" rows="1" cols="40"></textarea>' )
2751 - .growTextArea()
2752 - .attr( 'title', gM( 'mwe-upwiz-tooltip-author' ) )
2753 - .tipsyPlus();
2754 - licenseInputDiv = $j( '<div class="mwe-upwiz-deed-license"></div>' );
2755 - licenseInput = new mw.UploadWizardLicenseInput( licenseInputDiv );
2756 - licenseInput.setDefaultValues();
2757 -
2758 - var thirdPartyDeed = $j.extend( new mw.UploadWizardDeed(), {
2759 - sourceInput: sourceInput,
2760 - authorInput: authorInput,
2761 - licenseInput: licenseInput,
2762 -
2763 - isReady: function() {
2764 - return (! mw.isEmpty( $j( this.sourceInput ).val() ) )
2765 - && (! mw.isEmpty( $j( this.authorInput ).val() ) )
2766 - && this.licenseInput.isSet()
2767 - },
2768 -
2769 - createInterface: function( deedChooser ) {
2770 - var _this = this;
2771 - _this.deedChooser = deedChooser;
2772 -
2773 - $j( deedChooser.selector ).find( '.mwe-upwiz-macro-deed-thirdparty .mwe-upwiz-deed-form' ).append(
2774 - $j( '<div class="mwe-upwiz-deed-form-internal"/>' )
2775 - .append(
2776 - $j( '<div class="mwe-upwiz-source-thirdparty-custom-multiple-intro" />' ),
2777 - $j( '<div class="mwe-upwiz-thirdparty-fields" />' )
2778 - .append( $j( '<label for="source"/>' ).text( gM( 'mwe-upwiz-source' ) ),
2779 - sourceInput ),
2780 - $j( '<div class="mwe-upwiz-thirdparty-fields" />' )
2781 - .append( $j( '<label for="author"/>' ).text( gM( 'mwe-upwiz-author' ) ),
2782 - authorInput ),
2783 - $j( '<div class="mwe-upwiz-thirdparty-license" />' ),
2784 - licenseInputDiv
2785 - )
2786 - );
2787 -
2788 - _this.count = 1;
2789 - _this.setQuantity();
2790 -
2791 - },
2792 -
2793 - setQuantity: function() {
2794 - var _this = this;
2795 - $j( _this.deedChooser.selector )
2796 - .find( 'div.mwe-upwiz-source-thirdparty-custom-multiple-intro' )
2797 - .html( _this.count > 1 ? gM( 'mwe-upwiz-source-thirdparty-custom-multiple-intro' ) : '' );
2798 -
2799 - $j( _this.deedChooser.selector )
2800 - .find( 'div.mwe-upwiz-thirdparty-license' )
2801 - .text( gM( 'mwe-upwiz-source-thirdparty-license', _this.count ) );
2802 - },
2803 -
2804 - showValidationTips: function() {
2805 - // TBD
2806 - }
2807 -
2808 -
2809 - } );
2810 -
2811 - thirdPartyDeed.createInterface( _this );
2812 -
2813 - // set up the header
2814 - $j( _this.selector ).find( '.mwe-upwiz-macro-deed-thirdparty .mwe-upwiz-deed-header-link').click(
2815 - function() {
2816 - _this.showDeed( $j( _this.selector ).find( '.mwe-upwiz-macro-deed-thirdparty' ) );
2817 - _this.choose( thirdPartyDeed );
2818 - }
2819 - );
2820 -
2821 - return thirdPartyDeed;
2822 - }
28232756 };
28242757
28252758
@@ -2976,6 +2909,7 @@
29772910 };
29782911
29792912
 2913+
29802914 /**
29812915 * jQuery extension. Makes a textarea automatically grow if you enter overflow
29822916 * (This feature was in the old Commons interface with a confusing arrow icon; it's nicer to make it automatic.)
@@ -3091,7 +3025,6 @@
30923026 return this.css( { 'height' : '0px', 'overflow' : 'hidden' } );
30933027 };
30943028
3095 -// XXX check overflow properties, is auto/auto not the right thing?
30963029 // may be causing scrollbar to appear when div changes size
30973030 // re-enable form fields (disabled so we did not tab through them when hidden)
30983031 jQuery.fn.maskSafeShow = function( options ) {

Status & tagging log