ব্যবহারকারী:Md.Farhan Mahmud/undo.js
লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।
- ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
- গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
- ইন্টারনেট এক্সপ্লোরার / এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন
- অপেরা: Ctrl-F5 টিপুন।
//সতর্কতা: মোবাইলআনডু সরঞ্জামের মাধ্যমে সকল সম্পাদনা ব্যবহারকারী নিজ দায়িত্বে করছেন বলে ধরে দেয়া হবে। এই সরঞ্জামটি ব্যবহার করার জন্য অবশ্যই আপনার উইকিপিডিয়ার নীতিমালা ও নির্দেশাবলী সম্পর্কে ধারনা থাকতে হবে এবং আপনার কার্যক্রম এই সকল নীতিমালার পরিপন্থি হলে আপনাকে বাধা দেয়া হতে পারে।
// mobileUndo 2.0.3, a script allowing reversion of edits on mobile.
// All code is released under the default Wikipedia content license.
// Installation instructions at [[User:Md.Farhan Mahmud/undo]].
// <doc> This script basically connects an API endpoint to
// a mw-ui-destructive button which is added to the
// footer by using jQuery. Additional functionality
// includes changing the position of the thanks button
// and the addition of a confirm dialog to the thank button,
// to prevent mis-clicks due to both buttons being close
// to each other.
// </doc>
// fork of [[:w:User:FR30799386/undo]].
//combination of two scripts that can undo & restore edits on mobile device
//<nowiki>
console.time('mobileUndo');
$.when(mw.loader.using(['mediawiki.util', 'mediawiki.api', 'oojs-ui-windows', 'oojs-ui-core', 'oojs-ui.styles.icons-editing-core'])).then(function() {
return new mw.Api().getMessages(['editundo', 'Undo-nochange']);
}).then(function(globalmessages) {
var mobileUndo, i18n_lang = mw.config.get('wgUserLanguage');
var i18n = {
"en": {
"mu-success": "Successful",
"mu-fail": "Failed",
"mu-loading": "Loading...",
"editsummary-ad": " ([[w:bn:User:Md.Farhan Mahmud/undo|Undo]]) ",
"mu-undo-successful": "Revert successful.... Reloading in a sec",
"mu-empty-reponse-from-server": "An empty response was received from the server",
"mu-edit-summary-prompt": "Add a reason to your edit summary !",
"mu-edit-summary-prompt-placeholder": "Reason...",
"mu-thank-success": "Thanked",
"mu-thank-confirm": "Send public thanks ?",
"mu-thank-loading": "Thanking...",
"mu-thank-successful": "You thanked $1.",
"mu-thank-failed": "Failed to thank $1.",
"mu-http-error":"HTTP error: "
},
"bn": {
"mu-success": "সফল",
"mu-fail": "ব্যর্থ হয়েছে",
"mu-loading": "লোড করা হচ্ছে...",
"editsummary-ad": " ([[w:bn:ব্যবহারকারী:Md.Farhan Mahmud/undo|মোবাইল আনডু সরঞ্জাম]])",
"mu-undo-successful": " মোবাইল আনডুর মাধ্যমে এই সম্পাদনা করা সফল হয়েছে....... কিছুক্ষণ অপেক্ষা করুন...... পুনঃলোড করা হচ্ছে",
"mu-empty-reponse-from-server": "সার্ভার সাড়া দেয়নি।",
"mu-edit-summary-prompt": " মোবাইল আনডু সরঞ্জামের মাধ্যমে এই সম্পাদনা করার কারণ লিখুন এবং নীতিমালা বিরোধী কাজে ব্যবহার করা থেকে বিরত থাকুন!" ,
"mu-edit-summary-prompt-placeholder": "কারণ লিখুন...",
"mu-thank-success": "ধন্যবাদ জানিয়েছেন",
"mu-thank-confirm": "প্রকাশ্যে ধন্যবাদ জানাবেন?",
"mu-thank-loading": "ধন্যবাদ জানানো হচ্ছে...",
"mu-thank-successful": "আপনি $1 কে ধন্যবাদ জানিয়েছেন।",
"mu-thank-failed": "$1 কে ধন্যবাদ জানানো ব্যর্থ হয়েছে।",
"mu-http-error":"HTTP ত্রুটি: "
}
};
if(undefined === i18n[i18n_lang]){
i18n_lang = 'en';
}
if (mw.config.get('wgCanonicalSpecialPageName') === 'MobileDiff') {
mw.util.addCSS('#mw-mf-userinfo .mobileUndo-ui .mw-ui-icon.mw-ui-icon-before:before{display:none;}\n#mobileUndo > a > span.oo-ui-iconElement-icon.oo-ui-icon-editUndo.oo-ui-image-invert{display:inline-block; position:initial;}\n#mobileUndo > a{padding:0.57142857em 0.9375em;}'+
'#mw-mf-userinfo > div > div.mobileUndo-ui > a > div{line-height:normal;}');
if (mw.config.get('wgVisualEditor').pageLanguageDir === 'ltr') {
$('#mw-mf-userinfo .post-content').append($('<div>').attr('class', 'mobileUndo-ui').css({
'display': 'inline-block',
'float': 'right'
}));
} else {
$('#mw-mf-userinfo .post-content').append($('<div>').attr('class', 'mobileUndo-ui').css({
'display': 'inline-block',
'float': 'left'
}));
}
$('.mobileUndo-ui').append($('.mw-mf-action-button').remove().css({
'clear': 'none'
}));
if (!$('.warningbox').length && mw.config.get('wgRelevantPageIsProbablyEditable')) {
mobileUndo = new OO.ui.ButtonWidget({
label: (globalmessages.editundo).charAt(0).toUpperCase() + (globalmessages.editundo).slice(1),
icon: 'editUndo',
title: 'mobileUndo',
flags: ['destructive', 'primary'],
id: 'mobileUndo'
});
$('.mobileUndo-ui').append(mobileUndo.$element);
if (mw.config.get('wgVisualEditor').pageLanguageDir === 'ltr') {
$('#mobileUndo').css('margin-right', '0.3em');
} else {
$('#mobileUndo').css('margin-left', '0.3em');
}
}
window.wgRelevantUser = function() {
var user;
if ($('.mw-mf-user-link').text() !== '') {
user = $('.mw-mf-user-link').text();
} else {
user = $('#mw-mf-userinfo .post-content div:nth-child(2)').text();
}
return user;
};
window.wgRevId = ($('#mw-mf-diffarea > div.mw-mf-diff-info > h3 > a').attr('href')).split('&oldid=')[1];
var revId = wgRevId;
console.log(revId);
var username = wgRelevantUser();
$('#mw-mf-userinfo .post-content .mobileUndo-ui .mw-mf-action-button').click(function(e) {
e.preventDefault();
OO.ui.confirm(i18n[i18n_lang]['mu-thank-confirm']).done(function(confirmed) {
if (confirmed) {
$('.mw-mf-action-button').css('pointer-events', 'none').text(i18n[i18n_lang]['mu-thank-loading']);
var api = new mw.Api();
api.postWithToken('csrf', {
action: "thank",
rev: revId,
}).done(function(result) {
mw.notify((i18n[i18n_lang]['mu-thank-successful']).replace(/\$1/g, username));
$('.mw-mf-action-button').text(i18n[i18n_lang]['mu-thank-success']);
}).fail(function() {
mw.notify((i18n[i18n_lang]['mu-thank-failed']).replace(/\$1/g, username));
$('.mw-mf-action-button').text(i18n[i18n_lang]['mu-failed']);
});
}
});
});
console.timeEnd('mobileUndo');
mobileUndo.on('click', function() {
OO.ui.prompt(i18n[i18n_lang]['mu-edit-summary-prompt'], {
textInput: {
placeholder: i18n[i18n_lang]['mu-edit-summary-prompt-placeholder']
}
}).done(function(customEditSummary) {
$.when(mw.loader.using('mediawiki.api')).then(function() {
return new mw.Api().getMessages(['undo-summary'], {
amlang: mw.config.get('wgServerName').split('.wik')[0]
});
}).then(function(message) {
var editSummaryMessage = message['undo-summary'];
var editSummary = editSummaryMessage.replace(/\$1/g, revId);
editSummary = editSummary.replace(/\$2/g, username);
if (customEditSummary !== null) {
mobileUndo.setDisabled(true);
editSummary = editSummary + ' –' + customEditSummary + (i18n[i18n_lang]['editsummary-ad']);
//call the API
var api = new mw.Api({
ajax: {
headers: {
'Api-User-Agent': 'mobileUndo/2.0.2(https://en.wikipedia.org/wiki/User:FR30799386/undo.js)'
}
}
});
//Feedback UI
mobileUndo.setLabel(i18n[i18n_lang]['mu-loading']);
api.postWithToken('csrf', {
action: "edit",
title: mw.config.get('wgRelevantPageName'),
summary: editSummary,
undo: revId,
}).done(function(result) {
if (result.edit.code === 'abusefilter-warning' || result.edit.code === 'abusefilter-disallowed') {
mobileUndo.setLabel(i18n[i18n_lang]['mu-fail']);
OO.ui.alert($('<p>').html(result.edit.warning), {
title: result.edit.info
}).done(function() {});
return;
} else if (typeof result.edit.nochange !== 'undefined') {
mobileUndo.setLabel(i18n[i18n_lang]['mu-fail']);
OO.ui.alert($('<p>').html(globalmessages['Undo-nochange'])).done(function() {});
return;
}
console.log(result);
mobileUndo.setLabel(i18n[i18n_lang]['mu-success']);
mw.notify(i18n[i18n_lang]['mu-undo-successful']);
setTimeout(function() {
location.href = mw.util.getUrl('Special:MobileDiff/' + result.edit.newrevid);
}, 1500);
}).fail(function(code, jqxhr) {
mobileUndo.setLabel(i18n[i18n_lang]['mu-fail']);
var details;
if (code === 'http' && jqxhr.textStatus === 'error') {
details = i18n[i18n_lang]['mu-http-error'] + jqxhr.xhr.status;
} else if (code === 'http') {
details = i18n[i18n_lang]['mu-http-error'] + jqxhr.textStatus;
} else if (code === 'ok-but-empty') {
details = i18n[i18n_lang]['mu-empty response-from-server'];
} else {
details = jqxhr.error.info;
}
OO.ui.alert($('<p>').html(details)).done(function() {});
});
}
});
});
});
}
});
//End of code
//</nowiki>
///restore///
mw.loader.using('mediawiki.util', function () {
var mobile_revert = function($){
var currentpage = '/wiki/' + mw.config.get( 'wgPageName' ) ;
var revert = '/w/index.php?title=' + mw.config.get( 'wgRelevantPageName' ) + '&action=edit&undoafter=' + mw.config.get('wgRevisionId') + '&undo=' + mw.config.get('wgCurRevisionId') ;
$("#mw-revision-nav").after("<div><a href=" + currentpage + " data-title='currentpage'>View the latest version</a> - <a href=" + revert + " data-title='revert'>Restore this version</a></div>") ;
} ;
$(document).ready(mobile_revert) ;
});
// [[বিষয়শ্রেণী:উইকিপিডিয়া স্ক্রিপ্ট]]