| 1 |
'use strict'; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.dm.MWDocumentReferences = function VeDmMWDocumentReferences( doc ) { |
| 17 |
|
| 18 |
OO.EventEmitter.call( this ); |
| 19 |
|
| 20 |
|
| 21 |
this.doc = doc; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
this.cachedByGroup = {}; |
| 28 |
|
| 29 |
doc.getInternalList().connect( this, { update: 'updateGroups' } ); |
| 30 |
this.updateAllGroups(); |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
OO.mixinClass( ve.dm.MWDocumentReferences, OO.EventEmitter ); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
ve.dm.MWDocumentReferences.static.refsForDoc = function ( doc ) { |
| 49 |
let docRefs; |
| 50 |
|
| 51 |
if ( !doc.getOriginalDocument() ) { |
| 52 |
docRefs = doc.extCiteDocumentReferences; |
| 53 |
} |
| 54 |
if ( docRefs === undefined ) { |
| 55 |
docRefs = new ve.dm.MWDocumentReferences( doc ); |
| 56 |
} |
| 57 |
if ( !doc.getOriginalDocument() ) { |
| 58 |
doc.extCiteDocumentReferences = docRefs; |
| 59 |
} |
| 60 |
return docRefs; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
ve.dm.MWDocumentReferences.prototype.updateAllGroups = function () { |
| 67 |
this.updateGroups( this.getAllGroupNames() ); |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
ve.dm.MWDocumentReferences.prototype.updateGroups = function ( groupsChanged ) { |
| 76 |
groupsChanged.forEach( ( groupName ) => this.updateGroup( groupName ) ); |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
ve.dm.MWDocumentReferences.prototype.updateGroup = function ( groupName ) { |
| 85 |
const nodeGroup = this.doc.getInternalList().getNodeGroup( groupName ); |
| 86 |
this.cachedByGroup[ groupName ] = ve.dm.MWGroupReferences.static.makeGroupRefs( nodeGroup ); |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
ve.dm.MWDocumentReferences.prototype.getGroupRefs = function ( groupName ) { |
| 94 |
return this.cachedByGroup[ groupName.startsWith( 'mwReference/' ) ? groupName : 'mwReference/' + groupName ] || |
| 95 |
new ve.dm.MWGroupReferences(); |
| 96 |
}; |
| 97 |
|
| 98 |
ve.dm.MWDocumentReferences.prototype.getAllGroupNames = function () { |
| 99 |
return Object.keys( this.doc.getInternalList().getNodeGroups() ); |
| 100 |
}; |
| 101 |
|
| 102 |
ve.dm.MWDocumentReferences.prototype.hasRefs = function () { |
| 103 |
return this.getAllGroupNames().some( ( groupName ) => !this.getGroupRefs( groupName ).isEmpty() ); |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
ve.dm.MWDocumentReferences.static.contentLangDigits = function ( num ) { |
| 115 |
const contentLang = mw.config.get( 'wgContentLanguage' ); |
| 116 |
const digitLookup = mw.config.get( 'wgTranslateNumerals' ) && |
| 117 |
mw.language.getData( contentLang, 'digitTransformTable' ); |
| 118 |
const numString = String( num ); |
| 119 |
if ( !digitLookup ) { |
| 120 |
return numString; |
| 121 |
} |
| 122 |
return numString.split( '' ).map( ( numChar ) => digitLookup[ numChar ] ).join( '' ); |
| 123 |
}; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
ve.dm.MWDocumentReferences.prototype.getIndexLabel = function ( groupName, listKey ) { |
| 134 |
return this.getGroupRefs( groupName ).getIndexLabel( listKey ); |
| 135 |
}; |