r86594 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86593‎ | r86594 | r86595 >
Date:05:12, 21 April 2011
Author:neilk
Status:ok (Comments)
Tags:
Comment:
in order to fix description page errors we may want to just drop the associated uploads. This makes deleting uploads work on pages that are not the first upload page; to prove that we fix bug 24762, add bail options if no license is acceptable
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
@@ -174,6 +174,11 @@
175175 'licenses' => array(
176176 'fal'
177177 )
 178+ ),
 179+ array(
 180+ 'head' => 'mwe-upwiz-license-none-applicable-head',
 181+ 'subhead' => 'mwe-upwiz-license-none-applicable-subhead',
 182+ 'special' => 'delete'
178183 )
179184 ),
180185 'defaults' => array(),
Index: trunk/extensions/UploadWizard/UploadWizardHooks.php
@@ -298,6 +298,11 @@
299299 'mwe-upwiz-license-public-domain-subhead',
300300 'mwe-upwiz-license-usgov-head',
301301 'mwe-upwiz-license-misc',
 302+ 'mwe-upwiz-license-custom-head',
 303+ 'mwe-upwiz-license-custom-subhead',
 304+ 'mwe-upwiz-license-none-applicable-head',
 305+ 'mwe-upwiz-license-none-applicable-subhead',
 306+ 'mwe-upwiz-license-none-applicable',
302307 'mwe-upwiz-categories',
303308 'mwe-upwiz-categories-add',
304309 'mwe-upwiz-category-remove',
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -245,6 +245,15 @@
246246 'mwe-upwiz-license-usgov-head' => '{{PLURAL:$1|This work was|These works were}} made by the United States government',
247247 'mwe-upwiz-license-misc' => 'Miscellaneous reasons',
248248
 249+ 'mwe-upwiz-license-custom-head' => 'Experts only: enter the code for a license not shown here',
 250+ 'mwe-upwiz-license-custom-subhead' => 'Enter wikitext that will add a license template to your uploads.',
 251+
 252+ 'mwe-upwiz-license-none-applicable-head' => 'I don\'t know if any of the above choices apply or not! Help!',
 253+ 'mwe-upwiz-license-none-applicable-subhead' => 'If you aren\'t absolutely sure what the intentions of the original author were then please do not upload {{PLURAL:$1|this file|these files}} to {{SITENAME}}. Press the button below to abandon {{PLURAL:$1|this upload|these uploads}} -- don\'t worry, nothing\'s been published yet.',
 254+
 255+ 'mwe-upwiz-license-none-applicable' => 'Abandon {{PLURAL:$1|this upload|these uploads}} without publishing',
 256+
 257+
