ميدياويكي:Comments.js
ملاحظة: بعد النشر، أنت قد تحتاج إلى إفراغ الكاش الخاص بمتصفحك لرؤية التغييرات.
- فايرفوكس / سافاري: أمسك Shift أثناء ضغط Reload، أو اضغط على إما Ctrl-F5 أو Ctrl-R (⌘-R على ماك)
- جوجل كروم: اضغط Ctrl-Shift-R (⌘-Shift-R على ماك)
- إنترنت إكسبلورر/إيدج: أمسك Ctrl أثناء ضغط Refresh، أو اضغط Ctrl-F5
- أوبرا: اضغط Ctrl-F5.
// MediaWiki interface button for Comments page based on [[commons:mediawiki:extra-tabs.js]].
// Originally written by Dbenbenn, Avatar, Duesentrieb and Arnomane
// Modified by en:Bawolff for Wikinews. Fixed by en:Darklama
// Re-written by Bawolff in May 2010.
//
// Brought to ar.wikinews from [[es:wikinews:MediaWiki:Common.js]] and adapted by Ciphers in June 2012.
jQuery( function () {
// Interface strings, if translating, change only these.
var OpinionTabName = 'تعليقات';
var TalkTabName = 'نقاش';
var ArticleTabName = 'خبر';
var OpinionTabTooltip = 'عبر عن آرائك حول الموضوع';
var OpinionNS = 102;
// Extra things to add to edit urls:
var OpinionParams = 'preload=ويكي_الأخبار:صفحات_تعليق_على_الأخبار/نص&editintro=ويكي_الأخبار:صفحات_تعليق_على_الأخبار/مقدمة';
// End stuff to translate.
// -------------------
var title = mw.config.get('wgTitle');
if (title === 'الصفحة الرئيسية') return;
var portlet = mw.config.get('skin') === 'vector' ? 'p-namespaces' : 'p-cactions';
// 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.
// This would be better if it could check multiple pages with one query.
var checkCommentaryPageExist = function (pageName, id, query) {
pageName = mw.util.wikiUrlencode( pageName );
var success = function (x) {
if ( !x || !x.query || !x.query.pages ) {
mw.log( "Error getting redlinks for opinion tab" );
return;
}
if ( x.query.pages['-1'] ) {
// Means its missing.
var url = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) +
'/index.php?action=edit&redlink=1&title=' + pageName + '&' + query;
jQuery( '#' + id + ' a' ).attr( 'href', url );
jQuery( '#' + id ).addClass( 'new' );
}
};
jQuery.ajax( {
url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php?action=query&format=json&titles=' + pageName,
success: success
});
};
switch(mw.config.get('wgNamespaceNumber')) {
case 1:
case 0:
var targetPage = mw.config.get( 'wgFormattedNamespaces' )[OpinionNS] + ':' + title;
var url = mw.util.getUrl( targetPage );
var res = mw.util.addPortletLink(
'p-namespaces',
url,
OpinionTabName,
'ca-comments',
OpinionTabTooltip
);
if ( !res ) {
// No p-namespaces portal. Must be monobook then.
var res2 = mw.util.addPortletLink(
'p-cactions',
url,
OpinionTabName,
'ca-comments',
OpinionTabTooltip,
undefined, /* accesskey */
jQuery('#ca-edit')[0] /* nextnode */
);
if ( !res2 ) {
mw.log( "Error adding opinions tab" );
}
}
checkCommentaryPageExist(targetPage, 'ca-comments', OpinionParams);
break;
case 90: /* LQT thread */
var targetPage = mw.config.get( 'wgTitle' ).replace(/\/.*$/, '');
var talkTarget = mw.config.get( 'wgFormattedNamespaces' )[1] + ':' + targetPage;
var before = document.getElementById('ca-nstab-thread');
var talk = mw.util.addPortletLink(
portlet,
mw.util.getUrl( talkTarget ),
TalkTabName,
"ca-main-talk", undefined, undefined, before
);
mw.util.addPortletLink(
portlet,
mw.util.getUrl( targetPage ),
ArticleTabName,
"ca-nstab-main",
undefined, undefined, talk
);
checkCommentaryPageExist(targetPage, 'ca-nstab-main', '');
checkCommentaryPageExist(talkTarget, 'ca-main-talk', '');
break;
case OpinionNS:
var targetPage = mw.config.get( 'wgTitle' );
var talkTarget = mw.config.get( 'wgFormattedNamespaces' )[1] + ':' + targetPage;
var before = document.getElementById('ca-nstab-' +
mw.config.get( 'wgFormattedNamespaces' )[OpinionNS].toLowerCase() );
var talk = mw.util.addPortletLink(
portlet,
mw.util.getUrl( talkTarget ),
TalkTabName,
"ca-main-talk", undefined, undefined, before
);
mw.util.addPortletLink(
portlet,
mw.util.getUrl( targetPage ),
ArticleTabName,
"ca-nstab-main",
undefined, undefined, talk
);
checkCommentaryPageExist(targetPage, 'ca-nstab-main', '');
checkCommentaryPageExist(talkTarget, 'ca-main-talk', '');
break;
/* do stuff */
}
});