Esanders has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/326003 )
Change subject: WIP Support section=new in NWE ...................................................................... WIP Support section=new in NWE Bug: T150709 Change-Id: I1002b97060d642df0988da15860a36c13712bade --- M ApiVisualEditorEdit.php M extension.json M modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css M modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-monobook.css M modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-vector.css M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js M modules/ve-mw/init/ve.init.mw.ArticleTarget.js M modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js M modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js 10 files changed, 89 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/03/326003/1 diff --git a/ApiVisualEditorEdit.php b/ApiVisualEditorEdit.php index 443fdfb..c63d945 100644 --- a/ApiVisualEditorEdit.php +++ b/ApiVisualEditorEdit.php @@ -405,6 +405,7 @@ ], 'wikitext' => null, 'section' => null, + 'sectiontitle' => null, 'basetimestamp' => null, 'starttimestamp' => null, 'oldid' => null, diff --git a/extension.json b/extension.json index afe3f0a..41e0772 100644 --- a/extension.json +++ b/extension.json @@ -390,6 +390,7 @@ "parentheses", "readonlywarning", "redirectpagesub", + "subject", "visualeditor-loadwarning", "visualeditor-loadwarning-noconnect", "visualeditor-loadwarning-token", diff --git a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css index 9065a74..49e52eb 100644 --- a/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css +++ b/modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget.css @@ -61,3 +61,16 @@ .ve-init-mw-desktopArticleTarget #bodyContent { /* stylelint-disable-line selector-no-id */ z-index: 1; } + +.ve-ui-init-desktopArticleTarget-sectionTitle { + max-width: none; + margin: 1em 0 0.5em 0; +} + +.ve-ui-init-desktopArticleTarget-sectionTitle .oo-ui-inputWidget-input { + padding: 0 !important; + border: 0 !important; + outline: 0 !important; + box-shadow: none !important; + line-height: inherit; +} diff --git a/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-monobook.css b/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-monobook.css index 9e4ec8a..7a4584a 100644 --- a/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-monobook.css +++ b/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-monobook.css @@ -24,3 +24,8 @@ /* Monobook sets a background:url(); rule which overrides the colour. TODO: Fix upstream */ background-color: #e6f1ff; } + +.ve-ui-init-desktopArticleTarget-sectionTitle { + font-size: 150%; + border-bottom: 1px solid #aaa; +} diff --git a/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-vector.css b/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-vector.css index 7e0389c..c7b4095 100644 --- a/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-vector.css +++ b/modules/ve-mw/init/styles/ve.init.mw.DesktopTarget-vector.css @@ -32,3 +32,14 @@ /* Reset -2px from VE-core */ margin-right: 0; } + +.ve-ui-surface-placeholder { + opacity: 0.5; +} + +.ve-ui-init-desktopArticleTarget-sectionTitle { + font-family: 'Linux Libertine', 'Georgia', 'Times', serif; + line-height: 1.3; + font-size: 1.5em; + border-bottom: 1px solid #aaa; +} diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js index 11ff2ef..5e9cbca 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js @@ -103,7 +103,7 @@ function parseSection( section ) { var parsedSection = section; - // Section must be 'new' (not yet supported) or a number + // Section must be 'new' or a number if ( section !== 'new' ) { parsedSection = +section; if ( isNaN( parsedSection ) ) { @@ -240,7 +240,7 @@ * * @private * @param {string} mode Target mode: 'visual' or 'source' - * @param {number} [section] Section to edit (currently just source mode) + * @param {number|string} [section] Section to edit (currently just source mode) * @param {jQuery.Promise} [targetPromise] Promise that will be resolved with a ve.init.mw.DesktopArticleTarget * @param {boolean} [modified] The page was been modified before loading (e.g. in source mode) */ @@ -478,7 +478,7 @@ $caVeEdit.on( 'click', init.onEditTabClick.bind( init, 'visual' ) ); } if ( pageCanLoadEditor && init.isWikitextAvailable ) { - $caEdit.on( 'click', init.onEditTabClick.bind( init, 'source' ) ); + $caEdit.add( '#ca-addsection' ).on( 'click', init.onEditTabClick.bind( init, 'source' ) ); } // Alter the edit tab (#ca-edit) @@ -581,6 +581,7 @@ }, onEditTabClick: function ( mode, e ) { + var isNewSection; if ( !init.isUnmodifiedLeftClick( e ) ) { return; } @@ -588,7 +589,12 @@ if ( isLoading ) { return; } - if ( active ) { + + isNewSection = !!$( e.target ).closest( '#ca-addsection' ).length; + + if ( isNewSection ) { + this.onEditSectionLinkClick( mode, e, 'new' ); + } else if ( active ) { targetPromise.done( function ( target ) { if ( mode === 'visual' && target.getDefaultMode() === 'source' ) { target.switchToVisualEditor(); @@ -646,8 +652,15 @@ } }, - onEditSectionLinkClick: function ( mode, e ) { - var section, targetPromise; + /** + * Handle section edit links being clicked + * + * @param {string} mode Edit mode + * @param {jQuery.Event} e Click event + * @param {number|string} [section] Override edit section, taken from link URL if not specified + */ + onEditSectionLinkClick: function ( mode, e, section ) { + var targetPromise; if ( !init.isUnmodifiedLeftClick( e ) ) { return; } diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index e20c935..fbf5437 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -462,11 +462,15 @@ ve.init.mw.DesktopArticleTarget.prototype.afterActivate = function () { $( 'html' ).removeClass( 've-activating' ).addClass( 've-active' ); if ( !this.editingTabDialog ) { - // We have to focus the page after hiding the original content, otherwise - // in firefox the contentEditable container was below the view page, and - // 'focus' scrolled the screen down. - // Support: Firefox - this.getSurface().getView().focus(); + if ( this.sectionTitle ) { + this.sectionTitle.focus(); + } else { + // We have to focus the page after hiding the original content, otherwise + // in firefox the contentEditable container was below the view page, and + // 'focus' scrolled the screen down. + // Support: Firefox + this.getSurface().getView().focus(); + } } }; @@ -475,6 +479,18 @@ */ ve.init.mw.DesktopArticleTarget.prototype.setSurface = function ( surface ) { if ( surface !== this.surface ) { + if ( surface.getMode() === 'source' && this.section === 'new' ) { + if ( !this.sectionTitle ) { + this.sectionTitle = new OO.ui.TextInputWidget( { + classes: [ 've-ui-init-desktopArticleTarget-sectionTitle' ], + maxLength: 255, + placeholder: 'Subject' // TODO: i18n + } ); + } + surface.setPlaceholder( 'New section' ); // TODO: i18n + this.$editableContent.before( this.sectionTitle.$element ); + } + this.$editableContent.after( surface.$element ); } @@ -506,6 +522,10 @@ if ( this.editingTabDialog ) { this.editingTabDialog.close(); } + if ( this.sectionTitle ) { + this.sectionTitle.$element.remove(); + this.sectionTitle = null; + } this.editingTabDialog = null; if ( noDialog || this.activating || !this.edited ) { diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js index 2beeca6..4d917a0 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js @@ -40,6 +40,7 @@ this.pageExists = mw.config.get( 'wgRelevantArticleId', 0 ) !== 0; this.toolbarScrollOffset = mw.config.get( 'wgVisualEditorToolbarScrollOffset', 0 ); this.section = null; + this.sectionTitle = null; this.checkboxFields = null; this.checkboxesByName = null; @@ -1299,11 +1300,15 @@ wikitext: doc, format: 'json' }; - if ( this.section !== null ) { - data.section = this.section; - } postData = ve.extendObject( {}, options, data ); - if ( data.token ) { + if ( this.section !== null ) { + postData.section = this.section; + } + if ( this.sectionTitle ) { + postData.sectiontitle = this.sectionTitle.getValue(); + postData.summary = undefined; + } + if ( postData.token ) { return new mw.Api().post( postData, { contentType: 'multipart/form-data' } ); } return new mw.Api().postWithToken( 'csrf', postData, { contentType: 'multipart/form-data' } ); diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js b/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js index 8b62bd9..804f874 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js @@ -108,7 +108,7 @@ * * @param {string} mode Target mode: 'visual' or 'source' * @param {string} pageName Page name to request - * @param {number} [section] Section to edit (currently just source mode) + * @param {number|string} [section] Section to edit, number or 'new' (currently just source mode) * @param {string} [oldid] Old revision ID, current if omitted * @param {string} [targetName] Optional target name for tracking * @param {boolean} [modified] The page was been modified before loading (e.g. in source mode) diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js index bcfa856..b4c7e1a 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWSaveDialog.js @@ -26,7 +26,6 @@ this.restoring = false; this.messages = {}; this.setupDeferred = $.Deferred(); - this.target = null; this.checkboxesByName = null; this.changedEditSummary = false; @@ -527,7 +526,10 @@ ve.ui.MWSaveDialog.prototype.getSetupProcess = function ( data ) { return ve.ui.MWSaveDialog.super.prototype.getSetupProcess.call( this, data ) .next( function () { - if ( !this.changedEditSummary ) { + if ( ve.init.target.sectionTitle ) { + this.setEditSummary( ve.init.target.sectionTitle.getValue() ); + this.editSummaryInput.setDisabled( true ); + } else if ( !this.changedEditSummary ) { this.setEditSummary( data.editSummary ); } this.setupCheckboxes( data.checkboxFields || [] ); @@ -561,7 +563,6 @@ return ve.ui.MWSaveDialog.super.prototype.getTeardownProcess.call( this, data ) .next( function () { this.emit( 'close' ); - this.target = null; }, this ); }; -- To view, visit https://gerrit.wikimedia.org/r/326003 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1002b97060d642df0988da15860a36c13712bade Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits