مدیاویکی:Comments.js
نکته: پس از انتشار ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.
- فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلیدهای Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-R)
- گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانههای اپل مکینتاش کلیدهای ⌘-Shift-R)
- اینترنت اکسپلورر/ Edge: کلید Ctrl را نگهدارید و روی دکمهٔ Refresh کلیک کنید، یا کلیدهای Ctrl-F5 را با هم فشار دهید
- اپرا: Ctrl-F5 را بفشارید.
// This script has some crappy hacks in it
// ==========================================================================
// افزودن گزینهای جدید برای سرصفحه رابط کاربری
// Originally written by Dbenbenn, Avatar, Duesentrieb and Arnomane
// Modified by bawolff for wikinews.en . fixed by darklama.en and sahim for wikinews.fa
var _hasAttribute = function(elm, attribute) {
//IE does not element hasAttribute method of XML Dom elements
try {
return elm.hasAttribute(attribute);
}
catch(e) {
return elm.getAttribute(attribute) !== null;
}
}
// Interface strings,
tab_view_comment_on_article = 'نظرها';
// Switch for people that don't want the extra tabs.
// var load_extratabs = false;
// Appends a new tab.
function global_append_tab(action, name, where, id, title)
{
var tools = document.getElementById(where ? where : 'column-one');
if (!where && tools)
tools = tools.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
if (!tools)
return;
var na = document.createElement('a').appendChild(document.createTextNode(name)).parentNode;
if (typeof action == "string")
na.setAttribute('href', action);
else if (typeof action == "function")
na.onclick = action;
else
return;
var li = document.createElement('li').appendChild(na).parentNode;
if (id) li.id = id;
if (title) li.setAttribute("title", title);
if (typeof id == "string") li.id = id;
if (where)
tools.parentNode.insertBefore(li, tools.nextSibling);
else
tools.appendChild(li);
}
function global_do_onload()
{
if (window.load_extratabs && load_extratabs == false)
return;
var title = mw.config.get('wgPageName');
switch( mw.config.get('wgNamespaceNumber'))
{
case 1:
title = title.replace(/^[^:]*:/, "");
case 0:
if (title === 'صفحهٔ_اصلی')
return;
title = encodeURIComponent(title).replace(/%2F/g, "/");
if (skin == "vector") {
//crappy temp hack. probably will break
mw.util.addPortletLink('p-namespaces', mw.config.get('wgArticlePath').replace("$1", "نظرها:" + title), tab_view_comment_on_article, 'ca-comments', 'نظردهی در مورد این خبر', null, document.getElementById('ca-talk'));
} else {
global_append_tab( mw.config.get('wgArticlePath').replace("$1", "نظرها:" + title), tab_view_comment_on_article, 'ca-talk', 'ca-comments');
}
try {
checkCommentaryPageExist("نظرها:" + title);
}
catch (e) {
//In case Same orgin policy issue, problem with initiling, etc AJAX seems to have a lot of things that could go wrong
//Ignore error: Is it really that bad if its the wrong colour?
}
break;
}
}
// Run a background check of api.php to see if the particular page exists,
// so a non-existing comment page can be red, and an existing comment page
// will look like a normal tab.
function checkCommentaryPageExist(pageName) {
var x;
x = sajax_init_object();
// do nothing if we can't check
if (!x) {
return;
}
x.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&format=xml&titles=" + pageName, true);
x.setRequestHeader("Pragma", "cache=yes");
x.setRequestHeader("Cache-Control", "no-transform");
x.onreadystatechange = function() {
if (x.readyState == 4) {
if (x.status == 200) {
var xmldoc = x.responseXML;
var xpage = xmldoc.getElementsByTagName('page');
if (_hasAttribute(xpage[0], 'missing')) { // is missing
document.getElementById('ca-comments').className = 'new';
document.getElementById('ca-comments').firstChild.setAttribute('href',
mw.config.get('wgServer')+ mw.config.get('wgScript')+ "?title=" + pageName + '&action=edit&preload=ویکیخبر:صفحههای تفسیر در مورد رویدادهای خبری/بدنه اصلی');
}
}
}
};
x.send(null);
}
$( global_do_onload );
$(document).ready(function() {
if(mw.config.get('wgNamespaceNumber') == 102)
{
var regex = new RegExp("[\\?&]section=([^&#]*)");
var results = regex.exec(location.search);
var section = results === null ? "new" : results[1].replace(/\+/g, " ")
var tab = $('<li/>').attr('id','ca-addsection').append(
$('<span/>').append(
$('<a/>').attr('title','نظر خود را اضافه کنید [Alt+Shift++]')
.attr('accesskey','+')
.text('افزودن نظر')
.attr('href',mw.config.get('wgScript')+'?title='+encodeURI(mw.config.get('wgPageName'))+'&action=edit§ion='+section)
)
);
if(mw.config.get('wgAction') == 'edit')
{
if(results!==null)
{
tab.attr('class','selected');
$('#ca-edit').attr('class','');
}
}
tab.insertAfter($('#ca-edit'));
}
});