mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-03 19:16:09 +00:00
c921c76dd2
Introduce a static method so we don't need to copy paste code. Note that the static method still largely duplicates what the method .buildIndex() will later do. Both loops iterate the reference groups and the references in each group. The main difference is that the "is empty" check stops extremely early the moment it finds any non-empty group. That's also why I'm convinced it's not worth caching the result. I benchmarked it and it's nanoseconds. But there are more reasons: The non-static .isIndexEmpty() method is currently only used when Citoid is active the same time. Which means the cached result was entirely unused on installations without Citoid. Bug: T356871 Change-Id: Id5c4295086bc977ef52ad141be9962d2eecb1bcc
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
/*!
|
|
* VisualEditor UserInterface MediaWiki UseExistingReferenceCommand class.
|
|
*
|
|
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
|
|
* @license MIT
|
|
*/
|
|
|
|
/**
|
|
* Use existing reference command.
|
|
*
|
|
* @constructor
|
|
* @extends ve.ui.Command
|
|
*/
|
|
ve.ui.MWUseExistingReferenceCommand = function VeUiMWUseExistingReferenceCommand() {
|
|
// Parent constructor
|
|
ve.ui.MWUseExistingReferenceCommand.super.call(
|
|
this, 'reference/existing', 'window', 'open',
|
|
{ args: [ 'reference', { useExisting: true } ], supportedSelections: [ 'linear' ] }
|
|
);
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWUseExistingReferenceCommand, ve.ui.Command );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* @override
|
|
*/
|
|
ve.ui.MWUseExistingReferenceCommand.prototype.isExecutable = function ( fragment ) {
|
|
return ve.ui.MWUseExistingReferenceCommand.super.prototype.isExecutable.apply( this, arguments ) &&
|
|
!ve.ui.MWReferenceSearchWidget.static.isIndexEmpty( fragment.getDocument().getInternalList() );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.commandRegistry.register( new ve.ui.MWUseExistingReferenceCommand() );
|