2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWLanguagesPage class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-12-02 20:10:55 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki meta dialog Languages page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
2018-04-04 20:37:32 +00:00
|
|
|
* @cfg {jQuery} [$overlay] Overlay to render dropdowns in
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWLanguagesPage = function VeUiMWLanguagesPage() {
|
2013-12-02 20:10:55 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWLanguagesPage.super.apply( this, arguments );
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.languagesFieldset = new OO.ui.FieldsetLayout( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-dialog-meta-languages-label' ),
|
2015-04-16 20:46:49 +00:00
|
|
|
icon: 'textLanguage'
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.languagesFieldset.$element.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<span>' )
|
2013-12-02 20:10:55 +00:00
|
|
|
.text( ve.msg( 'visualeditor-dialog-meta-languages-readonlynote' ) )
|
|
|
|
);
|
|
|
|
this.$element.append( this.languagesFieldset.$element );
|
|
|
|
|
2014-07-08 22:33:32 +00:00
|
|
|
this.getAllLanguageItems().done( this.onLoadLanguageData.bind( this ) );
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWLanguagesPage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-15 10:10:56 +00:00
|
|
|
ve.ui.MWLanguagesPage.prototype.setupOutlineItem = function () {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'textLanguage' )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-meta-languages-section' ) );
|
2014-02-15 01:37:32 +00:00
|
|
|
};
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWLanguagesPage.prototype.onLoadLanguageData = function ( languages ) {
|
2022-02-21 18:07:07 +00:00
|
|
|
var $languagesTable = $( '<table>' ),
|
2015-01-31 00:41:37 +00:00
|
|
|
languageslength = languages.length;
|
2013-12-02 20:10:55 +00:00
|
|
|
|
|
|
|
$languagesTable
|
2014-07-28 12:07:49 +00:00
|
|
|
.addClass( 've-ui-mwLanguagesPage-languages-table' )
|
2015-04-09 23:47:15 +00:00
|
|
|
.append( $( '<tr>' )
|
2013-12-11 01:46:46 +00:00
|
|
|
.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<th>' )
|
2021-10-25 15:51:29 +00:00
|
|
|
.text( ve.msg( 'visualeditor-dialog-meta-languages-code-label' ) )
|
2013-12-11 01:46:46 +00:00
|
|
|
)
|
2013-12-02 20:10:55 +00:00
|
|
|
.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<th>' )
|
2021-10-25 15:51:29 +00:00
|
|
|
.text( ve.msg( 'visualeditor-dialog-meta-languages-name-label' ) )
|
2013-12-02 20:10:55 +00:00
|
|
|
)
|
|
|
|
.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<th>' )
|
2021-10-25 15:51:29 +00:00
|
|
|
.text( ve.msg( 'visualeditor-dialog-meta-languages-link-label' ) )
|
2013-12-02 20:10:55 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2022-02-21 18:07:07 +00:00
|
|
|
for ( var i = 0; i < languageslength; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
languages[ i ].safelang = languages[ i ].lang;
|
|
|
|
languages[ i ].dir = 'auto';
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( $.uls ) {
|
|
|
|
// site codes don't always represent official language codes
|
|
|
|
// using real language code instead of a dummy ('redirect' in ULS' terminology)
|
2015-08-19 17:33:02 +00:00
|
|
|
languages[ i ].safelang = $.uls.data.isRedirect( languages[ i ].lang ) || languages[ i ].lang;
|
|
|
|
languages[ i ].dir = ve.init.platform.getLanguageDirection( languages[ i ].safelang );
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
2017-07-18 11:55:33 +00:00
|
|
|
$languagesTable.append(
|
|
|
|
$( '<tr>' ).append(
|
|
|
|
$( '<td>' ).text( languages[ i ].lang ),
|
|
|
|
$( '<td>' ).text( languages[ i ].langname ).add( $( '<td>' ).text( languages[ i ].title ) )
|
|
|
|
.attr( {
|
|
|
|
lang: languages[ i ].safelang,
|
|
|
|
dir: languages[ i ].dir
|
|
|
|
} )
|
|
|
|
)
|
|
|
|
);
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.languagesFieldset.$element.append( $languagesTable );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle language items being loaded.
|
2016-10-28 19:02:36 +00:00
|
|
|
*
|
|
|
|
* @param {jQuery.Deferred} deferred Deferred to resolve with language data
|
|
|
|
* @param {Object} response API response
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
2013-12-04 15:30:21 +00:00
|
|
|
ve.ui.MWLanguagesPage.prototype.onAllLanguageItemsSuccess = function ( deferred, response ) {
|
2022-02-21 18:07:07 +00:00
|
|
|
var languages = [],
|
2019-03-16 11:19:29 +00:00
|
|
|
langlinks = OO.getProp( response, 'query', 'pages', 0, 'langlinks' );
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( langlinks ) {
|
2022-02-21 18:07:07 +00:00
|
|
|
for ( var i = 0, iLen = langlinks.length; i < iLen; i++ ) {
|
2013-12-02 20:10:55 +00:00
|
|
|
languages.push( {
|
2015-08-19 17:33:02 +00:00
|
|
|
lang: langlinks[ i ].lang,
|
2019-03-16 11:19:29 +00:00
|
|
|
langname: langlinks[ i ].autonym,
|
|
|
|
title: langlinks[ i ].title,
|
2014-08-22 20:50:48 +00:00
|
|
|
metaItem: null
|
2013-12-02 20:10:55 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deferred.resolve( languages );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets language item from meta list item
|
|
|
|
*
|
2014-02-20 20:36:52 +00:00
|
|
|
* @param {ve.dm.MWLanguageMetaItem} metaItem
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {Object} item
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWLanguagesPage.prototype.getLanguageItemFromMetaListItem = function ( metaItem ) {
|
2018-08-09 14:10:53 +00:00
|
|
|
// TODO: get real values from metaItem once Parsoid actually provides them - T50970
|
2013-12-02 20:10:55 +00:00
|
|
|
return {
|
2014-08-22 20:50:48 +00:00
|
|
|
lang: 'lang',
|
|
|
|
langname: 'langname',
|
|
|
|
title: 'title',
|
|
|
|
metaItem: metaItem
|
2013-12-02 20:10:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get array of language items from meta list
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {Object[]} items
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWLanguagesPage.prototype.getLocalLanguageItems = function () {
|
2022-02-21 18:07:07 +00:00
|
|
|
var items = [],
|
2013-12-02 20:10:55 +00:00
|
|
|
languages = this.metaList.getItemsInGroup( 'mwLanguage' ),
|
|
|
|
languageslength = languages.length;
|
|
|
|
|
|
|
|
// Loop through MWLanguages and build out items
|
|
|
|
|
2022-02-21 18:07:07 +00:00
|
|
|
for ( var i = 0; i < languageslength; i++ ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
items.push( this.getLanguageItemFromMetaListItem( languages[ i ] ) );
|
2013-12-02 20:10:55 +00:00
|
|
|
}
|
|
|
|
return items;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get array of language items from meta list
|
|
|
|
*
|
2015-08-19 18:09:34 +00:00
|
|
|
* @return {jQuery.Promise}
|
2013-12-02 20:10:55 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWLanguagesPage.prototype.getAllLanguageItems = function () {
|
2019-11-02 05:06:28 +00:00
|
|
|
var deferred = ve.createDeferred();
|
2013-12-02 20:10:55 +00:00
|
|
|
// TODO: Detect paging token if results exceed limit
|
2018-05-04 13:30:10 +00:00
|
|
|
ve.init.target.getContentApi().get( {
|
2019-03-16 11:19:29 +00:00
|
|
|
action: 'query',
|
|
|
|
prop: 'langlinks',
|
|
|
|
llprop: 'autonym',
|
|
|
|
lllimit: 500,
|
|
|
|
titles: ve.init.target.getPageName()
|
2013-12-02 20:10:55 +00:00
|
|
|
} )
|
2014-07-08 22:33:32 +00:00
|
|
|
.done( this.onAllLanguageItemsSuccess.bind( this, deferred ) )
|
|
|
|
.fail( this.onAllLanguageItemsError.bind( this, deferred ) );
|
2013-12-02 20:10:55 +00:00
|
|
|
return deferred.promise();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle language items failing to be loaded.
|
|
|
|
*
|
|
|
|
* TODO: This error function should probably not be empty.
|
|
|
|
*/
|
2013-12-04 15:30:21 +00:00
|
|
|
ve.ui.MWLanguagesPage.prototype.onAllLanguageItemsError = function () {};
|
2018-10-28 19:18:40 +00:00
|
|
|
|
|
|
|
ve.ui.MWLanguagesPage.prototype.getFieldsets = function () {
|
|
|
|
return [
|
|
|
|
this.languagesFieldset
|
|
|
|
];
|
|
|
|
};
|