2013-12-19 16:38:02 +00:00
|
|
|
|
/*!
|
|
|
|
|
* VisualEditor user interface MWSettingsPage class.
|
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
|
* @copyright See AUTHORS.txt
|
2013-12-19 16:38:02 +00:00
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MediaWiki meta dialog settings page.
|
|
|
|
|
*
|
|
|
|
|
* @class
|
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
|
* @param {Object} [config] Configuration options
|
2017-12-30 01:39:09 +00:00
|
|
|
|
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
|
2013-12-19 16:38:02 +00:00
|
|
|
|
*/
|
2014-04-04 17:42:13 +00:00
|
|
|
|
ve.ui.MWSettingsPage = function VeUiMWSettingsPage( name, config ) {
|
2014-04-15 14:09:48 +00:00
|
|
|
|
var settingsPage = this;
|
|
|
|
|
|
2013-12-19 16:38:02 +00:00
|
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
|
ve.ui.MWSettingsPage.super.apply( this, arguments );
|
2013-12-19 16:38:02 +00:00
|
|
|
|
|
|
|
|
|
// Properties
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment = null;
|
2013-12-19 16:38:02 +00:00
|
|
|
|
this.tocOptionTouched = false;
|
2013-11-13 20:15:44 +00:00
|
|
|
|
this.redirectOptionsTouched = false;
|
2014-01-22 20:13:59 +00:00
|
|
|
|
this.tableOfContentsTouched = false;
|
|
|
|
|
this.label = ve.msg( 'visualeditor-dialog-meta-settings-section' );
|
|
|
|
|
|
2013-12-19 16:38:02 +00:00
|
|
|
|
this.settingsFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-label' ),
|
2018-08-16 23:58:54 +00:00
|
|
|
|
icon: 'pageSettings'
|
2013-12-19 16:38:02 +00:00
|
|
|
|
} );
|
2013-11-15 20:02:34 +00:00
|
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
|
|
|
|
|
|
// Table of Contents items
|
2014-01-22 20:13:59 +00:00
|
|
|
|
this.tableOfContents = new OO.ui.FieldLayout(
|
2015-02-05 09:35:18 +00:00
|
|
|
|
new OO.ui.ButtonSelectWidget( {
|
|
|
|
|
classes: [ 've-test-page-settings-table-of-contents' ]
|
|
|
|
|
} )
|
2014-01-22 20:13:59 +00:00
|
|
|
|
.addItems( [
|
2014-11-22 01:40:00 +00:00
|
|
|
|
new OO.ui.ButtonOptionWidget( {
|
2017-04-07 00:55:45 +00:00
|
|
|
|
data: 'mw:PageProp/forcetoc',
|
2014-11-22 01:40:00 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-toc-force' )
|
|
|
|
|
} ),
|
|
|
|
|
new OO.ui.ButtonOptionWidget( {
|
|
|
|
|
data: 'default',
|
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-toc-default' )
|
|
|
|
|
} ),
|
|
|
|
|
new OO.ui.ButtonOptionWidget( {
|
2017-04-07 00:55:45 +00:00
|
|
|
|
data: 'mw:PageProp/notoc',
|
2014-11-22 01:40:00 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-toc-disable' )
|
|
|
|
|
} )
|
2014-01-22 20:13:59 +00:00
|
|
|
|
] )
|
2014-08-22 20:50:48 +00:00
|
|
|
|
.connect( this, { select: 'onTableOfContentsFieldChange' } ),
|
2014-01-22 20:13:59 +00:00
|
|
|
|
{
|
2017-02-16 01:56:03 +00:00
|
|
|
|
$overlay: config.$overlay,
|
2014-08-22 20:50:48 +00:00
|
|
|
|
align: 'top',
|
2014-07-19 17:39:34 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-toc-label' ),
|
|
|
|
|
help: ve.msg( 'visualeditor-dialog-meta-settings-toc-help' )
|
2014-01-22 20:13:59 +00:00
|
|
|
|
}
|
2013-12-19 16:38:02 +00:00
|
|
|
|
);
|
2013-11-15 20:02:34 +00:00
|
|
|
|
|
2013-11-13 20:15:44 +00:00
|
|
|
|
// Redirect items
|
2015-04-09 23:47:15 +00:00
|
|
|
|
this.enableRedirectInput = new OO.ui.CheckboxInputWidget();
|
2014-01-22 20:13:59 +00:00
|
|
|
|
this.enableRedirectField = new OO.ui.FieldLayout(
|
|
|
|
|
this.enableRedirectInput,
|
|
|
|
|
{
|
2017-02-16 01:56:03 +00:00
|
|
|
|
$overlay: config.$overlay,
|
2015-02-05 09:35:18 +00:00
|
|
|
|
classes: [ 've-test-page-settings-enable-redirect' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
|
align: 'inline',
|
2014-07-19 17:39:34 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-redirect-label' ),
|
|
|
|
|
help: ve.msg( 'visualeditor-dialog-meta-settings-redirect-help' )
|
2014-01-22 20:13:59 +00:00
|
|
|
|
}
|
|
|
|
|
);
|
2015-06-15 10:25:44 +00:00
|
|
|
|
this.redirectTargetInput = new mw.widgets.TitleInputWidget( {
|
2014-11-01 04:48:07 +00:00
|
|
|
|
placeholder: ve.msg( 'visualeditor-dialog-meta-settings-redirect-placeholder' ),
|
2018-05-04 13:30:10 +00:00
|
|
|
|
$overlay: config.$overlay,
|
|
|
|
|
api: ve.init.target.getContentApi()
|
2013-11-13 20:15:44 +00:00
|
|
|
|
} );
|
2020-03-06 01:38:57 +00:00
|
|
|
|
this.redirectTargetInput.$input.attr( 'aria-label', ve.msg( 'visualeditor-dialog-meta-settings-redirect-placeholder' ) );
|
|
|
|
|
|
2014-01-22 20:13:59 +00:00
|
|
|
|
this.redirectTargetField = new OO.ui.FieldLayout(
|
|
|
|
|
this.redirectTargetInput,
|
2015-04-09 23:47:15 +00:00
|
|
|
|
{ align: 'top' }
|
2014-01-22 20:13:59 +00:00
|
|
|
|
);
|
2015-04-09 23:47:15 +00:00
|
|
|
|
this.enableStaticRedirectInput = new OO.ui.CheckboxInputWidget();
|
2014-01-22 20:13:59 +00:00
|
|
|
|
this.enableStaticRedirectField = new OO.ui.FieldLayout(
|
|
|
|
|
this.enableStaticRedirectInput,
|
|
|
|
|
{
|
2017-02-16 01:56:03 +00:00
|
|
|
|
$overlay: config.$overlay,
|
2015-02-05 09:35:18 +00:00
|
|
|
|
classes: [ 've-test-page-settings-prevent-redirect' ],
|
2014-08-22 20:50:48 +00:00
|
|
|
|
align: 'inline',
|
2014-07-19 17:39:34 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-redirect-staticlabel' ),
|
|
|
|
|
help: ve.msg( 'visualeditor-dialog-meta-settings-redirect-statichelp' )
|
2014-01-22 20:13:59 +00:00
|
|
|
|
}
|
2013-11-13 20:15:44 +00:00
|
|
|
|
);
|
2014-08-22 20:50:48 +00:00
|
|
|
|
this.enableRedirectInput.connect( this, { change: 'onEnableRedirectChange' } );
|
|
|
|
|
this.redirectTargetInput.connect( this, { change: 'onRedirectTargetChange' } );
|
|
|
|
|
this.enableStaticRedirectInput.connect( this, { change: 'onEnableStaticRedirectChange' } );
|
2013-11-13 20:15:44 +00:00
|
|
|
|
|
2014-04-15 14:09:48 +00:00
|
|
|
|
this.metaItemCheckboxes = [
|
2014-01-22 20:13:59 +00:00
|
|
|
|
{
|
2014-04-15 14:09:48 +00:00
|
|
|
|
metaName: 'mwNoEditSection',
|
2014-07-19 17:39:34 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-noeditsection-label' ),
|
2015-02-25 02:37:15 +00:00
|
|
|
|
help: ve.msg( 'visualeditor-dialog-meta-settings-noeditsection-help' ),
|
|
|
|
|
classes: [ 've-test-page-settings-noeditsection' ]
|
2014-01-22 20:13:59 +00:00
|
|
|
|
}
|
2014-04-29 12:43:14 +00:00
|
|
|
|
].concat( ve.ui.MWSettingsPage.static.extraMetaCheckboxes );
|
2014-07-19 17:41:06 +00:00
|
|
|
|
|
2014-04-15 14:09:48 +00:00
|
|
|
|
if ( mw.config.get( 'wgNamespaceNumber' ) === mw.config.get( 'wgNamespaceIds' ).category ) {
|
|
|
|
|
this.metaItemCheckboxes.push(
|
|
|
|
|
{
|
|
|
|
|
metaName: 'mwHiddenCategory',
|
2014-07-19 17:39:34 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-hiddencat-label' ),
|
|
|
|
|
help: ve.msg( 'visualeditor-dialog-meta-settings-hiddencat-help' )
|
2014-04-15 14:09:48 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
metaName: 'mwNoGallery',
|
2014-07-19 17:39:34 +00:00
|
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-settings-nogallery-label' ),
|
|
|
|
|
help: ve.msg( 'visualeditor-dialog-meta-settings-nogallery-help' )
|
2014-04-15 14:09:48 +00:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-11-15 20:02:34 +00:00
|
|
|
|
|
2014-01-22 20:13:59 +00:00
|
|
|
|
this.settingsFieldset.addItems( [
|
|
|
|
|
this.enableRedirectField,
|
|
|
|
|
this.redirectTargetField,
|
|
|
|
|
this.enableStaticRedirectField,
|
2014-04-15 14:09:48 +00:00
|
|
|
|
this.tableOfContents
|
2014-01-22 20:13:59 +00:00
|
|
|
|
] );
|
2014-04-15 14:09:48 +00:00
|
|
|
|
|
2019-02-25 11:47:28 +00:00
|
|
|
|
this.metaItemCheckboxes.forEach( function ( metaItemCheckbox ) {
|
|
|
|
|
metaItemCheckbox.fieldLayout = new OO.ui.FieldLayout(
|
2015-04-09 23:47:15 +00:00
|
|
|
|
new OO.ui.CheckboxInputWidget(),
|
2020-04-09 13:33:54 +00:00
|
|
|
|
// See above for classes
|
|
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
2014-04-15 14:09:48 +00:00
|
|
|
|
{
|
2017-02-16 01:56:03 +00:00
|
|
|
|
$overlay: config.$overlay,
|
2019-02-25 11:47:28 +00:00
|
|
|
|
classes: metaItemCheckbox.classes,
|
2014-08-22 20:50:48 +00:00
|
|
|
|
align: 'inline',
|
2019-02-25 11:47:28 +00:00
|
|
|
|
label: metaItemCheckbox.label,
|
|
|
|
|
help: metaItemCheckbox.help || ''
|
2014-04-15 14:09:48 +00:00
|
|
|
|
}
|
|
|
|
|
);
|
2019-02-25 11:47:28 +00:00
|
|
|
|
settingsPage.settingsFieldset.addItems( [ metaItemCheckbox.fieldLayout ] );
|
2014-04-15 14:09:48 +00:00
|
|
|
|
} );
|
|
|
|
|
|
2013-12-19 16:38:02 +00:00
|
|
|
|
this.$element.append( this.settingsFieldset.$element );
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWSettingsPage, OO.ui.PageLayout );
|
|
|
|
|
|
2014-04-29 12:43:14 +00:00
|
|
|
|
/* Allow extra meta item checkboxes to be added by extensions etc. */
|
|
|
|
|
ve.ui.MWSettingsPage.static.extraMetaCheckboxes = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a checkbox to the list of changeable page settings
|
2015-08-19 18:21:01 +00:00
|
|
|
|
*
|
2014-04-29 12:43:14 +00:00
|
|
|
|
* @param {string} metaName The name of the DM meta item
|
|
|
|
|
* @param {string} label The label to show next to the checkbox
|
|
|
|
|
*/
|
|
|
|
|
ve.ui.MWSettingsPage.static.addMetaCheckbox = function ( metaName, label ) {
|
2014-08-22 20:50:48 +00:00
|
|
|
|
this.extraMetaCheckboxes.push( { metaName: metaName, label: label } );
|
2014-04-29 12:43:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-12-19 16:38:02 +00:00
|
|
|
|
/* Methods */
|
|
|
|
|
|
2013-11-13 20:15:44 +00:00
|
|
|
|
/* Table of Contents methods */
|
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2021-09-15 10:10:56 +00:00
|
|
|
|
ve.ui.MWSettingsPage.prototype.setupOutlineItem = function () {
|
|
|
|
|
this.outlineItem
|
|
|
|
|
.setIcon( 'pageSettings' )
|
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-meta-settings-section' ) );
|
2014-02-15 01:37:32 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-12-19 16:38:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Handle Table Of Contents display change events.
|
|
|
|
|
*/
|
2014-01-22 20:13:59 +00:00
|
|
|
|
ve.ui.MWSettingsPage.prototype.onTableOfContentsFieldChange = function () {
|
|
|
|
|
this.tableOfContentsTouched = true;
|
2013-12-19 16:38:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-11-13 20:15:44 +00:00
|
|
|
|
/* Redirect methods */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle redirect state change events.
|
|
|
|
|
*
|
|
|
|
|
* @param {boolean} value Whether a redirect is to be set for this page
|
|
|
|
|
*/
|
|
|
|
|
ve.ui.MWSettingsPage.prototype.onEnableRedirectChange = function ( value ) {
|
2016-06-10 16:28:19 +00:00
|
|
|
|
var page = this;
|
2013-11-13 20:15:44 +00:00
|
|
|
|
this.redirectTargetInput.setDisabled( !value );
|
|
|
|
|
this.enableStaticRedirectInput.setDisabled( !value );
|
2015-07-29 22:58:43 +00:00
|
|
|
|
if ( value ) {
|
2016-06-10 16:28:19 +00:00
|
|
|
|
/*
|
|
|
|
|
* HACK: When editing a page which has a redirect, the meta dialog
|
|
|
|
|
* automatically opens with the settings page's redirect field focused.
|
|
|
|
|
* When this happens, we don't want the lookup dropdown to appear until
|
|
|
|
|
* the user actually does something.
|
|
|
|
|
* Using setTimeout because we need to defer this until after the
|
|
|
|
|
* dialog has opened - otherwise its internal lookupDisabled logic will
|
|
|
|
|
* fail to have any effect during the actual focusing and calling of
|
|
|
|
|
* OO.ui.LookupElement#onLookupInputFocus/OO.ui.LookupElement#populateLookupMenu.
|
|
|
|
|
* https://phabricator.wikimedia.org/T137309
|
|
|
|
|
*/
|
|
|
|
|
setTimeout( function () {
|
|
|
|
|
page.redirectTargetInput.focus();
|
|
|
|
|
} );
|
2015-07-29 22:58:43 +00:00
|
|
|
|
} else {
|
2013-11-13 20:15:44 +00:00
|
|
|
|
this.redirectTargetInput.setValue( '' );
|
2015-01-19 23:31:04 +00:00
|
|
|
|
this.enableStaticRedirectInput.setSelected( false );
|
2013-11-13 20:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
this.redirectOptionsTouched = true;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-31 20:56:13 +00:00
|
|
|
|
/**
|
2019-04-16 15:17:29 +00:00
|
|
|
|
* @return {boolean} Whether redirect link is valid.
|
2018-10-31 20:56:13 +00:00
|
|
|
|
*/
|
|
|
|
|
ve.ui.MWSettingsPage.prototype.checkValidRedirect = function () {
|
|
|
|
|
if ( this.enableRedirectInput.isSelected() ) {
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var title = this.redirectTargetInput.getValue();
|
2018-10-31 20:56:13 +00:00
|
|
|
|
|
|
|
|
|
if ( !mw.Title.newFromText( title ) ) {
|
|
|
|
|
/*
|
|
|
|
|
* TODO more precise error message. Modify the Title.newFromText method in Title.js
|
|
|
|
|
* my idea is to in the parse method instead of a boolean return a string with an error message (not an error code since the error string can have parameters),
|
|
|
|
|
* then in Title.newFromText instead of returning null, return the error string. Use that string there in setErrors.
|
|
|
|
|
* Problem: some methods might depend on it returning null.
|
2022-08-05 08:00:54 +00:00
|
|
|
|
* Solution: either make it a new method (Title.newFromTextThrow), or add a an optional parameter to return the error message.
|
2018-10-31 20:56:13 +00:00
|
|
|
|
*/
|
|
|
|
|
this.redirectTargetField.setErrors( [ mw.msg( 'visualeditor-title-error' ) ] );
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
this.redirectTargetField.setErrors( [] );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.redirectTargetField.setErrors( [] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-13 20:15:44 +00:00
|
|
|
|
/**
|
|
|
|
|
* Handle redirect target change events.
|
|
|
|
|
*/
|
|
|
|
|
ve.ui.MWSettingsPage.prototype.onRedirectTargetChange = function () {
|
|
|
|
|
this.redirectOptionsTouched = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle static redirect state change events.
|
|
|
|
|
*/
|
|
|
|
|
ve.ui.MWSettingsPage.prototype.onEnableStaticRedirectChange = function () {
|
|
|
|
|
this.redirectOptionsTouched = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2014-04-15 14:09:48 +00:00
|
|
|
|
* Get the first meta item of a given name
|
2013-11-15 20:02:34 +00:00
|
|
|
|
*
|
2014-04-15 14:09:48 +00:00
|
|
|
|
* @param {string} name Name of the meta item
|
2015-08-19 18:09:34 +00:00
|
|
|
|
* @return {Object|null} Meta item, if any
|
2013-11-15 20:02:34 +00:00
|
|
|
|
*/
|
2014-04-15 14:09:48 +00:00
|
|
|
|
ve.ui.MWSettingsPage.prototype.getMetaItem = function ( name ) {
|
2022-01-19 14:25:39 +00:00
|
|
|
|
return this.fragment.getDocument().getMetaList().getItemsInGroup( name )[ 0 ] || null;
|
2013-11-15 20:02:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-12-19 16:38:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Setup settings page.
|
|
|
|
|
*
|
2022-01-19 14:25:39 +00:00
|
|
|
|
* @param {ve.dm.SurfaceFragment} fragment Surface fragment
|
2021-09-11 08:05:31 +00:00
|
|
|
|
* @param {Object} config
|
2019-02-25 12:04:03 +00:00
|
|
|
|
* @param {Object} [config.data] Dialog setup data
|
2022-02-14 15:18:57 +00:00
|
|
|
|
* @param {boolean} [config.isReadOnly=false] Dialog is in read-only mode
|
2018-10-30 18:53:43 +00:00
|
|
|
|
* @return {jQuery.Promise}
|
2013-12-19 16:38:02 +00:00
|
|
|
|
*/
|
2022-01-19 14:25:39 +00:00
|
|
|
|
ve.ui.MWSettingsPage.prototype.setup = function ( fragment, config ) {
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var settingsPage = this;
|
2013-12-19 16:38:02 +00:00
|
|
|
|
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment = fragment;
|
2015-08-19 18:05:01 +00:00
|
|
|
|
|
2013-11-15 20:02:34 +00:00
|
|
|
|
// Table of Contents items
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var tableOfContentsField = this.tableOfContents.getField();
|
|
|
|
|
var tableOfContentsMetaItem = this.getMetaItem( 'mwTOC' );
|
|
|
|
|
var tableOfContentsMode = tableOfContentsMetaItem && tableOfContentsMetaItem.getAttribute( 'property' ) || 'default';
|
2019-02-25 12:04:03 +00:00
|
|
|
|
tableOfContentsField
|
|
|
|
|
.selectItemByData( tableOfContentsMode )
|
|
|
|
|
.setDisabled( config.isReadOnly );
|
2014-01-22 20:13:59 +00:00
|
|
|
|
this.tableOfContentsTouched = false;
|
2013-11-15 20:02:34 +00:00
|
|
|
|
|
2013-11-13 20:15:44 +00:00
|
|
|
|
// Redirect items (disabled states set by change event)
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var redirectTargetItem = this.getMetaItem( 'mwRedirect' );
|
|
|
|
|
var redirectTarget = redirectTargetItem && redirectTargetItem.getAttribute( 'title' ) || '';
|
|
|
|
|
var redirectStatic = this.getMetaItem( 'mwStaticRedirect' );
|
2019-02-25 12:04:03 +00:00
|
|
|
|
this.enableRedirectInput
|
|
|
|
|
.setSelected( !!redirectTargetItem )
|
|
|
|
|
.setDisabled( config.isReadOnly );
|
|
|
|
|
this.redirectTargetInput
|
|
|
|
|
.setValue( redirectTarget )
|
|
|
|
|
.setDisabled( !redirectTargetItem )
|
|
|
|
|
.setReadOnly( config.isReadOnly );
|
|
|
|
|
this.enableStaticRedirectInput
|
|
|
|
|
.setSelected( !!redirectStatic )
|
|
|
|
|
.setDisabled( !redirectTargetItem || config.isReadOnly );
|
2013-11-13 20:15:44 +00:00
|
|
|
|
this.redirectOptionsTouched = false;
|
|
|
|
|
|
2014-04-15 14:09:48 +00:00
|
|
|
|
// Simple checkbox items
|
2019-02-25 11:47:28 +00:00
|
|
|
|
this.metaItemCheckboxes.forEach( function ( metaItemCheckbox ) {
|
|
|
|
|
var isSelected = !!settingsPage.getMetaItem( metaItemCheckbox.metaName );
|
2019-02-25 12:04:03 +00:00
|
|
|
|
metaItemCheckbox.fieldLayout.getField()
|
|
|
|
|
.setSelected( isSelected )
|
|
|
|
|
.setDisabled( config.isReadOnly );
|
2014-04-15 14:09:48 +00:00
|
|
|
|
} );
|
2018-10-30 18:53:43 +00:00
|
|
|
|
|
2019-11-02 05:06:28 +00:00
|
|
|
|
return ve.createDeferred().resolve().promise();
|
2013-12-19 16:38:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tear down settings page.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} [data] Dialog tear down data
|
|
|
|
|
*/
|
|
|
|
|
ve.ui.MWSettingsPage.prototype.teardown = function ( data ) {
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var settingsPage = this;
|
2015-08-19 18:05:01 +00:00
|
|
|
|
|
2013-12-19 16:38:02 +00:00
|
|
|
|
// Data initialisation
|
|
|
|
|
data = data || {};
|
2019-02-19 17:08:38 +00:00
|
|
|
|
if ( data.action !== 'done' ) {
|
2015-07-30 23:21:52 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2013-12-19 16:38:02 +00:00
|
|
|
|
|
2015-08-19 18:05:01 +00:00
|
|
|
|
// Table of Contents items
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var currentTableOfContents = this.getMetaItem( 'mwTOC' );
|
|
|
|
|
var newTableOfContentsData = this.tableOfContents.getField().findSelectedItem();
|
2013-11-13 20:15:44 +00:00
|
|
|
|
|
2015-08-19 18:05:01 +00:00
|
|
|
|
// Redirect items
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var currentRedirectTargetItem = this.getMetaItem( 'mwRedirect' );
|
|
|
|
|
var newRedirectData = this.redirectTargetInput.getValue();
|
|
|
|
|
var newRedirectItemData = { type: 'mwRedirect', attributes: { title: newRedirectData } };
|
2013-11-13 20:15:44 +00:00
|
|
|
|
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var currentStaticRedirectItem = this.getMetaItem( 'mwStaticRedirect' );
|
|
|
|
|
var newStaticRedirectState = this.enableStaticRedirectInput.isSelected();
|
2013-12-19 16:38:02 +00:00
|
|
|
|
|
|
|
|
|
// Alter the TOC option flag iff it's been touched & is actually different
|
2014-01-22 20:13:59 +00:00
|
|
|
|
if ( this.tableOfContentsTouched ) {
|
2017-04-07 00:55:45 +00:00
|
|
|
|
if ( newTableOfContentsData.data === 'default' ) {
|
|
|
|
|
if ( currentTableOfContents ) {
|
2023-03-15 13:07:40 +00:00
|
|
|
|
this.fragment.removeMeta( currentTableOfContents );
|
2013-12-19 16:38:02 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-02-21 18:07:07 +00:00
|
|
|
|
var newTableOfContentsItem = { type: 'mwTOC', attributes: { property: newTableOfContentsData.data } };
|
2017-04-07 00:55:45 +00:00
|
|
|
|
|
|
|
|
|
if ( !currentTableOfContents ) {
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment.insertMeta( newTableOfContentsItem );
|
2017-04-07 00:55:45 +00:00
|
|
|
|
} else if ( currentTableOfContents.getAttribute( 'property' ) !== newTableOfContentsData.data ) {
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment.replaceMeta(
|
|
|
|
|
currentTableOfContents,
|
2017-04-07 00:55:45 +00:00
|
|
|
|
ve.extendObject( true, {}, currentTableOfContents.getElement(), newTableOfContentsItem )
|
2013-12-19 16:38:02 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-15 20:02:34 +00:00
|
|
|
|
|
2013-11-13 20:15:44 +00:00
|
|
|
|
// Alter the redirect options iff they've been touched & are different
|
|
|
|
|
if ( this.redirectOptionsTouched ) {
|
|
|
|
|
if ( currentRedirectTargetItem ) {
|
|
|
|
|
if ( newRedirectData ) {
|
2014-02-20 01:33:37 +00:00
|
|
|
|
if ( currentRedirectTargetItem.getAttribute( 'title' ) !== newRedirectData ) {
|
2013-11-13 20:15:44 +00:00
|
|
|
|
// There was a redirect and is a new one, but they differ, so replace
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment.replaceMeta(
|
|
|
|
|
currentRedirectTargetItem,
|
2013-11-13 20:15:44 +00:00
|
|
|
|
ve.extendObject( true, {},
|
|
|
|
|
currentRedirectTargetItem.getElement(),
|
|
|
|
|
newRedirectItemData
|
2017-07-18 11:55:33 +00:00
|
|
|
|
)
|
|
|
|
|
);
|
2013-11-13 20:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// There was a redirect and is no new one, so remove
|
2023-03-15 13:07:40 +00:00
|
|
|
|
this.fragment.removeMeta( currentRedirectTargetItem );
|
2013-11-13 20:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ( newRedirectData ) {
|
|
|
|
|
// There's no existing redirect but there is a new one, so create
|
2018-02-12 19:26:53 +00:00
|
|
|
|
// HACK: Putting this at position 0 so that it works – T63862
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment.insertMeta( newRedirectItemData, 0 );
|
2013-11-13 20:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( currentStaticRedirectItem && ( !newStaticRedirectState || !newRedirectData ) ) {
|
2023-03-15 13:07:40 +00:00
|
|
|
|
this.fragment.removeMeta( currentStaticRedirectItem );
|
2013-11-13 20:15:44 +00:00
|
|
|
|
}
|
2014-02-24 20:11:23 +00:00
|
|
|
|
if ( !currentStaticRedirectItem && newStaticRedirectState && newRedirectData ) {
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment.insertMeta( { type: 'mwStaticRedirect' } );
|
2013-11-13 20:15:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-25 11:47:28 +00:00
|
|
|
|
this.metaItemCheckboxes.forEach( function ( metaItemCheckbox ) {
|
|
|
|
|
var currentItem = settingsPage.getMetaItem( metaItemCheckbox.metaName ),
|
|
|
|
|
isSelected = metaItemCheckbox.fieldLayout.getField().isSelected();
|
2014-04-15 14:09:48 +00:00
|
|
|
|
|
2014-12-09 21:01:13 +00:00
|
|
|
|
if ( currentItem && !isSelected ) {
|
2023-03-15 13:07:40 +00:00
|
|
|
|
this.fragment.removeMeta( currentItem );
|
2014-12-09 21:01:13 +00:00
|
|
|
|
} else if ( !currentItem && isSelected ) {
|
2023-03-15 13:07:40 +00:00
|
|
|
|
settingsPage.fragment.insertMeta( { type: metaItemCheckbox.metaName } );
|
2014-04-15 14:09:48 +00:00
|
|
|
|
}
|
|
|
|
|
} );
|
2014-04-04 17:42:13 +00:00
|
|
|
|
|
2022-01-19 14:25:39 +00:00
|
|
|
|
this.fragment = null;
|
2013-12-19 16:38:02 +00:00
|
|
|
|
};
|
2018-10-28 19:18:40 +00:00
|
|
|
|
|
|
|
|
|
ve.ui.MWSettingsPage.prototype.getFieldsets = function () {
|
|
|
|
|
return [
|
|
|
|
|
this.settingsFieldset
|
|
|
|
|
];
|
|
|
|
|
};
|