ব্যবহারকারী:ShahadatHossain/Notifier.js
লক্ষ্য করুন: প্রকাশ করার পর, পরিবর্তনগুলো দেখতে আপনাকে আপনার ব্রাউজারের ক্যাশে পরিষ্কার করার প্রয়োজন হতে পারে।
- ফায়ারফক্স / সাফারি: পুনরায় লোড-এ ক্লিক করার সময় শিফট টিপে ধরে রাখুন, অথবা হয় Ctrl-F5 বা Ctrl-R টিপুন (ম্যাকে ⌘-R টিপুন)
- গুগল ক্রোম: Ctrl-Shift-R (ম্যাকে ⌘-Shift-R) টিপুন
- এজ: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 টিপুন।
- অপেরা: Ctrl-F5 টিপুন।
// Notifier (beta)
// Notifies other talk pages of a discussion on the current page
// Please provide feedback at [[User talk:ShahadatHossain]]
$(function () {
var api, log, pageName, texts, windowManager
var dialogReady = false
function init () {
mw.loader.using('mediawiki.util', function () {
pageName = mw.config.get('wgPageName').replace(/_/g, ' ')
if (pageName === 'Wikipedia:Reliable sources/Noticeboard' && $('body.skin-vector').length) {
markHeadings()
} else {
var markLink = mw.util.addPortletLink('p-cactions', '#', 'বিজ্ঞপ্তি ব্যবস্থাপক', 'ca-notifier',
'এই পাতার আলোচনায় অন্যান্য আলাপের পাতাগুলো অবহিত করুন')
$(markLink).click(function (event) {
event.preventDefault()
markHeadings()
})
}
})
}
function initDialog () {
OO.inheritClass(Dialog, OO.ui.ProcessDialog)
Dialog.static.name = 'notifierDialog'
Dialog.static.title = 'বিজ্ঞপ্তি ব্যবস্থাপক'
Dialog.static.actions = [
{
action: 'notify',
label: 'বিজ্ঞপ্তি পাঠান',
flags: ['primary', 'progressive']
}, {
label: 'বাতিল',
flags: 'safe'
}
]
Dialog.prototype.initialize = function () {
Dialog.super.prototype.initialize.call(this)
this.$notifyingLabel = $('<div>আলোচনার বিজ্ঞপ্তি:</div>')
this.$discussionName = $('<div style="font-weight: bold" />')
this.$info = $('<p />')
this.$info.append(this.$notifyingLabel, this.$discussionName)
this.targetPages = new OO.ui.MultilineTextInputWidget({rows: 5})
this.targetPagesField = new OO.ui.FieldLayout(this.targetPages, {
label: 'যে পাতায় বার্তা রাখবেন',
align: 'top',
help: 'প্রতি লাইনে একটি পাতা',
helpInline: true
})
this.messageTitle = new OO.ui.TextInputWidget({})
this.messageTitleField = new OO.ui.FieldLayout(this.messageTitle, {
label: 'বার্তার শিরোনাম',
align: 'top'
})
this.message = new OO.ui.MultilineTextInputWidget({rows: 5})
this.messageField = new OO.ui.FieldLayout(this.message, {
label: 'বার্তা',
align: 'top',
help: 'স্বাক্ষর প্রয়োজন নেই',
helpInline: true
})
this.log = new OO.ui.MultilineTextInputWidget({
readOnly: true,
rows: 5,
value: log
})
this.logField = new OO.ui.FieldLayout(this.log, {
label: 'লগ',
align: 'top'
})
this.notificationTemplate = new OO.ui.TextInputWidget({readOnly: true})
this.notificationTemplateField = new OO.ui.FieldLayout(this.notificationTemplate, {
label: 'বিজ্ঞপ্তি টেমপ্লেট',
align: 'top',
help: 'প্রয়োজনীয় হলে বিজ্ঞপ্তি দেওয়ার পরে, মূল আলোচনার শেষে এই টেমপ্লেটটি যোগ করতে পারেন',
helpInline: true
})
this.panel = new OO.ui.PanelLayout({
padded: true,
expanded: false
})
this.panel.$element.append(this.$info, this.targetPagesField.$element, this.messageTitleField.$element,
this.messageField.$element, this.logField.$element, this.notificationTemplateField.$element)
this.$body.append(this.panel.$element)
}
Dialog.prototype.getSetupProcess = function (data) {
data = data || {}
return Dialog.super.prototype.getSetupProcess.call(this, data)
.next(function () {
this.$discussionName.text(pageName + ' § ' + texts[data.id])
this.message.setValue('{{slink|' + pageName + '|' + texts[data.id] + '}} <!-- এখানে বিস্তারিত লিখুন -->')
}, this)
}
Dialog.prototype.getActionProcess = function (action) {
if (action === 'notify') {
sendMessages(this)
}
return Dialog.super.prototype.getActionProcess.call(this, action)
}
Dialog.prototype.getBodyHeight = function () {
return this.panel.$element.outerHeight(true)
}
windowManager = new OO.ui.WindowManager()
$(document.body).append(windowManager.$element)
dialogReady = true
}
function Dialog (config) {
Dialog.super.call(this, config)
}
function markHeadings () {
texts = {}
var $headings = $('#mw-content-text h2:not(.toctitle h2)')
$headings.each(function (index) {
var $headline = $(this).children('.mw-headline')
var id = $headline.attr('id')
var text = $headline.contents().not($headline.children('.mw-headline-number')).text().trim()
createLink($(this), id, text)
texts[id] = text
})
}
function createLink ($heading, id, text) {
var $link = $('<a href="#">বিজ্ঞপ্তি</a>')
var $leftBracket = $('<span class="mw-editsection-bracket">[</span>')
var $rightBracket = $('<span class="mw-editsection-bracket">]</span>')
var $editSection = $('<span class="mw-editsection" />')
$link.click(function (event) {
event.preventDefault()
promptNotify(id)
})
$editSection.append($leftBracket, $link, $rightBracket)
$heading.append($editSection)
return $link
}
function promptNotify (id) {
mw.loader.using(['oojs', 'oojs-ui'], function () {
if (!dialogReady) {
initDialog()
}
log = 'বিজ্ঞপ্তি প্রদানে প্রস্তুত'
var dialog = new Dialog()
windowManager.addWindows([dialog])
windowManager.openWindow(dialog, {id: id})
})
}
function sendMessages (dialog) {
api = api || new mw.Api()
var targetPages = dialog.targetPages.getValue().trim().split('\n').map(function (targetPage) {
return targetPage.trim()
})
var messageTitle = dialog.messageTitle.getValue().trim()
var message = dialog.message.getValue().trim()
if (message.slice(-4) !== '~~' + '~~') {
message += ' ~~' + '~~'
}
var notificationTemplate = '{{subst' + ':notified|' + targetPages.join('|') + '}}'
dialog.notificationTemplate.setValue(notificationTemplate)
var tasks = []
$.each(targetPages, function(index, targetPage) {
addLog(dialog, 'বিজ্ঞপ্তি প্রদান করা হচ্ছে: ' + targetPage)
var task = api.newSection(targetPage, messageTitle, message, { redirect: true })
.then(function () {
addLog(dialog, 'সফলভাবে বিজ্ঞপ্তি পাঠানো হয়েছে: ' + targetPage)
}, function(error) {
addLog(dialog, 'বিজ্ঞপ্তি পাঠাতে ব্যর্থ হয়েছে: ' + targetPage)
addLog(dialog, 'ত্রুটি: ' + error)
})
tasks.push(task)
})
$.when.apply(null, tasks).then(function () {
addLog(dialog, 'সম্পূর্ণ হয়েছে!')
})
}
function addLog (dialog, message) {
log += '\n' + message
dialog.log.setValue(log)
}
init()
})