mediawiki-extensions-Visual.../modules/ve-mw/init/ve.init.mw.LinkCache.js
James D. Forrester bed038b509 build: Bump devDependencies to latest
Updates:
* grunt-contrib-csslint  0.3.1  ->  0.4.0
* grunt-contrib-jslint   0.10.0 -> 0.11.0
* grunt-jscs             0.8.1  ->  1.2.0

For jscs, leaving requireSpacesInsideArrayBrackets to avoid headaches for now.

Change-Id: I62d34444edbba65c8bd22d2fa5e50e16cabb0042
2015-02-02 14:30:39 -08:00

74 lines
2 KiB
JavaScript

/*!
* VisualEditor MediaWiki Initialization LinkCache class.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
( function () {
/**
* Caches information about titles.
* @class
* @extends ve.init.mw.ApiResponseCache
* @constructor
*/
ve.init.mw.LinkCache = function VeInitMwLinkCache() {
ve.init.mw.LinkCache.super.call( this );
// Keys are page names, values are link data objects
// This is kept for synchronous retrieval of cached values via #getCached
this.cacheValues = {};
};
OO.inheritClass( ve.init.mw.LinkCache, ve.init.mw.ApiResponseCache );
// TODO unit tests
/**
* Requests information about the title, then adds classes to the provided element as appropriate.
*
* @param {string} title
* @param {jQuery} $element Element to style
*/
ve.init.mw.LinkCache.prototype.styleElement = function ( title, $element ) {
this.get( title ).done( function ( data ) {
if ( data.missing ) {
$element.addClass( 'new' );
} else {
// Provided by core MediaWiki, no styles by default.
if ( data.redirect ) {
$element.addClass( 'mw-redirect' );
}
// Should be provided by the Disambiguator extension, but no one has yet written a suitably
// performant patch to do it. It is instead implemented in JavaScript in on-wiki gadgets.
if ( data.disambiguation ) {
$element.addClass( 'mw-disambig' );
}
}
} );
};
/**
* @inheritdoc
*/
ve.init.mw.LinkCache.prototype.getRequestPromise = function ( subqueue ) {
return ve.init.target.constructor.static.apiRequest( {
action: 'query',
prop: 'info|pageprops',
ppprop: 'disambiguation',
titles: subqueue.join( '|' )
} );
};
/**
* @inheritdoc
*/
ve.init.mw.LinkCache.prototype.processPage = function ( page ) {
return {
missing: page.missing !== undefined,
redirect: page.redirect !== undefined,
// Disambiguator extension
disambiguation: page.pageprops && page.pageprops.disambiguation !== undefined
};
};
}() );