Remove JSON polyfill, deprecate 'json' module
[lhc/web/wiklou.git] / resources / src / mediawiki / mediawiki.Upload.BookletLayout.js
1 /* global moment*/
2 ( function ( $, mw, moment ) {
3
4 /**
5 * mw.Upload.BookletLayout encapsulates the process of uploading a file
6 * to MediaWiki using the {@link mw.Upload upload model}.
7 * The booklet emits events that can be used to get the stashed
8 * upload and the final file. It can be extended to accept
9 * additional fields from the user for specific scenarios like
10 * for Commons, or campaigns.
11 *
12 * ## Structure
13 *
14 * The {@link OO.ui.BookletLayout booklet layout} has three steps:
15 *
16 * - **Upload**: Has a {@link OO.ui.SelectFileWidget field} to get the file object.
17 *
18 * - **Information**: Has a {@link OO.ui.FormLayout form} to collect metadata. This can be
19 * extended.
20 *
21 * - **Insert**: Has details on how to use the file that was uploaded.
22 *
23 * Each step has a form associated with it defined in
24 * {@link #renderUploadForm renderUploadForm},
25 * {@link #renderInfoForm renderInfoForm}, and
26 * {@link #renderInsertForm renderInfoForm}. The
27 * {@link #getFile getFile},
28 * {@link #getFilename getFilename}, and
29 * {@link #getText getText} methods are used to get
30 * the information filled in these forms, required to call
31 * {@link mw.Upload mw.Upload}.
32 *
33 * ## Usage
34 *
35 * See the {@link mw.Upload.Dialog upload dialog}.
36 *
37 * The {@link #event-fileUploaded fileUploaded},
38 * and {@link #event-fileSaved fileSaved} events can
39 * be used to get details of the upload.
40 *
41 * ## Extending
42 *
43 * To extend using {@link mw.Upload mw.Upload}, override
44 * {@link #renderInfoForm renderInfoForm} to render
45 * the form required for the specific use-case. Update the
46 * {@link #getFilename getFilename}, and
47 * {@link #getText getText} methods to return data
48 * from your newly created form. If you added new fields you'll also have
49 * to update the {@link #clear} method.
50 *
51 * If you plan to use a different upload model, apart from what is mentioned
52 * above, you'll also have to override the
53 * {@link #createUpload createUpload} method to
54 * return the new model. The {@link #saveFile saveFile}, and
55 * the {@link #uploadFile uploadFile} methods need to be
56 * overridden to use the new model and data returned from the forms.
57 *
58 * @class
59 * @extends OO.ui.BookletLayout
60 *
61 * @constructor
62 * @param {Object} config Configuration options
63 * @cfg {jQuery} [$overlay] Overlay to use for widgets in the booklet
64 * @cfg {string} [filekey] Sets the stashed file to finish uploading. Overrides most of the file selection process, and fetches a thumbnail from the server.
65 */
66 mw.Upload.BookletLayout = function ( config ) {
67 // Parent constructor
68 mw.Upload.BookletLayout.parent.call( this, config );
69
70 this.$overlay = config.$overlay;
71
72 this.filekey = config.filekey;
73
74 this.renderUploadForm();
75 this.renderInfoForm();
76 this.renderInsertForm();
77
78 this.addPages( [
79 new OO.ui.PageLayout( 'upload', {
80 scrollable: true,
81 padded: true,
82 content: [ this.uploadForm ]
83 } ),
84 new OO.ui.PageLayout( 'info', {
85 scrollable: true,
86 padded: true,
87 content: [ this.infoForm ]
88 } ),
89 new OO.ui.PageLayout( 'insert', {
90 scrollable: true,
91 padded: true,
92 content: [ this.insertForm ]
93 } )
94 ] );
95 };
96
97 /* Setup */
98
99 OO.inheritClass( mw.Upload.BookletLayout, OO.ui.BookletLayout );
100
101 /* Events */
102
103 /**
104 * Progress events for the uploaded file
105 *
106 * @event fileUploadProgress
107 * @param {number} progress In percentage
108 * @param {Object} duration Duration object from `moment.duration()`
109 */
110
111 /**
112 * The file has finished uploading
113 *
114 * @event fileUploaded
115 */
116
117 /**
118 * The file has been saved to the database
119 *
120 * @event fileSaved
121 * @param {Object} imageInfo See mw.Upload#getImageInfo
122 */
123
124 /**
125 * The upload form has changed
126 *
127 * @event uploadValid
128 * @param {boolean} isValid The form is valid
129 */
130
131 /**
132 * The info form has changed
133 *
134 * @event infoValid
135 * @param {boolean} isValid The form is valid
136 */
137
138 /* Properties */
139
140 /**
141 * @property {OO.ui.FormLayout} uploadForm
142 * The form rendered in the first step to get the file object.
143 * Rendered in {@link #renderUploadForm renderUploadForm}.
144 */
145
146 /**
147 * @property {OO.ui.FormLayout} infoForm
148 * The form rendered in the second step to get metadata.
149 * Rendered in {@link #renderInfoForm renderInfoForm}
150 */
151
152 /**
153 * @property {OO.ui.FormLayout} insertForm
154 * The form rendered in the third step to show usage
155 * Rendered in {@link #renderInsertForm renderInsertForm}
156 */
157
158 /* Methods */
159
160 /**
161 * Initialize for a new upload
162 *
163 * @return {jQuery.Promise} Promise resolved when everything is initialized
164 */
165 mw.Upload.BookletLayout.prototype.initialize = function () {
166 var booklet = this;
167
168 this.clear();
169 this.upload = this.createUpload();
170
171 this.setPage( 'upload' );
172
173 if ( this.filekey ) {
174 this.setFilekey( this.filekey );
175 }
176
177 return this.upload.getApi().then(
178 function ( api ) {
179 return $.when(
180 booklet.upload.loadConfig().then(
181 null,
182 function ( errorMsg ) {
183 booklet.getPage( 'upload' ).$element.msg( errorMsg );
184 return $.Deferred().resolve();
185 }
186 ),
187 // If the user can't upload anything, don't give them the option to.
188 api.getUserInfo().then( function ( userInfo ) {
189 if ( userInfo.rights.indexOf( 'upload' ) === -1 ) {
190 // TODO Use a better error message when not all logged-in users can upload
191 booklet.getPage( 'upload' ).$element.msg( 'api-error-mustbeloggedin' );
192 }
193 return $.Deferred().resolve();
194 } )
195 ).then(
196 null,
197 // Always resolve, never reject
198 function () { return $.Deferred().resolve(); }
199 );
200 },
201 function ( errorMsg ) {
202 booklet.getPage( 'upload' ).$element.msg( errorMsg );
203 return $.Deferred().resolve();
204 }
205 );
206 };
207
208 /**
209 * Create a new upload model
210 *
211 * @protected
212 * @return {mw.Upload} Upload model
213 */
214 mw.Upload.BookletLayout.prototype.createUpload = function () {
215 return new mw.Upload();
216 };
217
218 /* Uploading */
219
220 /**
221 * Uploads the file that was added in the upload form. Uses
222 * {@link #getFile getFile} to get the HTML5
223 * file object.
224 *
225 * @protected
226 * @fires fileUploadProgress
227 * @fires fileUploaded
228 * @return {jQuery.Promise}
229 */
230 mw.Upload.BookletLayout.prototype.uploadFile = function () {
231 var deferred = $.Deferred(),
232 startTime = new Date(),
233 layout = this,
234 file = this.getFile();
235
236 this.setPage( 'info' );
237
238 if ( this.filekey ) {
239 if ( file === null ) {
240 // Someone gonna get-a hurt real bad
241 throw new Error( 'filekey not passed into file select widget, which is impossible. Quitting while we\'re behind.' );
242 }
243
244 // Stashed file already uploaded.
245 deferred.resolve();
246 this.uploadPromise = deferred;
247 this.emit( 'fileUploaded' );
248 return deferred;
249 }
250
251 this.setFilename( file.name );
252
253 this.upload.setFile( file );
254 // The original file name might contain invalid characters, so use our sanitized one
255 this.upload.setFilename( this.getFilename() );
256
257 this.uploadPromise = this.upload.uploadToStash();
258 this.uploadPromise.then( function () {
259 deferred.resolve();
260 layout.emit( 'fileUploaded' );
261 }, function () {
262 // These errors will be thrown while the user is on the info page.
263 layout.getErrorMessageForStateDetails().then( function ( errorMessage ) {
264 deferred.reject( errorMessage );
265 } );
266 }, function ( progress ) {
267 var elapsedTime = new Date() - startTime,
268 estimatedTotalTime = ( 1 / progress ) * elapsedTime,
269 estimatedRemainingTime = moment.duration( estimatedTotalTime - elapsedTime );
270 layout.emit( 'fileUploadProgress', progress, estimatedRemainingTime );
271 } );
272
273 // If there is an error in uploading, come back to the upload page
274 deferred.fail( function () {
275 layout.setPage( 'upload' );
276 } );
277
278 return deferred;
279 };
280
281 /**
282 * Saves the stash finalizes upload. Uses
283 * {@link #getFilename getFilename}, and
284 * {@link #getText getText} to get details from
285 * the form.
286 *
287 * @protected
288 * @fires fileSaved
289 * @return {jQuery.Promise} Rejects the promise with an
290 * {@link OO.ui.Error error}, or resolves if the upload was successful.
291 */
292 mw.Upload.BookletLayout.prototype.saveFile = function () {
293 var layout = this,
294 deferred = $.Deferred();
295
296 this.upload.setFilename( this.getFilename() );
297 this.upload.setText( this.getText() );
298
299 this.uploadPromise.then( function () {
300 layout.upload.finishStashUpload().then( function () {
301 var name;
302
303 // Normalize page name and localise the 'File:' prefix
304 name = new mw.Title( 'File:' + layout.upload.getFilename() ).toString();
305 layout.filenameUsageWidget.setValue( '[[' + name + ']]' );
306 layout.setPage( 'insert' );
307
308 deferred.resolve();
309 layout.emit( 'fileSaved', layout.upload.getImageInfo() );
310 }, function () {
311 layout.getErrorMessageForStateDetails().then( function ( errorMessage ) {
312 deferred.reject( errorMessage );
313 } );
314 } );
315 } );
316
317 return deferred.promise();
318 };
319
320 /**
321 * Get an error message (as OO.ui.Error object) that should be displayed to the user for current
322 * state and state details.
323 *
324 * @protected
325 * @return {jQuery.Promise} A Promise that will be resolved with an OO.ui.Error.
326 */
327 mw.Upload.BookletLayout.prototype.getErrorMessageForStateDetails = function () {
328 var message,
329 state = this.upload.getState(),
330 stateDetails = this.upload.getStateDetails(),
331 error = stateDetails.error,
332 warnings = stateDetails.upload && stateDetails.upload.warnings;
333
334 if ( state === mw.Upload.State.ERROR ) {
335 if ( !error ) {
336 // If there's an 'exception' key, this might be a timeout, or other connection problem
337 return $.Deferred().resolve( new OO.ui.Error(
338 $( '<p>' ).msg( 'api-error-unknownerror', JSON.stringify( stateDetails ) ),
339 { recoverable: false }
340 ) );
341 }
342
343 // Errors in this format are produced by TitleBlacklist and AbuseFilter. Perhaps other
344 // extensions will follow this format in the future.
345 if ( error.message ) {
346 return this.upload.getApi()
347 .then( function ( api ) {
348 // 'amenableparser' will expand templates and parser functions server-side.
349 // We still do the rest of wikitext parsing here (through jqueryMsg).
350 return api.loadMessagesIfMissing( [ error.message.key ], { amenableparser: true } )
351 .then( function () {
352 if ( !mw.message( error.message.key ).exists() ) {
353 return $.Deferred().reject();
354 }
355 return new OO.ui.Error(
356 $( '<p>' ).msg( error.message.key, error.message.params || [] ),
357 { recoverable: false }
358 );
359 } );
360 } )
361 .then( null, function () {
362 // We failed when loading the error message, or it doesn't actually exist, fall back
363 return $.Deferred().resolve( new OO.ui.Error(
364 $( '<p>' ).msg( 'api-error-unknownerror', JSON.stringify( stateDetails ) ),
365 { recoverable: false }
366 ) );
367 } );
368 }
369
370 if ( error.code === 'protectedpage' ) {
371 message = mw.message( 'protectedpagetext' );
372 } else {
373 message = mw.message( 'api-error-' + error.code );
374 if ( !message.exists() ) {
375 message = mw.message( 'api-error-unknownerror', JSON.stringify( stateDetails ) );
376 }
377 }
378 return $.Deferred().resolve( new OO.ui.Error(
379 $( '<p>' ).append( message.parseDom() ),
380 { recoverable: false }
381 ) );
382 }
383
384 if ( state === mw.Upload.State.WARNING ) {
385 // We could get more than one of these errors, these are in order
386 // of importance. For example fixing the thumbnail like file name
387 // won't help the fact that the file already exists.
388 if ( warnings.stashfailed !== undefined ) {
389 return $.Deferred().resolve( new OO.ui.Error(
390 $( '<p>' ).msg( 'api-error-stashfailed' ),
391 { recoverable: false }
392 ) );
393 } else if ( warnings.exists !== undefined ) {
394 return $.Deferred().resolve( new OO.ui.Error(
395 $( '<p>' ).msg( 'fileexists', 'File:' + warnings.exists ),
396 { recoverable: false }
397 ) );
398 } else if ( warnings[ 'exists-normalized' ] !== undefined ) {
399 return $.Deferred().resolve( new OO.ui.Error(
400 $( '<p>' ).msg( 'fileexists', 'File:' + warnings[ 'exists-normalized' ] ),
401 { recoverable: false }
402 ) );
403 } else if ( warnings[ 'page-exists' ] !== undefined ) {
404 return $.Deferred().resolve( new OO.ui.Error(
405 $( '<p>' ).msg( 'filepageexists', 'File:' + warnings[ 'page-exists' ] ),
406 { recoverable: false }
407 ) );
408 } else if ( warnings.duplicate !== undefined ) {
409 return $.Deferred().resolve( new OO.ui.Error(
410 $( '<p>' ).msg( 'api-error-duplicate', warnings.duplicate.length ),
411 { recoverable: false }
412 ) );
413 } else if ( warnings[ 'thumb-name' ] !== undefined ) {
414 return $.Deferred().resolve( new OO.ui.Error(
415 $( '<p>' ).msg( 'filename-thumb-name' ),
416 { recoverable: false }
417 ) );
418 } else if ( warnings[ 'bad-prefix' ] !== undefined ) {
419 return $.Deferred().resolve( new OO.ui.Error(
420 $( '<p>' ).msg( 'filename-bad-prefix', warnings[ 'bad-prefix' ] ),
421 { recoverable: false }
422 ) );
423 } else if ( warnings[ 'duplicate-archive' ] !== undefined ) {
424 return $.Deferred().resolve( new OO.ui.Error(
425 $( '<p>' ).msg( 'api-error-duplicate-archive', 1 ),
426 { recoverable: false }
427 ) );
428 } else if ( warnings[ 'was-deleted' ] !== undefined ) {
429 return $.Deferred().resolve( new OO.ui.Error(
430 $( '<p>' ).msg( 'api-error-was-deleted' ),
431 { recoverable: false }
432 ) );
433 } else if ( warnings.badfilename !== undefined ) {
434 // Change the name if the current name isn't acceptable
435 // TODO This might not really be the best place to do this
436 this.setFilename( warnings.badfilename );
437 return $.Deferred().resolve( new OO.ui.Error(
438 $( '<p>' ).msg( 'badfilename', warnings.badfilename )
439 ) );
440 } else {
441 return $.Deferred().resolve( new OO.ui.Error(
442 // Let's get all the help we can if we can't pin point the error
443 $( '<p>' ).msg( 'api-error-unknown-warning', JSON.stringify( stateDetails ) ),
444 { recoverable: false }
445 ) );
446 }
447 }
448 };
449
450 /* Form renderers */
451
452 /**
453 * Renders and returns the upload form and sets the
454 * {@link #uploadForm uploadForm} property.
455 *
456 * @protected
457 * @fires selectFile
458 * @return {OO.ui.FormLayout}
459 */
460 mw.Upload.BookletLayout.prototype.renderUploadForm = function () {
461 var fieldset,
462 layout = this;
463
464 this.selectFileWidget = this.getFileWidget();
465 fieldset = new OO.ui.FieldsetLayout();
466 fieldset.addItems( [ this.selectFileWidget ] );
467 this.uploadForm = new OO.ui.FormLayout( { items: [ fieldset ] } );
468
469 // Validation (if the SFW is for a stashed file, this never fires)
470 this.selectFileWidget.on( 'change', this.onUploadFormChange.bind( this ) );
471
472 this.selectFileWidget.on( 'change', function () {
473 layout.updateFilePreview();
474 } );
475
476 return this.uploadForm;
477 };
478
479 /**
480 * Gets the widget for displaying or inputting the file to upload.
481 *
482 * @return {OO.ui.SelectFileWidget|mw.widgets.StashedFileWidget}
483 */
484 mw.Upload.BookletLayout.prototype.getFileWidget = function () {
485 if ( this.filekey ) {
486 return new mw.widgets.StashedFileWidget( {
487 filekey: this.filekey
488 } );
489 }
490
491 return new OO.ui.SelectFileWidget( {
492 showDropTarget: true
493 } );
494 };
495
496 /**
497 * Updates the file preview on the info form when a file is added.
498 *
499 * @protected
500 */
501 mw.Upload.BookletLayout.prototype.updateFilePreview = function () {
502 this.selectFileWidget.loadAndGetImageUrl().done( function ( url ) {
503 this.filePreview.$element.find( 'p' ).remove();
504 this.filePreview.$element.css( 'background-image', 'url(' + url + ')' );
505 this.infoForm.$element.addClass( 'mw-upload-bookletLayout-hasThumbnail' );
506 }.bind( this ) ).fail( function () {
507 this.filePreview.$element.find( 'p' ).remove();
508 if ( this.selectFileWidget.getValue() ) {
509 this.filePreview.$element.append(
510 $( '<p>' ).text( this.selectFileWidget.getValue().name )
511 );
512 }
513 this.filePreview.$element.css( 'background-image', '' );
514 this.infoForm.$element.removeClass( 'mw-upload-bookletLayout-hasThumbnail' );
515 }.bind( this ) );
516 };
517
518 /**
519 * Handle change events to the upload form
520 *
521 * @protected
522 * @fires uploadValid
523 */
524 mw.Upload.BookletLayout.prototype.onUploadFormChange = function () {
525 this.emit( 'uploadValid', !!this.selectFileWidget.getValue() );
526 };
527
528 /**
529 * Renders and returns the information form for collecting
530 * metadata and sets the {@link #infoForm infoForm}
531 * property.
532 *
533 * @protected
534 * @return {OO.ui.FormLayout}
535 */
536 mw.Upload.BookletLayout.prototype.renderInfoForm = function () {
537 var fieldset;
538
539 this.filePreview = new OO.ui.Widget( {
540 classes: [ 'mw-upload-bookletLayout-filePreview' ]
541 } );
542 this.progressBarWidget = new OO.ui.ProgressBarWidget( {
543 progress: 0
544 } );
545 this.filePreview.$element.append( this.progressBarWidget.$element );
546
547 this.filenameWidget = new OO.ui.TextInputWidget( {
548 indicator: 'required',
549 required: true,
550 validate: /.+/
551 } );
552 this.descriptionWidget = new OO.ui.TextInputWidget( {
553 indicator: 'required',
554 required: true,
555 validate: /\S+/,
556 multiline: true,
557 autosize: true
558 } );
559
560 fieldset = new OO.ui.FieldsetLayout( {
561 label: mw.msg( 'upload-form-label-infoform-title' )
562 } );
563 fieldset.addItems( [
564 new OO.ui.FieldLayout( this.filenameWidget, {
565 label: mw.msg( 'upload-form-label-infoform-name' ),
566 align: 'top',
567 help: mw.msg( 'upload-form-label-infoform-name-tooltip' )
568 } ),
569 new OO.ui.FieldLayout( this.descriptionWidget, {
570 label: mw.msg( 'upload-form-label-infoform-description' ),
571 align: 'top',
572 help: mw.msg( 'upload-form-label-infoform-description-tooltip' )
573 } )
574 ] );
575 this.infoForm = new OO.ui.FormLayout( {
576 classes: [ 'mw-upload-bookletLayout-infoForm' ],
577 items: [ this.filePreview, fieldset ]
578 } );
579
580 this.on( 'fileUploadProgress', function ( progress ) {
581 this.progressBarWidget.setProgress( progress * 100 );
582 }.bind( this ) );
583
584 this.filenameWidget.on( 'change', this.onInfoFormChange.bind( this ) );
585 this.descriptionWidget.on( 'change', this.onInfoFormChange.bind( this ) );
586
587 return this.infoForm;
588 };
589
590 /**
591 * Handle change events to the info form
592 *
593 * @protected
594 * @fires infoValid
595 */
596 mw.Upload.BookletLayout.prototype.onInfoFormChange = function () {
597 var layout = this;
598 $.when(
599 this.filenameWidget.getValidity(),
600 this.descriptionWidget.getValidity()
601 ).done( function () {
602 layout.emit( 'infoValid', true );
603 } ).fail( function () {
604 layout.emit( 'infoValid', false );
605 } );
606 };
607
608 /**
609 * Renders and returns the insert form to show file usage and
610 * sets the {@link #insertForm insertForm} property.
611 *
612 * @protected
613 * @return {OO.ui.FormLayout}
614 */
615 mw.Upload.BookletLayout.prototype.renderInsertForm = function () {
616 var fieldset;
617
618 this.filenameUsageWidget = new OO.ui.TextInputWidget();
619 fieldset = new OO.ui.FieldsetLayout( {
620 label: mw.msg( 'upload-form-label-usage-title' )
621 } );
622 fieldset.addItems( [
623 new OO.ui.FieldLayout( this.filenameUsageWidget, {
624 label: mw.msg( 'upload-form-label-usage-filename' ),
625 align: 'top'
626 } )
627 ] );
628 this.insertForm = new OO.ui.FormLayout( { items: [ fieldset ] } );
629
630 return this.insertForm;
631 };
632
633 /* Getters */
634
635 /**
636 * Gets the file object from the
637 * {@link #uploadForm upload form}.
638 *
639 * @protected
640 * @return {File|null}
641 */
642 mw.Upload.BookletLayout.prototype.getFile = function () {
643 return this.selectFileWidget.getValue();
644 };
645
646 /**
647 * Gets the file name from the
648 * {@link #infoForm information form}.
649 *
650 * @protected
651 * @return {string}
652 */
653 mw.Upload.BookletLayout.prototype.getFilename = function () {
654 var filename = this.filenameWidget.getValue();
655 if ( this.filenameExtension ) {
656 filename += '.' + this.filenameExtension;
657 }
658 return filename;
659 };
660
661 /**
662 * Prefills the {@link #infoForm information form} with the given filename.
663 *
664 * @protected
665 * @param {string} filename
666 */
667 mw.Upload.BookletLayout.prototype.setFilename = function ( filename ) {
668 var title = mw.Title.newFromFileName( filename );
669
670 if ( title ) {
671 this.filenameWidget.setValue( title.getNameText() );
672 this.filenameExtension = mw.Title.normalizeExtension( title.getExtension() );
673 } else {
674 // Seems to happen for files with no extension, which should fail some checks anyway...
675 this.filenameWidget.setValue( filename );
676 this.filenameExtension = null;
677 }
678 };
679
680 /**
681 * Gets the page text from the
682 * {@link #infoForm information form}.
683 *
684 * @protected
685 * @return {string}
686 */
687 mw.Upload.BookletLayout.prototype.getText = function () {
688 return this.descriptionWidget.getValue();
689 };
690
691 /* Setters */
692
693 /**
694 * Sets the file object
695 *
696 * @protected
697 * @param {File|null} file File to select
698 */
699 mw.Upload.BookletLayout.prototype.setFile = function ( file ) {
700 this.selectFileWidget.setValue( file );
701 };
702
703 /**
704 * Sets the filekey of a file already stashed on the server
705 * as the target of this upload operation.
706 *
707 * @protected
708 * @param {string} filekey
709 */
710 mw.Upload.BookletLayout.prototype.setFilekey = function ( filekey ) {
711 this.upload.setFilekey( this.filekey );
712 this.selectFileWidget.setValue( filekey );
713
714 this.onUploadFormChange();
715 };
716
717 /**
718 * Clear the values of all fields
719 *
720 * @protected
721 */
722 mw.Upload.BookletLayout.prototype.clear = function () {
723 this.selectFileWidget.setValue( null );
724 this.progressBarWidget.setProgress( 0 );
725 this.filenameWidget.setValue( null ).setValidityFlag( true );
726 this.descriptionWidget.setValue( null ).setValidityFlag( true );
727 this.filenameUsageWidget.setValue( null );
728 };
729
730 }( jQuery, mediaWiki, moment ) );