| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.ui.MWAdvancedSettingsPage = function VeUiMWAdvancedSettingsPage( name, config ) { |
| 20 |
|
| 21 |
ve.ui.MWAdvancedSettingsPage.super.apply( this, arguments ); |
| 22 |
|
| 23 |
|
| 24 |
this.fragment = null; |
| 25 |
this.indexingOptionTouched = false; |
| 26 |
this.newSectionEditLinkOptionTouched = false; |
| 27 |
|
| 28 |
this.advancedSettingsFieldset = new OO.ui.FieldsetLayout( { |
| 29 |
label: ve.msg( 'visualeditor-dialog-meta-advancedsettings-label' ), |
| 30 |
icon: 'settings' |
| 31 |
} ); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
this.indexing = new OO.ui.FieldLayout( |
| 37 |
new OO.ui.ButtonSelectWidget() |
| 38 |
.addItems( [ |
| 39 |
new OO.ui.ButtonOptionWidget( { |
| 40 |
data: 'mw:PageProp/index', |
| 41 |
label: ve.msg( 'visualeditor-dialog-meta-settings-index-force' ) |
| 42 |
} ), |
| 43 |
new OO.ui.ButtonOptionWidget( { |
| 44 |
data: 'default', |
| 45 |
label: ve.msg( 'visualeditor-dialog-meta-settings-index-default' ) |
| 46 |
} ), |
| 47 |
new OO.ui.ButtonOptionWidget( { |
| 48 |
data: 'mw:PageProp/noindex', |
| 49 |
label: ve.msg( 'visualeditor-dialog-meta-settings-index-disable' ) |
| 50 |
} ) |
| 51 |
] ) |
| 52 |
.connect( this, { select: 'onIndexingOptionChange' } ), |
| 53 |
{ |
| 54 |
$overlay: config.$overlay, |
| 55 |
align: 'top', |
| 56 |
label: ve.msg( 'visualeditor-dialog-meta-settings-index-label' ), |
| 57 |
help: ve.msg( 'visualeditor-dialog-meta-settings-index-help' ) |
| 58 |
} |
| 59 |
); |
| 60 |
|
| 61 |
|
| 62 |
this.newEditSectionLink = new OO.ui.FieldLayout( |
| 63 |
new OO.ui.ButtonSelectWidget() |
| 64 |
.addItems( [ |
| 65 |
new OO.ui.ButtonOptionWidget( { |
| 66 |
data: 'mw:PageProp/newsectionlink', |
| 67 |
label: ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-force' ) |
| 68 |
} ), |
| 69 |
new OO.ui.ButtonOptionWidget( { |
| 70 |
data: 'default', |
| 71 |
label: ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-default' ) |
| 72 |
} ), |
| 73 |
new OO.ui.ButtonOptionWidget( { |
| 74 |
data: 'mw:PageProp/nonewsectionlink', |
| 75 |
label: ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-disable' ) |
| 76 |
} ) |
| 77 |
] ) |
| 78 |
.connect( this, { select: 'onNewSectionEditLinkOptionChange' } ), |
| 79 |
{ |
| 80 |
$overlay: config.$overlay, |
| 81 |
align: 'top', |
| 82 |
label: ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-label' ), |
| 83 |
|
| 84 |
help: ve.msg( 'visualeditor-dialog-meta-settings-newsectioneditlink-help', $( '#ca-edit' ).text() ) |
| 85 |
} |
| 86 |
); |
| 87 |
|
| 88 |
this.displayTitleTouched = false; |
| 89 |
this.displayTitleInput = new OO.ui.TextInputWidget(); |
| 90 |
this.displayTitleInput.connect( this, { change: 'onDisplayTitleInputChange' } ); |
| 91 |
this.displayTitleField = new OO.ui.FieldLayout( |
| 92 |
this.displayTitleInput, |
| 93 |
{ |
| 94 |
$overlay: config.$overlay, |
| 95 |
align: 'top', |
| 96 |
label: ve.msg( 'visualeditor-dialog-meta-settings-displaytitle' ), |
| 97 |
help: ve.msg( 'visualeditor-dialog-meta-settings-displaytitle-help' ) |
| 98 |
} |
| 99 |
); |
| 100 |
|
| 101 |
this.advancedSettingsFieldset.addItems( [ this.indexing, this.newEditSectionLink, this.displayTitleField ] ); |
| 102 |
|
| 103 |
this.metaItemCheckboxes = []; |
| 104 |
if ( mw.config.get( 'wgVariantArticlePath' ) ) { |
| 105 |
this.metaItemCheckboxes.push( |
| 106 |
{ |
| 107 |
metaName: 'mwNoContentConvert', |
| 108 |
label: ve.msg( 'visualeditor-dialog-meta-settings-nocontentconvert-label' ), |
| 109 |
help: ve.msg( 'visualeditor-dialog-meta-settings-nocontentconvert-help' ) |
| 110 |
}, |
| 111 |
{ |
| 112 |
metaName: 'mwNoTitleConvert', |
| 113 |
label: ve.msg( 'visualeditor-dialog-meta-settings-notitleconvert-label' ), |
| 114 |
help: ve.msg( 'visualeditor-dialog-meta-settings-notitleconvert-help' ) |
| 115 |
} |
| 116 |
); |
| 117 |
} |
| 118 |
|
| 119 |
this.metaItemCheckboxes.forEach( ( metaItemCheckbox ) => { |
| 120 |
metaItemCheckbox.fieldLayout = new OO.ui.FieldLayout( |
| 121 |
new OO.ui.CheckboxInputWidget(), |
| 122 |
{ |
| 123 |
$overlay: config.$overlay, |
| 124 |
align: 'inline', |
| 125 |
label: metaItemCheckbox.label, |
| 126 |
help: metaItemCheckbox.help |
| 127 |
} |
| 128 |
); |
| 129 |
this.advancedSettingsFieldset.addItems( [ metaItemCheckbox.fieldLayout ] ); |
| 130 |
} ); |
| 131 |
|
| 132 |
this.$element.append( this.advancedSettingsFieldset.$element ); |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
OO.inheritClass( ve.ui.MWAdvancedSettingsPage, OO.ui.PageLayout ); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
ve.ui.MWAdvancedSettingsPage.prototype.onDisplayTitleInputChange = function () { |
| 147 |
this.displayTitleTouched = true; |
| 148 |
}; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
ve.ui.MWAdvancedSettingsPage.prototype.setupOutlineItem = function () { |
| 154 |
this.outlineItem |
| 155 |
.setIcon( 'settings' ) |
| 156 |
.setLabel( ve.msg( 'visualeditor-dialog-meta-advancedsettings-section' ) ); |
| 157 |
}; |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
ve.ui.MWAdvancedSettingsPage.prototype.onIndexingOptionChange = function () { |
| 165 |
this.indexingOptionTouched = true; |
| 166 |
}; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
ve.ui.MWAdvancedSettingsPage.prototype.getMetaItem = function ( name ) { |
| 175 |
return this.fragment.getDocument().getMetaList().getItemsInGroup( name )[ 0 ] || null; |
| 176 |
}; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
ve.ui.MWAdvancedSettingsPage.prototype.onNewSectionEditLinkOptionChange = function () { |
| 184 |
this.newSectionEditLinkOptionTouched = true; |
| 185 |
}; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
ve.ui.MWAdvancedSettingsPage.prototype.setup = function ( fragment, config ) { |
| 197 |
this.fragment = fragment; |
| 198 |
|
| 199 |
|
| 200 |
const indexingField = this.indexing.getField(); |
| 201 |
const indexingOption = this.getMetaItem( 'mwIndex' ); |
| 202 |
const indexingType = indexingOption && indexingOption.getAttribute( 'property' ) || 'default'; |
| 203 |
indexingField |
| 204 |
.selectItemByData( indexingType ) |
| 205 |
.setDisabled( config.isReadOnly ); |
| 206 |
this.indexingOptionTouched = false; |
| 207 |
|
| 208 |
|
| 209 |
const newSectionEditField = this.newEditSectionLink.getField(); |
| 210 |
const newSectionEditLinkOption = this.getMetaItem( 'mwNewSectionEdit' ); |
| 211 |
const newSectionEditLinkType = newSectionEditLinkOption && newSectionEditLinkOption.getAttribute( 'property' ) || 'default'; |
| 212 |
newSectionEditField |
| 213 |
.selectItemByData( newSectionEditLinkType ) |
| 214 |
.setDisabled( config.isReadOnly ); |
| 215 |
this.newSectionEditLinkOptionTouched = false; |
| 216 |
|
| 217 |
|
| 218 |
const displayTitleItem = this.getMetaItem( 'mwDisplayTitle' ); |
| 219 |
let displayTitle = displayTitleItem && displayTitleItem.getAttribute( 'content' ) || ''; |
| 220 |
if ( !displayTitle ) { |
| 221 |
displayTitle = mw.Title.newFromText( ve.init.target.getPageName() ).getPrefixedText(); |
| 222 |
} |
| 223 |
this.displayTitleInput |
| 224 |
.setValue( displayTitle ) |
| 225 |
.setReadOnly( config.isReadOnly ); |
| 226 |
this.displayTitleTouched = false; |
| 227 |
|
| 228 |
|
| 229 |
this.metaItemCheckboxes.forEach( ( metaItemCheckbox ) => { |
| 230 |
const isSelected = !!this.getMetaItem( metaItemCheckbox.metaName ); |
| 231 |
metaItemCheckbox.fieldLayout.getField() |
| 232 |
.setSelected( isSelected ) |
| 233 |
.setDisabled( config.isReadOnly ); |
| 234 |
} ); |
| 235 |
|
| 236 |
return ve.createDeferred().resolve().promise(); |
| 237 |
}; |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
ve.ui.MWAdvancedSettingsPage.prototype.teardown = function ( data ) { |
| 245 |
|
| 246 |
data = data || {}; |
| 247 |
if ( data.action !== 'done' ) { |
| 248 |
return; |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
const currentIndexingItem = this.getMetaItem( 'mwIndex' ); |
| 253 |
const newIndexingData = this.indexing.getField().findSelectedItem(); |
| 254 |
|
| 255 |
|
| 256 |
if ( this.indexingOptionTouched ) { |
| 257 |
if ( newIndexingData.data === 'default' ) { |
| 258 |
if ( currentIndexingItem ) { |
| 259 |
this.fragment.removeMeta( currentIndexingItem ); |
| 260 |
} |
| 261 |
} else { |
| 262 |
const newIndexingItem = { type: 'mwIndex', attributes: { property: newIndexingData.data } }; |
| 263 |
|
| 264 |
if ( !currentIndexingItem ) { |
| 265 |
this.fragment.insertMeta( newIndexingItem ); |
| 266 |
} else if ( currentIndexingItem.getAttribute( 'property' ) !== newIndexingData.data ) { |
| 267 |
this.fragment.replaceMeta( |
| 268 |
currentIndexingItem, |
| 269 |
ve.extendObject( true, {}, currentIndexingItem.getElement(), newIndexingItem ) |
| 270 |
); |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
const currentNewSectionEditLinkItem = this.getMetaItem( 'mwNewSectionEdit' ); |
| 277 |
const newNewSectionEditLinkData = this.newEditSectionLink.getField().findSelectedItem(); |
| 278 |
|
| 279 |
|
| 280 |
if ( this.newSectionEditLinkOptionTouched ) { |
| 281 |
if ( newNewSectionEditLinkData.data === 'default' ) { |
| 282 |
if ( currentNewSectionEditLinkItem ) { |
| 283 |
this.fragment.removeMeta( currentNewSectionEditLinkItem ); |
| 284 |
} |
| 285 |
} else { |
| 286 |
const newNewSectionEditLinkItem = { type: 'mwNewSectionEdit', attributes: { property: newNewSectionEditLinkData.data } }; |
| 287 |
|
| 288 |
if ( !currentNewSectionEditLinkItem ) { |
| 289 |
this.fragment.insertMeta( newNewSectionEditLinkItem ); |
| 290 |
} else if ( currentNewSectionEditLinkItem.getAttribute( 'property' ) !== newNewSectionEditLinkData.data ) { |
| 291 |
this.fragment.replaceMeta( |
| 292 |
currentNewSectionEditLinkItem, |
| 293 |
ve.extendObject( true, {}, currentNewSectionEditLinkItem.getElement(), newNewSectionEditLinkItem ) |
| 294 |
); |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
const currentDisplayTitleItem = this.getMetaItem( 'mwDisplayTitle' ); |
| 301 |
let newDisplayTitle = this.displayTitleInput.getValue(); |
| 302 |
if ( newDisplayTitle === mw.Title.newFromText( ve.init.target.getPageName() ).getPrefixedText() ) { |
| 303 |
newDisplayTitle = ''; |
| 304 |
} |
| 305 |
const newDisplayTitleItem = { type: 'mwDisplayTitle', attributes: { content: newDisplayTitle } }; |
| 306 |
|
| 307 |
|
| 308 |
if ( this.displayTitleTouched ) { |
| 309 |
if ( currentDisplayTitleItem ) { |
| 310 |
if ( newDisplayTitle ) { |
| 311 |
if ( currentDisplayTitleItem.getAttribute( 'content' ) !== newDisplayTitle ) { |
| 312 |
|
| 313 |
this.fragment.replaceMeta( |
| 314 |
currentDisplayTitleItem, |
| 315 |
ve.extendObject( true, {}, |
| 316 |
currentDisplayTitleItem.getElement(), |
| 317 |
newDisplayTitleItem |
| 318 |
) |
| 319 |
); |
| 320 |
} |
| 321 |
} else { |
| 322 |
|
| 323 |
this.fragment.removeMeta( currentDisplayTitleItem ); |
| 324 |
} |
| 325 |
} else { |
| 326 |
if ( newDisplayTitle ) { |
| 327 |
|
| 328 |
62 |
| 329 |
this.fragment.insertMeta( newDisplayTitleItem, 0 ); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
this.metaItemCheckboxes.forEach( ( metaItemCheckbox ) => { |
| 335 |
const currentItem = this.getMetaItem( metaItemCheckbox.metaName ), |
| 336 |
isSelected = metaItemCheckbox.fieldLayout.getField().isSelected(); |
| 337 |
|
| 338 |
if ( currentItem && !isSelected ) { |
| 339 |
this.fragment.removeMeta( currentItem ); |
| 340 |
} else if ( !currentItem && isSelected ) { |
| 341 |
this.fragment.insertMeta( { type: metaItemCheckbox.metaName } ); |
| 342 |
} |
| 343 |
} ); |
| 344 |
|
| 345 |
this.fragment = null; |
| 346 |
}; |
| 347 |
|
| 348 |
ve.ui.MWAdvancedSettingsPage.prototype.getFieldsets = function () { |
| 349 |
return [ |
| 350 |
this.advancedSettingsFieldset |
| 351 |
]; |
| 352 |
}; |