249258 'mwe-upwiz-categories' => 'Categories',
250259 'mwe-upwiz-categories-add' => 'Add',
251260 'mwe-upwiz-category-remove' => 'Remove this category',
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js
@@ -290,14 +290,14 @@
291291
292292 /**
293293 * Interface widget to choose among various deeds -- for instance, if own work, or not own work, or other such cases.
294 - * @param selector where to put this deed chooser
295 - * @param deeds Array of UploadWizardDeed
296 - * @param uploadCount whether this chooser applies to multiple files (changes messaging mostly)
 294+ * @param {String|jQuery} selector where to put this deed chooser
 295+ * @param {Array[UploadWizardDeed]} deeds
 296+ * @param {Array[UploadWizardUpload]} uploads that this applies to (this is just to make deleting and plurals work)
297297 */
298 -mw.UploadWizardDeedChooser = function( selector, deeds, uploadCount ) {
 298+mw.UploadWizardDeedChooser = function( selector, deeds, uploads ) {
299299 var _this = this;
300300 _this.$selector = $j( selector );
301 - _this.uploadCount = uploadCount ? uploadCount : 1;
 301+ _this.uploads = mw.isDefined( uploads ) ? uploads : [];
302302
303303
304304 _this.$errorEl = $j( '<div class="mwe-error"></div>' );
@@ -315,7 +315,7 @@
316316 + '<span class="mwe-upwiz-deed-header">'
317317 + '<input id="' + id +'" name="' + _this.name + '" type="radio" value="' + deed.name + ' /">'
318318 + '<label for="' + id + '" class="mwe-upwiz-deed-name">'
319 - + gM( 'mwe-upwiz-source-' + deed.name, _this.uploadCount )
 319+ + gM( 'mwe-upwiz-source-' + deed.name, _this.uploads.length )
320320 + '</label>'
321321 + '</span>'
322322 + '</div>'
@@ -342,6 +342,10 @@
343343 // set the "value" to be the null deed; which will cause an error if the data is submitted.
344344 _this.choose( mw.UploadWizardNullDeed );
345345
 346+ // set the "delete associated upload" option, if available
 347+ // this has a somewhat nasty & twisted dependency on the licenses config, since if you enable the 'special delete'
 348+ // option there, you have to remember to pass a deleter here
 349+ _this.bindDeleter();
346350 };
347351
348352
@@ -366,7 +370,7 @@
367371 _this.hideError();
368372 } else {
369373 if ( _this.deed === mw.UploadWizardNullDeed ) {
370 - _this.showError( gM( 'mwe-upwiz-deeds-need-deed', _this.uploadCount ) );
 374+ _this.showError( gM( 'mwe-upwiz-deeds-need-deed', _this.uploads.length ) );
371375 $j( _this ).bind( 'chooseDeed', function() {
372376 _this.hideError();
373377 } );
@@ -386,9 +390,9 @@
387391 },
388392
389393 /**
390 - * How many uploads this deed controls
 394+ * Uploads this deed controls
391395 */
392 - uploadCount: 0,
 396+ uploads: [],
393397
394398
395399 // XXX it's impossible to choose the null deed if we stick with radio buttons, so that may be useless later
@@ -442,8 +446,35 @@
443447
444448 remove: function() {
445449 this.$selector.html('');
 450+ },
 451+
 452+ /**
 453+ * This is a bit of a hack -- originally deeds were not supposed to know what uploads they applied to,
 454+ * the associated upload would just read that data when it needed to, or rebind itself on the fly.
 455+ * Unfortunately it's starting to become a bit messed up; to make deleting work, now the deeds know about the uploads,
 456+ * and the uploads know about the deeds. Really ought to be that there is some channel of communication that the uploads
 457+ * listen to, which could include a 'delete yourself' event.
 458+ * So, what this does:
 459+ * In the event that our license config includes the "special" item for i-don't-know-what-the-license-is,
 460+ * this will create a button there that deletes all the associated uploads.
 461+ */
 462+ bindDeleter: function() {
 463+ var deedChooser = this;
 464+ $j( deedChooser.$selector.find( '.mwe-upwiz-license-special-delete' ) ).each( function() {
 465+ $j( this ).append(
 466+ $j( '<button></button>' )
 467+ .attr( 'type', 'button' )
 468+ .msg( 'mwe-upwiz-license-none-applicable', deedChooser.uploads.length )
 469+ .button()
 470+ .addClass( 'ui-button-text ui-button-textonly' )
 471+ .click( function() {
 472+ $j.each( deedChooser.uploads, function( i, upload ) {
 473+ upload.remove();
 474+ } );
 475+ } )
 476+ );
 477+ } );
446478 }
447 -
448479 };
449480
450481 } )( jQuery );
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardLicenseInput.js
@@ -7,6 +7,7 @@
88 * 'defaults' => array of template string names (can be empty array),
99 * 'licenses' => array of template string names (matching keys in mw.UploadWizard.config.licenses)
1010 * optional: 'licenseGroups' => groups of licenses, with more explanation
 11+ * optional: 'special' => String -- indicates, don't put licenses here, instead leave a placeholder div, with class based on this string.
1112 * @param {Numbe} count of the things we are licensing (it matters to some texts)
1213 */
1314
@@ -97,12 +98,10 @@
9899 }
99100 } );
100101 }
 102+
101103
102104 if ( mw.isDefined( config['licenseGroups'] ) ) {
103105 $j.each( config['licenseGroups'], function( i, group ) {
104 - if ( !mw.isDefined( group['licenses'] ) ) {
105 - throw new Error( 'improper config' );
106 - }
107106 var $group = $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license-group' );
108107 // if there is no header, just append licenses to the group div.
109108 var $body = $group;
@@ -120,7 +119,12 @@
121120 $body.append( $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license-group-subhead' ).msg( group.subhead, _this.count ) );
122121 }
123122 var $licensesDiv = $j( '<div></div>' ).addClass( 'mwe-upwiz-deed-license' );
124 - appendLicenses( $licensesDiv, group );
 123+ if ( mw.isDefined( group['special'] ) ) {
 124+ // put a placeholder in our interface for our caller to place some special interface in
 125+ $licensesDiv.append( $j( '<div></div>' ).addClass( 'mwe-upwiz-license-special-' + group.special ) );
 126+ } else {
 127+ appendLicenses( $licensesDiv, group );
 128+ }
125129 $body.append( $licensesDiv );
126130 _this.$selector.append( $group );
127131 } );
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizard.js
@@ -547,17 +547,11 @@
548548
549549 /**
550550 * Reset the entire interface so we can upload more stuff
 551+ * (depends on updateFileCounts to reset the interface when uploads go down to 0)
551552 * Depending on whether we split uploading / detailing, it may actually always be as simple as loading a URL
552553 */
553554 reset: function() {
554 - // window.location = wgArticlePath.replace( '$1', 'Special:UploadWizard?skiptutorial=true' );
555 - var _this = this;
556 - // deeds page
557 - _this.deedChooser.remove();
558 - _this.removeMatchingUploads( function() { return true; } );
559 - // this could be slicker... need to reset the headline AND get rid of individual divs
560 - $( '#mwe-upwiz-thanks' ).html( '' );
561 - _this.moveToStep( 'file' );
 555+ this.removeMatchingUploads( function() { return true; } );
562556 },
563557
564558
@@ -577,7 +571,7 @@
578572 $j( '#mwe-first-spinner' ).remove();
579573
580574 // feedback request
581 - if ( mw.isDefined( mw.UploadWizard.config['feedbackPage'] ) && mw.UploadWizard.config['feedbackPage'] != '' ) {
 575+ if ( mw.isDefined( mw.UploadWizard.config['feedbackPage'] ) && mw.UploadWizard.config['feedbackPage'] !== '' ) {
582576 var feedback = new mw.Feedback( _this.api,
583577 new mw.Title( mw.UploadWizard.config['feedbackPage'] ) );
584578 $j( '#contentSub' )
@@ -734,10 +728,12 @@
735729 deeds.push( customDeed );
736730 }
737731
 732+ var uploadsClone = $j.map( _this.uploads, function( x ) { return x; } );
738733 _this.deedChooser = new mw.UploadWizardDeedChooser(
739734 '#mwe-upwiz-deeds',
740735 deeds,
741 - _this.uploads.length );
 736+ uploadsClone
 737+ );
742738
743739
744740 $j( '<div></div>' )
@@ -749,7 +745,7 @@
750746 .insertBefore( _this.deedChooser.$selector.find( '.mwe-upwiz-deed-custom' ) )
751747 .msg( 'mwe-upwiz-deeds-custom-prompt' );
752748 }
753 -
 749+
