2013-12-02 20:10:55 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface MWLanguagesPage class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
2013-12-02 20:10:55 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*global mw*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki meta dialog Languages page.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguagesPage = function VeUiMWLanguagesPage( name, config ) {
|
|
|
|
// Parent constructor
|
|
|
|
OO.ui.PageLayout.call( this, name, config );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.languagesFieldset = new OO.ui.FieldsetLayout( {
|
|
|
|
'$': this.$,
|
|
|
|
'label': ve.msg( 'visualeditor-dialog-meta-languages-label' ),
|
|
|
|
'icon': 'language'
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.languagesFieldset.$element.append(
|
|
|
|
this.$( '<span>' )
|
|
|
|
.text( ve.msg( 'visualeditor-dialog-meta-languages-readonlynote' ) )
|
|
|
|
);
|
|
|
|
this.$element.append( this.languagesFieldset.$element );
|
|
|
|
|
|
|
|
this.getAllLanguageItems().done( ve.bind( this.onLoadLanguageData, this ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWLanguagesPage, OO.ui.PageLayout );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2014-02-15 01:37:32 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguagesPage.prototype.setOutlineItem = function ( outlineItem ) {
|
|
|
|
// Parent method
|
|
|
|
OO.ui.PageLayout.prototype.setOutlineItem.call( this, outlineItem );
|
|
|
|
|
|
|
|
if ( this.outlineItem ) {
|
|
|
|
this.outlineItem
|
|
|
|
.setIcon( 'language' )
|
|
|
|
.setLabel( ve.msg( 'visualeditor-dialog-meta-languages-section' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-02 20:10:55 +00:00
|
|
|
ve.ui.MWLanguagesPage.prototype.onLoadLanguageData = function ( languages ) {
|
|
|
|
var i, $languagesTable = this.$( '<table>' ), languageslength = languages.length;
|
|
|
|
|
|
|
|
$languagesTable
|
|
|
|
.addClass( 've-ui-MWLanguagesPage-languages-table' )
|
|
|
|
.append( this.$( '<tr>' )
|
2013-12-11 01:46:46 +00:00
|
|
|
.append(
|
|
|
|
this.$( '<th>' )
|
|
|
|
.append( ve.msg( 'visualeditor-dialog-meta-languages-code-label' ) )
|
|
|
|
)
|
2013-12-02 20:10:55 +00:00
|
|
|
.append(
|
|
|
|
this.$( '<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(
|
|
|
|
this.$( '<th>' )
|
|
|
|
.append( ve.msg( 'visualeditor-dialog-meta-languages-link-label' ) )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
for ( i = 0; i < languageslength; i++ ) {
|
|
|
|
languages[i].safelang = languages[i].lang;
|
|
|
|
languages[i].dir = 'auto';
|
|
|
|
if ( $.uls ) {
|
|
|
|
// site codes don't always represent official language codes
|
|
|
|
// using real language code instead of a dummy ('redirect' in ULS' terminology)
|
|
|
|
languages[i].safelang = $.uls.data.isRedirect( languages[i].lang ) || languages[i].lang;
|
|
|
|
languages[i].dir = $.uls.data.getDir( languages[i].safelang );
|
|
|
|
}
|
|
|
|
$languagesTable
|
|
|
|
.append( this.$( '<tr>' )
|
2013-12-11 01:46:46 +00:00
|
|
|
.append( this.$( '<td>' ).text( languages[i].lang ) )
|
|
|
|
.append( this.$( '<td>' ).text( languages[i].langname ).add(
|
|
|
|
this.$( '<td>' ).text( languages[i].title )
|
|
|
|
)
|
2013-12-02 20:10:55 +00:00
|
|
|
.attr( 'lang', languages[i].safelang )
|
|
|
|
.attr( 'dir', languages[i].dir ) )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.languagesFieldset.$element.append( $languagesTable );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle language items being loaded.
|
|
|
|
*/
|
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( {
|
|
|
|
'lang': langlinks[i].lang,
|
2013-12-04 15:30:21 +00:00
|
|
|
'langname': langlinks[i].langname,
|
2013-12-02 20:10:55 +00:00
|
|
|
'title': langlinks[i]['*'],
|
|
|
|
'metaItem': null
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
deferred.resolve( languages );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets language item from meta list item
|
|
|
|
*
|
2014-02-20 20:36:52 +00:00
|
|
|
* @param {ve.dm.MWLanguageMetaItem} metaItem
|
2013-12-02 20:10:55 +00:00
|
|
|
* @returns {Object} item
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguagesPage.prototype.getLanguageItemFromMetaListItem = function ( metaItem ) {
|
|
|
|
// TODO: get real values from metaItem once Parsoid actually provides them - bug 48970
|
|
|
|
return {
|
|
|
|
'lang': 'lang',
|
2013-12-04 15:30:21 +00:00
|
|
|
'langname': 'langname',
|
2013-12-02 20:10:55 +00:00
|
|
|
'title': 'title',
|
|
|
|
'metaItem': metaItem
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get array of language items from meta list
|
|
|
|
*
|
|
|
|
* @returns {Object[]} items
|
|
|
|
*/
|
|
|
|
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++ ) {
|
|
|
|
items.push( this.getLanguageItemFromMetaListItem( languages[i] ) );
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get array of language items from meta list
|
|
|
|
*
|
|
|
|
* @returns {jQuery.Promise}
|
|
|
|
*/
|
|
|
|
ve.ui.MWLanguagesPage.prototype.getAllLanguageItems = function () {
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
// TODO: Detect paging token if results exceed limit
|
2014-01-05 04:44:13 +00:00
|
|
|
ve.init.mw.Target.static.apiRequest( {
|
|
|
|
'action': 'visualeditor',
|
|
|
|
'paction': 'getlanglinks',
|
2014-04-19 00:21:47 +00:00
|
|
|
'page': mw.config.get( 'wgPageName' )
|
2013-12-02 20:10:55 +00:00
|
|
|
} )
|
2013-12-04 15:30:21 +00:00
|
|
|
.done( ve.bind( this.onAllLanguageItemsSuccess, this, deferred ) )
|
|
|
|
.fail( ve.bind( this.onAllLanguageItemsError, 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 () {};
|