| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.init.mw.LinkCache = function VeInitMwLinkCache() { |
| 17 |
|
| 18 |
ve.init.mw.LinkCache.super.apply( this, arguments ); |
| 19 |
}; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
OO.inheritClass( ve.init.mw.LinkCache, ve.init.mw.ApiResponseCache ); |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
ve.init.mw.LinkCache.static.getIconForLink = function ( linkData ) { |
| 34 |
if ( linkData.missing ) { |
| 35 |
return 'articleNotFound'; |
| 36 |
} |
| 37 |
if ( linkData.redirect ) { |
| 38 |
return 'articleRedirect'; |
| 39 |
} |
| 40 |
if ( linkData.disambiguation ) { |
| 41 |
return 'articleDisambiguation'; |
| 42 |
} |
| 43 |
return 'article'; |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
ve.init.mw.LinkCache.static.processPage = function ( page ) { |
| 50 |
return { |
| 51 |
missing: page.missing !== undefined, |
| 52 |
known: page.known !== undefined, |
| 53 |
redirect: page.redirect !== undefined, |
| 54 |
disambiguation: ve.getProp( page, 'pageprops', 'disambiguation' ) !== undefined, |
| 55 |
hidden: ve.getProp( page, 'pageprops', 'hiddencat' ) !== undefined, |
| 56 |
imageUrl: ve.getProp( page, 'thumbnail', 'source' ), |
| 57 |
description: page.description |
| 58 |
}; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
ve.init.mw.LinkCache.prototype.styleElement = function ( title, $element, hasFragment ) { |
| 71 |
const cachedMissingData = this.getCached( '_missing/' + title ); |
| 72 |
|
| 73 |
let promise; |
| 74 |
|
| 75 |
if ( cachedMissingData ) { |
| 76 |
promise = ve.createDeferred().resolve( cachedMissingData ).promise(); |
| 77 |
} else { |
| 78 |
promise = this.get( title ); |
| 79 |
} |
| 80 |
|
| 81 |
promise.done( ( data ) => { |
| 82 |
if ( data.missing && !data.known ) { |
| 83 |
$element.addClass( 'new' ); |
| 84 |
} else { |
| 85 |
|
| 86 |
if ( !hasFragment && this.constructor.static.normalizeTitle( title ) === this.constructor.static.normalizeTitle( mw.config.get( 'wgRelevantPageName' ) ) ) { |
| 87 |
$element.addClass( 'mw-selflink' ); |
| 88 |
} |
| 89 |
|
| 90 |
if ( data.redirect ) { |
| 91 |
$element.addClass( 'mw-redirect' ); |
| 92 |
} |
| 93 |
|
| 94 |
if ( data.disambiguation ) { |
| 95 |
$element.addClass( 'mw-disambig' ); |
| 96 |
} |
| 97 |
} |
| 98 |
} ); |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
ve.init.mw.LinkCache.prototype.styleParsoidElements = function ( $elements ) { |
| 114 |
if ( ve.dm.MWLanguageVariantNode ) { |
| 115 |
|
| 116 |
$elements.each( ( i, element ) => { |
| 117 |
ve.dm.MWLanguageVariantNode.static.processVariants( element ); |
| 118 |
} ); |
| 119 |
} |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
ve.init.mw.LinkCache.prototype.setAssumeExistence = function ( assume ) { |
| 131 |
this.assumeExistence = !!assume; |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
ve.init.mw.LinkCache.prototype.setMissing = function ( entries ) { |
| 142 |
const missingEntries = {}; |
| 143 |
for ( const name in entries ) { |
| 144 |
missingEntries[ '_missing/' + name ] = entries[ name ]; |
| 145 |
} |
| 146 |
this.set( missingEntries ); |
| 147 |
}; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
ve.init.mw.LinkCache.prototype.get = function ( title ) { |
| 153 |
const data = {}; |
| 154 |
if ( this.assumeExistence ) { |
| 155 |
data[ this.constructor.static.normalizeTitle( title ) ] = { missing: false }; |
| 156 |
this.setMissing( data ); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
return ve.init.mw.LinkCache.super.prototype.get.call( this, title ); |
| 161 |
}; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
ve.init.mw.LinkCache.prototype.getRequestPromise = function ( subqueue ) { |
| 167 |
return this.api.get( { |
| 168 |
action: 'query', |
| 169 |
prop: 'info|pageprops|pageimages|description', |
| 170 |
pithumbsize: 80, |
| 171 |
pilimit: subqueue.length, |
| 172 |
ppprop: 'disambiguation|hiddencat', |
| 173 |
titles: subqueue, |
| 174 |
continue: '' |
| 175 |
} ); |
| 176 |
}; |