r68410 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68409‎ | r68410 | r68411 >
Date:16:32, 22 June 2010
Author:neilk
Status:deferred
Tags:
Comment:
reasonable filename checking, needs a bit more slickness
Modified paths:
  • /trunk/extensions/UploadWizard/UploadWizard.i18n.php (modified) (history)
  • /trunk/extensions/UploadWizard/js/mw.DestinationChecker.js (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
@@ -279,7 +279,7 @@
280280
281281 /* XXX add spinner gif instead, maybe */
282282 .busy {
283 - background: yellow;
 283+ /* background: yellow; */
284284 }
285285
286286 .mwe-upwiz-stepdiv {
@@ -361,6 +361,11 @@
362362 float: left;
363363 }
364364
 365+.mwe-upwiz-details-input.mwe-error {
 366+ float: none;
 367+ margin-left: 9em;
 368+}
 369+
365370 .mwe-upwiz-desc-lang-select {
366371 width: 130px;
367372 font-family: sans-serif;
Index: trunk/extensions/UploadWizard/UploadWizard.i18n.php
@@ -89,6 +89,7 @@
9090 'mwe-upwiz-ok' => 'OK',
9191 'mwe-upwiz-cancel' => 'Cancel',
9292 'mwe-upwiz-change' => '(change)',
 93+ 'mwe-upwiz-fileexists-replace' => 'A file with the title "$1" exists already. Please change your title to something unique.',
9394 'mwe-upwiz-fileexists' => 'A file with this name exists already.
9495 Please check <b><tt>$1</tt></b> if you are not sure if you want to replace it.',
9596 'mwe-upwiz-thumbnail-more' => 'Enlarge',
Index: trunk/extensions/UploadWizard/js/mw.UploadWizard.js
@@ -1079,15 +1079,16 @@
10801080 spinner: function(bool) { _this.toggleDestinationBusy(bool); },
10811081 preprocess: function( name ) { return _this.getFilenameFromTitle(); }, // XXX this is no longer a pre-process
10821082 processResult: function( result ) { _this.processDestinationCheck( result ); }
1083 - } )
1084 - ;
 1083+ } );
10851084
1086 - _this.titleErrorDiv = $j('<div></div>');
 1085+ _this.titleErrorDiv = $j('<div class="mwe-upwiz-details-input mwe-error"></div>');
10871086
10881087 _this.titleContainerDiv = $j('<div class="mwe-upwiz-details-label-input ui-helper-clearfix"></div>')
1089 - .append( $j( '<div class="mwe-upwiz-details-label"></div>' ).append( gM( 'mwe-upwiz-title' ) ) )
1090 - .append( $j( '<div class="mwe-upwiz-details-input"></div>' ).append( _this.titleInput ) )
1091 - .append( _this.titleErrorDiv );
 1088+ .append(
 1089+ _this.titleErrorDiv,
 1090+ $j( '<div class="mwe-upwiz-details-label"></div>' ).append( gM( 'mwe-upwiz-title' ) ),
 1091+ $j( '<div class="mwe-upwiz-details-input"></div>' ).append( _this.titleInput )
 1092+ )
