VOOZH about

URL: https://minecraft.wiki/w/MediaWiki:Gadget-articlefeedback-core.js

⇱ MediaWiki:Gadget-articlefeedback-core.js – Minecraft Wiki


MediaWiki:Gadget-articlefeedback-core.js

From Minecraft Wiki
Jump to navigation Jump to search
In other languages

Note: After saving, you have to bypass your browser's cache to see the changes.

Google Chrome, Firefox, Microsoft Edge, and Safari: Hold down the key and click the Reload toolbar button.
For details and instructions about other browsers, see Wikipedia:Bypass your cache.

/** <nowiki>
 * Gadget for the wiki article feedback feature.
 * @license CC BY-NC-SA 3.0
 */
mw.loader.using(['mediawiki.api','mediawiki.Title','oojs-ui-core','oojs-ui-windows','oojs-ui-widgets','oojs-ui.styles.icons-interactions'],require=>{
consti18n={
dialogTitle:'Give feedback on this article',
sumbit:'Submit',
cancel:'Cancel',
aboutButton:'About the feedback system',
aboutPage:'/w/Minecraft_Wiki:Article_feedback',
dialogIntro:'Feedback will be posted $1 and shared to our <a href="https://discord.gg/fGdE5ZE" target="_blank" rel="nofollow noreferrer noopener">Discord</a>.',
dialogIntroAnonymous:'anonymously',
dialogIntroAccount:'as $1',
feedbackMessagePlaceholder:'What can be improved on this article?',
dialogNotice:'To leave feedback for the game, <a href="https://feedback.minecraft.net/" target="_blank" rel="nofollow noreferrer noopener">click here</a>.',
error:'There was a problem. Please try again later.',
vectorButtonLabel:'Share article feedback',
vectorButtonTitle:'Share feedback on this article',
minervaButtonLong:'Share article feedback',
minervaButtonShort:'Feedback',
thankTitle:'Thank you!',
thankText:'Thank you for improving the wiki!<br>You can join us on <a href="https://discord.gg/fGdE5ZE" target="_blank" rel="nofollow noreferrer noopener">Discord</a> or visit our <a href="https://minecraft.wiki/w/Minecraft_Wiki:How_to_help" target="_blank" rel="nofollow noreferrer noopener">help page</a> for more ways to contribute!',
summary:'[Article feedback] Send feedback',
};
constAPI_ENDPOINT='https://api.weirdgloop.org/wiki/newfeedback';
constRESTRICTED_PAGES=[
// List of pages where only autoconfirmed users should see the feedback button
'Java_Edition_1.7',
];
constREDIRECT_PAGES={
// Map of pages where feedback should be left at the talk page of another page
// "page title": <id of page where feedback is left>,
"Minecraft_Wiki/editcopy":1,// "Minecraft Wiki"
};
constconf=mw.config.get([
'wgPageName',
'wgUserName',
'wgUserIsTemp',
'wgUserGroups',
'wgArticleId',
'skin'
]);
constisAnonymous=conf.wgUserName===null||conf.wgUserIsTemp;
if(RESTRICTED_PAGES.includes(conf.wgPageName)&&!conf.wgUserGroups.includes('autoconfirmed')){
return;
}
functionFeedbackDialog(config){
FeedbackDialog.super.call(this,config);
}
OO.inheritClass(FeedbackDialog,OO.ui.ProcessDialog);
FeedbackDialog.static.name='mcwFeedbackDialog';
FeedbackDialog.static.title=i18n.dialogTitle;
FeedbackDialog.static.size='medium';
FeedbackDialog.static.actions=[
{
action:'submit',
label:i18n.sumbit,
flags:['primary','progressive']
},
{
action:'cancel',
label:i18n.cancel,
flags:'safe'
},
{
action:'about',
label:i18n.aboutButton,
flags:'progressive'
},
];
FeedbackDialog.prototype.initialize=function(){
FeedbackDialog.super.prototype.initialize.call(this);
this.feedbackPanel=newOO.ui.PanelLayout({
scrollable:false,
expanded:false,
padded:true
});
this.feedbackMessageInput=newOO.ui.MultilineTextInputWidget({
placeholder:i18n.feedbackMessagePlaceholder,
autosize:true,
indicator:'required',
rows:5
});
constintroMessage=i18n.dialogIntro.replace('$1',isAnonymous
?i18n.dialogIntroAnonymous
:i18n.dialogIntroAccount.replace('$1',$('<bdi>').text(conf.wgUserName)[0].outerHTML)
);
this.feedbackPanel.$element.append(
$('<p>').append(
$('<strong>').html(i18n.dialogNotice)
),
this.feedbackMessageInput.$element,
$('<p>').html(introMessage)
);
this.feedbackMessageInput.connect(this,{change:'validateFeedbackForm'});
this.feedbackMessageInput.connect(this,{change:'updateSize'});
this.$body.append(this.feedbackPanel.$element);
};
FeedbackDialog.prototype.getSetupProcess=function(data){
returnFeedbackDialog.super.prototype.getSetupProcess.call(this,data).next(()=>{
this.feedbackMessageInput.setValue();
this.validateFeedbackForm();
});
};
FeedbackDialog.prototype.getReadyProcess=function(data){
returnFeedbackDialog.super.prototype.getReadyProcess.call(this,data).next(()=>{
this.feedbackMessageInput.focus();
});
};
FeedbackDialog.prototype.validateFeedbackForm=function(){
constisValid=this.feedbackMessageInput.getValue().trim()!=='';
this.actions.setAbilities({submit:isValid});
};
FeedbackDialog.prototype.getActionProcess=function(action){
if(action==='cancel'){
returnnewOO.ui.Process(()=>{
this.close({action:action});
});
}elseif(action==='about'){
returnnewOO.ui.Process(()=>{
window.open(i18n.aboutPage,'_blank');
});
}elseif(action==='submit'){
returnnewOO.ui.Process(()=>{
constfeedback=this.feedbackMessageInput.getValue().trim();
returnthis.submitToAPI(feedback).then(()=>{
this.close();
OO.ui.alert($('<span>').html(i18n.thankText),{title:i18n.thankTitle});
}).catch((err)=>{
console.error(err);
OO.ui.alert(newOO.ui.MessageWidget({type:'error',label:i18n.error}).$element);
});
});
}
returnFeedbackDialog.super.prototype.getActionProcess.call(this,action);
};
FeedbackDialog.prototype.submitToAPI=function(feedback){
constcurrentDate=newDate();
constsectionTitle=`Feedback (${currentDate.toUTCString().replace(/GMT$/,'UTC')})`;
constgeneratedId=window.crypto.randomUUID();
consttalkPage=newmw.Title(conf.wgPageName).getTalkPage().getPrefixedDb();
// Use the MW api to add a talk page section. This will use an existing account if logged in, or create a temporary account if logged out.
returnnewmw.Api().newSection(
talkPage,
i18n.summary+' /* '+sectionTitle+' */',
`<!-- This was added automatically using a bot. Please do not remove or manually change the following template. -->\n{{Feedback\n|id=${generatedId}\n|date=${currentDate.valueOf()}\n|resolved=no\n|category=\n|feedback=${feedback}\n}} ~~~~`,
{
tags:['ArticleFeedback'],
notminor:true,
redirect:true,
sectiontitle:sectionTitle
}
).then(resp=>{
// Send a post to the weird gloop api to tell it to check recent changes and post the change to the discord channel.
return$.ajax(API_ENDPOINT,{
data:JSON.stringify({
wiki:'enmcw',
revid:resp.edit.newrevid,
uuid:generatedId,
section:sectionTitle
}),
type:'POST',
contentType:'application/json'
}).catch(console.error);
});
};
if(window.OOUIWindowManager==undefined){
window.OOUIWindowManager=newOO.ui.WindowManager();
$(OO.ui.getTeleportTarget()).append(window.OOUIWindowManager.$element);
}
constfeedbackDialog=newFeedbackDialog();
OOUIWindowManager.addWindows([feedbackDialog]);
if(conf.skin==='minerva'){
consttrigger=$('<li>',{
id:'page-actions-feedback',
'class':'page-actions-menu__list-item'
}).append(
$('<a>',{
role:'button',
tabindex:'0',
rel:'nofollow',
'class':'cdx-button cdx-button--size-large cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet'
}).append(
$('<span>',{'class':'minerva-icon minerva-icon--userTalk'}),
$('<span>').text(isAnonymous?i18n.minervaButtonLong:i18n.minervaButtonShort)
).click(function(){
OOUIWindowManager.openWindow(feedbackDialog);
})
);
if(isAnonymous){
$('#page-actions-watch').replaceWith(trigger);
}else{
$('a',trigger).addClass('cdx-button--icon-only');
$('#page-actions-watch').before(trigger);
}
}else{
consttrigger=newOO.ui.ButtonWidget({
label:i18n.vectorButtonLabel,
title:i18n.vectorButtonTitle,
icon:'feedback',
framed:false,
flags:'progressive',
classes:['wgl-feedback-button']
});
trigger.on('click',function(){
OOUIWindowManager.openWindow(feedbackDialog);
});
$('#firstHeading').append(
$('<div>').addClass('wgl-feedback-container').append(trigger.$element)
);
}
});
// </nowiki>
Retrieved from "https://minecraft.wiki/w/MediaWiki:Gadget-articlefeedback-core.js?oldid=3651898"

Navigation menu