if (!('isekai' in window)) window.isekai = {}; /** * @class isekai.ContribDialog * @param {*} config */ isekai.ContribDialog = function IsekaiContribDialog(config) { isekai.ContribDialog.super.call(this, config); this.broken = false; }; OO.inheritClass(isekai.ContribDialog, OO.ui.ProcessDialog); isekai.ContribDialog.static.name = 'isekaicontrib-dialog'; isekai.ContribDialog.static.title = mw.msg('isekaicontrib-dialog-title'); isekai.ContribDialog.static.actions = [ { action: 'cancel', label: mw.msg('isekaicontrib-dialog-cancel'), flags: ['safe', 'close'] } ]; isekai.ContribDialog.prototype.initialize = function () { isekai.ContribDialog.super.prototype.initialize.apply(this, arguments); this.api = new mw.Api(); this.content = new OO.ui.PanelLayout({ padded: false }); //加载动画 this.loadingWidget = new OO.ui.ProgressBarWidget({ progress: false, classes: ['isekai-contrib-loading'] }); this.content.$element.append(this.loadingWidget.$element); //贡献者列表容器 this.content.$element.append('
'); this.contribContainer = this.content.$element.find('.isekai-contrib-list'); this.$body.append(this.content.$element); } isekai.ContribDialog.prototype.getUserAvatar = function (userName) { var template = mw.config.get('wgIsekaiContributorAvatar'); if (template) { return template.replace(/\%s/g, userName); } else { return ''; } }; /** * 生成用户栏目html * @param {any} userData - 用户信息 * @returns {string} 生成的html */ isekai.ContribDialog.prototype.getUserListItem = function (userData) { return '' + '
' + '
' + '
' + userData.display_name + '
' + '
@' + userData.user_name + '
' + '
' + '
'; }; /** * 加载贡献者列表 */ isekai.ContribDialog.prototype.loadContributors = function () { var currentPageId = mw.config.get('wgArticleId'); this.api.get({ action: 'query', prop: 'pagecredit', pageids: currentPageId, }).done((data) => { if('query' in data && 'pages' in data.query){ if(currentPageId in data.query.pages){ var pageData = data.query.pages[currentPageId]; if('missing' in pageData) return; if(!pageData.pagecredit || 'error' in pageData.pagecredit) return; var creditData = pageData.pagecredit; this.loadingWidget.toggle(false); this.contribContainer.empty(); if('creator' in creditData){ this.contribContainer.append('
' + mw.msg('isekaicontrib-dialog-subtitle-creator') + '
'); this.contribContainer.append(this.getUserListItem(creditData.creator)); } if('last_editor' in creditData){ this.contribContainer.append('
' + mw.msg('isekaicontrib-dialog-subtitle-last-editor') + '
'); this.contribContainer.append(this.getUserListItem(creditData.last_editor)); } if(('contributors' in creditData) && creditData.contributors.length > 0){ this.contribContainer.append('
' + mw.msg('isekaicontrib-dialog-subtitle-contributors') + '
'); creditData.contributors.forEach((editor) => { this.contribContainer.append(this.getUserListItem(editor)); this.contribContainer.append('
'); }); } } } }); }; isekai.ContribDialog.prototype.getBodyHeight = function () { return 400; }; isekai.ContribDialog.prototype.getSetupProcess = function (data) { var _this = this; return isekai.ContribDialog.super.prototype.getSetupProcess.call(this, data).next(function(){ _this.loadContributors(); return true; }); } isekai.ContribDialog.prototype.getActionProcess = function (action) { var dialog = this; return new OO.ui.Process(function () { dialog.close({ action: action }); }); }; // ============================================================== var contribDialog = new isekai.ContribDialog({}); var windowManager = new OO.ui.WindowManager(); $(document.body).append(windowManager.$element); windowManager.addWindows([contribDialog]); $('.isekai-contrib-open-dialog').click(function () { windowManager.openWindow(contribDialog); return false; });