10921093
10931094 _this.deedDiv = $j( '<div class="mwe-upwiz-custom-deed" />' );
10941095
@@ -1154,6 +1155,38 @@
11551156 mw.UploadWizardDetails.prototype = {
11561157
11571158 /**
 1159+ * check entire form for validity
 1160+ */
 1161+ // return boolean if we are ready to go.
 1162+ // side effect: add error text to the page for fields in an incorrect state.
 1163+ valid: function() {
 1164+ var _this = this;
 1165+ // at least one description -- never mind, we are disallowing removal of first description
 1166+ // all the descriptions -- check min & max length
 1167+
 1168+ // the title
 1169+ var titleInputValid = $j( _this.titleInput ).data( 'valid' );
 1170+ if ( typeof titleInputValid == 'undefined' ) {
 1171+ alert( "please wait, still checking the title for uniqueness..." );
 1172+ return false;
 1173+ }
 1174+
 1175+ return titleInputValid;
 1176+
 1177+ // length restrictions
 1178+ // not already taken
 1179+
 1180+ // the license, if any
 1181+
 1182+ // pop open the 'more-options' if the date is bad
 1183+ // the date
 1184+ // other information
 1185+ // no validation required
 1186+ },
 1187+
 1188+
 1189+
 1190+ /**
11581191 * toggles whether we use the 'macro' deed or our own
11591192 */
11601193 useCustomDeedChooser: function() {
@@ -1196,6 +1229,7 @@
11971230 var _this = this;
11981231 if (busy) {
11991232 _this.titleInput.addClass( "busy" );
 1233+ $j( _this.titleInput ).data( 'valid', undefined );
12001234 } else {
12011235 _this.titleInput.removeClass( "busy" );
12021236 }
@@ -1212,18 +1246,24 @@
12131247 var _this = this;
12141248
12151249 if ( result.isUnique ) {
 1250+ $j( _this.titleInput ).data( 'valid', true );
12161251 _this.titleErrorDiv.hide().empty();
12171252 _this.ignoreWarningsInput = undefined;
12181253 return;
12191254 }
12201255
 1256+ $j( _this.titleInput ).data( 'valid', false );
 1257+
12211258 // result is NOT unique
12221259 var title = result.title;
12231260 var img = result.img;
12241261 var href = result.href;
12251262
 1263+ _this.titleErrorDiv.html( gM( 'mwe-upwiz-fileexists-replace', result.title ) ).show();
 1264+
 1265+ /* temporarily commenting out the full thumbnail etc. thing. For now, we just want the user to change
 1266+ to a different name
12261267 _this.ignoreWarningsInput = $j("<input />").attr( { type: 'checkbox', name: 'ignorewarnings' } );
1227 -
12281268 var $fileAlreadyExists = $j('<div />')
12291269 .append(
12301270 gM( 'mwe-upwiz-fileexists',
@@ -1296,7 +1336,9 @@
12971337 )
12981338 )
12991339 ).show();
 1340+ */
13001341
 1342+
13011343 },
13021344
13031345 /**
@@ -1617,8 +1659,7 @@
16181660
16191661 /**
16201662 * Check if we are ready to post wikitext
1621 - */
1622 - valid: function() {
 1663+ deedValid: function() {
16231664 var _this = this;
16241665 return _this.upload.deedChooser.deed.valid();
16251666
@@ -1626,6 +1667,7 @@
16271668 // where we can then check on
16281669 // perhaps as simple as _this.issues or _this.agenda
16291670 },
 1671+ */
16301672
16311673 /**
16321674 * Post wikitext as edited here, to the file
@@ -2014,9 +2056,11 @@
20152057 if ( i < lastUploadIndex ) {
20162058 upload.details.div.css( 'border-bottom', '1px solid #e0e0e0' );
20172059 }
 2060+
 2061+ upload.details.titleInput.checkUnique();
20182062 } );
20192063
2020 - _this.moveToStep('details');
 2064+ _this.moveToStep( 'details' );
20212065 }
20222066 } );
20232067
@@ -2026,10 +2070,12 @@
20272071 $j( '#mwe-upwiz-stepdiv-details .mwe-upwiz-button-next' )
20282072 .append( gM( 'mwe-upwiz-next-details' ) )
20292073 .click( function() {
2030 - _this.detailsSubmit( function() {
2031 - _this.prefillThanksPage();
2032 - _this.moveToStep('thanks');
2033 - } );
 2074+ if ( _this.detailsValid() ) {
 2075+ _this.detailsSubmit( function() {
 2076+ _this.prefillThanksPage();
 2077+ _this.moveToStep( 'thanks' );
 2078+ } );
 2079+ }
20342080 } );
20352081
20362082
@@ -2316,7 +2362,21 @@
23172363
23182364 },
23192365
 2366+
23202367 /**
 2368+ * are all the details valid?
 2369+ * @return boolean
 2370+ */
 2371+ detailsValid: function() {
 2372+ var _this = this;
 2373+ var valid = true;
 2374+ $j.each( _this.uploads, function(i, upload) {
 2375+ valid &= upload.details.valid();
 2376+ } );
 2377+ return valid;
 2378+ },
 2379+
 2380+ /**
23212381 * Submit all edited details and other metadata
23222382 * Works just like startUploads -- parallel simultaneous submits with progress bar.
23232383 */
@@ -2917,7 +2977,7 @@
29182978 * @return typical title as would appear on MediaWiki
29192979 */
29202980 pathToTitle: function ( filename ) {
2921 - return mw.ucfirst( filename.replace(/ /g, '_' ) );
 2981+ return mw.ucfirst( $j.trim( filename ).replace(/ /g, '_' ) );
29222982 },
29232983
29242984 /**
@@ -2926,7 +2986,7 @@
29272987 * @return plausible local filename, with spaces changed to underscores.
29282988 */
29292989 titleToPath: function ( title ) {
2930 - return mw.ucfirst( title.replace(/_/g, ' ' ) );
 2990+ return mw.ucfirst( $j.trim( title ).replace(/_/g, ' ' ) );
29312991 },
29322992
29332993 /**
Index: trunk/extensions/UploadWizard/js/mw.DestinationChecker.js
@@ -188,6 +188,7 @@
189189 _this.cachedResult[name] = result;
190190 _this.processResult( result );
191191 }
 192+
192193 } );
193194 }
194195
@@ -201,7 +202,9 @@
202203 $.fn.destinationChecked = function( options ) {
203204 var _this = this;
204205 options.selector = _this;
205 - new mw.DestinationChecker( options );
 206+ var checker = new mw.DestinationChecker( options );
 207+ // this should really be done with triggers
 208+ _this.checkUnique = function() { checker.checkUnique(); };
206209 return _this;
207210 };
208211 } )( jQuery );

Status & tagging log