2016-12-18 19:04:20 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWTemplatesUsedPage class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2016-12-18 19:04:20 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki meta dialog TemplatesUsed page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
2024-05-27 04:59:02 +00:00
|
|
|
* @param {jQuery} [config.$overlay] Overlay to render dropdowns in
|
2016-12-18 19:04:20 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWTemplatesUsedPage = function VeUiMWTemplatesUsedPage() {
|
2024-05-21 14:22:56 +00:00
|
|
|
const target = ve.init.target;
|
2019-02-22 18:50:46 +00:00
|
|
|
|
2016-12-18 19:04:20 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWTemplatesUsedPage.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.templatesUsedFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
label: ve.msg( 'visualeditor-templatesused-tool' ),
|
2017-07-06 16:52:56 +00:00
|
|
|
icon: 'puzzle'
|
2016-12-18 19:04:20 +00:00
|
|
|
} );
|
|
|
|
|
2022-01-11 22:42:12 +00:00
|
|
|
this.templatesUsedFieldset.$group.addClass( [
|
2023-10-31 21:06:04 +00:00
|
|
|
'mw-body-content'
|
2022-01-11 22:42:12 +00:00
|
|
|
] );
|
|
|
|
|
2019-02-22 18:50:46 +00:00
|
|
|
target.getContentApi().get( {
|
|
|
|
action: 'visualeditor',
|
|
|
|
paction: 'templatesused',
|
|
|
|
page: target.getPageName(),
|
|
|
|
uselang: mw.config.get( 'wgUserLanguage' )
|
2024-04-30 16:44:25 +00:00
|
|
|
} ).then( ( response ) => {
|
2024-05-21 14:22:56 +00:00
|
|
|
const templatesUsed = $.parseHTML( response.visualeditor );
|
2019-02-22 18:50:46 +00:00
|
|
|
if ( templatesUsed.length && $( templatesUsed ).find( 'li' ).length ) {
|
|
|
|
return templatesUsed;
|
|
|
|
} else {
|
2019-11-02 05:06:28 +00:00
|
|
|
return ve.createDeferred().reject().promise();
|
2019-02-22 18:50:46 +00:00
|
|
|
}
|
2024-04-30 16:44:25 +00:00
|
|
|
} ).then( ( templatesUsed ) => {
|
2021-10-25 15:51:29 +00:00
|
|
|
// templatesUsed is an array of nodes
|
|
|
|
// eslint-disable-next-line no-jquery/no-append-html
|
2024-05-01 12:32:49 +00:00
|
|
|
this.templatesUsedFieldset.$group.append( templatesUsed );
|
|
|
|
ve.targetLinksToNewWindow( this.templatesUsedFieldset.$group[ 0 ] );
|
2024-04-30 16:44:25 +00:00
|
|
|
}, () => {
|
2024-05-01 12:32:49 +00:00
|
|
|
this.templatesUsedFieldset.$group.append(
|
2016-12-18 19:04:20 +00:00
|
|
|
$( '<em>' ).text( ve.msg( 'visualeditor-dialog-meta-templatesused-noresults' ) )
|
|
|
|
);
|
2019-02-22 18:50:46 +00:00
|
|
|
} );
|
2016-12-18 19:04:20 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.append( this.templatesUsedFieldset.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWTemplatesUsedPage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-15 10:10:56 +00:00
|
|
|
ve.ui.MWTemplatesUsedPage.prototype.setupOutlineItem = function () {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'puzzle' )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-templatesused-tool' ) );
|
2016-12-18 19:04:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTemplatesUsedPage.prototype.focus = function () {
|
|
|
|
// No controls, just focus the whole page instead of the first link
|
2019-01-18 21:03:38 +00:00
|
|
|
this.$element[ 0 ].focus();
|
2016-12-18 19:04:20 +00:00
|
|
|
};
|
2018-10-28 19:18:40 +00:00
|
|
|
|
|
|
|
ve.ui.MWTemplatesUsedPage.prototype.getFieldsets = function () {
|
|
|
|
return [
|
|
|
|
this.templatesUsedFieldset
|
|
|
|
];
|
|
|
|
};
|