754750 _this.moveToStep( 'deeds' );
755751
756752 },
@@ -874,13 +870,13 @@
875871 // remove the div that passed along the trigger
876872 var $div = $j( upload.ui.div );
877873 $div.unbind(); // everything
878 - // sexily fade away
879 - $div.fadeOut('fast', function() {
 874+ // sexily fade away (TODO if we are looking at it)
 875+ //$div.fadeOut('fast', function() {
880876 $div.remove();
881877 // and do what we in the wizard need to do after an upload is removed
882878 mw.UploadWizardUtil.removeItem( _this.uploads, upload );
883879 _this.updateFileCounts();
884 - });
 880+ //} );
885881 },
886882
887883
@@ -996,8 +992,8 @@
997993 } );
998994
999995 this.allowCloseWindow = mw.confirmCloseWindow( {
1000 - message: function() { return gM( 'mwe-upwiz-prevent-close', _this.uploads.length ) },
1001 - test: function() { return _this.uploads.length > 0 }
 996+ message: function() { return gM( 'mwe-upwiz-prevent-close', _this.uploads.length ); },
 997+ test: function() { return _this.uploads.length > 0; }
1002998 } );
1003999
10041000 $j( '#mwe-upwiz-progress' ).show();
@@ -1047,6 +1043,7 @@
10481044 $j( '#mwe-upwiz-progress' ).hide();
10491045 $j( '#mwe-upwiz-upload-ctrls' ).show();
10501046 $j( '#mwe-upwiz-add-file' ).show();
 1047+ this.moveToStep( 'file' );
10511048 return;
10521049 }
10531050 var errorCount = 0;
@@ -1127,6 +1124,21 @@
11281125 $j( '#mwe-upwiz-upload-ctrls' ).show();
11291126 $j( '#mwe-upwiz-progress' ).hide();
11301127 $j( '#mwe-upwiz-add-file' ).show();
 1128+
 1129+ // fix various other pages that may have state
 1130+ $j( '#mwe-upwiz-thanks' ).html( '' );
 1131+
 1132+ if ( mw.isDefined( _this.deedChooser ) ) {
 1133+ _this.deedChooser.remove();
 1134+ }
 1135+
 1136+ // remove any blocks on closing the window
 1137+ if ( mw.isDefined( _this.allowCloseWindow ) ) {
 1138+ _this.allowCloseWindow();
 1139+ }
 1140+
 1141+ // and move back to the file step
 1142+ _this.moveToStep( 'file' );
11311143 }
11321144
11331145 // allow an "add another upload" button only if we aren't at max
Index: trunk/extensions/UploadWizard/resources/mw.UploadWizardDetails.js
@@ -279,7 +279,8 @@
280280 _this.upload.deedChooser = new mw.UploadWizardDeedChooser(
281281 _this.deedDiv,
282282 [ new mw.UploadWizardDeedOwnWork(),
283 - new mw.UploadWizardDeedThirdParty() ]
 283+ new mw.UploadWizardDeedThirdParty() ],
 284+ [ _this.upload ]
284285 );
285286 },
286287

Comments

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:35, 25 April 2011
$j( '#mwe-upwiz-thanks' ).html( '' );

might be better written as

$j( '#mwe-upwiz-thanks' ).empty();

Status & tagging log