2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWLanguagesPage class.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 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
|
|
|
|
*/
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWLanguagesPage.prototype.setOutlineItem = function () {
|
2014-02-15 01:37:32 +00:00
|
|
|
// Parent method
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ui.MWLanguagesPage.super.prototype.setOutlineItem.apply( this, arguments );
|
2014-02-15 01:37:32 +00:00
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
this.outlineItem
|
2015-04-28 19:55:58 +00:00
|
|
|
.setIcon( 'textLanguage' )
|
2014-02-15 01:37:32 +00:00
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-meta-languages-section' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWLanguagesPage.prototype.onLoadLanguageData = function ( languages ) {
|
2015-01-31 00:41:37 +00:00
|
|
|
var i,
|
2015-04-09 23:47:15 +00:00
|
|
|
$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>' )
|
2013-12-11 01:46:46 +00:00
|
|
|
.append( ve.msg( 'visualeditor-dialog-meta-languages-code-label' ) )
|
|
|
|
)
|
2013-12-02 20:10:55 +00:00
|
|
|
.append(
|
2015-04-09 23:47:15 +00:00
|
|
|
$( '<th>' )
|
2013-12-04 15:30:21 +00:00
|
|
|
.append( 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>' )
|
2013-12-02 20:10:55 +00:00
|
|
|
.append( ve.msg( 'visualeditor-dialog-meta-languages-link-label' ) )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
for ( 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 ) {
|
2014-01-07 03:25:56 +00:00
|
|
|
var i, iLen, languages = [],
|
|
|
|
langlinks = response && response.visualeditor && response.visualeditor.langlinks;
|
2013-12-02 20:10:55 +00:00
|
|
|
if ( langlinks ) {
|
|
|
|
for ( i = 0, iLen = langlinks.length; i < iLen; i++ ) {
|
|
|
|
languages.push( {
|
2015-08-19 17:33:02 +00:00
|
|
|
lang: langlinks[ i ].lang,
|
|
|
|
langname: langlinks[ i ].langname,
|
|
|
|
title: langlinks[ i ][ '*' ],
|
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 () {
|
|
|
|
var i,
|
|
|
|
items = [],
|
|
|
|
languages = this.metaList.getItemsInGroup( 'mwLanguage' ),
|
|
|
|
languageslength = languages.length;
|
|
|
|
|
|
|
|
// Loop through MWLanguages and build out items
|
|
|
|
|
|
|
|
for ( 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 () {
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
// TODO: Detect paging token if results exceed limit
|
2018-05-04 13:30:10 +00:00
|
|
|
ve.init.target.getContentApi().get( {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'visualeditor',
|
|
|
|
paction: 'getlanglinks',
|
2018-05-04 13:30:10 +00:00
|
|
|
page: 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 () {};
|