Discussion MediaWiki:Gadget-Adiutor-INF.js
Dernier commentaire : il y a 1 an par Doğu dans le sujet Please update this module
Please update this module
modifierThe module currently displays "Créé par undefined" because it uses response.author and response.author_editcount. The XTools API returns these fields as `creator` and creator_editcount.
Please update the code to replace:
/*
* Adiutor: Adiutor is a gadget that gives Wikipedia's a quick way of performing common maintenance tasks, such as nominating pages for deletion and cleaning up vandalism.
* Author: Doğu
* Learn more at: https://meta.wikimedia.org/wiki/Adiutor
* Licensing and Attribution: Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
* Module: Article Info
*/
/* <nowiki> */
var mwConfig = mw.config.get(["wgArticleId", "wgPageName"]);
var api = new mw.Api();
var adiutorUserOptions = JSON.parse(mw.user.options.get('userjs-adiutor-frwiki'));
var newArticleToWorkOnIt = {
"id": mwConfig.wgArticleId,
"name": mwConfig.wgPageName
};
var apiUrl = "https://xtools.wmcloud.org/api/page/articleinfo/fr.wikipedia.org/" + encodeURIComponent(mwConfig.wgPageName) + "?format=json";
$.ajax({
url: apiUrl,
method: "GET",
dataType: "json",
success: function(response) {
var isAlreadyAdded = adiutorUserOptions.myWorks.some(function(article) {
return article.id === newArticleToWorkOnIt.id;
});
var creatorEditcount = response.creator_editcount || 0;
var addButtonInfo = {
icon: isAlreadyAdded ? 'unFlag' : 'flag',
label: isAlreadyAdded ? mw.msg('unpin-from-works') : mw.msg('pin-to-works')
};
var infoButton = new OO.ui.ButtonWidget({
icon: 'info'
});
var AboutArticleActionButtons = new OO.ui.ButtonGroupWidget({
items: [
new OO.ui.ButtonWidget(Object.assign({}, addButtonInfo)),
infoButton
],
classes: ['adiutor-aricle-detail-box-button-group']
});
infoButton.on('click', function() {
api.get({
action: 'query',
prop: 'revisions',
titles: mw.config.get('wgPageName'),
rvprop: 'user|content|timestamp',
rvlimit: 1,
formatversion: 2
}).then(function(data) {
var revision = data.query.pages[0].revisions[0];
var text = revision.content;
text = text.replace(/{{[^}]+}}/g, '');
text = text.replace(/\[\[Catégorie:[^\]]+\]\]/g, '');
text = text.replace(/==[ ]*Notes et références[ ]*==[\s\S]*/g, '');
text = text.replace(/==[ ]*Liens externes[ ]*==[\s\S]*/g, '');
text = text.replace(/^\*.*$/gm, '');
text = text.replace(/{\|[^}]+}\|/g, '');
var words = text.match(/\b\w+\b/g);
var wordCount = words ? words.length : 0;
function ArticleInfoDialog(config) {
ArticleInfoDialog.super.call(this, config);
}
OO.inheritClass(ArticleInfoDialog, OO.ui.ProcessDialog);
ArticleInfoDialog.static.title = mw.config.get('wgPageName').replace(/_/g, " ");
ArticleInfoDialog.static.name = 'ArticleInfoDialog';
ArticleInfoDialog.static.actions = [{
action: 'policy',
modes: 'edit',
label: mw.msg('more-about-this-page'),
framed: false
}, {
modes: 'edit',
label: new OO.ui.deferMsg('cancel'),
flags: ['safe', 'close']
}, {
action: 'back',
modes: 'help',
label: new OO.ui.deferMsg('back'),
flags: ['safe', 'back']
}];
ArticleInfoDialog.prototype.initialize = function() {
ArticleInfoDialog.super.prototype.initialize.apply(this, arguments);
var authorMessage = mw.msg('page-more-info-tip-author');
var authorMessageWithStrong = authorMessage.replace(/\$1/g, '<strong><a href="https://fr.m.vvikipidea.org/wiki/Utilisateur:' + response.creator + '">' + response.creator + '</a></strong>');
var articleCreator = new OO.ui.MessageWidget({
type: 'warning',
icon: 'infoFilled',
inline: false,
label: new OO.ui.HtmlSnippet(mw.msg('page-more-info-tip-author-title') + '<br>' + authorMessageWithStrong),
classes: ['adiutor-page-more-info-tip-author']
});
var articleDate = new OO.ui.MessageWidget({
type: 'notice',
icon: 'edit',
inline: false,
label: new OO.ui.HtmlSnippet(mw.msg('page-more-info-tip-date-title') + '<br>' + mw.msg('page-more-info-tip-date', response.created_at)),
classes: ['adiutor-page-more-info-tip-date']
});
var wordCountLabel = new OO.ui.MessageWidget({
type: 'notice',
icon: 'article',
inline: false,
label: new OO.ui.HtmlSnippet(mw.msg('page-more-info-tip-keyword-title') + '<br>' + mw.msg('page-more-info-tip-keyword', wordCount)),
classes: ['adiutor-page-more-info-tip-keyword']
});
this.$body.append(articleCreator.$element, articleDate.$element, wordCountLabel.$element);
};
ArticleInfoDialog.prototype.getSetupProcess = function(data) {
return ArticleInfoDialog.super.prototype.getSetupProcess.call(this, data).next(function() {
this.actions.setMode('edit');
}, this);
};
ArticleInfoDialog.prototype.getActionProcess = function(action) {
if(action === 'policy') {
var targetURL = 'https://xtools.wmcloud.org/articleinfo/fr.wikipedia.org/' + encodeURIComponent(mwConfig.wgPageName);
window.open(targetURL, '_blank');
}
return ArticleInfoDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new ArticleInfoDialog({
size: 'medium'
});
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
});
});
var translationKey = "page-info-tip";
var translation = mw.msg(translationKey);
var translatedText = translation.replace(/\$1/g, '<strong>' + response.created_at + '</strong>').replace(/\$2/g, "<strong><a href='/wiki/Utilisateur:" + response.creator + "'>" + response.creator + "</a></strong>").replace(/\$3/g, creatorEditcount).replace(/\$4/g, response.revisions).replace(/\$5/g, response.editors).replace(/\$6/g, '<strong>' + response.pageviews + '</strong>').replace(/\$7/g, response.pageviews_offset);
var AboutArticleContent = $('<div>').html(translatedText).append(AboutArticleActionButtons.$element);
var AboutArticle = new OO.ui.MessageWidget({
type: 'notice',
icon: 'article',
showClose: true,
label: new OO.ui.HtmlSnippet(AboutArticleContent),
classes: ['adiutor-aricle-detail-box']
});
AboutArticleActionButtons.items[0].on('click', function() {
if(isAlreadyAdded) {
var indexToRemove = adiutorUserOptions.myWorks.findIndex(function(article) {
return article.id === newArticleToWorkOnIt.id;
});
adiutorUserOptions.myWorks.splice(indexToRemove, 1);
} else {
adiutorUserOptions.myWorks.push(newArticleToWorkOnIt);
}
var addButtonInfo = {
icon: isAlreadyAdded ? 'flag' : 'unFlag',
label: isAlreadyAdded ? mw.msg('pin-to-works') : mw.msg('unpin-from-works')
};
isAlreadyAdded = !isAlreadyAdded;
AboutArticleActionButtons.items[0].setIcon(addButtonInfo.icon);
AboutArticleActionButtons.items[0].setLabel(addButtonInfo.label);
updateOptions(adiutorUserOptions);
});
$('.vector-body-before-content').prepend(AboutArticle.$element);
},
error: function(xhr, status, error) {
console.error("AJAX error:", error);
}
});
function updateOptions(updatedOptions) {
api.postWithEditToken({
action: 'globalpreferences',
format: 'json',
optionname: 'userjs-adiutor-frwiki',
optionvalue: JSON.stringify(updatedOptions),
formatversion: 2,
}).done(function() {});
}
/* </nowiki> */
Doğu (discuter) 27 août 2025 à 10:33 (CEST)
- please before pasting code, format it via this tool.Doğu (discuter) 27 août 2025 à 23:01 (CEST)
- @Aelxen, could you please update again, I made a mistake. Doğu (discuter) 27 août 2025 à 23:02 (CEST)