Fix TypeError in MWTocWidget.initFromMetaList

If a page contains __NOTOC__ magic word, it would break the VisualEditor
with "Uncaught (in promise) TypeError: Right-hand side of 'instanceof' is not
an object at VeUiMWTocWidget.ve.ui.MWTocWidget.initFromMetaList".

The issue seems to be that we removed ve.dm.MWTOCForceMetaItem and
ve.dm.MWTOCDisableMetaItem in commit 57a06a6e75,
but the code in initFromMetaList still refers to them.

Change-Id: I857cddcc7d4aa73375357ef922591ed94d760166
This commit is contained in:
Chunliang Lyu 2019-02-06 17:21:15 -08:00 committed by Bartosz Dziewoński
parent d2fe2f7f8d
commit 4774fbdf5c

View file

@ -101,15 +101,18 @@ ve.ui.MWTocWidget.prototype.onMetaListRemove = function ( metaItem ) {
ve.ui.MWTocWidget.prototype.initFromMetaList = function () {
var i = 0,
items = this.metaList.getItemsInGroup( 'mwTOC' ),
len = items.length;
len = items.length,
property;
if ( len > 0 ) {
for ( ; i < len; i++ ) {
if ( items[ i ] instanceof ve.dm.MWTOCForceMetaItem ) {
this.mwTOCForce = true;
}
// Needs testing
if ( items[ i ] instanceof ve.dm.MWTOCDisableMetaItem ) {
this.mwTOCDisable = true;
if ( items[ i ] instanceof ve.dm.MWTOCMetaItem ) {
property = items[ i ].getAttribute( 'property' );
if ( property === 'mw:PageProp/forcetoc' ) {
this.mwTOCForce = true;
}
if ( property === 'mw:PageProp/notoc' ) {
this.mwTOCDisable = true;
}
}
}
this.updateVisibility();